[cairo-commit] 2 commits - src/cairo-pdf-surface.c

Carl Worth cworth at kemper.freedesktop.org
Wed Jun 21 17:28:23 PDT 2006


 src/cairo-pdf-surface.c |   79 ++++++++++++++++++++++++++++++++++--------------
 1 files changed, 57 insertions(+), 22 deletions(-)

New commits:
diff-tree 25e0acfee0ae790329c2f558ce6a9f997eeace6d (from b4720ca51d4b1de02d6beb898b7d04a33e1d99fd)
Author: Carl Worth <cworth at cworth.org>
Date:   Wed Jun 21 17:23:35 2006 -0700

    PDF: Fix display of bitmapped glyphs (bitmap-font test now passes)

diff --git a/src/cairo-pdf-surface.c b/src/cairo-pdf-surface.c
index ca93634..039e362 100644
--- a/src/cairo-pdf-surface.c
+++ b/src/cairo-pdf-surface.c
@@ -1845,6 +1845,9 @@ _cairo_pdf_surface_emit_bitmap_glyph (ca
 {
     cairo_scaled_glyph_t *scaled_glyph;
     cairo_status_t status;
+    cairo_image_surface_t *image;
+    unsigned char *row, *byte;
+    int rows, cols, bytes_per_row;
 
     status = _cairo_scaled_glyph_lookup (scaled_font,
 					 glyph_index,
@@ -1854,6 +1857,9 @@ _cairo_pdf_surface_emit_bitmap_glyph (ca
     if (status)
 	return status;
 
+    image = scaled_glyph->surface;
+    assert (image->format == CAIRO_FORMAT_A1);
+
     *glyph_ret = _cairo_pdf_surface_open_stream (surface, NULL);
 
     _cairo_output_stream_printf (surface->output,
@@ -1863,13 +1869,34 @@ _cairo_pdf_surface_emit_bitmap_glyph (ca
 				 _cairo_fixed_to_double (scaled_glyph->bbox.p2.x),
 				 - _cairo_fixed_to_double (scaled_glyph->bbox.p1.y));
 
-    /* XXX: Should be painting the surface from scaled_glyph here, not just a filled rectangle. */
     _cairo_output_stream_printf (surface->output,
-				 "%f %f %f %f re f\r\n",
-				 _cairo_fixed_to_double (scaled_glyph->bbox.p1.x),
-				 - _cairo_fixed_to_double (scaled_glyph->bbox.p2.y),
+				 "%f 0.0 0.0 %f %f %f cm\r\n",
 				 _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.p1.y) - _cairo_fixed_to_double (scaled_glyph->bbox.p2.y));
+				 _cairo_fixed_to_double (scaled_glyph->bbox.p1.y) - _cairo_fixed_to_double (scaled_glyph->bbox.p2.y),
+				 _cairo_fixed_to_double (scaled_glyph->bbox.p1.x),
+				 _cairo_fixed_to_double (scaled_glyph->bbox.p2.y));
+
+    _cairo_output_stream_printf (surface->output,
+				 "BI\r\n"
+				 "/IM true\r\n"
+				 "/W %d\r\n"
+				 "/H %d\r\n"
+				 "/BPC 1\r\n"
+				 "/D [1 0]\r\n",
+				 image->width,
+				 image->height);
+
+    _cairo_output_stream_printf (surface->output,
+				 "ID ");
+    bytes_per_row = (image->width + 7) / 8;
+    for (row = image->data, rows = image->height; rows; row += image->stride, rows--) {
+	for (byte = row, cols = (image->width + 7) / 8; cols; byte++, cols--) {
+	    unsigned char output_byte = CAIRO_BITSWAP8_IF_LITTLE_ENDIAN (*byte);
+	    _cairo_output_stream_write (surface->output, &output_byte, 1);
+	}
+    }
+    _cairo_output_stream_printf (surface->output,
+				 "\r\nEI\r\n");
 
     _cairo_pdf_surface_close_stream (surface);
 
diff-tree b4720ca51d4b1de02d6beb898b7d04a33e1d99fd (from 83a8a50735746a4591c3bcc1aaa46fb7a0f87224)
Author: Carl Worth <cworth at cworth.org>
Date:   Tue Jun 20 23:12:58 2006 -0700

    PDF: Push glyph stream creation down from emit glyph to outline/bitmap variants

diff --git a/src/cairo-pdf-surface.c b/src/cairo-pdf-surface.c
index 8f7194a..ca93634 100644
--- a/src/cairo-pdf-surface.c
+++ b/src/cairo-pdf-surface.c
@@ -1792,13 +1792,14 @@ _cairo_pdf_surface_emit_truetype_font_su
 }
 
 static cairo_int_status_t
-_cairo_pdf_surface_emit_outline_glyph_data (cairo_pdf_surface_t	*surface,
-					    cairo_scaled_font_t	*scaled_font,
-					    unsigned long	 glyph_index)
+_cairo_pdf_surface_emit_outline_glyph (cairo_pdf_surface_t	*surface,
+				       cairo_scaled_font_t	*scaled_font,
+				       unsigned long		 glyph_index,
+				       cairo_pdf_resource_t	*glyph_ret)
 {
     cairo_scaled_glyph_t *scaled_glyph;
     pdf_path_info_t info;
-    cairo_status_t status;
+    cairo_status_t status = CAIRO_STATUS_SUCCESS;
 
     status = _cairo_scaled_glyph_lookup (scaled_font,
 					 glyph_index,
@@ -1808,6 +1809,8 @@ _cairo_pdf_surface_emit_outline_glyph_da
     if (status)
 	return status;
 
+    *glyph_ret = _cairo_pdf_surface_open_stream (surface, NULL);
+
     _cairo_output_stream_printf (surface->output,
 				 "0 0 %f %f %f %f d1\r\n",
 				 _cairo_fixed_to_double (scaled_glyph->bbox.p1.x),
@@ -1829,13 +1832,16 @@ _cairo_pdf_surface_emit_outline_glyph_da
     _cairo_output_stream_printf (surface->output,
 				 " f");
 
+    _cairo_pdf_surface_close_stream (surface);
+
     return CAIRO_STATUS_SUCCESS;
 }
 
 static cairo_int_status_t
-_cairo_pdf_surface_emit_bitmap_glyph_data (cairo_pdf_surface_t	*surface,
-					   cairo_scaled_font_t	*scaled_font,
-					   unsigned long	 glyph_index)
+_cairo_pdf_surface_emit_bitmap_glyph (cairo_pdf_surface_t	*surface,
+				      cairo_scaled_font_t	*scaled_font,
+				      unsigned long		 glyph_index,
+				      cairo_pdf_resource_t	*glyph_ret)
 {
     cairo_scaled_glyph_t *scaled_glyph;
     cairo_status_t status;
@@ -1848,6 +1854,8 @@ _cairo_pdf_surface_emit_bitmap_glyph_dat
     if (status)
 	return status;
 
+    *glyph_ret = _cairo_pdf_surface_open_stream (surface, NULL);
+
     _cairo_output_stream_printf (surface->output,
 				 "0 0 %f %f %f %f d1\r\n",
 				 _cairo_fixed_to_double (scaled_glyph->bbox.p1.x),
@@ -1863,6 +1871,8 @@ _cairo_pdf_surface_emit_bitmap_glyph_dat
 				 _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.p1.y) - _cairo_fixed_to_double (scaled_glyph->bbox.p2.y));
 
+    _cairo_pdf_surface_close_stream (surface);
+
     return CAIRO_STATUS_SUCCESS;
 }
 
@@ -1874,17 +1884,15 @@ _cairo_pdf_surface_emit_glyph (cairo_pdf
 {
     cairo_status_t status;
 
-    *glyph_ret = _cairo_pdf_surface_open_stream (surface, NULL);
-
-    status = _cairo_pdf_surface_emit_outline_glyph_data (surface,
-							 scaled_font,
-							 glyph_index);
+    status = _cairo_pdf_surface_emit_outline_glyph (surface,
+						    scaled_font,
+						    glyph_index,
+						    glyph_ret);
     if (status == CAIRO_INT_STATUS_UNSUPPORTED)
-	status = _cairo_pdf_surface_emit_bitmap_glyph_data (surface,
-							    scaled_font,
-							    glyph_index);
-
-    _cairo_pdf_surface_close_stream (surface);
+	status = _cairo_pdf_surface_emit_bitmap_glyph (surface,
+						       scaled_font,
+						       glyph_index,
+						       glyph_ret);
 
     if (status)
 	_cairo_surface_set_error (&surface->base, status);


More information about the cairo-commit mailing list