[cairo-commit] 9 commits - configure.in pixman/src src/cairo-pdf-surface.c src/cairo-ps-surface.c src/cairo-scaled-font-subsets-private.h src/cairo-svg-surface.c test/select-font-face-pdf-argb32-ref.png

Carl Worth cworth at kemper.freedesktop.org
Mon May 15 10:26:22 PDT 2006


 configure.in                             |    2 
 pixman/src/Makefile.am                   |    4 
 pixman/src/fbpict.c                      |   17 -
 pixman/src/icimage.c                     |   66 -----
 src/cairo-pdf-surface.c                  |  380 ++++++++++++++++++++++++-------
 src/cairo-ps-surface.c                   |   58 +---
 src/cairo-scaled-font-subsets-private.h  |    2 
 src/cairo-svg-surface.c                  |   25 --
 test/select-font-face-pdf-argb32-ref.png |binary
 9 files changed, 337 insertions(+), 217 deletions(-)

New commits:
diff-tree 621ebc4726c075c183028818af1944f67a60b7ce (from 636cbe5a191cf8065facfbe45f32620cea2009a5)
Author: Carl Worth <cworth at cworth.org>
Date:   Mon May 15 10:16:06 2006 -0700

    pixman: Remove unused code to quiet compiler warnings

diff --git a/pixman/src/fbpict.c b/pixman/src/fbpict.c
index 89a2a39..bdf6a4c 100644
--- a/pixman/src/fbpict.c
+++ b/pixman/src/fbpict.c
@@ -72,20 +72,6 @@ fbIn (CARD32 x, CARD8 y)
     return m|n|o|p;
 }
 
-static CARD32
-fbIn24 (CARD32 x, CARD8 y)
-{
-    CARD16  a = y;
-    CARD16  t;
-    CARD32  m,n,o,p;
-
-    m = FbInU(x,0,a,t);
-    n = FbInU(x,8,a,t);
-    o = FbInU(x,16,a,t);
-    p = (y << 24);
-    return m|n|o|p;
-}
-
 #define genericCombine24(a,b,c,d) (((a)*(c)+(b)*(d)))
 
 /*
diff --git a/pixman/src/icimage.c b/pixman/src/icimage.c
index 90b1bca..c166cfb 100644
--- a/pixman/src/icimage.c
+++ b/pixman/src/icimage.c
@@ -155,72 +155,6 @@ pixman_gradient_color (pixman_gradient_s
 }
 
 static int
-pixman_init_gradient_color_table (pixman_gradient_image_t *gradient,
-				  int			  tableSize)
-{
-    int begin_pos, end_pos;
-    xFixed incr, dpos;
-    int pos, current_stop;
-    pixman_gradient_stop_t *stops = gradient->stops;
-    int nstops = gradient->nstops;
-
-    if (gradient->colorTableSize < tableSize)
-    {
-	uint32_t *newColorTable;
-
-	newColorTable = realloc (gradient->colorTable,
-				 tableSize * sizeof (uint32_t));
-	if (!newColorTable)
-	    return 1;
-
-	gradient->colorTable = newColorTable;
-	gradient->colorTableSize = tableSize;
-    }
-
-    gradient->stopRange = tableSize;
-
-    /* The position where the gradient begins and ends */
-    begin_pos = (stops[0].x * gradient->colorTableSize) >> 16;
-    end_pos = (stops[nstops - 1].x * gradient->colorTableSize) >> 16;
-
-    pos = 0; /* The position in the color table. */
-
-    /* Up to first point */
-    while (pos <= begin_pos) {
-	gradient->colorTable[pos] = xRenderColorToCard32(stops[0].color);
-        ++pos;
-    }
-
-    incr =  (1<<16)/ gradient->colorTableSize; /* the double increment. */
-    dpos = incr * pos; /* The position in terms of 0-1. */
-
-    current_stop = 0; /* We always interpolate between current and current + 1. */
-
-    /* Gradient area */
-    while (pos < end_pos) {
-	gradient->colorTable[pos] =
-	    pixman_gradient_color (&stops[current_stop],
-				   &stops[current_stop + 1],
-				   dpos);
-
-        ++pos;
-        dpos += incr;
-
-        if (dpos > stops[current_stop + 1].x)
-            ++current_stop;
-    }
-
-    /* After last point */
-    while (pos < gradient->colorTableSize) {
-	gradient->colorTable[pos] =
-	    xRenderColorToCard32 (stops[nstops - 1].color);
-        ++pos;
-    }
-
-    return 0;
-}
-
-static int
 _pixman_init_gradient (pixman_gradient_image_t	    *gradient,
 		       const pixman_gradient_stop_t *stops,
 		       int			    n_stops)
diff-tree 636cbe5a191cf8065facfbe45f32620cea2009a5 (from 2e4c8924ad1c27d807e86a155c6582fd506c66c0)
Author: Carl Worth <cworth at cworth.org>
Date:   Mon May 15 10:14:39 2006 -0700

    pixman: Add default case to quiet compiler warning

diff --git a/pixman/src/fbpict.c b/pixman/src/fbpict.c
index a091740..89a2a39 100644
--- a/pixman/src/fbpict.c
+++ b/pixman/src/fbpict.c
@@ -1816,6 +1816,9 @@ pixman_composite (pixman_operator_t	op,
 	    }
 	}
 	break;
