[cairo-commit] 4 commits - src/cairo-pdf-operators.c src/cairo-ps-surface.c src/cairo-ps-surface-private.h

Adrian Johnson ajohnson at kemper.freedesktop.org
Sat Jul 5 00:07:17 PDT 2008


 src/cairo-pdf-operators.c      |    5 +--
 src/cairo-ps-surface-private.h |    6 ++++
 src/cairo-ps-surface.c         |   52 ++++++++++++++++++++++++++++++++---------
 3 files changed, 49 insertions(+), 14 deletions(-)

New commits:
commit f92131c38a21a15a5adfbc831cf6eea7a749714d
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Sat Jul 5 16:23:43 2008 +0930

    PS: Remember current color
    
    This allows PDF operators to merge text strings together when they are
    all the same color.

diff --git a/src/cairo-ps-surface-private.h b/src/cairo-ps-surface-private.h
index b78e525..657e14b 100644
--- a/src/cairo-ps-surface-private.h
+++ b/src/cairo-ps-surface-private.h
@@ -69,6 +69,12 @@ typedef struct cairo_ps_surface {
     void *image_extra;
     cairo_bool_t use_string_datasource;
 
+    cairo_bool_t current_pattern_is_solid_color;
+    double current_color_red;
+    double current_color_green;
+    double current_color_blue;
+    double current_color_alpha;
+
     int num_pages;
 
     cairo_paginated_mode_t paginated_mode;
diff --git a/src/cairo-ps-surface.c b/src/cairo-ps-surface.c
index d533a62..a64ddae 100644
--- a/src/cairo-ps-surface.c
+++ b/src/cairo-ps-surface.c
@@ -691,6 +691,7 @@ _cairo_ps_surface_create_for_stream_internal (cairo_output_stream_t *stream,
     surface->force_fallbacks = FALSE;
     surface->content = CAIRO_CONTENT_COLOR_ALPHA;
     surface->use_string_datasource = FALSE;
+    surface->current_pattern_is_solid_color = FALSE;
 
     _cairo_pdf_operators_init (&surface->pdf_operators,
 			       surface->stream,
@@ -2029,6 +2030,7 @@ _cairo_ps_surface_emit_meta_surface (cairo_ps_surface_t  *surface,
     old_clip = _cairo_surface_get_clip (&surface->base);
     surface->width = meta_extents.width;
     surface->height = meta_extents.height;
+    surface->current_pattern_is_solid_color = FALSE;
     cairo_matrix_init (&surface->cairo_to_ps, 1, 0, 0, -1, 0, surface->height);
     _cairo_pdf_operators_set_cairo_to_pdf_matrix (&surface->pdf_operators,
 						  &surface->cairo_to_ps);
@@ -2061,6 +2063,7 @@ _cairo_ps_surface_emit_meta_surface (cairo_ps_surface_t  *surface,
     surface->content = old_content;
     surface->width = old_width;
     surface->height = old_height;
+    surface->current_pattern_is_solid_color = FALSE;
     surface->cairo_to_ps = old_cairo_to_ps;
     status = _cairo_surface_set_clip (&surface->base, old_clip);
     if (status)
@@ -2808,17 +2811,41 @@ _cairo_ps_surface_emit_pattern (cairo_ps_surface_t *surface,
 				cairo_pattern_t *pattern,
 				cairo_operator_t op)
 {
-    /* FIXME: We should keep track of what pattern is currently set in
-     * the postscript file and only emit code if we're setting a
-     * different pattern. */
     cairo_status_t status;
 
+    if (pattern->type == CAIRO_PATTERN_TYPE_SOLID) {
+	cairo_solid_pattern_t *solid = (cairo_solid_pattern_t *) pattern;
+
+	if (surface->current_pattern_is_solid_color == FALSE ||
+	    surface->current_color_red != solid->color.red ||
+	    surface->current_color_green != solid->color.green ||
+	    surface->current_color_blue != solid->color.blue ||
+	    surface->current_color_alpha != solid->color.alpha)
+	{
+	    status = _cairo_pdf_operators_flush (&surface->pdf_operators);
+	    if (status)
+		return status;
+
+	    _cairo_ps_surface_emit_solid_pattern (surface, (cairo_solid_pattern_t *) pattern);
+
+	    surface->current_pattern_is_solid_color = TRUE;
+	    surface->current_color_red = solid->color.red;
+	    surface->current_color_green = solid->color.green;
+	    surface->current_color_blue = solid->color.blue;
+	    surface->current_color_alpha = solid->color.alpha;
+	}
+
+	return CAIRO_STATUS_SUCCESS;
+    }
+
+    surface->current_pattern_is_solid_color = FALSE;
     status = _cairo_pdf_operators_flush (&surface->pdf_operators);
     if (status)
 	    return status;
 
     switch (pattern->type) {
     case CAIRO_PATTERN_TYPE_SOLID:
+
 	_cairo_ps_surface_emit_solid_pattern (surface, (cairo_solid_pattern_t *) pattern);
 	break;
 
@@ -3177,6 +3204,7 @@ _cairo_ps_surface_set_bounding_box (void		*abstract_surface,
 	if (y2 > surface->bbox_y2)
 	    surface->bbox_y2 = y2;
     }
+    surface->current_pattern_is_solid_color = FALSE;
 
     return _cairo_output_stream_get_status (surface->stream);
 }
commit dac22cf2b9541c1da72e12a1fb66c5a58775f3b3
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Sat Jul 5 16:22:35 2008 +0930

    PDF: Fix glyph positioning bug in Tj operator
    
    Previously this was not correctly checking the position of the first
    glyph and falling back to using TJ if the glyph was not at the the
    standard glyph advance.

diff --git a/src/cairo-pdf-operators.c b/src/cairo-pdf-operators.c
index 7ebd00b..4aec095 100644
--- a/src/cairo-pdf-operators.c
+++ b/src/cairo-pdf-operators.c
@@ -905,7 +905,7 @@ _cairo_pdf_operators_flush_glyphs (cairo_pdf_operators_t    *pdf_operators)
 	return _cairo_output_stream_destroy (word_wrap_stream);
 
     /* Check if glyph advance used to position every glyph */
-    x = pdf_operators->glyphs[0].x_position;
+    x = pdf_operators->cur_x;
     for (i = 0; i < pdf_operators->num_glyphs; i++) {
 	if (fabs(pdf_operators->glyphs[i].x_position - x) > GLYPH_POSITION_TOLERANCE)
 	    break;
commit c9c4b0eded58e44e527806f24aa76e7874fb2111
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Sat Jul 5 16:19:30 2008 +0930

    PDF: Fix glyph positioning bug in TJ operator
    
    Previously this was not correctly positioning the first glyph in a TJ
    string if the glyph was not at the the standard glyph advance.

diff --git a/src/cairo-pdf-operators.c b/src/cairo-pdf-operators.c
index a954282..7ebd00b 100644
--- a/src/cairo-pdf-operators.c
+++ b/src/cairo-pdf-operators.c
@@ -850,8 +850,7 @@ _cairo_pdf_operators_emit_glyph_string_with_positioning (
 
     _cairo_output_stream_printf (stream, "[<");
     for (i = 0; i < pdf_operators->num_glyphs; i++) {
-	if (i != 0 &&
-	    pdf_operators->glyphs[i].x_position != pdf_operators->cur_x)
+	if (pdf_operators->glyphs[i].x_position != pdf_operators->cur_x)
 	{
 	    double delta = pdf_operators->glyphs[i].x_position - pdf_operators->cur_x;
 	    int rounded_delta;
commit 0f748df6705731b94204d6dd0c903e18f1d4a8a5
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Sat Jul 5 16:14:31 2008 +0930

    PS: Remember position when changing font
    
    Previously the PS emulation of the PDF operators would change the
    current position to the text line matrix instead of the the text
    matrix when changing the font.

diff --git a/src/cairo-ps-surface.c b/src/cairo-ps-surface.c
index 3261247..d533a62 100644
--- a/src/cairo-ps-surface.c
+++ b/src/cairo-ps-surface.c
@@ -180,23 +180,25 @@ _cairo_ps_surface_emit_header (cairo_ps_surface_t *surface)
 				 "    /cleartomark load def end } ifelse\n"
 				 "/BDC { mark 3 1 roll /BDC pdfmark } bind def\n"
 				 "/EMC { mark /EMC pdfmark } bind def\n"
-				 "/Tj { show } bind def\n"
+				 "/cairo_store_point { /cairo_point_y exch def /cairo_point_x exch def } def\n"
+				 "/Tj { show currentpoint cairo_store_point } bind def\n"
 				 "/TJ {\n"
 				 "  {\n"
 				 "    dup\n"
 				 "    type /stringtype eq\n"
 				 "    { show } { -0.001 mul 0 cairo_font_matrix dtransform rmoveto } ifelse\n"
 				 "  } forall\n"
+				 "  currentpoint cairo_store_point\n"
 				 "} bind def\n"
-				 "/cairo_selectfont { cairo_font_matrix aload pop 6 2 roll\n"
-				 "      0 0 6 array astore cairo_font exch selectfont moveto } bind def\n"
+				 "/cairo_selectfont { cairo_font_matrix aload pop pop pop 0 0 6 array astore\n"
+				 "    cairo_font exch selectfont cairo_point_x cairo_point_y moveto } bind def\n"
 				 "/Tf { pop /cairo_font exch def /cairo_font_matrix where\n"
 				 "      { cairo_selectfont } if } bind def\n"
-				 "/Td { matrix translate cairo_font_matrix matrix concatmatrix\n"
-				 "      /cairo_font_matrix exch def /cairo_font where\n"
-				 "      { cairo_selectfont } if } bind def\n"
-				 "/Tm { 6 array astore /cairo_font_matrix exch def /cairo_font where\n"
-				 "      { cairo_selectfont } if } bind def\n"
+				 "/Td { matrix translate cairo_font_matrix matrix concatmatrix dup\n"
+				 "      /cairo_font_matrix exch def dup 4 get exch 5 get cairo_store_point\n"
+				 "      /cairo_font where { cairo_selectfont } if } bind def\n"
+				 "/Tm { 2 copy 8 2 roll 6 array astore /cairo_font_matrix exch def\n"
+				 "      cairo_store_point /cairo_font where { cairo_selectfont } if } bind def\n"
 				 "/g { setgray } bind def\n"
 				 "/rg { setrgbcolor } bind def\n"
 				 "/d1 { setcachedevice } bind def\n");


More information about the cairo-commit mailing list