[cairo-commit] 2 commits - src/cairo-type1-subset.c

Adrian Johnson ajohnson at kemper.freedesktop.org
Sat Feb 18 03:20:01 PST 2012


 src/cairo-type1-subset.c |   72 ++++++++++++++++++++++++++++++++---------------
 1 file changed, 50 insertions(+), 22 deletions(-)

New commits:
commit 01ea2d31cbbc12dafbe7831ef8c08a1bc78046a7
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Sat Feb 18 21:46:31 2012 +1030

    type1-subset: ensure additional glyphs required by seac operator are parsed

diff --git a/src/cairo-type1-subset.c b/src/cairo-type1-subset.c
index 2b837ba..607ac8e 100644
--- a/src/cairo-type1-subset.c
+++ b/src/cairo-type1-subset.c
@@ -1124,6 +1124,7 @@ cairo_type1_font_subset_write_private_dict (cairo_type1_font_subset_t *font,
     int length;
     const cairo_scaled_font_backend_t *backend;
     unsigned int i;
+    int glyph, j;
 
     /* The private dict holds hint information, common subroutines and
      * the actual glyph definitions (charstrings).
@@ -1241,18 +1242,18 @@ skip_subrs:
 
     /* Go through the charstring of each glyph in use, get the glyph
      * width and figure out which extra glyphs may be required by the
-     * seac operator. Also subset the Subrs. */
-    for (i = 0; i < font->base.num_glyphs; i++) {
-	if (font->glyphs[i].subset_index >= 0) {
-	    font->build_stack.sp = 0;
-	    font->ps_stack.num_other_subr_args = 0;
-	    status = cairo_type1_font_subset_parse_charstring (font,
-							       i,
-							       font->glyphs[i].encrypted_charstring,
-							       font->glyphs[i].encrypted_charstring_length);
-	    if (unlikely (status))
-		return status;
-	}
+     * seac operator (which may cause font->num_glyphs to increase
+     * while this loop is executing). Also subset the Subrs. */
+    for (j = 0; j < font->num_glyphs; j++) {
+	glyph = font->subset_index_to_glyphs[j];
+	font->build_stack.sp = 0;
+	font->ps_stack.num_other_subr_args = 0;
+	status = cairo_type1_font_subset_parse_charstring (font,
+							   glyph,
+							   font->glyphs[glyph].encrypted_charstring,
+							   font->glyphs[glyph].encrypted_charstring_length);
+	if (unlikely (status))
+	    return status;
     }
 
     closefile_token = find_token (dict_end, font->cleartext_end, "closefile");
commit 09b90611a1bca771968417c589df00c0b2d3c0e6
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Sat Feb 18 17:10:55 2012 +1030

    type1-subset: some fonts have "noaccess put" instead of NP in the Subrs

diff --git a/src/cairo-type1-subset.c b/src/cairo-type1-subset.c
index e12d1c2..2b837ba 100644
--- a/src/cairo-type1-subset.c
+++ b/src/cairo-type1-subset.c
@@ -98,6 +98,8 @@ typedef struct _cairo_type1_font_subset {
     struct {
 	const char *subr_string;
 	int subr_length;
+	const char *np;
+	int np_length;
 	cairo_bool_t used;
     } *subrs;
 
@@ -847,11 +849,14 @@ cairo_type1_font_subset_parse_charstring (cairo_type1_font_subset_t *font,
 static cairo_status_t
 cairo_type1_font_subset_build_subr_list (cairo_type1_font_subset_t *font,
 					 int subr_number,
-					 const char *encrypted_charstring, int encrypted_charstring_length)
+					 const char *encrypted_charstring, int encrypted_charstring_length,
+					 const char *np, int np_length)
 {
 
     font->subrs[subr_number].subr_string = encrypted_charstring;
     font->subrs[subr_number].subr_length = encrypted_charstring_length;
+    font->subrs[subr_number].np = np;
+    font->subrs[subr_number].np_length = np_length;
 
     return CAIRO_STATUS_SUCCESS;
 }
@@ -859,7 +864,8 @@ cairo_type1_font_subset_build_subr_list (cairo_type1_font_subset_t *font,
 static cairo_status_t
 write_used_subrs (cairo_type1_font_subset_t *font,
 		  int subr_number,
-		  const char *subr_string, int subr_string_length)
+		  const char *subr_string, int subr_string_length,
+		  const char *np, int np_length)
 {
     cairo_status_t status;
     char buffer[256];
@@ -881,8 +887,12 @@ write_used_subrs (cairo_type1_font_subset_t *font,
     if (unlikely (status))
 	return status;
 
-    length = snprintf (buffer, sizeof buffer, "%s\n", font->np);
-    status = cairo_type1_font_subset_write_encrypted (font, buffer, length);
+    if (np) {
+	status = cairo_type1_font_subset_write_encrypted (font, np, np_length);
+    } else {
+	length = snprintf (buffer, sizeof buffer, "%s\n", font->np);
+	status = cairo_type1_font_subset_write_encrypted (font, buffer, length);
+    }
     if (unlikely (status))
 	return status;
 
@@ -890,8 +900,9 @@ write_used_subrs (cairo_type1_font_subset_t *font,
 }
 
 typedef cairo_status_t (*subr_func_t) (cairo_type1_font_subset_t *font,
-					int subr_number,
-			                const char *subr_string, int subr_string_length);
+				       int subr_number,
+				       const char *subr_string, int subr_string_length,
+				       const char *np, int np_length);
 
 static cairo_status_t
 cairo_type1_font_for_each_subr (cairo_type1_font_subset_t  *font,
@@ -903,6 +914,8 @@ cairo_type1_font_for_each_subr (cairo_type1_font_subset_t  *font,
     const char *p, *subr_string;
     char *end;
     int subr_num, subr_length;
+    const char *np;
+    int np_length;
     cairo_status_t status;
 
     /* We're looking at "dup" at the start of the first subroutine. The subroutines
@@ -936,15 +949,29 @@ cairo_type1_font_for_each_subr (cairo_type1_font_subset_t  *font,
 	 * between the -| or RD token and the encrypted data, thus '+ 1'. */
 	subr_string = skip_token (end, cleartext_end) + 1;
 
-	status = func (font, subr_num,
-		       subr_string, subr_length);
-	if (unlikely (status))
-	    return status;
+	np = NULL;
+	np_length = 0;
 
 	/* Skip binary data and | or NP token. */
 	p = skip_token (subr_string + subr_length, cleartext_end);
 	while (p < cleartext_end && _cairo_isspace(*p))
 	    p++;
+
+	/* Some fonts have "noaccess put" instead of "NP" */
+	if (p + 3 < cleartext_end && strncmp (p, "put", 3) == 0) {
+	    p = skip_token (p, cleartext_end);
+	    while (p < cleartext_end && _cairo_isspace(*p))
+		p++;
+
+	    np = subr_string + subr_length;
+	    np_length = p - np;
+	}
+
+	status = func (font, subr_num,
+		       subr_string, subr_length, np, np_length);
+	if (unlikely (status))
+	    return status;
+
     }
 
     *array_end = (char *) p;


More information about the cairo-commit mailing list