+    default:
+	/* For any operator not specifically handled above we default out to the general code. */
+	func = NULL;
     }
 
     if (!func) {
diff-tree 2e4c8924ad1c27d807e86a155c6582fd506c66c0 (from bf2ab0de927dae4a1dd67a0cbacefabaf0e4255b)
Author: Carl Worth <cworth at cworth.org>
Date:   Mon May 15 10:07:57 2006 -0700

    pixman: Fix build to enable warnings again

diff --git a/configure.in b/configure.in
index bcdb50d..1335e4c 100644
--- a/configure.in
+++ b/configure.in
@@ -586,6 +586,8 @@ if test "x$GCC" = "xyes"; then
 	-Wnested-externs -fno-strict-aliasing"
 fi
 
+AC_SUBST(WARN_CFLAGS)
+
 CAIRO_CFLAGS="$CAIRO_CFLAGS $WARN_CFLAGS"
 CAIRO_LIBS="$CAIRO_LIBS"
 
diff --git a/pixman/src/Makefile.am b/pixman/src/Makefile.am
index 376d696..179c557 100644
--- a/pixman/src/Makefile.am
+++ b/pixman/src/Makefile.am
@@ -36,8 +36,8 @@ noinst_LTLIBRARIES += libpixman-mmx.la
 libpixman_mmx_la_SOURCES = \
 	fbmmx.c		\
 	fbmmx.h
-libpixman_mmx_la_CFLAGS = @MMX_CFLAGS@
+libpixman_mmx_la_CFLAGS = @MMX_CFLAGS@ $(WARN_CFLAGS)
 libpixman_la_LIBADD = libpixman-mmx.la
 endif
 
-INCLUDES = -I$(top_srcdir) -I$(srcdir) $(WARN_CFLAGS)
+INCLUDES = -I$(top_srcdir) -I$(srcdir) @WARN_CFLAGS@
diff-tree bf2ab0de927dae4a1dd67a0cbacefabaf0e4255b (from 6f417fed51672ccca305b7fcc8b1bc3af7609534)
Author: Carl Worth <cworth at cworth.org>
Date:   Mon May 15 10:04:53 2006 -0700

    PDF: Add Type3 font support to PDF output.
    
    This uses the recently added cairo-scaled-font-subsets interface in a
    style very similar to what the PS surface does.

diff --git a/src/cairo-pdf-surface.c b/src/cairo-pdf-surface.c
index f55db04..a48182d 100644
--- a/src/cairo-pdf-surface.c
+++ b/src/cairo-pdf-surface.c
@@ -38,7 +38,7 @@
 
 #include "cairoint.h"
 #include "cairo-pdf.h"
-#include "cairo-font-subset-private.h"
+#include "cairo-scaled-font-subsets-private.h"
 #include "cairo-ft-private.h"
 #include "cairo-paginated-surface-private.h"
 #include "cairo-path-fixed-private.h"
@@ -94,6 +94,12 @@ typedef struct _cairo_pdf_resource {
     unsigned int id;
 } cairo_pdf_resource_t;
 
+typedef struct _cairo_pdf_font {
+    unsigned int font_id;
+    unsigned int subset_id;
+    cairo_pdf_resource_t subset_resource;
+} cairo_pdf_font_t;
+
 typedef struct _cairo_pdf_surface {
     cairo_surface_t base;
 
@@ -113,6 +119,9 @@ typedef struct _cairo_pdf_surface {
     cairo_array_t streams;
     cairo_array_t alphas;
 
+    cairo_scaled_font_subsets_t *font_subsets;
+    cairo_array_t fonts;
+
     cairo_pdf_resource_t next_available_resource;
     cairo_pdf_resource_t pages_resource;
 
@@ -128,7 +137,8 @@ typedef struct _cairo_pdf_surface {
     cairo_paginated_mode_t paginated_mode;
 } cairo_pdf_surface_t;
 
-#define PDF_SURFACE_DPI_DEFAULT 300
+#define PDF_SURFACE_DPI_DEFAULT		300
+#define PDF_SURFACE_MAX_GLYPHS_PER_FONT	256
 
 static cairo_pdf_resource_t
 _cairo_pdf_surface_new_object (cairo_pdf_surface_t *surface);
@@ -162,6 +172,9 @@ _cairo_pdf_surface_write_xref (cairo_pdf
 static cairo_status_t
 _cairo_pdf_surface_write_page (cairo_pdf_surface_t *surface);
 
+static cairo_status_t
+_cairo_pdf_surface_emit_font_subsets (cairo_pdf_surface_t *surface);
+
 static const cairo_surface_backend_t cairo_pdf_surface_backend;
 static const cairo_paginated_surface_backend_t cairo_pdf_surface_paginated_backend;
 
@@ -264,6 +277,15 @@ _cairo_pdf_surface_create_for_stream_int
     _cairo_array_init (&surface->streams, sizeof (cairo_pdf_resource_t));
     _cairo_array_init (&surface->alphas, sizeof (double));
 
+    surface->font_subsets = _cairo_scaled_font_subsets_create (PDF_SURFACE_MAX_GLYPHS_PER_FONT);
+    if (! surface->font_subsets) {
+	_cairo_error (CAIRO_STATUS_NO_MEMORY);
+	free (surface);
+	return (cairo_surface_t*) &_cairo_surface_nil;
+    }
+
+    _cairo_array_init (&surface->fonts, sizeof (cairo_pdf_font_t));
+
     surface->next_available_resource.id = 1;
     surface->pages_resource = _cairo_pdf_surface_new_object (surface);
 
@@ -538,6 +560,8 @@ _cairo_pdf_surface_finish (void *abstrac
 
     _cairo_pdf_surface_close_stream (surface);
 
+    _cairo_pdf_surface_emit_font_subsets (surface);
+
     _cairo_pdf_surface_write_pages (surface);
 
     info = _cairo_pdf_surface_write_info (surface);
@@ -570,6 +594,13 @@ _cairo_pdf_surface_finish (void *abstrac
     _cairo_array_fini (&surface->streams);
     _cairo_array_fini (&surface->alphas);
 
+    if (surface->font_subsets) {
+	_cairo_scaled_font_subsets_destroy (surface->font_subsets);
+	surface->font_subsets = NULL;
+    }
+
+    _cairo_array_fini (&surface->fonts);
+
     return status;
 }
 
@@ -1541,7 +1572,8 @@ static void
 _cairo_pdf_surface_write_pages (cairo_pdf_surface_t *surface)
 {
     cairo_pdf_resource_t page, *res;
-    int num_pages, i;
+    cairo_pdf_font_t font;
+    int num_pages, num_fonts, i;
     int num_alphas, num_resources;
     double alpha;
 
@@ -1612,6 +1644,15 @@ _cairo_pdf_surface_write_pages (cairo_pd
 				     " >>\r\n");
     }
 
+    _cairo_output_stream_printf (surface->output,"      /Font <<\r\n");
+    num_fonts = _cairo_array_num_elements (&surface->fonts);
+    for (i = 0; i < num_fonts; i++) {
+	_cairo_array_copy_element (&surface->fonts, i, &font);
+	_cairo_output_stream_printf (surface->output, "         /CairoFont-%d-%d %d 0 R\r\n",
+				     font.font_id, font.subset_id, font.subset_resource.id);
+    }
+    _cairo_output_stream_printf (surface->output, "      >>\r\n");
+
     _cairo_output_stream_printf (surface->output,
 				 "   >>\r\n");
 
@@ -1625,6 +1666,162 @@ _cairo_pdf_surface_write_pages (cairo_pd
 				 surface->height);
 }
 
+static void
+_cairo_pdf_surface_emit_glyph (cairo_pdf_surface_t	*surface,
+			       cairo_scaled_font_t	*scaled_font,
+			       unsigned long		 scaled_font_glyph_index,
+			       unsigned int		 subset_glyph_index,
+			       cairo_pdf_resource_t	*glyph_ret)
+{
+    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 (&surface->base, status);
+	return;
+    }
+
+    /* XXX: Need to actually use the image not the path if that's all
+     * we could get... */
+
+    *glyph_ret = _cairo_pdf_surface_open_stream (surface, NULL);
+
+    _cairo_output_stream_printf (surface->output,
+				 "0 0 %f %f %f %f d1\r\n"
+				 "                                                                                                             \r\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.x),
+				 -_cairo_fixed_to_double (scaled_glyph->bbox.p1.y));
+
+    status = _cairo_path_fixed_interpret (scaled_glyph->path,
+					  CAIRO_DIRECTION_FORWARD,
+					  _cairo_pdf_path_move_to,
+					  _cairo_pdf_path_line_to,
+					  _cairo_pdf_path_curve_to,
+					  _cairo_pdf_path_close_path,
+					  surface->output);
+
+    _cairo_output_stream_printf (surface->output,
+				 " f");
+
+    _cairo_pdf_surface_close_stream (surface);
+
+    if (status)
+	_cairo_surface_set_error (&surface->base, status);
+}
+
+static void
+_cairo_pdf_surface_emit_font_subset (cairo_scaled_font_subset_t	*font_subset,
+				     void			*closure)
+{
+    cairo_pdf_surface_t *surface = closure;
+    cairo_pdf_resource_t *glyphs, encoding, char_procs, subset_resource;
+    cairo_pdf_font_t font;
+    int i;
+
+    glyphs = malloc (font_subset->num_glyphs * sizeof (cairo_pdf_resource_t));
+    if (glyphs == NULL) {
+	_cairo_surface_set_error (&surface->base, CAIRO_STATUS_NO_MEMORY);
+	return;
+    }
+
+    for (i = 0; i < font_subset->num_glyphs; i++) {
+	_cairo_pdf_surface_emit_glyph (surface,
+				       font_subset->scaled_font,
+				       font_subset->glyphs[i], i,
+				       &glyphs[i]);
+    }
+
+    encoding = _cairo_pdf_surface_new_object (surface);
+    _cairo_output_stream_printf (surface->output,
+				 "%d 0 obj\r\n"
+				 "<< /Type /Encoding\r\n"
+				 "   /Differences [0", encoding.id);
+    for (i = 0; i < font_subset->num_glyphs; i++)
+	_cairo_output_stream_printf (surface->output,
+				     " /%d", i);
+    _cairo_output_stream_printf (surface->output,
+				 "]\r\n"
+				 ">>\r\n"
+				 "endobj\r\n");
+
+    char_procs = _cairo_pdf_surface_new_object (surface);
+    _cairo_output_stream_printf (surface->output,
+				 "%d 0 obj\r\n"
+				 "<<\r\n", char_procs.id);
+    for (i = 0; i < font_subset->num_glyphs; i++)
+	_cairo_output_stream_printf (surface->output,
+				     " /%d %d 0 R\r\n",
+				     i, glyphs[i].id);
+    _cairo_output_stream_printf (surface->output,
+				 ">>\r\n"
+				 "endobj\r\n");
+
+    subset_resource = _cairo_pdf_surface_new_object (surface);
+    _cairo_output_stream_printf (surface->output,
+				 "%d 0 obj\r\n"
+				 "<< /Type /Font\r\n"
+				 "   /Subtype /Type3\r\n"
+				 "   /FontBBox [0 0 0 0]\r\n"
+				 "   /FontMatrix\t[1 0 0 1 0 0]\r\n"
+				 "   /Encoding %d 0 R\r\n"
+				 "   /CharProcs %d 0 R\r\n"
+				 "   /FirstChar 0\r\n"
+				 "   /LastChar %d\r\n",
+				 subset_resource.id,
+				 encoding.id,
+				 char_procs.id,
+				 font_subset->num_glyphs - 1);
+
+    _cairo_output_stream_printf (surface->output,
+				 "   /Widths [");
+    for (i = 0; i < font_subset->num_glyphs; i++)
+	_cairo_output_stream_printf (surface->output, " 0");
+    _cairo_output_stream_printf (surface->output,
+				 "]\r\n");
+
+    _cairo_output_stream_printf (surface->output,
+				 ">>\r\n"
+				 "endobj\r\n");
+
+    font.font_id = font_subset->font_id;
+    font.subset_id = font_subset->subset_id;
+    font.subset_resource = subset_resource;
+    _cairo_array_append (&surface->fonts, &font);
+}
+
+static cairo_status_t
+_cairo_pdf_surface_emit_font_subsets (cairo_pdf_surface_t *surface)
+{
+    cairo_status_t status;
+
+    status = _cairo_scaled_font_subsets_foreach (surface->font_subsets,
+						 _cairo_pdf_surface_emit_font_subset,
+						 surface);
+    _cairo_scaled_font_subsets_destroy (surface->font_subsets);
+    surface->font_subsets = NULL;
+
+    if (status)
+	return status;
+
+    return CAIRO_STATUS_SUCCESS;
+}
+
 #if 0
 static cairo_status_t
 _cairo_pdf_surface_write_fonts (cairo_pdf_surface_t *surface)
@@ -2125,6 +2322,14 @@ _cairo_pdf_surface_fill (void			*abstrac
     return status;
 }
 
+static char
+hex_digit (int i)
+{
+    i &= 0xf;
+    if (i < 10) return '0' + i;
+    return 'a' + (i - 10);
+}
+
 static cairo_int_status_t
 _cairo_pdf_surface_show_glyphs (void			*abstract_surface,
 				cairo_operator_t	 op,
@@ -2134,8 +2339,10 @@ _cairo_pdf_surface_show_glyphs (void			*
 				cairo_scaled_font_t	*scaled_font)
 {
     cairo_pdf_surface_t *surface = abstract_surface;
-    cairo_path_fixed_t path;
+    int current_subset_id = -1;
+    unsigned int font_id, subset_id, subset_glyph_index;
     cairo_status_t status;
+    int i;
 
     if (surface->paginated_mode == CAIRO_PAGINATED_MODE_ANALYZE)
 	return _analyze_operation (surface, op, source);
@@ -2146,14 +2353,27 @@ _cairo_pdf_surface_show_glyphs (void			*
     if (status)
 	return status;
 
-    _cairo_path_fixed_init (&path);
-    _cairo_scaled_font_glyph_path (scaled_font, glyphs, num_glyphs, &path);
-    status = _cairo_pdf_surface_fill (surface, op, source,
-				      &path, CAIRO_FILL_RULE_WINDING,
-				      0.1, scaled_font->options.antialias);
-    _cairo_path_fixed_fini (&path);
+    for (i = 0; i < num_glyphs; i++) {
+	status = _cairo_scaled_font_subsets_map_glyph (surface->font_subsets,
+						       scaled_font, glyphs[i].index,
+						       &font_id, &subset_id, &subset_glyph_index);
+	if (status)
+	    return status;
 
-    return status;
+	if (subset_id != current_subset_id) {
+	    _cairo_output_stream_printf (surface->output,
+					 "/CairoFont-%d-%d 1 Tf\r\n",
+					 font_id, subset_id);
+	    current_subset_id = subset_id;
+	}
+	_cairo_output_stream_printf (surface->output,
+				     "BT %f %f Td <%c%c> Tj ET\r\n",
+				     glyphs[i].x, glyphs[i].y,
+				     hex_digit (subset_glyph_index >> 4),
+				     hex_digit (subset_glyph_index));
+    }
+
+    return _cairo_output_stream_get_status (surface->output);
 }
 
 static void
diff --git a/test/select-font-face-pdf-argb32-ref.png b/test/select-font-face-pdf-argb32-ref.png
index b2de418..9b8c07a 100644
Binary files a/test/select-font-face-pdf-argb32-ref.png and b/test/select-font-face-pdf-argb32-ref.png differ
diff-tree 6f417fed51672ccca305b7fcc8b1bc3af7609534 (from 049100fb870bee89b28bd14a9625add33f38a2bd)
Author: Carl Worth <cworth at cworth.org>
Date:   Mon May 15 10:00:18 2006 -0700

    PDF: Move Resources dictionary up from Page objects to Pages object.
    
    This allows for more sharing of resource objects. It also avoids some
    confusion in trying to set independent resources at a global and a
    per-page level, (which doesn't work since the inheritance only works
    for an entire resources object---it can only be overriden in its
    entirety, not for subsets of the resources).

diff --git a/src/cairo-pdf-surface.c b/src/cairo-pdf-surface.c
index f96a06d..f55db04 100644
--- a/src/cairo-pdf-surface.c
+++ b/src/cairo-pdf-surface.c
@@ -455,9 +455,6 @@ static void
 _cairo_pdf_surface_clear (cairo_pdf_surface_t *surface)
 {
     _cairo_array_truncate (&surface->streams, 0);
-    _cairo_array_truncate (&surface->patterns, 0);
-    _cairo_array_truncate (&surface->xobjects, 0);
-    _cairo_array_truncate (&surface->alphas, 0);
 }
 
 static cairo_surface_t *
@@ -1543,8 +1540,10 @@ _cairo_pdf_surface_write_info (cairo_pdf
 static void
 _cairo_pdf_surface_write_pages (cairo_pdf_surface_t *surface)
 {
-    cairo_pdf_resource_t page;
+    cairo_pdf_resource_t page, *res;
     int num_pages, i;
+    int num_alphas, num_resources;
+    double alpha;
 
     _cairo_pdf_surface_update_object (surface, surface->pages_resource);
     _cairo_output_stream_printf (surface->output,
@@ -1562,6 +1561,60 @@ _cairo_pdf_surface_write_pages (cairo_pd
     _cairo_output_stream_printf (surface->output, "]\r\n");
     _cairo_output_stream_printf (surface->output, "   /Count %d\r\n", num_pages);
 
+    _cairo_output_stream_printf (surface->output, "   /Resources <<\r\n");
+
+    num_alphas =  _cairo_array_num_elements (&surface->alphas);
+    if (num_alphas > 0) {
+	_cairo_output_stream_printf (surface->output,
+				     "      /ExtGState <<\r\n");
+
+	for (i = 0; i < num_alphas; i++) {
+	    /* With some work, we could separate the stroking
+	     * or non-stroking alpha here as actually needed. */
+	    _cairo_array_copy_element (&surface->alphas, i, &alpha);
+	    _cairo_output_stream_printf (surface->output,
+					 "         /a%d << /CA %f /ca %f >>\r\n",
+					 i, alpha, alpha);
+	}
+
+	_cairo_output_stream_printf (surface->output,
+				     "      >>\r\n");
+    }
+
+    num_resources = _cairo_array_num_elements (&surface->patterns);
+    if (num_resources > 0) {
+	_cairo_output_stream_printf (surface->output,
+				     "      /Pattern <<");
+	for (i = 0; i < num_resources; i++) {
+	    res = _cairo_array_index (&surface->patterns, i);
+	    _cairo_output_stream_printf (surface->output,
+					 " /res%d %d 0 R",
+					 res->id, res->id);
+	}
+
+	_cairo_output_stream_printf (surface->output,
+				     " >>\r\n");
+    }
+
+    num_resources = _cairo_array_num_elements (&surface->xobjects);
+    if (num_resources > 0) {
+	_cairo_output_stream_printf (surface->output,
+				     "      /XObject <<");
+
+	for (i = 0; i < num_resources; i++) {
+	    res = _cairo_array_index (&surface->xobjects, i);
+	    _cairo_output_stream_printf (surface->output,
+					 " /res%d %d 0 R",
+					 res->id, res->id);
+	}
+
+	_cairo_output_stream_printf (surface->output,
+				     " >>\r\n");
+    }
+
+    _cairo_output_stream_printf (surface->output,
+				 "   >>\r\n");
+
     /* TODO: Figure out wich other defaults to be inherited by /Page
      * objects. */
     _cairo_output_stream_printf (surface->output,
@@ -1730,11 +1783,9 @@ static cairo_status_t
 _cairo_pdf_surface_write_page (cairo_pdf_surface_t *surface)
 {
     cairo_status_t status;
-    cairo_pdf_resource_t *res;
     cairo_pdf_resource_t page;
-    double alpha;
     cairo_pdf_resource_t stream;
-    int num_streams, num_alphas, num_resources, i;
+    int num_streams, i;
 
     if (surface->has_clip) {
 	_cairo_output_stream_printf (surface->output, "Q\r\n");
@@ -1773,59 +1824,6 @@ _cairo_pdf_surface_write_page (cairo_pdf
 				 " ]\r\n");
 
     _cairo_output_stream_printf (surface->output,
-				 "   /Resources <<\r\n");
-
-    num_alphas =  _cairo_array_num_elements (&surface->alphas);
-    if (num_alphas > 0) {
-	_cairo_output_stream_printf (surface->output,
-				     "      /ExtGState <<\r\n");
-
-	for (i = 0; i < num_alphas; i++) {
-	    /* With some work, we could separate the stroking
-	     * or non-stroking alpha here as actually needed. */
-	    _cairo_array_copy_element (&surface->alphas, i, &alpha);
-	    _cairo_output_stream_printf (surface->output,
-					 "         /a%d << /CA %f /ca %f >>\r\n",
-					 i, alpha, alpha);
-	}
-
-	_cairo_output_stream_printf (surface->output,
-				     "      >>\r\n");
-    }
-
-    num_resources = _cairo_array_num_elements (&surface->patterns);
-    if (num_resources > 0) {
-	_cairo_output_stream_printf (surface->output,
-				     "      /Pattern <<");
-	for (i = 0; i < num_resources; i++) {
-	    res = _cairo_array_index (&surface->patterns, i);
-	    _cairo_output_stream_printf (surface->output,
-					 " /res%d %d 0 R",
-					 res->id, res->id);
-	}
-
-	_cairo_output_stream_printf (surface->output,
-				     " >>\r\n");
-    }
-
-    num_resources = _cairo_array_num_elements (&surface->xobjects);
-    if (num_resources > 0) {
-	_cairo_output_stream_printf (surface->output,
-				     "      /XObject <<");
-
-	for (i = 0; i < num_resources; i++) {
-	    res = _cairo_array_index (&surface->xobjects, i);
-	    _cairo_output_stream_printf (surface->output,
-					 " /res%d %d 0 R",
-					 res->id, res->id);
-	}
-
-	_cairo_output_stream_printf (surface->output,
-				     " >>\r\n");
-    }
-
-    _cairo_output_stream_printf (surface->output,
-				 "   >>\r\n"
 				 ">>\r\n"
 				 "endobj\r\n");
 
diff-tree 049100fb870bee89b28bd14a9625add33f38a2bd (from 45d0540c3375bfdb09973a809c08b5dec1ae2219)
Author: Carl Worth <cworth at cworth.org>
Date:   Mon May 15 09:52:57 2006 -0700

    PDF: Use consistent style for typedef struct and macro naming.

diff --git a/src/cairo-pdf-surface.c b/src/cairo-pdf-surface.c
index 2746cd0..f96a06d 100644
--- a/src/cairo-pdf-surface.c
+++ b/src/cairo-pdf-surface.c
@@ -86,19 +86,15 @@
  *   instead of outputting the cm operator in every page.
  */
 
-typedef struct cairo_pdf_object cairo_pdf_object_t;
-typedef struct cairo_pdf_resource cairo_pdf_resource_t;
-typedef struct cairo_pdf_surface cairo_pdf_surface_t;
-
-struct cairo_pdf_object {
+typedef struct _cairo_pdf_object {
     long offset;
-};
+} cairo_pdf_object_t;
 
-struct cairo_pdf_resource {
+typedef struct _cairo_pdf_resource {
     unsigned int id;
-};
+} cairo_pdf_resource_t;
 
-struct cairo_pdf_surface {
+typedef struct _cairo_pdf_surface {
     cairo_surface_t base;
 
     /* Prefer the name "output" here to avoid confusion over the
@@ -130,9 +126,9 @@ struct cairo_pdf_surface {
     cairo_bool_t has_clip;
 
     cairo_paginated_mode_t paginated_mode;
-};
+} cairo_pdf_surface_t;
 
-#define DEFAULT_DPI 300
+#define PDF_SURFACE_DPI_DEFAULT 300
 
 static cairo_pdf_resource_t
 _cairo_pdf_surface_new_object (cairo_pdf_surface_t *surface);
@@ -258,8 +254,8 @@ _cairo_pdf_surface_create_for_stream_int
 
     surface->width = width;
     surface->height = height;
-    surface->x_dpi = DEFAULT_DPI;
-    surface->y_dpi = DEFAULT_DPI;
+    surface->x_dpi = PDF_SURFACE_DPI_DEFAULT;
+    surface->y_dpi = PDF_SURFACE_DPI_DEFAULT;
 
     _cairo_array_init (&surface->objects, sizeof (cairo_pdf_object_t));
     _cairo_array_init (&surface->pages, sizeof (cairo_pdf_resource_t));
diff-tree 45d0540c3375bfdb09973a809c08b5dec1ae2219 (from cb32b41a4e24df612dc0cabbe1e22098584759e9)
Author: Carl Worth <cworth at cworth.org>
Date:   Mon May 15 09:41:36 2006 -0700

    PS: Remove the fallback case from _cairo_ps_surface_show_glyphs
    
    The only expected errors that would lead to this fallback are serious
    problems such as out of memory. There's no reason to go to heroic
    efforts to draw as much as possible in face of an error like that.
    
    Prefer simpler code instead.

diff --git a/src/cairo-ps-surface.c b/src/cairo-ps-surface.c
index 3ba42b4..fb8935b 100644
--- a/src/cairo-ps-surface.c
+++ b/src/cairo-ps-surface.c
@@ -1732,11 +1732,10 @@ _cairo_ps_surface_show_glyphs (void		   
 {
     cairo_ps_surface_t *surface = abstract_surface;
     cairo_output_stream_t *stream = surface->stream;
-    cairo_int_status_t status;
-    cairo_path_fixed_t *path;
-    int i;
     int current_subset_id = -1;
     unsigned int font_id, subset_id, subset_glyph_index;
+    cairo_status_t status;
+    int i;
 
     if (surface->paginated_mode == CAIRO_PAGINATED_MODE_ANALYZE)
 	return _analyze_operation (surface, op, source);
@@ -1753,11 +1752,9 @@ _cairo_ps_surface_show_glyphs (void		   
 	status = _cairo_scaled_font_subsets_map_glyph (surface->font_subsets,
 						       scaled_font, glyphs[i].index,
 						       &font_id, &subset_id, &subset_glyph_index);
-	if (status) {
-	    glyphs += i;
-	    num_glyphs -= i;
-	    goto fallback;
-	}
+	if (status)
+	    return status;
+
 	if (subset_id != current_subset_id) {
 	    _cairo_output_stream_printf (surface->stream,
 					 "/CairoFont-%d-%d 1 selectfont\n",
@@ -1770,19 +1767,8 @@ _cairo_ps_surface_show_glyphs (void		   
 				     hex_digit (subset_glyph_index >> 4),
 				     hex_digit (subset_glyph_index));
     }
-	
-    return CAIRO_STATUS_SUCCESS;
-
-fallback:
-    
-    path = _cairo_path_fixed_create ();
-    _cairo_scaled_font_glyph_path (scaled_font, glyphs, num_glyphs, path);
-    status = _cairo_ps_surface_fill (abstract_surface, op, source,
-				     path, CAIRO_FILL_RULE_WINDING,
-				     0.1, scaled_font->options.antialias);
-    _cairo_path_fixed_destroy (path);
 
-    return CAIRO_STATUS_SUCCESS;
+    return _cairo_output_stream_get_status (surface->stream);
 }
 
 static void
diff-tree cb32b41a4e24df612dc0cabbe1e22098584759e9 (from e2c03d51daa60bf18b66ace148e6f8df7c454e2c)
Author: Carl Worth <cworth at cworth.org>
Date:   Mon May 15 09:39:16 2006 -0700

    PS: Fix arguments to setcachedevice
    
    Since we are only ever displaying a single glyph at a time we don't
    care about the width values passed to setcachedevice at all---we only
    care about the bounding box.
    
    That's what the code was trying to do before, but the arguments were
    misaligned and we were instead passing bounding-box values for the
    widths and hard-coding half of the bounding-box values as 0.

diff --git a/src/cairo-ps-surface.c b/src/cairo-ps-surface.c
index a91a107..3ba42b4 100644
--- a/src/cairo-ps-surface.c
+++ b/src/cairo-ps-surface.c
@@ -246,7 +246,7 @@ _cairo_ps_surface_emit_glyph (cairo_ps_s
 				 "\t\t{ %% %d\n", subset_glyph_index);
 
     _cairo_output_stream_printf (surface->final_stream,
-				 "%f %f %f %f 0 0 setcachedevice\n",
+				 "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.x),
diff-tree e2c03d51daa60bf18b66ace148e6f8df7c454e2c (from f500cef19f049a4a0ed296172618db2f26794932)
Author: Carl Worth <cworth at cworth.org>
Date:   Mon May 15 09:28:32 2006 -0700

    Change scaled_font_subsets_callback to have return type of void.
    
    The return of status from this callback was misleading. The function
    actually calling the callback was also a hash table callback function,
    which itself is void---so any status value returned was being lost.
    
    Instead, we now stash any errors that occur during the fallback into
    surface->status.

diff --git a/src/cairo-ps-surface.c b/src/cairo-ps-surface.c
index 42196b0..a91a107 100644
--- a/src/cairo-ps-surface.c
+++ b/src/cairo-ps-surface.c
@@ -211,7 +211,7 @@ _cairo_ps_surface_emit_header (cairo_ps_
     }
 }
 
-static cairo_status_t
+static void
 _cairo_ps_surface_emit_glyph (cairo_ps_surface_t	*surface,
 			      cairo_scaled_font_t	*scaled_font,
 			      unsigned long		 scaled_font_glyph_index,
@@ -220,9 +220,6 @@ _cairo_ps_surface_emit_glyph (cairo_ps_s
     cairo_scaled_glyph_t    *scaled_glyph;
     cairo_status_t	    status;
 
-    _cairo_output_stream_printf (surface->final_stream,
-				 "\t\t{ %% %d\n", subset_glyph_index);
-
     status = _cairo_scaled_glyph_lookup (scaled_font,
 					 scaled_font_glyph_index,
 					 CAIRO_SCALED_GLYPH_INFO_METRICS|
@@ -238,14 +235,17 @@ _cairo_ps_surface_emit_glyph (cairo_ps_s
 					     CAIRO_SCALED_GLYPH_INFO_SURFACE,
 					     &scaled_glyph);
     if (status) {
-	_cairo_output_stream_printf (surface->final_stream, "\t\t}\n");
-	return status;
+	_cairo_surface_set_error (&surface->base, status);
+	return;
     }
 
     /* XXX: Need to actually use the image not the path if that's all
      * we could get... */
 
     _cairo_output_stream_printf (surface->final_stream,
+				 "\t\t{ %% %d\n", subset_glyph_index);
+
+    _cairo_output_stream_printf (surface->final_stream,
 				 "%f %f %f %f 0 0 setcachedevice\n",
 				 _cairo_fixed_to_double (scaled_glyph->bbox.p1.x),
 				 -_cairo_fixed_to_double (scaled_glyph->bbox.p2.y),
@@ -265,10 +265,9 @@ _cairo_ps_surface_emit_glyph (cairo_ps_s
     
     _cairo_output_stream_printf (surface->final_stream,
 				 "\t\t}\n");
-    return CAIRO_STATUS_SUCCESS;
 }
 
-static cairo_status_t
+static void
 _cairo_ps_surface_emit_font_subset (cairo_scaled_font_subset_t	*font_subset,
 				    void			*closure)
 {
@@ -303,22 +302,23 @@ _cairo_ps_surface_emit_font_subset (cair
 				 "\t\texch get exec\n"
 				 "\t}\n"
 				 ">> definefont pop\n");
-
-    return _cairo_output_stream_get_status (surface->final_stream);
 }
 
-
-static void
+static cairo_status_t
 _cairo_ps_surface_emit_font_subsets (cairo_ps_surface_t *surface)
 {
+    cairo_status_t status;
+
     _cairo_output_stream_printf (surface->final_stream,
 				 "%% _cairo_ps_surface_emit_font_subsets\n");
 
-    _cairo_scaled_font_subsets_foreach (surface->font_subsets,
-					_cairo_ps_surface_emit_font_subset,
-					surface);
+    status = _cairo_scaled_font_subsets_foreach (surface->font_subsets,
+						 _cairo_ps_surface_emit_font_subset,
+						 surface);
     _cairo_scaled_font_subsets_destroy (surface->font_subsets);
     surface->font_subsets = NULL;
+
+    return status;
 }
 
 static void
diff --git a/src/cairo-scaled-font-subsets-private.h b/src/cairo-scaled-font-subsets-private.h
index d4137d4..aed01a3 100644
--- a/src/cairo-scaled-font-subsets-private.h
+++ b/src/cairo-scaled-font-subsets-private.h
@@ -140,7 +140,7 @@ _cairo_scaled_font_subsets_map_glyph (ca
 				      unsigned int			*subset_id_ret,
 				      unsigned int			*subset_glyph_index_ret);
 
-typedef cairo_status_t
+typedef void
 (*cairo_scaled_font_subset_callback_func_t) (cairo_scaled_font_subset_t	*font_subset,
 					     void			*closure);
 
diff --git a/src/cairo-svg-surface.c b/src/cairo-svg-surface.c
index 3bd5121..8a0fd97 100644
--- a/src/cairo-svg-surface.c
+++ b/src/cairo-svg-surface.c
@@ -545,7 +545,7 @@ _cairo_svg_path_close_path (void *closur
     return CAIRO_STATUS_SUCCESS;
 }
 
-static cairo_status_t
+static void
 _cairo_svg_document_emit_glyph (cairo_svg_document_t	*document,
 				cairo_scaled_font_t	*scaled_font,
 				unsigned long		 scaled_font_glyph_index,
@@ -572,8 +572,10 @@ _cairo_svg_document_emit_glyph (cairo_sv
 					     CAIRO_SCALED_GLYPH_INFO_METRICS|
 					     CAIRO_SCALED_GLYPH_INFO_SURFACE,
 					     &scaled_glyph);
-    if (status) 
-	return status;
+    if (status) {
+	_cairo_surface_set_error (document->owner, status);
+	return;
+    }
     
     info.document = document;
     info.path = xmlBufferCreate ();
@@ -597,28 +599,21 @@ _cairo_svg_document_emit_glyph (cairo_sv
     xmlSetProp (child, CC2XML ("style"), CC2XML ("stroke: none;"));
     
     xmlBufferFree (info.path);
-
-    return CAIRO_STATUS_SUCCESS;
 }
 
-static cairo_status_t
+static void
 _cairo_svg_document_emit_font_subset (cairo_scaled_font_subset_t	*font_subset,
 				      void				*closure)
 {
     cairo_svg_document_t *document = closure;
-    cairo_status_t status;
     int i;
 
     for (i = 0; i < font_subset->num_glyphs; i++) {
-	status = _cairo_svg_document_emit_glyph (document,
-						 font_subset->scaled_font,
-						 font_subset->glyphs[i],
-						 font_subset->font_id, i);
-	if (status)
-	    return status;
+	_cairo_svg_document_emit_glyph (document,
+					font_subset->scaled_font,
+					font_subset->glyphs[i],
+					font_subset->font_id, i);
     }
-
-    return CAIRO_STATUS_SUCCESS;
 }
 
 static void


More information about the cairo-commit mailing list