[cairo-commit] 5 commits - src/cairo-ps-surface.c

Adrian Johnson ajohnson at kemper.freedesktop.org
Thu Nov 29 05:08:44 PST 2007


 src/cairo-ps-surface.c |   76 +++++++++++++++++++++++++++++++------------------
 1 file changed, 49 insertions(+), 27 deletions(-)

New commits:
commit f4b93cceb7fb83de558ed058915f92d4f75c1a6a
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Thu Nov 29 23:18:45 2007 +1030

    PS: Use correct glyphs widths for Type 3 fonts
    
    Previously the widths were set to 0.

diff --git a/src/cairo-ps-surface.c b/src/cairo-ps-surface.c
index 17fc225..8dac043 100644
--- a/src/cairo-ps-surface.c
+++ b/src/cairo-ps-surface.c
@@ -611,6 +611,7 @@ _cairo_ps_surface_emit_bitmap_glyph_data (cairo_ps_surface_t	*surface,
     cairo_image_surface_t *image;
     unsigned char *row, *byte;
     int rows, cols;
+    double x_advance, y_advance;
 
     status = _cairo_scaled_glyph_lookup (scaled_font,
 					 glyph_index,
@@ -620,6 +621,10 @@ _cairo_ps_surface_emit_bitmap_glyph_data (cairo_ps_surface_t	*surface,
     if (status)
 	return status;
 
+    x_advance = scaled_glyph->metrics.x_advance;
+    y_advance = scaled_glyph->metrics.y_advance;
+    cairo_matrix_transform_distance (&scaled_font->ctm, &x_advance, &y_advance);
+
     image = scaled_glyph->surface;
     if (image->format != CAIRO_FORMAT_A1) {
 	image = _cairo_image_surface_clone (image, CAIRO_FORMAT_A1);
@@ -628,7 +633,8 @@ _cairo_ps_surface_emit_bitmap_glyph_data (cairo_ps_surface_t	*surface,
     }
 
     _cairo_output_stream_printf (surface->final_stream,
-				 "0 0 %f %f %f %f setcachedevice\n",
+				 "%f 0 %f %f %f %f setcachedevice\n",
+				 x_advance,
 				 _cairo_fixed_to_double (scaled_glyph->bbox.p1.x),
 				 _cairo_fixed_to_double (scaled_glyph->bbox.p2.y),
 				 _cairo_fixed_to_double (scaled_glyph->bbox.p2.x),
commit 2729af6c123983c1599fae9f7a0fac88ad320d7c
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Thu Nov 29 23:07:47 2007 +1030

    PS: Fix the Type 3 FontBBox
    
    This was previously a fixed size. Make it [0 0 0 0] the same as the
    other fonts.

diff --git a/src/cairo-ps-surface.c b/src/cairo-ps-surface.c
index 9823fb3..17fc225 100644
--- a/src/cairo-ps-surface.c
+++ b/src/cairo-ps-surface.c
@@ -727,7 +727,7 @@ _cairo_ps_surface_emit_type3_font_subset (cairo_ps_surface_t		*surface,
 				 "8 dict begin\n"
 				 "/FontType 3 def\n"
 				 "/FontMatrix [%f %f %f %f 0 0] def\n"
-				 "/FontBBox [0 0 10 10] def\n"
+				 "/FontBBox [0 0 0 0] def\n"
 				 "/Encoding 256 array def\n"
 				 "0 1 255 { Encoding exch /.notdef put } for\n",
 				 matrix.xx,
commit 77aab8fdbb62e4e0ec0260651db7255d168cb25e
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Thu Nov 29 23:03:40 2007 +1030

    PS: Don't emit an image for Type 3 .notdef glyph
    
    Make the .notdef procedure an empty procedure instead
    of creating an empty image mask. This reduced the size
    of the PS file.

diff --git a/src/cairo-ps-surface.c b/src/cairo-ps-surface.c
index 7d370b5..9823fb3 100644
--- a/src/cairo-ps-surface.c
+++ b/src/cairo-ps-surface.c
@@ -680,18 +680,20 @@ _cairo_ps_surface_emit_glyph (cairo_ps_surface_t	*surface,
 			      unsigned long		 scaled_font_glyph_index,
 			      unsigned int		 subset_glyph_index)
 {
-    cairo_status_t	    status;
+    cairo_status_t	    status = CAIRO_STATUS_SUCCESS;
 
     _cairo_output_stream_printf (surface->final_stream,
 				 "\t\t{ %% %d\n", subset_glyph_index);
 
-    status = _cairo_ps_surface_emit_outline_glyph_data (surface,
-							scaled_font,
-							scaled_font_glyph_index);
-    if (status == CAIRO_INT_STATUS_UNSUPPORTED)
-	status = _cairo_ps_surface_emit_bitmap_glyph_data (surface,
-							   scaled_font,
-							   scaled_font_glyph_index);
+    if (subset_glyph_index != 0) {
+	status = _cairo_ps_surface_emit_outline_glyph_data (surface,
+							    scaled_font,
+							    scaled_font_glyph_index);
+	if (status == CAIRO_INT_STATUS_UNSUPPORTED)
+	    status = _cairo_ps_surface_emit_bitmap_glyph_data (surface,
+							       scaled_font,
+							       scaled_font_glyph_index);
+    }
 
     _cairo_output_stream_printf (surface->final_stream,
 				 "\t\t}\n");
commit 78e8d3d9bd2d4652f636a668a3fa53ef9edfd9ae
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Thu Nov 29 22:54:54 2007 +1030

    PS: Fix the bounding boxes of Type 3 glyphs
    
    When viewing with ghostscript the glyphs were clipped

diff --git a/src/cairo-ps-surface.c b/src/cairo-ps-surface.c
index d15a64d..7d370b5 100644
--- a/src/cairo-ps-surface.c
+++ b/src/cairo-ps-surface.c
@@ -630,9 +630,9 @@ _cairo_ps_surface_emit_bitmap_glyph_data (cairo_ps_surface_t	*surface,
     _cairo_output_stream_printf (surface->final_stream,
 				 "0 0 %f %f %f %f setcachedevice\n",
 				 _cairo_fixed_to_double (scaled_glyph->bbox.p1.x),
-				 - _cairo_fixed_to_double (scaled_glyph->bbox.p2.y),
+				 _cairo_fixed_to_double (scaled_glyph->bbox.p2.y),
 				 _cairo_fixed_to_double (scaled_glyph->bbox.p2.x),
-				 - _cairo_fixed_to_double (scaled_glyph->bbox.p1.y));
+				 _cairo_fixed_to_double (scaled_glyph->bbox.p1.y));
 
     _cairo_output_stream_printf (surface->final_stream,
 				 "<<\n"
commit 97b0d8b3c376f7848514debbe0697a2159a26eb9
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Thu Nov 29 22:36:07 2007 +1030

    PS: Make Type 3 fonts text selectable
    
    Put the glyph names in the Encoding array the same as is done for
    Type 1 and Type42 fonts.
    
    Acroread and Evince are still unable to correctly extract the text
    after conversion with ps2pdf. However examining the pdf file shows
    the glyph names are correct so this is probably a limitation of
    Acroread and Evince.

diff --git a/src/cairo-ps-surface.c b/src/cairo-ps-surface.c
index 0a0f841..d15a64d 100644
--- a/src/cairo-ps-surface.c
+++ b/src/cairo-ps-surface.c
@@ -717,26 +717,36 @@ _cairo_ps_surface_emit_type3_font_subset (cairo_ps_surface_t		*surface,
 				 "%% _cairo_ps_surface_emit_type3_font_subset\n");
 #endif
 
-    _cairo_output_stream_printf (surface->final_stream,
-				 "/CairoFont-%d-%d <<\n",
-				 font_subset->font_id,
-				 font_subset->subset_id);
-
     matrix = font_subset->scaled_font->scale;
     status = cairo_matrix_invert (&matrix);
     /* _cairo_scaled_font_init ensures the matrix is invertible */
     assert (status == CAIRO_STATUS_SUCCESS);
     _cairo_output_stream_printf (surface->final_stream,
-				 "\t/FontType\t3\n"
-				 "\t/FontMatrix\t[%f %f %f %f 0 0]\n"
-				 "\t/Encoding\t[0]\n"
-				 "\t/FontBBox\t[0 0 10 10]\n"
-				 "\t/Glyphs [\n",
+				 "8 dict begin\n"
+				 "/FontType 3 def\n"
+				 "/FontMatrix [%f %f %f %f 0 0] def\n"
+				 "/FontBBox [0 0 10 10] def\n"
+				 "/Encoding 256 array def\n"
+				 "0 1 255 { Encoding exch /.notdef put } for\n",
 				 matrix.xx,
 				 matrix.yx,
 				 -matrix.xy,
 				 -matrix.yy);
 
+    for (i = 1; i < font_subset->num_glyphs; i++) {
+	if (font_subset->glyph_names != NULL) {
+	    _cairo_output_stream_printf (surface->final_stream,
+					 "Encoding %d /%s put\n",
+					 i, font_subset->glyph_names[i]);
+	} else {
+	    _cairo_output_stream_printf (surface->final_stream,
+					 "Encoding %d /g%d put\n", i, i);
+	}
+    }
+
+    _cairo_output_stream_printf (surface->final_stream,
+				 "/Glyphs [\n");
+
     for (i = 0; i < font_subset->num_glyphs; i++) {
 	status = _cairo_ps_surface_emit_glyph (surface,
 				               font_subset->scaled_font,
@@ -746,12 +756,16 @@ _cairo_ps_surface_emit_type3_font_subset (cairo_ps_surface_t		*surface,
     }
 
     _cairo_output_stream_printf (surface->final_stream,
-				 "\t]\n"
-				 "\t/BuildChar {\n"
-				 "\t\texch /Glyphs get\n"
-				 "\t\texch get exec\n"
-				 "\t}\n"
-				 ">> definefont pop\n");
+				 "] def\n"
+				 "/BuildChar {\n"
+				 "  exch /Glyphs get\n"
+				 "  exch get exec\n"
+				 "} bind def\n"
+				 "currentdict\n"
+				 "end\n"
+				 "/CairoFont-%d-%d exch definefont pop\n",
+				 font_subset->font_id,
+				 font_subset->subset_id);
 
     return CAIRO_STATUS_SUCCESS;
 }


More information about the cairo-commit mailing list