[cairo-commit] 5 commits - src/cairo-cff-subset.c src/cairo-pdf-surface.c src/cairo-ps-surface.c src/cairo-scaled-font-subsets-private.h src/cairo-truetype-subset.c

Adrian Johnson ajohnson at kemper.freedesktop.org
Thu Jan 22 04:38:02 PST 2009


 src/cairo-cff-subset.c                  |  128 +++++++-----------
 src/cairo-pdf-surface.c                 |  144 ++++++++++++++++++--
 src/cairo-ps-surface.c                  |    9 -
 src/cairo-scaled-font-subsets-private.h |   31 ++++
 src/cairo-truetype-subset.c             |  222 ++++++++++++++++++++------------
 5 files changed, 359 insertions(+), 175 deletions(-)

New commits:
commit 41feeedcc14bf8caef3c039de49f4f28143712c7
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Wed Dec 3 23:58:22 2008 +1030

    Use PS font name in PS TrueType fonts

diff --git a/src/cairo-ps-surface.c b/src/cairo-ps-surface.c
index a13be1d..8a039f6 100644
--- a/src/cairo-ps-surface.c
+++ b/src/cairo-ps-surface.c
@@ -335,14 +335,13 @@ _cairo_ps_surface_emit_truetype_font_subset (cairo_ps_surface_t		*surface,
     _cairo_output_stream_printf (surface->final_stream,
 				 "11 dict begin\n"
 				 "/FontType 42 def\n"
-				 "/FontName /f-%d-%d def\n"
+				 "/FontName /%s def\n"
 				 "/PaintType 0 def\n"
 				 "/FontMatrix [ 1 0 0 1 0 0 ] def\n"
 				 "/FontBBox [ 0 0 0 0 ] def\n"
 				 "/Encoding 256 array def\n"
 				 "0 1 255 { Encoding exch /.notdef put } for\n",
-				 font_subset->font_id,
-				 font_subset->subset_id);
+				 subset.ps_name);
 
     /* FIXME: Figure out how subset->x_max etc maps to the /FontBBox */
 
@@ -397,7 +396,9 @@ _cairo_ps_surface_emit_truetype_font_subset (cairo_ps_surface_t		*surface,
 
     _cairo_output_stream_printf (surface->final_stream,
 				 "] def\n"
-				 "FontName currentdict end definefont pop\n");
+				 "/f-%d-%d currentdict end definefont pop\n",
+				 font_subset->font_id,
+				 font_subset->subset_id);
 
     _cairo_truetype_subset_fini (&subset);
 
commit b7a9e1d4ac3972bc3d215070124b6a9eda68d3e3
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Wed Dec 3 23:58:05 2008 +1030

    Embed full font name in PDF TrueType and CFF fonts
    
    if the full font name was available in the font.

