[cairo-commit] 3 commits - src/cairo-pdf-operators.c test/.gitignore

Adrian Johnson ajohnson at kemper.freedesktop.org
Mon Mar 17 04:44:18 PDT 2008


 src/cairo-pdf-operators.c |  102 +++++++++++++++++++++++++---------------------
 test/.gitignore           |    1 
 2 files changed, 58 insertions(+), 45 deletions(-)

New commits:
commit e4f087b8b944a26d688afeef4b9ea7a0d0a6e9ec
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Sun Mar 16 17:29:48 2008 +1030

    Factor out common stroke code in pdf-operators

diff --git a/src/cairo-pdf-operators.c b/src/cairo-pdf-operators.c
index b92ed18..c0a8a9c 100644
--- a/src/cairo-pdf-operators.c
+++ b/src/cairo-pdf-operators.c
@@ -583,12 +583,13 @@ _cairo_pdf_operators_emit_stroke_style (cairo_pdf_operators_t	*pdf_operators,
 }
 
 
-cairo_int_status_t
-_cairo_pdf_operators_stroke (cairo_pdf_operators_t	*pdf_operators,
-			     cairo_path_fixed_t		*path,
-			     cairo_stroke_style_t	*style,
-			     cairo_matrix_t		*ctm,
-			     cairo_matrix_t		*ctm_inverse)
+static cairo_int_status_t
+_cairo_pdf_operators_emit_stroke (cairo_pdf_operators_t	*pdf_operators,
+				  cairo_path_fixed_t	*path,
+				  cairo_stroke_style_t	*style,
+				  cairo_matrix_t	*ctm,
+				  cairo_matrix_t	*ctm_inverse,
+				  const char 		*pdf_operator)
 {
     cairo_status_t status;
     cairo_matrix_t m, path_transform;
@@ -628,7 +629,7 @@ _cairo_pdf_operators_stroke (cairo_pdf_operators_t	*pdf_operators,
     if (status)
 	return status;
 
-    _cairo_output_stream_printf (pdf_operators->stream, "S");
+    _cairo_output_stream_printf (pdf_operators->stream, "%s", pdf_operator);
     if (has_ctm)
 	_cairo_output_stream_printf (pdf_operators->stream, " Q");
 
@@ -638,6 +639,21 @@ _cairo_pdf_operators_stroke (cairo_pdf_operators_t	*pdf_operators,
 }
 
 cairo_int_status_t
+_cairo_pdf_operators_stroke (cairo_pdf_operators_t	*pdf_operators,
+			     cairo_path_fixed_t		*path,
+			     cairo_stroke_style_t	*style,
+			     cairo_matrix_t		*ctm,
+			     cairo_matrix_t		*ctm_inverse)
+{
+    return _cairo_pdf_operators_emit_stroke (pdf_operators,
+					     path,
+					     style,
+					     ctm,
+					     ctm_inverse,
+					     "S");
+}
+
+cairo_int_status_t
 _cairo_pdf_operators_fill (cairo_pdf_operators_t	*pdf_operators,
 			   cairo_path_fixed_t		*path,
 			   cairo_fill_rule_t		fill_rule)
@@ -678,45 +694,25 @@ _cairo_pdf_operators_fill_stroke (cairo_pdf_operators_t 	*pdf_operators,
 				  cairo_matrix_t		*ctm,
 				  cairo_matrix_t		*ctm_inverse)
 {
-    const char *pdf_operator;
-    cairo_status_t status;
-    cairo_matrix_t m;
-
-    status = _cairo_pdf_operators_emit_stroke_style (pdf_operators, style);
-    if (status == CAIRO_INT_STATUS_NOTHING_TO_DO)
-	return CAIRO_STATUS_SUCCESS;
-    if (status)
-	return status;
-
-    cairo_matrix_multiply (&m, ctm, &pdf_operators->cairo_to_pdf);
-    _cairo_output_stream_printf (pdf_operators->stream,
-				 "q %f %f %f %f %f %f cm\n",
-				 m.xx, m.yx, m.xy, m.yy,
-				 m.x0, m.y0);
-
-    status = _cairo_pdf_operators_emit_path (pdf_operators,
-					     path,
-					     ctm_inverse,
-					     style->line_cap);
-    if (status)
-	return status;
+    const char *operator;
 
     switch (fill_rule) {
     case CAIRO_FILL_RULE_WINDING:
-	pdf_operator = "B";
+	operator = "B";
 	break;
     case CAIRO_FILL_RULE_EVEN_ODD:
-	pdf_operator = "B*";
+	operator = "B*";
 	break;
     default:
 	ASSERT_NOT_REACHED;
     }
 
-    _cairo_output_stream_printf (pdf_operators->stream,
-				 "%s Q\n",
-				 pdf_operator);
-
-    return _cairo_output_stream_get_status (pdf_operators->stream);
+    return _cairo_pdf_operators_emit_stroke (pdf_operators,
+					     path,
+					     style,
+					     ctm,
+					     ctm_inverse,
+					     operator);
 }
 
 #define GLYPH_POSITION_TOLERANCE 0.001
commit 8238a9fd4fa672299fd99aa95f5fcec03647f7c8
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Sat Mar 15 22:08:52 2008 +1030

    Add stroke-ctm-caps to .gitignore

diff --git a/test/.gitignore b/test/.gitignore
index 0747521..7f0a016 100644
--- a/test/.gitignore
+++ b/test/.gitignore
@@ -162,6 +162,7 @@ solid-pattern-cache-stress
 source-clip
 source-clip-scale
 source-surface-scale-paint
+stroke-ctm-caps
 surface-finish-twice
 surface-pattern
 surface-pattern-big-scale-down
commit 344af99d356203dce8cb97d3effa380cad0c9238
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Sat Mar 15 22:07:01 2008 +1030

    Improve the PDF operators word wrapping
    
    to correctly count the columns and avoid breaking hex strings
    immediately after the '<' and before any hex digits have been written.

diff --git a/src/cairo-pdf-operators.c b/src/cairo-pdf-operators.c
index bc22f79..b92ed18 100644
--- a/src/cairo-pdf-operators.c
+++ b/src/cairo-pdf-operators.c
@@ -108,6 +108,7 @@ typedef struct _word_wrap_stream {
     int column;
     cairo_bool_t last_write_was_space;
     cairo_bool_t in_hexstring;
+    cairo_bool_t empty_hexstring;
 } word_wrap_stream_t;
 
 static int
@@ -136,11 +137,15 @@ _count_hexstring_up_to (const unsigned char *s, int length, int columns)
 {
     int word = 0;
 
-    while (length-- && columns--) {
+    while (length--) {
 	if (*s++ != '>')
 	    word++;
 	else
 	    return word;
+
+	columns--;
+	if (columns < 0 && word > 1)
+	    return word;
     }
 
     return word;
@@ -158,14 +163,19 @@ _word_wrap_stream_write (cairo_output_stream_t  *base,
     while (length) {
 	if (*data == '<') {
 	    stream->in_hexstring = TRUE;
+	    stream->empty_hexstring = TRUE;
+	    stream->last_write_was_space = FALSE;
 	    data++;
 	    length--;
 	    _cairo_output_stream_printf (stream->output, "<");
+	    stream->column++;
 	} else if (*data == '>') {
 	    stream->in_hexstring = FALSE;
+	    stream->last_write_was_space = FALSE;
 	    data++;
 	    length--;
 	    _cairo_output_stream_printf (stream->output, ">");
+	    stream->column++;
 	} else if (isspace (*data)) {
 	    newline =  (*data == '\n' || *data == '\r');
 	    if (! newline && stream->column >= stream->max_column) {
@@ -175,8 +185,9 @@ _word_wrap_stream_write (cairo_output_stream_t  *base,
 	    _cairo_output_stream_write (stream->output, data, 1);
 	    data++;
 	    length--;
-	    if (newline)
+	    if (newline) {
 		stream->column = 0;
+	    }
 	    else
 		stream->column++;
 	    stream->last_write_was_space = TRUE;
@@ -189,17 +200,21 @@ _word_wrap_stream_write (cairo_output_stream_t  *base,
 	    }
 	    /* Don't wrap if this word is a continuation of a non hex
 	     * string word from a previous call to write. */
-	    if (stream->column + word >= stream->max_column &&
-		(stream->last_write_was_space || stream->in_hexstring))
-	    {
-		_cairo_output_stream_printf (stream->output, "\n");
-		stream->column = 0;
+	    if (stream->column + word >= stream->max_column) {
+		if (stream->last_write_was_space ||
+		    (stream->in_hexstring && !stream->empty_hexstring))
+		{
+		    _cairo_output_stream_printf (stream->output, "\n");
+		    stream->column = 0;
+		}
 	    }
 	    _cairo_output_stream_write (stream->output, data, word);
 	    data += word;
 	    length -= word;
 	    stream->column += word;
 	    stream->last_write_was_space = FALSE;
+	    if (stream->in_hexstring)
+		stream->empty_hexstring = FALSE;
 	}
     }
 
@@ -236,6 +251,7 @@ _word_wrap_stream_create (cairo_output_stream_t *output, int max_column)
     stream->column = 0;
     stream->last_write_was_space = FALSE;
     stream->in_hexstring = FALSE;
+    stream->empty_hexstring = TRUE;
 
     return &stream->base;
 }
@@ -365,7 +381,7 @@ _cairo_pdf_operators_emit_path (cairo_pdf_operators_t 	*pdf_operators,
     pdf_path_info_t info;
     cairo_box_t box;
 
-    word_wrap = _word_wrap_stream_create (pdf_operators->stream, 79);
+    word_wrap = _word_wrap_stream_create (pdf_operators->stream, 72);
     status = _cairo_output_stream_get_status (word_wrap);
     if (status)
 	return status;
@@ -723,7 +739,7 @@ _cairo_pdf_operators_show_glyphs (cairo_pdf_operators_t		*pdf_operators,
     for (i = 0; i < num_glyphs; i++)
 	cairo_matrix_transform_point (&pdf_operators->cairo_to_pdf, &glyphs[i].x, &glyphs[i].y);
 
-    word_wrap_stream = _word_wrap_stream_create (pdf_operators->stream, 79);
+    word_wrap_stream = _word_wrap_stream_create (pdf_operators->stream, 72);
     status = _cairo_output_stream_get_status (word_wrap_stream);
     if (status)
 	return status;


More information about the cairo-commit mailing list