[cairo-commit] src/cairo-pdf-surface.c src/cairo-ps-surface.c src/cairo-scaled-font-subsets.c src/cairo-type3-glyph-surface.c src/cairo-type3-glyph-surface-private.h

Adrian Johnson ajohnson at kemper.freedesktop.org
Wed Oct 22 04:31:30 PDT 2008


 src/cairo-pdf-surface.c                 |   19 +++-------
 src/cairo-ps-surface.c                  |   21 +++--------
 src/cairo-scaled-font-subsets.c         |   59 ++++++++++++++++++--------------
 src/cairo-type3-glyph-surface-private.h |    6 ---
 src/cairo-type3-glyph-surface.c         |   16 --------
 5 files changed, 48 insertions(+), 73 deletions(-)

New commits:
commit 5e4a1cb0b830f069d99c9512563c82ad628587e3
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Wed Oct 22 21:36:42 2008 +1030

    Don't add a notdef glyph to Type 3 font subsets
    
    This allows user-fonts to use glyph 0 when embedding in PS/PDF.
    According to ISO32000 Type 3 fonts do not require a notdef glyph.

diff --git a/src/cairo-pdf-surface.c b/src/cairo-pdf-surface.c
index 2823508..44f0ed8 100644
--- a/src/cairo-pdf-surface.c
+++ b/src/cairo-pdf-surface.c
@@ -3513,7 +3513,7 @@ _cairo_pdf_surface_analyze_user_font_subset (cairo_scaled_font_subset_t *font_su
 							  _cairo_pdf_surface_add_font,
 							  surface);
 
