[cairo-commit] Branch '1.4' - 6 commits - src/cairo-ps-surface.c src/cairo-type1-fallback.c

Adrian Johnson ajohnson at kemper.freedesktop.org
Wed Dec 12 04:47:06 PST 2007


 src/cairo-ps-surface.c     |   95 ++++++++++++++++++++++++++++++++-------------
 src/cairo-type1-fallback.c |    6 +-
 2 files changed, 73 insertions(+), 28 deletions(-)

New commits:
commit cd0ea998b6bb0fb2dc93df83ca7ce5fd7517212a
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Wed Dec 12 22:52:10 2007 +1030

    PS: Use the correct bounding box in Type 3 fonts
    
    Previously this was a fixed size.

diff --git a/src/cairo-ps-surface.c b/src/cairo-ps-surface.c
index d70b254..271fe2d 100644
--- a/src/cairo-ps-surface.c
+++ b/src/cairo-ps-surface.c
@@ -499,7 +499,8 @@ _cairo_ps_surface_emit_truetype_font_subset (cairo_ps_surface_t		*surface,
 static cairo_int_status_t
 _cairo_ps_surface_emit_outline_glyph_data (cairo_ps_surface_t	*surface,
 					   cairo_scaled_font_t	*scaled_font,
-					   unsigned long	 glyph_index)
+					   unsigned long	 glyph_index,
+					   cairo_box_t          *bbox)
 {
     cairo_scaled_glyph_t *scaled_glyph;
     cairo_status_t status;
@@ -512,6 +513,7 @@ _cairo_ps_surface_emit_outline_glyph_data (cairo_ps_surface_t	*surface,
     if (status)
 	return status;
 
+    *bbox = scaled_glyph->bbox;
     _cairo_output_stream_printf (surface->final_stream,
 				 "0 0 %f %f %f %f setcachedevice\n",
 				 _cairo_fixed_to_double (scaled_glyph->bbox.p1.x),
@@ -534,7 +536,8 @@ _cairo_ps_surface_emit_outline_glyph_data (cairo_ps_surface_t	*surface,
 static cairo_int_status_t
 _cairo_ps_surface_emit_bitmap_glyph_data (cairo_ps_surface_t	*surface,
 					  cairo_scaled_font_t	*scaled_font,
-					  unsigned long	 glyph_index)
+					  unsigned long	 glyph_index,
+					  cairo_box_t           *bbox)
 {
     cairo_scaled_glyph_t *scaled_glyph;
     cairo_status_t status;
@@ -551,6 +554,7 @@ _cairo_ps_surface_emit_bitmap_glyph_data (cairo_ps_surface_t	*surface,
     if (status)
 	return status;
 
+    *bbox = scaled_glyph->bbox;
     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);
@@ -614,7 +618,8 @@ static cairo_status_t
 _cairo_ps_surface_emit_glyph (cairo_ps_surface_t	*surface,
 			      cairo_scaled_font_t	*scaled_font,
 			      unsigned long		 scaled_font_glyph_index,
-			      unsigned int		 subset_glyph_index)
+			      unsigned int		 subset_glyph_index,
+			      cairo_box_t               *bbox)
 {
     cairo_status_t	    status;
 
@@ -623,11 +628,13 @@ _cairo_ps_surface_emit_glyph (cairo_ps_surface_t	*surface,
 
     status = _cairo_ps_surface_emit_outline_glyph_data (surface,
 							scaled_font,
-							scaled_font_glyph_index);
+							scaled_font_glyph_index,
+							bbox);
     if (status == CAIRO_INT_STATUS_UNSUPPORTED)
 	status = _cairo_ps_surface_emit_bitmap_glyph_data (surface,
 							   scaled_font,
-							   scaled_font_glyph_index);
+							   scaled_font_glyph_index,
+							   bbox);
 
     _cairo_output_stream_printf (surface->final_stream,
 				 "\t\t}\n");
@@ -647,6 +654,7 @@ _cairo_ps_surface_emit_type3_font_subset (cairo_ps_surface_t		*surface,
     cairo_status_t status;
     cairo_matrix_t matrix;
     unsigned int i;
+    cairo_box_t font_bbox, bbox;
 
     _cairo_output_stream_printf (surface->final_stream,
 				 "%% _cairo_ps_surface_emit_type3_font_subset\n");
@@ -659,7 +667,6 @@ _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"
 				 "/Encoding 256 array def\n"
 				 "0 1 255 { Encoding exch /.notdef put } for\n",
 				 matrix.xx,
@@ -678,13 +685,31 @@ _cairo_ps_surface_emit_type3_font_subset (cairo_ps_surface_t		*surface,
     for (i = 0; i < font_subset->num_glyphs; i++) {
 	status = _cairo_ps_surface_emit_glyph (surface,
 				               font_subset->scaled_font,
-					       font_subset->glyphs[i], i);
+					       font_subset->glyphs[i], i,
+					       &bbox);
 	if (status)
 	    return status;
+
+        if (i == 0) {
+            font_bbox.p1.x = bbox.p1.x;
+            font_bbox.p1.y = bbox.p1.y;
+            font_bbox.p2.x = bbox.p2.x;
+            font_bbox.p2.y = bbox.p2.y;
+        } else {
+            if (bbox.p1.x < font_bbox.p1.x)
+                font_bbox.p1.x = bbox.p1.x;
+            if (bbox.p1.y < font_bbox.p1.y)
+                font_bbox.p1.y = bbox.p1.y;
+            if (bbox.p2.x > font_bbox.p2.x)
+                font_bbox.p2.x = bbox.p2.x;
+            if (bbox.p2.y > font_bbox.p2.y)
+                font_bbox.p2.y = bbox.p2.y;
+        }
     }
 
     _cairo_output_stream_printf (surface->final_stream,
 				 "] def\n"
+				 "/FontBBox [%f %f %f %f] def\n"
 				 "/BuildChar {\n"
 				 "  exch /Glyphs get\n"
 				 "  exch get exec\n"
@@ -692,6 +717,10 @@ _cairo_ps_surface_emit_type3_font_subset (cairo_ps_surface_t		*surface,
 				 "currentdict\n"
 				 "end\n"
 				 "/CairoFont-%d-%d exch definefont pop\n",
+				 _cairo_fixed_to_double (font_bbox.p1.x),
+				 _cairo_fixed_to_double (font_bbox.p1.y),
+				 _cairo_fixed_to_double (font_bbox.p2.x),
+				 _cairo_fixed_to_double (font_bbox.p2.y),
 				 font_subset->font_id,
 				 font_subset->subset_id);
 
commit 5c3f22816f8324d2847b885e4c9c3e94837ce2bc
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Sun Dec 2 00:50:28 2007 +1030

    Fix regression in Type1 Fallback
    
    As a result of the changes to improve the status checking,
    _cairo_type2_charstrings_init() was failing due to the failure
    status returned when the font->output stream is destroyed.
    This is because _cairo_type2_charstrings_init() does not
    create an output stream.
    
    Fix this by initializing font->output to NULL and only
    destroy it if not NULL.
    (cherry picked from commit 1441e165f2338bc6a8e2945baca77611ff417b2f)

diff --git a/src/cairo-type1-fallback.c b/src/cairo-type1-fallback.c
index 3872777..0ad7817 100644
--- a/src/cairo-type1-fallback.c
+++ b/src/cairo-type1-fallback.c
@@ -110,6 +110,7 @@ cairo_type1_font_create (cairo_scaled_font_subset_t  *scaled_font_subset,
         goto fail;
 
     _cairo_array_init (&font->contents, sizeof (unsigned char));
+    font->output = NULL;
 
     *subset_return = font;
 
@@ -697,12 +698,13 @@ cairo_type1_font_generate (cairo_type1_font_t *font, const char *name)
 static cairo_status_t
 cairo_type1_font_destroy (cairo_type1_font_t *font)
 {
-    cairo_status_t status;
+    cairo_status_t status = CAIRO_STATUS_SUCCESS;
 
     free (font->widths);
     cairo_scaled_font_destroy (font->type1_scaled_font);
     _cairo_array_fini (&font->contents);
-    status = _cairo_output_stream_destroy (font->output);
+    if (font->output)
+	status = _cairo_output_stream_destroy (font->output);
     free (font);
 
     return status;
commit a94dc7499bd9bcff0e562bb81eba4e8c74e97163
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.
    (cherry picked from commit f4b93cceb7fb83de558ed058915f92d4f75c1a6a)

diff --git a/src/cairo-ps-surface.c b/src/cairo-ps-surface.c
index c30ff95..d70b254 100644
--- a/src/cairo-ps-surface.c
+++ b/src/cairo-ps-surface.c
@@ -541,6 +541,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,
@@ -550,6 +551,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);
@@ -558,7 +563,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 42b0552f119b4d2a29d76647eec89eb913021338
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
    (cherry picked from commit 78e8d3d9bd2d4652f636a668a3fa53ef9edfd9ae)

diff --git a/src/cairo-ps-surface.c b/src/cairo-ps-surface.c
index c48332b..c30ff95 100644
--- a/src/cairo-ps-surface.c
+++ b/src/cairo-ps-surface.c
@@ -560,9 +560,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 5d591b7649c3379a15e012ae160727853aca4b4d
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Wed Dec 12 22:27:13 2007 +1030

    PS: Fix typecheck error with Type 3 and recent versions of gs
    
    Ghostscipt requires the encoding vector to be filled in.

diff --git a/src/cairo-ps-surface.c b/src/cairo-ps-surface.c
index 30f0e71..c48332b 100644
--- a/src/cairo-ps-surface.c
+++ b/src/cairo-ps-surface.c
@@ -645,26 +645,30 @@ _cairo_ps_surface_emit_type3_font_subset (cairo_ps_surface_t		*surface,
     _cairo_output_stream_printf (surface->final_stream,
 				 "%% _cairo_ps_surface_emit_type3_font_subset\n");
 
-    _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++) {
+	_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,
@@ -674,12 +678,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;
 }
commit 9b4d39808875bb642de80ee61ab76ef83829ab3b
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Thu Nov 29 09:20:01 2007 +1030

    PS: Ensure that xyshow operator has a pair of offsets for each glyph
    
    The last entry should have been "0 0" instead of "0".
    (cherry picked from commit 5e8f60531a09f357db38c4b646b1bbd29b97a891)

diff --git a/src/cairo-ps-surface.c b/src/cairo-ps-surface.c
index 2da20d4..30f0e71 100644
--- a/src/cairo-ps-surface.c
+++ b/src/cairo-ps-surface.c
@@ -2298,7 +2298,7 @@ _cairo_ps_surface_show_glyphs (void		     *abstract_surface,
             } else {
                 for (j = i; j < last+1; j++) {
                     if (j == num_glyphs_unsigned - 1)
-                        _cairo_output_stream_printf (word_wrap, "0 ");
+                        _cairo_output_stream_printf (word_wrap, "0 0 ");
                     else
                         _cairo_output_stream_printf (word_wrap,
                                                      "%f %f ",


More information about the cairo-commit mailing list