diff --git a/src/cairo-pdf-surface.c b/src/cairo-pdf-surface.c
index ded3896..a901274 100644
--- a/src/cairo-pdf-surface.c
+++ b/src/cairo-pdf-surface.c
@@ -3422,7 +3422,18 @@ _cairo_pdf_surface_emit_cff_font (cairo_pdf_surface_t		*surface,
     _cairo_output_stream_printf (surface->output,
 				 "%d 0 obj\n"
 				 "<< /Type /FontDescriptor\n"
-				 "   /FontName /%s+%s\n"
+				 "   /FontName /%s+%s\n",
+				 descriptor.id,
+				 tag,
+				 subset->ps_name);
+
+    if (subset->font_name) {
+	_cairo_output_stream_printf (surface->output,
+				     "   /FontFamily (%s)\n",
+				     subset->font_name);
+    }
+
+    _cairo_output_stream_printf (surface->output,
 				 "   /Flags 4\n"
 				 "   /FontBBox [ %ld %ld %ld %ld ]\n"
 				 "   /ItalicAngle 0\n"
@@ -3434,9 +3445,6 @@ _cairo_pdf_surface_emit_cff_font (cairo_pdf_surface_t		*surface,
 				 "   /FontFile3 %u 0 R\n"
 				 ">>\n"
 				 "endobj\n",
-				 descriptor.id,
-				 tag,
-				 subset->ps_name,
 				 subset->x_min,
 				 subset->y_min,
 				 subset->x_max,
@@ -3766,7 +3774,18 @@ _cairo_pdf_surface_emit_truetype_font_subset (cairo_pdf_surface_t		*surface,
     _cairo_output_stream_printf (surface->output,
 				 "%d 0 obj\n"
 				 "<< /Type /FontDescriptor\n"
-				 "   /FontName /%s+%s\n"
+				 "   /FontName /%s+%s\n",
+				 descriptor.id,
+				 tag,
+				 subset.ps_name);
+
+    if (subset.font_name) {
+	_cairo_output_stream_printf (surface->output,
+				     "   /FontFamily (%s)\n",
+				     subset.font_name);
+    }
+
+    _cairo_output_stream_printf (surface->output,
 				 "   /Flags 4\n"
 				 "   /FontBBox [ %ld %ld %ld %ld ]\n"
 				 "   /ItalicAngle 0\n"
@@ -3778,9 +3797,6 @@ _cairo_pdf_surface_emit_truetype_font_subset (cairo_pdf_surface_t		*surface,
 				 "   /FontFile2 %u 0 R\n"
 				 ">>\n"
 				 "endobj\n",
-				 descriptor.id,
-				 tag,
-				 subset.ps_name,
 				 (long)(subset.x_min*PDF_UNITS_PER_EM),
 				 (long)(subset.y_min*PDF_UNITS_PER_EM),
                                  (long)(subset.x_max*PDF_UNITS_PER_EM),
commit 6f2db9a4b07cde2c4932ea481228abc248e90145
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Wed Dec 3 23:57:38 2008 +1030

    Use PS font name in CFF and TrueType PDF font subsets
    
    James Cloos found that the font name in embedded fonts should be the
    PostScript font name (nameID=6 in the name table).
    
    http://lists.cairographics.org/archives/cairo/2008-December/015919.html

diff --git a/src/cairo-cff-subset.c b/src/cairo-cff-subset.c
index 860e674..baa210e 100644
--- a/src/cairo-cff-subset.c
+++ b/src/cairo-cff-subset.c
@@ -108,6 +108,7 @@ typedef struct _cairo_cff_font {
     unsigned char       *data_end;
     cff_header_t        *header;
     char                *font_name;
+    char                *ps_name;
     cairo_hash_table_t  *top_dict;
     cairo_hash_table_t  *private_dict;
     cairo_array_t        strings_index;
@@ -1749,10 +1750,8 @@ _cairo_cff_font_create (cairo_scaled_font_subset_t  *scaled_font_subset,
         return status;
 
     font = malloc (sizeof (cairo_cff_font_t));
-    if (unlikely (font == NULL)) {
-        status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
-	goto fail1;
-    }
+    if (unlikely (font == NULL))
+        return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
     font->backend = backend;
     font->scaled_font_subset = scaled_font_subset;
@@ -1775,19 +1774,20 @@ _cairo_cff_font_create (cairo_scaled_font_subset_t  *scaled_font_subset,
     font->descent = (int16_t) be16_to_cpu (hhea.descender);
 
     status = _cairo_truetype_read_font_name (scaled_font_subset->scaled_font,
+					     &font->ps_name,
 					     &font->font_name);
     if (_cairo_status_is_error (status))
 	goto fail3;
 
-    /* If the font name is not found, create a CairoFont-x-y name. */
-    if (font->font_name == NULL) {
-        font->font_name = malloc (30);
-        if (unlikely (font->font_name == NULL)) {
-            status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
+    /* If the PS name is not found, create a CairoFont-x-y name. */
+    if (font->ps_name == NULL) {
+        font->ps_name = malloc (30);
+        if (unlikely (font->ps_name == NULL)) {
+	    status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
             goto fail3;
 	}
 
-        snprintf(font->font_name, 30, "CairoFont-%u-%u",
+        snprintf(font->ps_name, 30, "CairoFont-%u-%u",
                  scaled_font_subset->font_id,
                  scaled_font_subset->subset_id);
     }
@@ -1849,7 +1849,8 @@ fail6:
 fail5:
     free (font->widths);
 fail4:
-    free (font->font_name);
+    if (font->font_name)
+	free (font->font_name);
 fail3:
     free (font->subset_font_name);
 fail2:
@@ -1865,7 +1866,8 @@ cairo_cff_font_destroy (cairo_cff_font_t *font)
     unsigned int i;
 
     free (font->widths);
-    free (font->font_name);
+    if (font->font_name)
+	free (font->font_name);
     free (font->subset_font_name);
     _cairo_array_fini (&font->output);
     cff_dict_fini (font->top_dict);
@@ -1935,16 +1937,26 @@ _cairo_cff_subset_init (cairo_cff_subset_t          *cff_subset,
     if (unlikely (status))
 	goto fail1;
 
-    cff_subset->base_font = strdup (font->font_name);
-    if (unlikely (cff_subset->base_font == NULL)) {
+    cff_subset->ps_name = strdup (font->ps_name);
+    if (unlikely (cff_subset->ps_name == NULL)) {
 	status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	goto fail1;
     }
 
+    if (font->font_name) {
+	cff_subset->font_name = strdup (font->font_name);
+	if (cff_subset->font_name == NULL) {
+	    status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
+	    goto fail2;
+	}
+    } else {
+	cff_subset->font_name = NULL;
+    }
+
     cff_subset->widths = calloc (sizeof (int), font->scaled_font_subset->num_glyphs);
     if (unlikely (cff_subset->widths == NULL)) {
 	status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
-	goto fail2;
+	goto fail3;
     }
     for (i = 0; i < font->scaled_font_subset->num_glyphs; i++)
         cff_subset->widths[i] = font->widths[i];
@@ -1959,7 +1971,7 @@ _cairo_cff_subset_init (cairo_cff_subset_t          *cff_subset,
     cff_subset->data = malloc (length);
     if (unlikely (cff_subset->data == NULL)) {
 	status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
-	goto fail3;
+	goto fail4;
     }
 
     memcpy (cff_subset->data, data, length);
@@ -1969,10 +1981,13 @@ _cairo_cff_subset_init (cairo_cff_subset_t          *cff_subset,
 
     return CAIRO_STATUS_SUCCESS;
 
- fail3:
+ fail4:
     free (cff_subset->widths);
+ fail3:
+    if (cff_subset->font_name)
+	free (cff_subset->font_name);
  fail2:
-    free (cff_subset->base_font);
+    free (cff_subset->ps_name);
  fail1:
     cairo_cff_font_destroy (font);
 
@@ -1982,7 +1997,9 @@ _cairo_cff_subset_init (cairo_cff_subset_t          *cff_subset,
 void
 _cairo_cff_subset_fini (cairo_cff_subset_t *subset)
 {
-    free (subset->base_font);
+    free (subset->ps_name);
+    if (subset->font_name)
+	free (subset->font_name);
     free (subset->widths);
     free (subset->data);
 }
@@ -2013,11 +2030,12 @@ _cairo_cff_font_fallback_create (cairo_scaled_font_subset_t  *scaled_font_subset
 	goto fail1;
     }
 
-    font->font_name = strdup (subset_name);
+    font->ps_name = strdup (subset_name);
     if (unlikely (font->subset_font_name == NULL)) {
         status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	goto fail2;
     }
+    font->font_name = NULL;
 
     font->x_min = 0;
     font->y_min = 0;
@@ -2067,7 +2085,8 @@ fail5:
 fail4:
     free (font->widths);
 fail3:
-    free (font->font_name);
+    if (font->font_name)
+	free (font->font_name);
 fail2:
     free (font->subset_font_name);
 fail1:
@@ -2183,8 +2202,8 @@ _cairo_cff_fallback_init (cairo_cff_subset_t          *cff_subset,
     if (unlikely (status))
 	goto fail2;
 
-    cff_subset->base_font = strdup (font->font_name);
-    if (unlikely (cff_subset->base_font == NULL)) {
+    cff_subset->ps_name = strdup (font->ps_name);
+    if (unlikely (cff_subset->ps_name == NULL)) {
 	status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	goto fail2;
     }
@@ -2194,6 +2213,7 @@ _cairo_cff_fallback_init (cairo_cff_subset_t          *cff_subset,
 	status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	goto fail3;
     }
+
     for (i = 0; i < font->scaled_font_subset->num_glyphs; i++)
         cff_subset->widths[i] = type2_subset.widths[i];
 
@@ -2222,7 +2242,7 @@ _cairo_cff_fallback_init (cairo_cff_subset_t          *cff_subset,
  fail4:
     free (cff_subset->widths);
  fail3:
-    free (cff_subset->base_font);
+    free (cff_subset->ps_name);
  fail2:
     _cairo_type2_charstrings_fini (&type2_subset);
  fail1:
@@ -2234,7 +2254,7 @@ _cairo_cff_fallback_init (cairo_cff_subset_t          *cff_subset,
 void
 _cairo_cff_fallback_fini (cairo_cff_subset_t *subset)
 {
-    free (subset->base_font);
+    free (subset->ps_name);
     free (subset->widths);
     free (subset->data);
 }
diff --git a/src/cairo-pdf-surface.c b/src/cairo-pdf-surface.c
index 511d11d..ded3896 100644
--- a/src/cairo-pdf-surface.c
+++ b/src/cairo-pdf-surface.c
@@ -3387,7 +3387,7 @@ _cairo_pdf_surface_emit_cff_font (cairo_pdf_surface_t		*surface,
     cairo_status_t status;
     char tag[10];
 
-    _create_font_subset_tag (font_subset, subset->base_font, tag);
+    _create_font_subset_tag (font_subset, subset->ps_name, tag);
 
     subset_resource = _cairo_pdf_surface_get_font_resource (surface,
 							    font_subset->font_id,
@@ -3436,7 +3436,7 @@ _cairo_pdf_surface_emit_cff_font (cairo_pdf_surface_t		*surface,
 				 "endobj\n",
 				 descriptor.id,
 				 tag,
-				 subset->base_font,
+				 subset->ps_name,
 				 subset->x_min,
 				 subset->y_min,
 				 subset->x_max,
@@ -3463,7 +3463,7 @@ _cairo_pdf_surface_emit_cff_font (cairo_pdf_surface_t		*surface,
                                  "   /W [0 [",
                                  cidfont_dict.id,
 				 tag,
-                                 subset->base_font,
+                                 subset->ps_name,
                                  descriptor.id);
 
     for (i = 0; i < font_subset->num_glyphs; i++)
@@ -3486,7 +3486,7 @@ _cairo_pdf_surface_emit_cff_font (cairo_pdf_surface_t		*surface,
 				 "   /DescendantFonts [ %d 0 R]\n",
 				 subset_resource.id,
 				 tag,
-				 subset->base_font,
+				 subset->ps_name,
 				 cidfont_dict.id);
 
     if (to_unicode_stream.id != 0)
@@ -3728,7 +3728,7 @@ _cairo_pdf_surface_emit_truetype_font_subset (cairo_pdf_surface_t		*surface,
     if (unlikely (status))
 	return status;
 
-    _create_font_subset_tag (font_subset, subset.base_font, tag);
+    _create_font_subset_tag (font_subset, subset.ps_name, tag);
 
     status = _cairo_pdf_surface_open_stream (surface,
 					     NULL,
@@ -3780,7 +3780,7 @@ _cairo_pdf_surface_emit_truetype_font_subset (cairo_pdf_surface_t		*surface,
 				 "endobj\n",
 				 descriptor.id,
 				 tag,
-				 subset.base_font,
+				 subset.ps_name,
 				 (long)(subset.x_min*PDF_UNITS_PER_EM),
 				 (long)(subset.y_min*PDF_UNITS_PER_EM),
                                  (long)(subset.x_max*PDF_UNITS_PER_EM),
@@ -3810,7 +3810,7 @@ _cairo_pdf_surface_emit_truetype_font_subset (cairo_pdf_surface_t		*surface,
                                  "   /W [0 [",
                                  cidfont_dict.id,
 				 tag,
-                                 subset.base_font,
+                                 subset.ps_name,
                                  descriptor.id);
 
     for (i = 0; i < font_subset->num_glyphs; i++)
@@ -3833,7 +3833,7 @@ _cairo_pdf_surface_emit_truetype_font_subset (cairo_pdf_surface_t		*surface,
 				 "   /DescendantFonts [ %d 0 R]\n",
 				 subset_resource.id,
 				 tag,
-				 subset.base_font,
+				 subset.ps_name,
 				 cidfont_dict.id);
 
     if (to_unicode_stream.id != 0)
diff --git a/src/cairo-scaled-font-subsets-private.h b/src/cairo-scaled-font-subsets-private.h
index a78b82b..00344ae 100644
--- a/src/cairo-scaled-font-subsets-private.h
+++ b/src/cairo-scaled-font-subsets-private.h
@@ -332,7 +332,8 @@ cairo_private cairo_int_status_t
 _cairo_scaled_font_subset_create_glyph_names (cairo_scaled_font_subset_t *subset);
 
 typedef struct _cairo_cff_subset {
-    char *base_font;
+    char *font_name;
+    char *ps_name;
     int *widths;
     long x_min, y_min, x_max, y_max;
     long ascent, descent;
@@ -404,7 +405,8 @@ cairo_private void
 _cairo_cff_fallback_fini (cairo_cff_subset_t *cff_subset);
 
 typedef struct _cairo_truetype_subset {
-    char *base_font;
+    char *font_name;
+    char *ps_name;
     double *widths;
     double x_min, y_min, x_max, y_max;
     double ascent, descent;
@@ -638,11 +640,17 @@ _cairo_truetype_index_to_ucs4 (cairo_scaled_font_t *scaled_font,
 /**
  * _cairo_truetype_read_font_name:
  * @scaled_font: the #cairo_scaled_font_t
+ * @ps_name: returns the PostScript name of the font or NULL if the name could not be found.
  * @font_name: returns the font name or NULL if the name could not be found.
  *
  * If possible (depending on the format of the underlying
  * #cairo_scaled_font_t and the font backend in use) read the
- * font name from a TrueType/OpenType font.
+ * PostScript and Font names from a TrueType/OpenType font.
+ *
+ * The font name is the full name of the font eg "DejaVu Sans Bold".
+ * The PostScript name is a shortened name with spaces removed
+ * suitable for use as the font name in a PS or PDF file eg
+ * "DejaVuSans-Bold".
  *
  * Return value: %CAIRO_STATUS_SUCCESS if successful,
  * %CAIRO_INT_STATUS_UNSUPPORTED if the font is not TrueType/OpenType
@@ -650,8 +658,9 @@ _cairo_truetype_index_to_ucs4 (cairo_scaled_font_t *scaled_font,
  * %CAIRO_STATUS_NO_MEMORY.
  **/
 cairo_private cairo_int_status_t
-_cairo_truetype_read_font_name (cairo_scaled_font_t  	 *scaled_font,
-				char 	       		**font_name);
+_cairo_truetype_read_font_name (cairo_scaled_font_t   *scaled_font,
+				char 	       	     **ps_name,
+				char 	       	     **font_name);
 
 #endif /* CAIRO_HAS_FONT_SUBSET */
 
diff --git a/src/cairo-truetype-subset.c b/src/cairo-truetype-subset.c
index 8498005..a8c495f 100644
--- a/src/cairo-truetype-subset.c
+++ b/src/cairo-truetype-subset.c
@@ -72,7 +72,8 @@ struct _cairo_truetype_font {
     int num_tables;
 
     struct {
-	char *base_font;
+	char *font_name;
+	char *ps_name;
 	unsigned int num_glyphs;
 	int *widths;
 	long x_min, y_min, x_max, y_max;
@@ -201,19 +202,20 @@ _cairo_truetype_font_create (cairo_scaled_font_subset_t  *scaled_font_subset,
         font->base.units_per_em = 2048;
 
     status = _cairo_truetype_read_font_name (scaled_font_subset->scaled_font,
-					     &font->base.base_font);
+					     &font->base.ps_name,
+					     &font->base.font_name);
     if (_cairo_status_is_error (status))
 	goto fail3;
 
-    /* If the font name is not found, create a CairoFont-x-y name. */
-    if (font->base.base_font == NULL) {
-        font->base.base_font = malloc (30);
-        if (unlikely (font->base.base_font == NULL)) {
+    /* If the PS name is not found, create a CairoFont-x-y name. */
+    if (font->base.ps_name == NULL) {
+        font->base.ps_name = malloc (30);
+        if (unlikely (font->base.ps_name == NULL)) {
 	    status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
             goto fail3;
 	}
 
-        snprintf(font->base.base_font, 30, "CairoFont-%u-%u",
+        snprintf(font->base.ps_name, 30, "CairoFont-%u-%u",
                  scaled_font_subset->font_id,
                  scaled_font_subset->subset_id);
     }
@@ -239,9 +241,11 @@ _cairo_truetype_font_create (cairo_scaled_font_subset_t  *scaled_font_subset,
     _cairo_array_fini (&font->string_offsets);
     free (font->base.widths);
  fail4:
-    free (font->base.base_font);
+    free (font->base.ps_name);
  fail3:
     free (font->parent_to_subset);
+    if (font->base.font_name)
+	free (font->base.font_name);
  fail2:
     free (font->glyphs);
  fail1:
@@ -256,7 +260,9 @@ cairo_truetype_font_destroy (cairo_truetype_font_t *font)
 {
     _cairo_array_fini (&font->string_offsets);
     free (font->base.widths);
-    free (font->base.base_font);
+    free (font->base.ps_name);
+    if (font->base.font_name)
+	free (font->base.font_name);
     free (font->parent_to_subset);
     free (font->glyphs);
     _cairo_array_fini (&font->output);
@@ -1043,12 +1049,22 @@ _cairo_truetype_subset_init (cairo_truetype_subset_t    *truetype_subset,
     if (unlikely (status))
 	goto fail1;
 
-    truetype_subset->base_font = strdup (font->base.base_font);
-    if (unlikely (truetype_subset->base_font == NULL)) {
+    truetype_subset->ps_name = strdup (font->base.ps_name);
+    if (unlikely (truetype_subset->ps_name == NULL)) {
 	status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
 	goto fail1;
     }
 
+    if (font->base.font_name != NULL) {
+	truetype_subset->font_name = strdup (font->base.font_name);
+	if (unlikely (truetype_subset->font_name == NULL)) {
+	    status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
+	    goto fail2;
+	}
+    } else {
+	truetype_subset->font_name = NULL;
+    }
+
     /* The widths array returned must contain only widths for the
      * glyphs in font_subset. Any subglyphs appended after
      * font_subset->num_glyphs are omitted. */
@@ -1056,7 +1072,7 @@ _cairo_truetype_subset_init (cairo_truetype_subset_t    *truetype_subset,
                                       font->scaled_font_subset->num_glyphs);
     if (unlikely (truetype_subset->widths == NULL)) {
 	status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
-	goto fail2;
+	goto fail3;
     }
     for (i = 0; i < font->scaled_font_subset->num_glyphs; i++)
 	truetype_subset->widths[i] = (double)font->base.widths[i]/font->base.units_per_em;
@@ -1072,7 +1088,7 @@ _cairo_truetype_subset_init (cairo_truetype_subset_t    *truetype_subset,
 	truetype_subset->data = malloc (length);
 	if (unlikely (truetype_subset->data == NULL)) {
 	    status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
-	    goto fail3;
+	    goto fail4;
 	}
 
 	memcpy (truetype_subset->data, data, length);
@@ -1085,7 +1101,7 @@ _cairo_truetype_subset_init (cairo_truetype_subset_t    *truetype_subset,
 	truetype_subset->string_offsets = malloc (offsets_length);
 	if (unlikely (truetype_subset->string_offsets == NULL)) {
 	    status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
-	    goto fail4;
+	    goto fail5;
 	}
 
 	memcpy (truetype_subset->string_offsets, string_offsets, offsets_length);
@@ -1099,12 +1115,15 @@ _cairo_truetype_subset_init (cairo_truetype_subset_t    *truetype_subset,
 
     return CAIRO_STATUS_SUCCESS;
 
- fail4:
+ fail5:
     free (truetype_subset->data);
- fail3:
+ fail4:
     free (truetype_subset->widths);
+ fail3:
+    if (truetype_subset->font_name)
+	free (truetype_subset->font_name);
  fail2:
-    free (truetype_subset->base_font);
+    free (truetype_subset->ps_name);
  fail1:
     cairo_truetype_font_destroy (font);
 
@@ -1114,7 +1133,7 @@ _cairo_truetype_subset_init (cairo_truetype_subset_t    *truetype_subset,
 void
 _cairo_truetype_subset_fini (cairo_truetype_subset_t *subset)
 {
-    free (subset->base_font);
+    free (subset->ps_name);
     free (subset->widths);
     free (subset->data);
     free (subset->string_offsets);
@@ -1283,6 +1302,7 @@ cleanup:
 
 cairo_int_status_t
 _cairo_truetype_read_font_name (cairo_scaled_font_t  	 *scaled_font,
+				char 	       		**ps_name_out,
 				char 	       		**font_name_out)
 {
     cairo_status_t status;
@@ -1291,6 +1311,7 @@ _cairo_truetype_read_font_name (cairo_scaled_font_t  	 *scaled_font,
     tt_name_record_t *record;
     unsigned long size;
     int i, j;
+    char *ps_name;
     char *font_name;
 
     backend = scaled_font->backend;
@@ -1309,7 +1330,7 @@ _cairo_truetype_read_font_name (cairo_scaled_font_t  	 *scaled_font,
     if (name == NULL)
         return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
-    status = backend->load_truetype_table (scaled_font,
+   status = backend->load_truetype_table (scaled_font,
 					   TT_TAG_name, 0,
 					   (unsigned char *) name,
 					   &size);
@@ -1321,12 +1342,14 @@ _cairo_truetype_read_font_name (cairo_scaled_font_t  	 *scaled_font,
      * name. It should be extended to use any suitable font name in
      * the name table.
      */
+    ps_name = NULL;
     font_name = NULL;
     for (i = 0; i < be16_to_cpu(name->num_records); i++) {
         record = &(name->records[i]);
         if ((be16_to_cpu (record->platform) == 1) &&
-            (be16_to_cpu (record->encoding) == 0) &&
-	    (be16_to_cpu (record->name) == 4)) {
+            (be16_to_cpu (record->encoding) == 0)) {
+
+	    if (be16_to_cpu (record->name) == 4) {
 		font_name = malloc (be16_to_cpu(record->length) + 1);
 		if (font_name == NULL) {
 		    status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
@@ -1336,28 +1359,46 @@ _cairo_truetype_read_font_name (cairo_scaled_font_t  	 *scaled_font,
 			((char*)name) + be16_to_cpu (name->strings_offset) + be16_to_cpu (record->offset),
 			be16_to_cpu (record->length));
 		font_name[be16_to_cpu (record->length)] = 0;
+	    }
+
+	    if (be16_to_cpu (record->name) == 6) {
+		ps_name = malloc (be16_to_cpu(record->length) + 1);
+		if (ps_name == NULL) {
+		    status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
+		    goto fail;
+		}
+		strncpy(ps_name,
+			((char*)name) + be16_to_cpu (name->strings_offset) + be16_to_cpu (record->offset),
+			be16_to_cpu (record->length));
+		ps_name[be16_to_cpu (record->length)] = 0;
+	    }
+
+	    if (font_name && ps_name)
 		break;
-	}
+        }
     }
 
     free (name);
 
-    /* Ensure font name does not contain any spaces */
-    if (font_name) {
-	for (i = 0, j = 0; font_name[j]; j++) {
-	    if (font_name[j] == ' ')
+    /* Ensure PS name does not contain any spaces */
+    if (ps_name) {
+	for (i = 0, j = 0; ps_name[j]; j++) {
+	    if (ps_name[j] == ' ')
 		continue;
-	    font_name[i++] = font_name[j];
+	    ps_name[i++] = ps_name[j];
 	}
-	font_name[i] = '\0';
+	ps_name[i] = '\0';
     }
 
+    *ps_name_out = ps_name;
     *font_name_out = font_name;
 
     return CAIRO_STATUS_SUCCESS;
 
 fail:
     free (name);
+    *ps_name_out = NULL;
+    *font_name_out = NULL;
 
     return status;
 }
commit 2ed08f7801a2af27e35afcf57f00f4bf5d48384a
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Wed Dec 3 23:56:01 2008 +1030

    Factor out duplicate code in truetype and cff subsetting
    
    The code for reading the font name from the name table has been moved
    to a new function: _cairo_truetype_read_font_name().

diff --git a/src/cairo-cff-subset.c b/src/cairo-cff-subset.c
index 2baf414..860e674 100644
--- a/src/cairo-cff-subset.c
+++ b/src/cairo-cff-subset.c
@@ -1716,10 +1716,7 @@ _cairo_cff_font_create (cairo_scaled_font_subset_t  *scaled_font_subset,
     cairo_cff_font_t *font;
     tt_head_t head;
     tt_hhea_t hhea;
-    tt_name_t *name;
-    tt_name_record_t *record;
     unsigned long size, data_length;
-    int i, j;
 
     backend = scaled_font_subset->scaled_font->backend;
     if (!backend->load_truetype_table)
@@ -1751,22 +1748,6 @@ _cairo_cff_font_create (cairo_scaled_font_subset_t  *scaled_font_subset,
     if (unlikely (status))
         return status;
 
-    size = 0;
-    status = backend->load_truetype_table (scaled_font_subset->scaled_font,
-                                           TT_TAG_name, 0, NULL, &size);
-    if (unlikely (status))
-        return status;
-
-    name = malloc (size);
-    if (unlikely (name == NULL))
-	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
-
-    status = backend->load_truetype_table (scaled_font_subset->scaled_font,
-                                           TT_TAG_name, 0,
-                                           (unsigned char *) name, &size);
-    if (unlikely (status))
-        goto fail1;
-
     font = malloc (sizeof (cairo_cff_font_t));
     if (unlikely (font == NULL)) {
         status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
@@ -1793,47 +1774,24 @@ _cairo_cff_font_create (cairo_scaled_font_subset_t  *scaled_font_subset,
     font->ascent = (int16_t) be16_to_cpu (hhea.ascender);
     font->descent = (int16_t) be16_to_cpu (hhea.descender);
 
-    /* Extract the font name from the name table. At present this
-     * just looks for the Mac platform/Roman encoded font name. It
-     * should be extended to use any suitable font name in the
-     * name table. If the mac/roman font name is not found a
-     * CairoFont-x-y name is created.
-     */
-    font->font_name = NULL;
-    for (i = 0; i < be16_to_cpu(name->num_records); i++) {
-        record = &(name->records[i]);
-        if ((be16_to_cpu (record->platform) == 1) &&
-            (be16_to_cpu (record->encoding) == 0) &&
-            (be16_to_cpu (record->name) == 4)) {
-            font->font_name = malloc (be16_to_cpu(record->length) + 1);
-            if (font->font_name) {
-                strncpy(font->font_name,
-                        ((char*)name) + be16_to_cpu (name->strings_offset) + be16_to_cpu (record->offset),
-                        be16_to_cpu (record->length));
-                font->font_name[be16_to_cpu (record->length)] = 0;
-            }
-            break;
-        }
-    }
+    status = _cairo_truetype_read_font_name (scaled_font_subset->scaled_font,
+					     &font->font_name);
+    if (_cairo_status_is_error (status))
+	goto fail3;
 
+    /* If the font name is not found, create a CairoFont-x-y name. */
     if (font->font_name == NULL) {
         font->font_name = malloc (30);
         if (unlikely (font->font_name == NULL)) {
             status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
             goto fail3;
-        }
+	}
+
         snprintf(font->font_name, 30, "CairoFont-%u-%u",
                  scaled_font_subset->font_id,
                  scaled_font_subset->subset_id);
     }
 
-    for (i = 0, j = 0; font->font_name[j]; j++) {
-	if (font->font_name[j] == ' ')
-	    continue;
-	font->font_name[i++] = font->font_name[j];
-    }
-    font->font_name[i] = '\0';
-
     font->widths = calloc (font->scaled_font_subset->num_glyphs, sizeof (int));
     if (unlikely (font->widths == NULL)) {
         status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
@@ -1880,7 +1838,6 @@ _cairo_cff_font_create (cairo_scaled_font_subset_t  *scaled_font_subset,
     font->fd_subset_map = NULL;
     font->private_dict_offset = NULL;
 
-    free (name);
     *font_return = font;
 
     return CAIRO_STATUS_SUCCESS;
@@ -1898,8 +1855,7 @@ fail3:
 fail2:
     _cairo_array_fini (&font->output);
     free (font);
-fail1:
-    free (name);
+
     return status;
 }
 
diff --git a/src/cairo-scaled-font-subsets-private.h b/src/cairo-scaled-font-subsets-private.h
index 88dedb5..a78b82b 100644
--- a/src/cairo-scaled-font-subsets-private.h
+++ b/src/cairo-scaled-font-subsets-private.h
@@ -635,6 +635,24 @@ _cairo_truetype_index_to_ucs4 (cairo_scaled_font_t *scaled_font,
                                unsigned long        index,
                                uint32_t            *ucs4);
 
+/**
+ * _cairo_truetype_read_font_name:
+ * @scaled_font: the #cairo_scaled_font_t
+ * @font_name: returns the font name or NULL if the name could not be found.
+ *
+ * If possible (depending on the format of the underlying
+ * #cairo_scaled_font_t and the font backend in use) read the
+ * font name from a TrueType/OpenType font.
+ *
+ * Return value: %CAIRO_STATUS_SUCCESS if successful,
+ * %CAIRO_INT_STATUS_UNSUPPORTED if the font is not TrueType/OpenType
+ * or the name table is not present.  Possible errors include
+ * %CAIRO_STATUS_NO_MEMORY.
+ **/
+cairo_private cairo_int_status_t
+_cairo_truetype_read_font_name (cairo_scaled_font_t  	 *scaled_font,
+				char 	       		**font_name);
+
 #endif /* CAIRO_HAS_FONT_SUBSET */
 
 #endif /* CAIRO_SCALED_FONT_SUBSETS_PRIVATE_H */
diff --git a/src/cairo-truetype-subset.c b/src/cairo-truetype-subset.c
index 4662eaa..8498005 100644
--- a/src/cairo-truetype-subset.c
+++ b/src/cairo-truetype-subset.c
@@ -123,10 +123,7 @@ _cairo_truetype_font_create (cairo_scaled_font_subset_t  *scaled_font_subset,
     tt_head_t head;
     tt_hhea_t hhea;
     tt_maxp_t maxp;
-    tt_name_t *name;
-    tt_name_record_t *record;
     unsigned long size;
-    int i, j;
 
     backend = scaled_font_subset->scaled_font->backend;
     if (!backend->load_truetype_table)
@@ -165,30 +162,9 @@ _cairo_truetype_font_create (cairo_scaled_font_subset_t  *scaled_font_subset,
     if (unlikely (status))
 	return status;
 
-    size = 0;
-    status = backend->load_truetype_table (scaled_font_subset->scaled_font,
-	                                   TT_TAG_name, 0,
-					   NULL,
-					   &size);
-    if (unlikely (status))
-	return status;
-
-    name = malloc (size);
-    if (unlikely (name == NULL))
-        return _cairo_error (CAIRO_STATUS_NO_MEMORY);
-
-    status = backend->load_truetype_table (scaled_font_subset->scaled_font,
-					   TT_TAG_name, 0,
-					   (unsigned char *) name,
-					   &size);
-    if (unlikely (status))
-	goto fail0;
-
     font = malloc (sizeof (cairo_truetype_font_t));
-    if (unlikely (font == NULL)) {
-	status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
-	goto fail0;
-    }
+    if (unlikely (font == NULL))
+	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
     font->backend = backend;
     font->num_glyphs_in_face = be16_to_cpu (maxp.num_glyphs);
@@ -224,32 +200,12 @@ _cairo_truetype_font_create (cairo_scaled_font_subset_t  *scaled_font_subset,
     if (font->base.units_per_em == 0)
         font->base.units_per_em = 2048;
 
-    /* Extract the font name from the name table. At present this
-     * just looks for the Mac platform/Roman encoded font name. It
-     * should be extended to use any suitable font name in the
-     * name table. If the mac/roman font name is not found a
-     * CairoFont-x-y name is created.
-     */
-    font->base.base_font = NULL;
-    for (i = 0; i < be16_to_cpu(name->num_records); i++) {
-        record = &(name->records[i]);
-        if ((be16_to_cpu (record->platform) == 1) &&
-            (be16_to_cpu (record->encoding) == 0) &&
-            (be16_to_cpu (record->name) == 4)) {
-            font->base.base_font = malloc (be16_to_cpu(record->length) + 1);
-            if (font->base.base_font) {
-                strncpy(font->base.base_font,
-                        ((char*)name) + be16_to_cpu (name->strings_offset) + be16_to_cpu (record->offset),
-                        be16_to_cpu (record->length));
-                font->base.base_font[be16_to_cpu (record->length)] = 0;
-            }
-            break;
-        }
-    }
-
-    free (name);
-    name = NULL;
+    status = _cairo_truetype_read_font_name (scaled_font_subset->scaled_font,
+					     &font->base.base_font);
+    if (_cairo_status_is_error (status))
+	goto fail3;
 
+    /* If the font name is not found, create a CairoFont-x-y name. */
     if (font->base.base_font == NULL) {
         font->base.base_font = malloc (30);
         if (unlikely (font->base.base_font == NULL)) {
@@ -262,13 +218,6 @@ _cairo_truetype_font_create (cairo_scaled_font_subset_t  *scaled_font_subset,
                  scaled_font_subset->subset_id);
     }
 
-    for (i = 0, j = 0; font->base.base_font[j]; j++) {
-	if (font->base.base_font[j] == ' ')
-	    continue;
-	font->base.base_font[i++] = font->base.base_font[j];
-    }
-    font->base.base_font[i] = '\0';
-
     font->base.widths = calloc (font->num_glyphs_in_face, sizeof (int));
     if (unlikely (font->base.widths == NULL)) {
 	status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
@@ -298,9 +247,6 @@ _cairo_truetype_font_create (cairo_scaled_font_subset_t  *scaled_font_subset,
  fail1:
     _cairo_array_fini (&font->output);
     free (font);
- fail0:
-    if (name)
-	free (name);
 
     return status;
 }
@@ -1335,4 +1281,85 @@ cleanup:
     return status;
 }
 
+cairo_int_status_t
+_cairo_truetype_read_font_name (cairo_scaled_font_t  	 *scaled_font,
+				char 	       		**font_name_out)
+{
+    cairo_status_t status;
+    const cairo_scaled_font_backend_t *backend;
+    tt_name_t *name;
+    tt_name_record_t *record;
+    unsigned long size;
+    int i, j;
+    char *font_name;
+
+    backend = scaled_font->backend;
+    if (!backend->load_truetype_table)
+	return CAIRO_INT_STATUS_UNSUPPORTED;
+
+    size = 0;
+    status = backend->load_truetype_table (scaled_font,
+	                                   TT_TAG_name, 0,
+					   NULL,
+					   &size);
+    if (status)
+	return status;
+
+    name = malloc (size);
+    if (name == NULL)
+        return _cairo_error (CAIRO_STATUS_NO_MEMORY);
+
+    status = backend->load_truetype_table (scaled_font,
+					   TT_TAG_name, 0,
+					   (unsigned char *) name,
+					   &size);
+    if (status)
+	goto fail;
+
+    /* Extract the font name and PS name from the name table. At
+     * present this just looks for the Mac platform/Roman encoded font
+     * name. It should be extended to use any suitable font name in
+     * the name table.
+     */
+    font_name = NULL;
+    for (i = 0; i < be16_to_cpu(name->num_records); i++) {
+        record = &(name->records[i]);
+        if ((be16_to_cpu (record->platform) == 1) &&
+            (be16_to_cpu (record->encoding) == 0) &&
+	    (be16_to_cpu (record->name) == 4)) {
+		font_name = malloc (be16_to_cpu(record->length) + 1);
+		if (font_name == NULL) {
+		    status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
+		    goto fail;
+		}
+		strncpy(font_name,
+			((char*)name) + be16_to_cpu (name->strings_offset) + be16_to_cpu (record->offset),
+			be16_to_cpu (record->length));
+		font_name[be16_to_cpu (record->length)] = 0;
+		break;
+	}
+    }
+
+    free (name);
+
+    /* Ensure font name does not contain any spaces */
+    if (font_name) {
+	for (i = 0, j = 0; font_name[j]; j++) {
+	    if (font_name[j] == ' ')
+		continue;
+	    font_name[i++] = font_name[j];
+	}
+	font_name[i] = '\0';
+    }
+
+    *font_name_out = font_name;
+
+    return CAIRO_STATUS_SUCCESS;
+
+fail:
+    free (name);
+
+    return status;
+}
+
 #endif /* CAIRO_HAS_FONT_SUBSET */
commit 1deb1e451022b9dd5aa6ecb0b580b006047b630e
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Tue Nov 25 23:11:01 2008 +1030

    PDF: Include subset tag in font name
    
    PDF requires font names of subsetted fonts to be preprended with
    "XXXXXX+" where XXXXXX is a sequence of 6 uppercase letters unique the
    font and the set of glyphs in the subset.

diff --git a/src/cairo-pdf-surface.c b/src/cairo-pdf-surface.c
index d453f20..511d11d 100644
--- a/src/cairo-pdf-surface.c
+++ b/src/cairo-pdf-surface.c
@@ -3210,6 +3210,85 @@ _cairo_pdf_surface_emit_unicode_for_glyph (cairo_pdf_surface_t	*surface,
     return CAIRO_STATUS_SUCCESS;
 }
 
+/* Bob Jenkins hash
+ *
+ * Public domain code from:
+ *   http://burtleburtle.net/bob/hash/doobs.html
+ */
+
+#define HASH_MIX(a,b,c) 		\
+{ 					\
+    a -= b; a -= c; a ^= (c>>13);	\
+    b -= c; b -= a; b ^= (a<<8);	\
+    c -= a; c -= b; c ^= (b>>13);	\
+    a -= b; a -= c; a ^= (c>>12);	\
+    b -= c; b -= a; b ^= (a<<16);	\
+    c -= a; c -= b; c ^= (b>>5);	\
+    a -= b; a -= c; a ^= (c>>3);	\
+    b -= c; b -= a; b ^= (a<<10);	\
+    c -= a; c -= b; c ^= (b>>15);	\
+}
+
+static uint32_t
+_hash_data (const unsigned char *data, int length, uint32_t initval)
+{
+    uint32_t a, b, c, len;
+
+    len = length;
+    a = b = 0x9e3779b9;  /* the golden ratio; an arbitrary value */
+    c = initval;         /* the previous hash value */
+
+    while (len >= 12) {
+	a += (data[0] + ((uint32_t)data[1]<<8) + ((uint32_t)data[2]<<16) + ((uint32_t)data[3]<<24));
+	b += (data[4] + ((uint32_t)data[5]<<8) + ((uint32_t)data[6]<<16) + ((uint32_t)data[7]<<24));
+	c += (data[8] + ((uint32_t)data[9]<<8) + ((uint32_t)data[10]<<16)+ ((uint32_t)data[11]<<24));
+	HASH_MIX (a,b,c);
+	data += 12;
+	len -= 12;
+    }
+
+    c += length;
+    switch(len) {
+    case 11: c+= ((uint32_t) data[10] << 24);
+    case 10: c+= ((uint32_t) data[9] << 16);
+    case 9 : c+= ((uint32_t) data[8] << 8);
+    case 8 : b+= ((uint32_t) data[7] << 24);
+    case 7 : b+= ((uint32_t) data[6] << 16);
+    case 6 : b+= ((uint32_t) data[5] << 8);
+    case 5 : b+= data[4];
+    case 4 : a+= ((uint32_t) data[3] << 24);
+    case 3 : a+= ((uint32_t) data[2] << 16);
+    case 2 : a+= ((uint32_t) data[1] << 8);
+    case 1 : a+= data[0];
+    }
+    HASH_MIX (a,b,c);
+
+    return c;
+}
+
+static void
+_create_font_subset_tag (cairo_scaled_font_subset_t	*font_subset,
+			 const char 			*font_name,
+			 char				*tag)
+{
+    uint32_t hash;
+    int i;
+    long numerator;
+    ldiv_t d;
+
+    hash = _hash_data ((unsigned char *) font_name, strlen(font_name), 0);
+    hash = _hash_data ((unsigned char *) (font_subset->glyphs),
+		       font_subset->num_glyphs * sizeof(unsigned long), hash);
+
+    numerator = abs (hash);
+    for (i = 0; i < 6; i++) {
+	d = ldiv (numerator, 26);
+	numerator = d.quot;
+        tag[i] = 'A' + d.rem;
+    }
+    tag[i] = 0;
+}
+
 static cairo_int_status_t
 _cairo_pdf_surface_emit_to_unicode_stream (cairo_pdf_surface_t		*surface,
 					   cairo_scaled_font_subset_t	*font_subset,
@@ -3306,6 +3385,9 @@ _cairo_pdf_surface_emit_cff_font (cairo_pdf_surface_t		*surface,
     cairo_pdf_font_t font;
     unsigned int i;
     cairo_status_t status;
+    char tag[10];
+
+    _create_font_subset_tag (font_subset, subset->base_font, tag);
 
     subset_resource = _cairo_pdf_surface_get_font_resource (surface,
 							    font_subset->font_id,
@@ -3340,7 +3422,7 @@ _cairo_pdf_surface_emit_cff_font (cairo_pdf_surface_t		*surface,
     _cairo_output_stream_printf (surface->output,
 				 "%d 0 obj\n"
 				 "<< /Type /FontDescriptor\n"
-				 "   /FontName /%s\n"
+				 "   /FontName /%s+%s\n"
 				 "   /Flags 4\n"
 				 "   /FontBBox [ %ld %ld %ld %ld ]\n"
 				 "   /ItalicAngle 0\n"
@@ -3353,6 +3435,7 @@ _cairo_pdf_surface_emit_cff_font (cairo_pdf_surface_t		*surface,
 				 ">>\n"
 				 "endobj\n",
 				 descriptor.id,
+				 tag,
 				 subset->base_font,
 				 subset->x_min,
 				 subset->y_min,
@@ -3370,7 +3453,7 @@ _cairo_pdf_surface_emit_cff_font (cairo_pdf_surface_t		*surface,
                                  "%d 0 obj\n"
                                  "<< /Type /Font\n"
                                  "   /Subtype /CIDFontType0\n"
-                                 "   /BaseFont /%s\n"
+                                 "   /BaseFont /%s+%s\n"
                                  "   /CIDSystemInfo\n"
                                  "   << /Registry (Adobe)\n"
                                  "      /Ordering (Identity)\n"
@@ -3379,6 +3462,7 @@ _cairo_pdf_surface_emit_cff_font (cairo_pdf_surface_t		*surface,
                                  "   /FontDescriptor %d 0 R\n"
                                  "   /W [0 [",
                                  cidfont_dict.id,
+				 tag,
                                  subset->base_font,
                                  descriptor.id);
 
@@ -3397,10 +3481,11 @@ _cairo_pdf_surface_emit_cff_font (cairo_pdf_surface_t		*surface,
 				 "%d 0 obj\n"
 				 "<< /Type /Font\n"
 				 "   /Subtype /Type0\n"
-				 "   /BaseFont /%s\n"
+				 "   /BaseFont /%s+%s\n"
                                  "   /Encoding /Identity-H\n"
 				 "   /DescendantFonts [ %d 0 R]\n",
 				 subset_resource.id,
+				 tag,
 				 subset->base_font,
 				 cidfont_dict.id);
 
@@ -3473,6 +3558,9 @@ _cairo_pdf_surface_emit_type1_font (cairo_pdf_surface_t		*surface,
     cairo_status_t status;
     unsigned long length;
     unsigned int i;
+    char tag[10];
+
+    _create_font_subset_tag (font_subset, subset->base_font, tag);
 
     subset_resource = _cairo_pdf_surface_get_font_resource (surface,
 							    font_subset->font_id,
@@ -3512,7 +3600,7 @@ _cairo_pdf_surface_emit_type1_font (cairo_pdf_surface_t		*surface,
     _cairo_output_stream_printf (surface->output,
 				 "%d 0 obj\n"
 				 "<< /Type /FontDescriptor\n"
-				 "   /FontName /%s\n"
+				 "   /FontName /%s+%s\n"
 				 "   /Flags 4\n"
 				 "   /FontBBox [ %ld %ld %ld %ld ]\n"
 				 "   /ItalicAngle 0\n"
@@ -3525,6 +3613,7 @@ _cairo_pdf_surface_emit_type1_font (cairo_pdf_surface_t		*surface,
 				 ">>\n"
 				 "endobj\n",
 				 descriptor.id,
+				 tag,
 				 subset->base_font,
 				 subset->x_min,
 				 subset->y_min,
@@ -3539,12 +3628,13 @@ _cairo_pdf_surface_emit_type1_font (cairo_pdf_surface_t		*surface,
 				 "%d 0 obj\n"
 				 "<< /Type /Font\n"
 				 "   /Subtype /Type1\n"
-				 "   /BaseFont /%s\n"
+				 "   /BaseFont /%s+%s\n"
 				 "   /FirstChar 0\n"
 				 "   /LastChar %d\n"
 				 "   /FontDescriptor %d 0 R\n"
 				 "   /Widths [",
 				 subset_resource.id,
+				 tag,
 				 subset->base_font,
 				 font_subset->num_glyphs - 1,
 				 descriptor.id);
@@ -3626,6 +3716,7 @@ _cairo_pdf_surface_emit_truetype_font_subset (cairo_pdf_surface_t		*surface,
     cairo_pdf_font_t font;
     cairo_truetype_subset_t subset;
     unsigned int i;
+    char tag[10];
 
     subset_resource = _cairo_pdf_surface_get_font_resource (surface,
 							    font_subset->font_id,
@@ -3637,6 +3728,8 @@ _cairo_pdf_surface_emit_truetype_font_subset (cairo_pdf_surface_t		*surface,
     if (unlikely (status))
 	return status;
 
+    _create_font_subset_tag (font_subset, subset.base_font, tag);
+
     status = _cairo_pdf_surface_open_stream (surface,
 					     NULL,
 					     TRUE,
@@ -3673,7 +3766,7 @@ _cairo_pdf_surface_emit_truetype_font_subset (cairo_pdf_surface_t		*surface,
     _cairo_output_stream_printf (surface->output,
 				 "%d 0 obj\n"
 				 "<< /Type /FontDescriptor\n"
-				 "   /FontName /%s\n"
+				 "   /FontName /%s+%s\n"
 				 "   /Flags 4\n"
 				 "   /FontBBox [ %ld %ld %ld %ld ]\n"
 				 "   /ItalicAngle 0\n"
@@ -3686,6 +3779,7 @@ _cairo_pdf_surface_emit_truetype_font_subset (cairo_pdf_surface_t		*surface,
 				 ">>\n"
 				 "endobj\n",
 				 descriptor.id,
+				 tag,
 				 subset.base_font,
 				 (long)(subset.x_min*PDF_UNITS_PER_EM),
 				 (long)(subset.y_min*PDF_UNITS_PER_EM),
@@ -3706,7 +3800,7 @@ _cairo_pdf_surface_emit_truetype_font_subset (cairo_pdf_surface_t		*surface,
                                  "%d 0 obj\n"
                                  "<< /Type /Font\n"
                                  "   /Subtype /CIDFontType2\n"
-                                 "   /BaseFont /%s\n"
+                                 "   /BaseFont /%s+%s\n"
                                  "   /CIDSystemInfo\n"
                                  "   << /Registry (Adobe)\n"
                                  "      /Ordering (Identity)\n"
@@ -3715,6 +3809,7 @@ _cairo_pdf_surface_emit_truetype_font_subset (cairo_pdf_surface_t		*surface,
                                  "   /FontDescriptor %d 0 R\n"
                                  "   /W [0 [",
                                  cidfont_dict.id,
+				 tag,
                                  subset.base_font,
                                  descriptor.id);
 
@@ -3733,10 +3828,11 @@ _cairo_pdf_surface_emit_truetype_font_subset (cairo_pdf_surface_t		*surface,
 				 "%d 0 obj\n"
 				 "<< /Type /Font\n"
 				 "   /Subtype /Type0\n"
-				 "   /BaseFont /%s\n"
+				 "   /BaseFont /%s+%s\n"
                                  "   /Encoding /Identity-H\n"
 				 "   /DescendantFonts [ %d 0 R]\n",
 				 subset_resource.id,
+				 tag,
 				 subset.base_font,
 				 cidfont_dict.id);
 


More information about the cairo-commit mailing list