-    for (i = 1; i < font_subset->num_glyphs; i++) {
+    for (i = 0; i < font_subset->num_glyphs; i++) {
 	status = _cairo_type3_glyph_surface_analyze_glyph (type3_surface,
 							   font_subset->glyphs[i]);
 	if (status)
@@ -3578,18 +3578,11 @@ _cairo_pdf_surface_emit_type3_font_subset (cairo_pdf_surface_t		*surface,
 	    break;
 
 	glyphs[i] = surface->pdf_stream.self;
-	if (i == 0) {
-	    status = _cairo_type3_glyph_surface_emit_notdef_glyph (type3_surface,
-								   surface->output,
-								   &bbox,
-								   &widths[i]);
-	} else {
-	    status = _cairo_type3_glyph_surface_emit_glyph (type3_surface,
-							    surface->output,
-							    font_subset->glyphs[i],
-							    &bbox,
-							    &widths[i]);
-	}
+	status = _cairo_type3_glyph_surface_emit_glyph (type3_surface,
+							surface->output,
+							font_subset->glyphs[i],
+							&bbox,
+							&widths[i]);
 	if (status)
 	    break;
 
diff --git a/src/cairo-ps-surface.c b/src/cairo-ps-surface.c
index 816f0ea..bfe424d 100644
--- a/src/cairo-ps-surface.c
+++ b/src/cairo-ps-surface.c
@@ -455,7 +455,7 @@ _cairo_ps_surface_analyze_user_font_subset (cairo_scaled_font_subset_t *font_sub
 						       _cairo_ps_emit_imagemask,
 						       surface->font_subsets);
 
-    for (i = 1; i < font_subset->num_glyphs; i++) {
+    for (i = 0; i < font_subset->num_glyphs; i++) {
 	status = _cairo_type3_glyph_surface_analyze_glyph (type3_surface,
 							   font_subset->glyphs[i]);
 	if (status)
@@ -500,7 +500,7 @@ _cairo_ps_surface_emit_type3_font_subset (cairo_ps_surface_t		*surface,
 						       _cairo_ps_emit_imagemask,
 						       surface->font_subsets);
 
-    for (i = 1; i < font_subset->num_glyphs; i++) {
+    for (i = 0; i < font_subset->num_glyphs; i++) {
 	if (font_subset->glyph_names != NULL) {
 	    _cairo_output_stream_printf (surface->final_stream,
 					 "Encoding %d /%s put\n",
@@ -517,18 +517,11 @@ _cairo_ps_surface_emit_type3_font_subset (cairo_ps_surface_t		*surface,
     for (i = 0; i < font_subset->num_glyphs; i++) {
 	_cairo_output_stream_printf (surface->final_stream,
 				     "    { %% %d\n", i);
-	if (i == 0) {
-	    status = _cairo_type3_glyph_surface_emit_notdef_glyph (type3_surface,
-								   surface->final_stream,
-								   &bbox,
-								   &width);
-	} else {
-	    status = _cairo_type3_glyph_surface_emit_glyph (type3_surface,
-							    surface->final_stream,
-							    font_subset->glyphs[i],
-							    &bbox,
-							    &width);
-	}
+	status = _cairo_type3_glyph_surface_emit_glyph (type3_surface,
+							surface->final_stream,
+							font_subset->glyphs[i],
+							&bbox,
+							&width);
 	if (status)
 	    break;
 
diff --git a/src/cairo-scaled-font-subsets.c b/src/cairo-scaled-font-subsets.c
index f5212d7..066f637 100644
--- a/src/cairo-scaled-font-subsets.c
+++ b/src/cairo-scaled-font-subsets.c
@@ -290,12 +290,15 @@ _cairo_sub_font_create (cairo_scaled_font_subsets_t	*parent,
     }
     sub_font->next = NULL;
 
-    /* Reserve first glyph in subset for the .notdef glyph */
-    status = _cairo_sub_font_map_glyph (sub_font, 0, NULL, -1, &subset_glyph);
-    if (status) {
-	_cairo_hash_table_destroy (sub_font->sub_font_glyphs);
-	free (sub_font);
-	return status;
+    /* Reserve first glyph in subset for the .notdef glyph except for
+     * Type 3 fonts */
+    if (! _cairo_font_face_is_user (scaled_font->font_face)) {
+	status = _cairo_sub_font_map_glyph (sub_font, 0, NULL, -1, &subset_glyph);
+	if (status) {
+	    _cairo_hash_table_destroy (sub_font->sub_font_glyphs);
+	    free (sub_font);
+	    return status;
+	}
     }
 
     *sub_font_out = sub_font;
@@ -459,10 +462,13 @@ _cairo_sub_font_map_glyph (cairo_sub_font_t	*sub_font,
 	    sub_font->current_subset++;
 	    sub_font->num_glyphs_in_current_subset = 0;
 
-	    /* Reserve first glyph in subset for the .notdef glyph */
-	    status = _cairo_sub_font_map_glyph (sub_font, 0, NULL, -1, &tmp_subset_glyph);
-	    if (status)
-		return status;
+	    /* Reserve first glyph in subset for the .notdef glyph
+	     * except for Type 3 fonts */
+	    if (! _cairo_font_face_is_user (sub_font->scaled_font->font_face)) {
+		status = _cairo_sub_font_map_glyph (sub_font, 0, NULL, -1, &tmp_subset_glyph);
+		if (status)
+		    return status;
+	    }
 	}
 
 	_cairo_scaled_font_freeze_cache (sub_font->scaled_font);
@@ -705,7 +711,8 @@ _cairo_scaled_font_subsets_map_glyph (cairo_scaled_font_subsets_t	*subsets,
      * _scaled_glyph_lookup(_GLYPH_INFO_PATH). Type1-fallback creates
      * empty glyphs in this case so we can put the glyph in a unscaled
      * subset. */
-    if (scaled_font_glyph_index == 0) {
+    if (scaled_font_glyph_index == 0 ||
+	_cairo_font_face_is_user (scaled_font->font_face)) {
 	status = CAIRO_STATUS_SUCCESS;
     } else {
 	_cairo_scaled_font_freeze_cache (scaled_font);
@@ -980,23 +987,27 @@ _cairo_scaled_font_subset_create_glyph_names (cairo_scaled_font_subset_t *subset
 	goto CLEANUP_HASH;
     }
 
-    subset->glyph_names[0] = strdup (".notdef");
-    if (subset->glyph_names[0] == NULL) {
-	status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
-	goto CLEANUP_HASH;
-    }
+    i = 0;
+    if (! _cairo_font_face_is_user (subset->scaled_font->font_face)) {
+	subset->glyph_names[0] = strdup (".notdef");
+	if (subset->glyph_names[0] == NULL) {
+	    status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
+	    goto CLEANUP_HASH;
+	}
 
-    status = create_string_entry (subset->glyph_names[0], &entry);
-    if (status)
-	goto CLEANUP_HASH;
+	status = create_string_entry (subset->glyph_names[0], &entry);
+	if (status)
+	    goto CLEANUP_HASH;
 
-    status = _cairo_hash_table_insert (names, &entry->base);
-    if (status) {
-	free (entry);
-	goto CLEANUP_HASH;
+	status = _cairo_hash_table_insert (names, &entry->base);
+	if (status) {
+	    free (entry);
+	    goto CLEANUP_HASH;
+	}
+	i++;
     }
 
-    for (i = 1; i < subset->num_glyphs; i++) {
+    for (; i < subset->num_glyphs; i++) {
 	utf8 = subset->utf8[i];
 	utf16 = NULL;
 	utf16_len = 0;
diff --git a/src/cairo-type3-glyph-surface-private.h b/src/cairo-type3-glyph-surface-private.h
index 9dd6e85..33314ae 100644
--- a/src/cairo-type3-glyph-surface-private.h
+++ b/src/cairo-type3-glyph-surface-private.h
@@ -73,12 +73,6 @@ _cairo_type3_glyph_surface_analyze_glyph (void		     *abstract_surface,
 					  unsigned long	      glyph_index);
 
 cairo_private cairo_status_t
-_cairo_type3_glyph_surface_emit_notdef_glyph (void		    *abstract_surface,
-					      cairo_output_stream_t *stream,
-					      cairo_box_t           *bbox,
-					      double                *width);
-
-cairo_private cairo_status_t
 _cairo_type3_glyph_surface_emit_glyph (void		     *abstract_surface,
 				       cairo_output_stream_t *stream,
 				       unsigned long	      glyph_index,
diff --git a/src/cairo-type3-glyph-surface.c b/src/cairo-type3-glyph-surface.c
index ed8fff7..c84f5f0 100644
--- a/src/cairo-type3-glyph-surface.c
+++ b/src/cairo-type3-glyph-surface.c
@@ -435,22 +435,6 @@ cleanup:
 }
 
 cairo_status_t
-_cairo_type3_glyph_surface_emit_notdef_glyph (void		    *abstract_surface,
-					      cairo_output_stream_t *stream,
-					      cairo_box_t           *bbox,
-					      double                *width)
-{
-    bbox->p1.x = 0;
-    bbox->p1.y = 0;
-    bbox->p2.x = 0;
-    bbox->p2.y = 0;
-    *width = 0.0;
-    _cairo_output_stream_printf (stream, "0 0 0 0 0 0 d1\n");
-
-    return CAIRO_STATUS_SUCCESS;
-}
-
-cairo_status_t
 _cairo_type3_glyph_surface_emit_glyph (void		     *abstract_surface,
 				       cairo_output_stream_t *stream,
 				       unsigned long	      glyph_index,


More information about the cairo-commit mailing list