[cairo-commit] src/cairo-svg-surface.c test/6x13.pcf

Carl Worth cworth at kemper.freedesktop.org
Tue Jun 20 17:19:56 PDT 2006


 src/cairo-svg-surface.c |   87 ++++++++++++++++++++++++++++++++++--------------
 test/6x13.pcf           |binary
 2 files changed, 63 insertions(+), 24 deletions(-)

New commits:
diff-tree ab8ae66f9d5c92af96b4a530957537ec7d33c128 (from 2f43a79e4e87341dd0df49fc6c11fd17a21350c2)
Author: Carl Worth <cworth at cworth.org>
Date:   Tue Jun 20 17:15:07 2006 -0700

    SVG: Fix to not crash on bitmapped glyphs
    
    This is similar to a change that was recently made to the PDF and PS backends.
    Bitmap glyphs are not yet drawn correctly, (drawn as filled rectangles instead),
    but the crash is at least eliminated.

diff --git a/src/cairo-svg-surface.c b/src/cairo-svg-surface.c
index 9a3bda4..83d42c2 100644
--- a/src/cairo-svg-surface.c
+++ b/src/cairo-svg-surface.c
@@ -501,6 +501,60 @@ emit_path (cairo_output_stream_t *output
     return status;
 }
 
+static cairo_int_status_t
+_cairo_svg_document_emit_outline_glyph_data (cairo_svg_document_t	*document,
+					     cairo_scaled_font_t	*scaled_font,
+					     unsigned long		 glyph_index)
+{
+    cairo_scaled_glyph_t *scaled_glyph;
+    cairo_int_status_t status;
+
+    status = _cairo_scaled_glyph_lookup (scaled_font,
+					 glyph_index,
+					 CAIRO_SCALED_GLYPH_INFO_METRICS|
+					 CAIRO_SCALED_GLYPH_INFO_PATH,
+					 &scaled_glyph);
+    if (status)
+	return status;
+
+    _cairo_output_stream_printf (document->xml_node_glyphs,
+				 "<path style=\"stroke: none;\" ");
+
+    status = emit_path (document->xml_node_glyphs, scaled_glyph->path, NULL);
+
+    _cairo_output_stream_printf (document->xml_node_glyphs,
+				 "/>\n");
+
+    return status;
+}
+
+static cairo_int_status_t
+_cairo_svg_document_emit_bitmap_glyph_data (cairo_svg_document_t	*document,
+					    cairo_scaled_font_t		*scaled_font,
+					    unsigned long		 glyph_index)
+{
+    cairo_scaled_glyph_t *scaled_glyph;
+    cairo_status_t status;
+
+    status = _cairo_scaled_glyph_lookup (scaled_font,
+					 glyph_index,
+					 CAIRO_SCALED_GLYPH_INFO_METRICS|
+					 CAIRO_SCALED_GLYPH_INFO_SURFACE,
+					 &scaled_glyph);
+    if (status)
+	return status;
+
+    /* XXX: Should be painting the surface from scaled_glyph here, not just a filled rectangle. */
+    _cairo_output_stream_printf (document->xml_node_glyphs,
+				 "<rect style=\"stroke: none;\" x=\"%f\" y=\"%f\" width=\"%f\" height=\"%f\"/>\n",
+				 _cairo_fixed_to_double (scaled_glyph->bbox.p1.x),
+				 _cairo_fixed_to_double (scaled_glyph->bbox.p1.y),
+				 _cairo_fixed_to_double (scaled_glyph->bbox.p2.x) - _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.p1.y));
+
+    return CAIRO_STATUS_SUCCESS;
+}
+
 static void
 _cairo_svg_document_emit_glyph (cairo_svg_document_t	*document,
 				cairo_scaled_font_t	*scaled_font,
@@ -508,37 +562,22 @@ _cairo_svg_document_emit_glyph (cairo_sv
 				unsigned int		 font_id,
 				unsigned int		 subset_glyph_index)
 {
-    cairo_scaled_glyph_t    *scaled_glyph;
     cairo_status_t	     status;
 
-    status = _cairo_scaled_glyph_lookup (scaled_font,
-					 scaled_font_glyph_index,
-					 CAIRO_SCALED_GLYPH_INFO_METRICS|
-					 CAIRO_SCALED_GLYPH_INFO_PATH,
-					 &scaled_glyph);
-    /*
-     * If that fails, try again but ask for an image instead
-     */
-    if (status)
-	status = _cairo_scaled_glyph_lookup (scaled_font,
-					     scaled_font_glyph_index,
-					     CAIRO_SCALED_GLYPH_INFO_METRICS|
-					     CAIRO_SCALED_GLYPH_INFO_SURFACE,
-					     &scaled_glyph);
-    if (status) {
-	_cairo_surface_set_error (document->owner, status);
-	return;
-    }
-
     _cairo_output_stream_printf (document->xml_node_glyphs,
- 				 "<symbol id=\"glyph%d-%d\">\n"
- 				 "<path style=\"stroke: none;\" ",
+				 "<symbol id=\"glyph%d-%d\">\n",
  				 font_id,
  				 subset_glyph_index);
 
-    status = emit_path (document->xml_node_glyphs, scaled_glyph->path, NULL);
+    status = _cairo_svg_document_emit_outline_glyph_data (document,
+							  scaled_font,
+							  scaled_font_glyph_index);
+    if (status == CAIRO_INT_STATUS_UNSUPPORTED)
+	status = _cairo_svg_document_emit_bitmap_glyph_data (document,
+							     scaled_font,
+							     scaled_font_glyph_index);
 
-    _cairo_output_stream_printf (document->xml_node_glyphs, "/>\n</symbol>\n");
+    _cairo_output_stream_printf (document->xml_node_glyphs, "</symbol>\n");
 }
 
 static void
diff --git a/test/6x13.pcf b/test/6x13.pcf
new file mode 100644
index 0000000..e147bc6
Binary files /dev/null and b/test/6x13.pcf differ


More information about the cairo-commit mailing list