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

Adrian Johnson ajohnson at kemper.freedesktop.org
Sat Feb 16 16:48:09 PST 2008


 src/cairo-pdf-operators.c |   88 +++++++++++++++++++++++++++++++++++-----------
 1 file changed, 68 insertions(+), 20 deletions(-)

New commits:
commit 357f2334f0bd518815c80905e451b6ac1ba43553
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Sat Feb 16 20:37:16 2008 +1030

    PDF: Allow word_wrap_stream to split hex strings

diff --git a/src/cairo-pdf-operators.c b/src/cairo-pdf-operators.c
index 1db6a8e..3564e29 100644
--- a/src/cairo-pdf-operators.c
+++ b/src/cairo-pdf-operators.c
@@ -107,6 +107,7 @@ typedef struct _word_wrap_stream {
     int max_column;
     int column;
     cairo_bool_t last_write_was_space;
+    cairo_bool_t in_hexstring;
 } word_wrap_stream_t;
 
 static int
@@ -115,7 +116,28 @@ _count_word_up_to (const unsigned char *s, int length)
     int word = 0;
 
     while (length--) {
-	if (! isspace (*s++))
+	if (! (isspace (*s) || *s == '<')) {
+	    s++;
+	    word++;
+	} else {
+	    return word;
+	}
+    }
+
+    return word;
+}
+
+
+/* Count up to either the end of the ASCII hexstring or the number
+ * of columns remaining.
+ */
+static int
+_count_hexstring_up_to (const unsigned char *s, int length, int columns)
+{
+    int word = 0;
+
+    while (length-- && columns--) {
+	if (*s++ != '>')
 	    word++;
 	else
 	    return word;
@@ -134,7 +156,17 @@ _word_wrap_stream_write (cairo_output_stream_t  *base,
     int word;
 
     while (length) {
-	if (isspace (*data)) {
+	if (*data == '<') {
+	    stream->in_hexstring = TRUE;
+	    data++;
+	    length--;
+	    _cairo_output_stream_printf (stream->output, "<");
+	} else if (*data == '>') {
+	    stream->in_hexstring = FALSE;
+	    data++;
+	    length--;
+	    _cairo_output_stream_printf (stream->output, ">");
+	} else if (isspace (*data)) {
 	    newline =  (*data == '\n' || *data == '\r');
 	    if (! newline && stream->column >= stream->max_column) {
 		_cairo_output_stream_printf (stream->output, "\n");
@@ -149,11 +181,16 @@ _word_wrap_stream_write (cairo_output_stream_t  *base,
 		stream->column++;
 	    stream->last_write_was_space = TRUE;
 	} else {
-	    word = _count_word_up_to (data, length);
-	    /* Don't wrap if this word is a continuation of a word
-	     * from a previous call to write. */
+	    if (stream->in_hexstring) {
+		word = _count_hexstring_up_to (data, length,
+					       MAX (stream->max_column - stream->column, 0));
+	    } else {
+		word = _count_word_up_to (data, length);
+	    }
+	    /* 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->last_write_was_space || stream->in_hexstring))
 	    {
 		_cairo_output_stream_printf (stream->output, "\n");
 		stream->column = 0;
@@ -198,6 +235,7 @@ _word_wrap_stream_create (cairo_output_stream_t *output, int max_column)
     stream->max_column = max_column;
     stream->column = 0;
     stream->last_write_was_space = FALSE;
+    stream->in_hexstring = FALSE;
 
     return &stream->base;
 }
commit 204a27aadb2390b62bd75857d8736b34870f79b1
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Sat Feb 16 20:35:42 2008 +1030

    PDF: Word wrap _cairo_pdf_operators_show_glyphs output

diff --git a/src/cairo-pdf-operators.c b/src/cairo-pdf-operators.c
index f870b92..1db6a8e 100644
--- a/src/cairo-pdf-operators.c
+++ b/src/cairo-pdf-operators.c
@@ -589,11 +589,17 @@ _cairo_pdf_operators_show_glyphs (cairo_pdf_operators_t		*pdf_operators,
     double Tlm_x = 0, Tlm_y = 0;
     double Tm_x = 0, y;
     int i, hex_width;
+    cairo_output_stream_t *word_wrap_stream;
 
     for (i = 0; i < num_glyphs; i++)
 	cairo_matrix_transform_point (&pdf_operators->cairo_to_pdf, &glyphs[i].x, &glyphs[i].y);
 
-    _cairo_output_stream_printf (pdf_operators->stream,
+    word_wrap_stream = _word_wrap_stream_create (pdf_operators->stream, 79);
+    status = _cairo_output_stream_get_status (word_wrap_stream);
+    if (status)
+	return status;
+
+    _cairo_output_stream_printf (word_wrap_stream,
 				 "BT\r\n");
 
     if (scaled_font->scale.xy == 0.0 &&
@@ -624,10 +630,10 @@ _cairo_pdf_operators_show_glyphs (cairo_pdf_operators_t		*pdf_operators,
 
 	if (subset_glyph.subset_id != current_subset_id) {
             if (in_TJ) {
-                _cairo_output_stream_printf (pdf_operators->stream, ">] TJ\r\n");
+                _cairo_output_stream_printf (word_wrap_stream, ">] TJ\r\n");
                 in_TJ = FALSE;
             }
-	    _cairo_output_stream_printf (pdf_operators->stream,
+	    _cairo_output_stream_printf (word_wrap_stream,
 					 "/f-%d-%d 1 Tf\r\n",
 					 subset_glyph.font_id,
 					 subset_glyph.subset_id);
@@ -641,7 +647,7 @@ _cairo_pdf_operators_show_glyphs (cairo_pdf_operators_t		*pdf_operators,
         }
 
         if (subset_glyph.subset_id != current_subset_id || !diagonal) {
-            _cairo_output_stream_printf (pdf_operators->stream,
+            _cairo_output_stream_printf (word_wrap_stream,
                                          "%f %f %f %f %f %f Tm\r\n",
                                          scaled_font->scale.xx,
                                          -scaled_font->scale.yx,
@@ -662,7 +668,7 @@ _cairo_pdf_operators_show_glyphs (cairo_pdf_operators_t		*pdf_operators,
             {
                 if (!in_TJ) {
                     if (i != 0) {
-                        _cairo_output_stream_printf (pdf_operators->stream,
+                        _cairo_output_stream_printf (word_wrap_stream,
                                                      "%f %f Td\r\n",
                                                      (glyphs[i].x - Tlm_x)/scaled_font->scale.xx,
                                                      (glyphs[i].y - Tlm_y)/scaled_font->scale.yy);
@@ -671,7 +677,7 @@ _cairo_pdf_operators_show_glyphs (cairo_pdf_operators_t		*pdf_operators,
                         Tlm_y = glyphs[i].y;
                         Tm_x = Tlm_x;
                     }
-                    _cairo_output_stream_printf (pdf_operators->stream,
+                    _cairo_output_stream_printf (word_wrap_stream,
                                                  "[<%0*x",
                                                  hex_width,
                                                  subset_glyph.subset_glyph_index);
@@ -681,12 +687,12 @@ _cairo_pdf_operators_show_glyphs (cairo_pdf_operators_t		*pdf_operators,
                     if (fabs((glyphs[i].x - Tm_x)/scaled_font->scale.xx) > GLYPH_POSITION_TOLERANCE) {
                         double delta = glyphs[i].x - Tm_x;
 
-                        _cairo_output_stream_printf (pdf_operators->stream,
+                        _cairo_output_stream_printf (word_wrap_stream,
                                                      "> %f <",
                                                      -1000.0*delta/scaled_font->scale.xx);
                         Tm_x += delta;
                     }
-                    _cairo_output_stream_printf (pdf_operators->stream,
+                    _cairo_output_stream_printf (word_wrap_stream,
                                                  "%0*x",
                                                  hex_width,
                                                  subset_glyph.subset_glyph_index);
@@ -699,12 +705,12 @@ _cairo_pdf_operators_show_glyphs (cairo_pdf_operators_t		*pdf_operators,
                     if (fabs((glyphs[i].x - Tm_x)/scaled_font->scale.xx) > GLYPH_POSITION_TOLERANCE) {
                         double delta = glyphs[i].x - Tm_x;
 
-                        _cairo_output_stream_printf (pdf_operators->stream,
+                        _cairo_output_stream_printf (word_wrap_stream,
                                                      "> %f <",
                                                      -1000.0*delta/scaled_font->scale.xx);
                         Tm_x += delta;
                     }
-                    _cairo_output_stream_printf (pdf_operators->stream,
+                    _cairo_output_stream_printf (word_wrap_stream,
                                                  "%0*x>] TJ\r\n",
                                                  hex_width,
                                                  subset_glyph.subset_glyph_index);
@@ -712,7 +718,7 @@ _cairo_pdf_operators_show_glyphs (cairo_pdf_operators_t		*pdf_operators,
                     in_TJ = FALSE;
                 } else {
                     if (i != 0) {
-                        _cairo_output_stream_printf (pdf_operators->stream,
+                        _cairo_output_stream_printf (word_wrap_stream,
                                                      "%f %f Td ",
                                                      (glyphs[i].x - Tlm_x)/scaled_font->scale.xx,
                                                      (glyphs[i].y - Tlm_y)/-scaled_font->scale.yy);
@@ -720,7 +726,7 @@ _cairo_pdf_operators_show_glyphs (cairo_pdf_operators_t		*pdf_operators,
                         Tlm_y = glyphs[i].y;
                         Tm_x = Tlm_x;
                     }
-                    _cairo_output_stream_printf (pdf_operators->stream,
+                    _cairo_output_stream_printf (word_wrap_stream,
                                                  "<%0*x> Tj ",
                                                  hex_width,
                                                  subset_glyph.subset_glyph_index);
@@ -728,15 +734,19 @@ _cairo_pdf_operators_show_glyphs (cairo_pdf_operators_t		*pdf_operators,
                 }
             }
         } else {
-            _cairo_output_stream_printf (pdf_operators->stream,
+            _cairo_output_stream_printf (word_wrap_stream,
                                          "<%0*x> Tj\r\n",
                                          hex_width,
                                          subset_glyph.subset_glyph_index);
         }
     }
 
-    _cairo_output_stream_printf (pdf_operators->stream,
+    _cairo_output_stream_printf (word_wrap_stream,
 				 "ET\r\n");
 
+    status = _cairo_output_stream_destroy (word_wrap_stream);
+    if (status)
+	return status;
+
     return _cairo_output_stream_get_status (pdf_operators->stream);
 }


More information about the cairo-commit mailing list