[cairo-commit] 3 commits - src/cairo-pdf-surface.c src/cairo-type1-subset.c

Adrian Johnson ajohnson at kemper.freedesktop.org
Sun Nov 8 03:29:02 PST 2009


 src/cairo-pdf-surface.c  |    8 ++++----
 src/cairo-type1-subset.c |   30 ++++++++++++++++++++++--------
 2 files changed, 26 insertions(+), 12 deletions(-)

New commits:
commit cee3a6169bdf7f64c126c487b443dcb7a9f0586a
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Sun Nov 8 21:52:06 2009 +1030

    Type1-subset: Append "cleartomark" operator for binary fonts that don't include it
    
    Type 1 fonts embedded in PDF may omit the fixed-content portion of the
    font that contains the "cleartomark" operator.

diff --git a/src/cairo-type1-subset.c b/src/cairo-type1-subset.c
index 4cc72c4..304353a 100644
--- a/src/cairo-type1-subset.c
+++ b/src/cairo-type1-subset.c
@@ -1128,19 +1128,27 @@ cairo_type1_font_subset_write_trailer(cairo_type1_font_subset_t *font)
     static const char zeros[65] =
 	"0000000000000000000000000000000000000000000000000000000000000000\n";
 
-    /* Some fonts have conditional save/restore around the entire font
-     * dict, so we need to retain whatever postscript code that may
-     * come after 'cleartomark'. */
 
     for (i = 0; i < 8; i++)
 	_cairo_output_stream_write (font->output, zeros, sizeof zeros);
 
     cleartomark_token = find_token (font->type1_data, font->type1_end, "cleartomark");
-    if (cleartomark_token == NULL)
+    if (cleartomark_token) {
+	/* Some fonts have conditional save/restore around the entire
+	 * font dict, so we need to retain whatever postscript code
+	 * that may come after 'cleartomark'. */
+
+	_cairo_output_stream_write (font->output, cleartomark_token,
+				    font->type1_end - cleartomark_token);
+    } else if (!font->eexec_segment_is_ascii) {
+	/* Fonts embedded in PDF may omit the fixed-content portion
+	 * that includes the 'cleartomark' operator. Type 1 in PDF is
+	 * always binary. */
+
+	_cairo_output_stream_printf (font->output, "cleartomark");
+    } else {
 	return CAIRO_INT_STATUS_UNSUPPORTED;
-
-    _cairo_output_stream_write (font->output, cleartomark_token,
-				font->type1_end - cleartomark_token);
+    }
 
     /* some fonts do not have a newline at the end of the last line */
     _cairo_output_stream_printf (font->output, "\n");
commit d962d6bae2681ea1f3c9533a83c8902d76e81c6a
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Sun Nov 8 21:46:16 2009 +1030

    PDF: Include Type 1 fixed-content portion in the embedded font
    
    Some fonts may contain additional PostScript code after the
    cleartomark.

diff --git a/src/cairo-pdf-surface.c b/src/cairo-pdf-surface.c
index cdf3874..62178dc 100644
--- a/src/cairo-pdf-surface.c
+++ b/src/cairo-pdf-surface.c
@@ -3997,16 +3997,16 @@ _cairo_pdf_surface_emit_type1_font (cairo_pdf_surface_t		*surface,
     if (subset_resource.id == 0)
 	return CAIRO_STATUS_SUCCESS;
 
-    /* We ignore the zero-trailer and set Length3 to 0. */
-    length = subset->header_length + subset->data_length;
+    length = subset->header_length + subset->data_length + subset->trailer_length;
     status = _cairo_pdf_surface_open_stream (surface,
 					     NULL,
 					     TRUE,
 					     "   /Length1 %lu\n"
 					     "   /Length2 %lu\n"
-					     "   /Length3 0\n",
+					     "   /Length3 %lu\n",
 					     subset->header_length,
-					     subset->data_length);
+					     subset->data_length,
+					     subset->trailer_length);
     if (unlikely (status))
 	return status;
 
commit ac59c7580894fc5fd424f7f6f8c1532d15048566
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Sun Nov 8 21:38:58 2009 +1030

    Type1-subset: Check for binary eexec data
    
    Type 1 fonts embedded in PDF have the the encrypted portion in binary
    but the existing check for binary only works for Type 1 fonts in PFB
    format.
    
    Add an additional check based on the first 4 characters of eexec data.
    The Type 1 specification gurantees that at least one of the first 4
    bytes of ciphertext is not an ASCII Hex character.

diff --git a/src/cairo-type1-subset.c b/src/cairo-type1-subset.c
index b9e86c3..4cc72c4 100644
--- a/src/cairo-type1-subset.c
+++ b/src/cairo-type1-subset.c
@@ -58,6 +58,8 @@
 #include FT_OUTLINE_H
 #include FT_TYPE1_TABLES_H
 
+#include <ctype.h>
+
 typedef struct _cairo_type1_font_subset {
     cairo_scaled_font_subset_t *scaled_font_subset;
 
@@ -233,7 +235,7 @@ cairo_type1_font_subset_find_segments (cairo_type1_font_subset_t *font)
 {
     unsigned char *p;
     const char *eexec_token;
-    int size;
+    int size, i;
 
     p = (unsigned char *) font->type1_data;
     font->type1_end = font->type1_data + font->type1_length;
@@ -264,6 +266,10 @@ cairo_type1_font_subset_find_segments (cairo_type1_font_subset_t *font)
 	font->eexec_segment_size = font->type1_length - font->header_segment_size;
 	font->eexec_segment = (char *) p + font->header_segment_size;
 	font->eexec_segment_is_ascii = TRUE;
+	for (i = 0; i < 4; i++) {
+	    if (!isxdigit(font->eexec_segment[i]))
+		font->eexec_segment_is_ascii = FALSE;
+	}
     }
 
     return CAIRO_STATUS_SUCCESS;


More information about the cairo-commit mailing list