[cairo-commit] src/cairo-pdf-operators.c src/cairo-pdf-operators-private.h src/cairo-pdf-surface.c src/cairo-ps-surface.c src/cairo-type3-glyph-surface.c src/cairo-type3-glyph-surface-private.h

Adrian Johnson ajohnson at kemper.freedesktop.org
Fri Oct 31 01:57:13 PDT 2014


 src/cairo-pdf-operators-private.h       |    4 +++-
 src/cairo-pdf-operators.c               |   16 ++++++++++------
 src/cairo-pdf-surface.c                 |    9 ++++++---
 src/cairo-ps-surface.c                  |    9 ++++++---
 src/cairo-type3-glyph-surface-private.h |    3 ++-
 src/cairo-type3-glyph-surface.c         |    6 ++++--
 6 files changed, 31 insertions(+), 16 deletions(-)

New commits:
commit e4b78424ac82588bcb9b855d5b6d5872050d33f9
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Fri Oct 31 19:06:42 2014 +1030

    pdf-operators: only wrap text strings for PS output
    
    since the PS Document Structing Conventions impose a 255 character
    line limit. PDF does not require wrapping.
    
    pdf-operators is designed to emit the same output for PS and PDF.
    Unfortunately some PDF interpreters don't like strings split with
    '\\\n' and some PS interpreters don't like strings split with ')('.
    So we are forced to make pdf-operators handling string wrapping
    differently for PDF and PS.
    
    Bug 85662

diff --git a/src/cairo-pdf-operators-private.h b/src/cairo-pdf-operators-private.h
index 5d36879..4314a04 100644
--- a/src/cairo-pdf-operators-private.h
+++ b/src/cairo-pdf-operators-private.h
@@ -70,6 +70,7 @@ typedef struct _cairo_pdf_operators {
     cairo_scaled_font_subsets_t *font_subsets;
     cairo_pdf_operators_use_font_subset_t use_font_subset;
     void *use_font_subset_closure;
+    cairo_bool_t ps_output; /* output is for PostScript */
     cairo_bool_t use_actual_text;
     cairo_bool_t in_text_object; /* inside BT/ET pair */
 
@@ -101,7 +102,8 @@ cairo_private void
 _cairo_pdf_operators_init (cairo_pdf_operators_t       *pdf_operators,
 			   cairo_output_stream_t       *stream,
 			   cairo_matrix_t 	       *cairo_to_pdf,
-			   cairo_scaled_font_subsets_t *font_subsets);
+			   cairo_scaled_font_subsets_t *font_subsets,
+			   cairo_bool_t                 ps);
 
 cairo_private cairo_status_t
 _cairo_pdf_operators_fini (cairo_pdf_operators_t       *pdf_operators);
diff --git a/src/cairo-pdf-operators.c b/src/cairo-pdf-operators.c
index 48ae3a6..ee41eba 100644
--- a/src/cairo-pdf-operators.c
+++ b/src/cairo-pdf-operators.c
@@ -57,11 +57,13 @@ void
 _cairo_pdf_operators_init (cairo_pdf_operators_t	*pdf_operators,
 			   cairo_output_stream_t	*stream,
 			   cairo_matrix_t		*cairo_to_pdf,
-			   cairo_scaled_font_subsets_t  *font_subsets)
+			   cairo_scaled_font_subsets_t  *font_subsets,
+			   cairo_bool_t                  ps)
 {
     pdf_operators->stream = stream;
     pdf_operators->cairo_to_pdf = *cairo_to_pdf;
     pdf_operators->font_subsets = font_subsets;
+    pdf_operators->ps_output = ps;
     pdf_operators->use_font_subset = NULL;
     pdf_operators->use_font_subset_closure = NULL;
     pdf_operators->in_text_object = FALSE;
@@ -176,6 +178,7 @@ typedef struct _word_wrap_stream {
     cairo_output_stream_t base;
     cairo_output_stream_t *output;
     int max_column;
+    cairo_bool_t ps_output;
     int column;
     cairo_word_wrap_state_t state;
     cairo_bool_t in_escape;
@@ -269,7 +272,7 @@ _word_wrap_stream_count_string_up_to (word_wrap_stream_t *stream,
 	    if (*s == '\\') {
 		stream->in_escape = TRUE;
 		stream->escape_digits = 0;
-	    } else if (stream->column > stream->max_column) {
+	    } else if (stream->ps_output && stream->column > stream->max_column) {
 		newline = TRUE;
 		break;
 	    }
@@ -284,7 +287,7 @@ _word_wrap_stream_count_string_up_to (word_wrap_stream_t *stream,
 	_cairo_output_stream_write (stream->output, data, count);
 
     if (newline) {
-	_cairo_output_stream_printf (stream->output, ")\n(");
+	_cairo_output_stream_printf (stream->output, "\\\n");
 	stream->column = 0;
     }
 
@@ -348,7 +351,7 @@ _word_wrap_stream_close (cairo_output_stream_t *base)
 }
 
 static cairo_output_stream_t *
-_word_wrap_stream_create (cairo_output_stream_t *output, int max_column)
+_word_wrap_stream_create (cairo_output_stream_t *output, cairo_bool_t ps, int max_column)
 {
     word_wrap_stream_t *stream;
 
@@ -367,6 +370,7 @@ _word_wrap_stream_create (cairo_output_stream_t *output, int max_column)
 			       _word_wrap_stream_close);
     stream->output = output;
     stream->max_column = max_column;
+    stream->ps_output = ps;
     stream->column = 0;
     stream->state = WRAP_STATE_DELIMITER;
     stream->in_escape = FALSE;
@@ -502,7 +506,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, 72);
+    word_wrap = _word_wrap_stream_create (pdf_operators->stream, pdf_operators->ps_output, 72);
     status = _cairo_output_stream_get_status (word_wrap);
     if (unlikely (status))
 	return _cairo_output_stream_destroy (word_wrap);
@@ -1051,7 +1055,7 @@ _cairo_pdf_operators_flush_glyphs (cairo_pdf_operators_t    *pdf_operators)
     if (pdf_operators->num_glyphs == 0)
 	return CAIRO_STATUS_SUCCESS;
 
-    word_wrap_stream = _word_wrap_stream_create (pdf_operators->stream, 72);
+    word_wrap_stream = _word_wrap_stream_create (pdf_operators->stream, pdf_operators->ps_output, 72);
     status = _cairo_output_stream_get_status (word_wrap_stream);
     if (unlikely (status))
 	return _cairo_output_stream_destroy (word_wrap_stream);
diff --git a/src/cairo-pdf-surface.c b/src/cairo-pdf-surface.c
index 83ff48d..fd52b0d 100644
--- a/src/cairo-pdf-surface.c
+++ b/src/cairo-pdf-surface.c
@@ -430,7 +430,8 @@ _cairo_pdf_surface_create_for_stream_internal (cairo_output_stream_t	*output,
     _cairo_pdf_operators_init (&surface->pdf_operators,
 			       surface->output,
 			       &surface->cairo_to_pdf,
-			       surface->font_subsets);
+			       surface->font_subsets,
+			       FALSE);
     _cairo_pdf_operators_set_font_subsets_callback (&surface->pdf_operators,
 						    _cairo_pdf_surface_add_font,
 						    surface);
@@ -5677,7 +5678,8 @@ _cairo_pdf_surface_analyze_user_font_subset (cairo_scaled_font_subset_t *font_su
     type3_surface = _cairo_type3_glyph_surface_create (font_subset->scaled_font,
 						       null_stream,
 						       _cairo_pdf_emit_imagemask,
-						       surface->font_subsets);
+						       surface->font_subsets,
+						       FALSE);
     if (unlikely (type3_surface->status)) {
 	status2 = _cairo_output_stream_destroy (null_stream);
 	return type3_surface->status;
@@ -5738,7 +5740,8 @@ _cairo_pdf_surface_emit_type3_font_subset (cairo_pdf_surface_t		*surface,
     type3_surface = _cairo_type3_glyph_surface_create (font_subset->scaled_font,
 						       NULL,
 						       _cairo_pdf_emit_imagemask,
-						       surface->font_subsets);
+						       surface->font_subsets,
+						       FALSE);
     if (unlikely (type3_surface->status)) {
         free (glyphs);
         free (widths);
diff --git a/src/cairo-ps-surface.c b/src/cairo-ps-surface.c
index 706e305..03eba62 100644
--- a/src/cairo-ps-surface.c
+++ b/src/cairo-ps-surface.c
@@ -628,7 +628,8 @@ _cairo_ps_surface_analyze_user_font_subset (cairo_scaled_font_subset_t *font_sub
     type3_surface = _cairo_type3_glyph_surface_create (font_subset->scaled_font,
 						       NULL,
 						       _cairo_ps_emit_imagemask,
-						       surface->font_subsets);
+						       surface->font_subsets,
+						       TRUE);
 
     for (i = 0; i < font_subset->num_glyphs; i++) {
 	status = _cairo_type3_glyph_surface_analyze_glyph (type3_surface,
@@ -676,7 +677,8 @@ _cairo_ps_surface_emit_type3_font_subset (cairo_ps_surface_t		*surface,
     type3_surface = _cairo_type3_glyph_surface_create (font_subset->scaled_font,
 						       NULL,
 						       _cairo_ps_emit_imagemask,
-						       surface->font_subsets);
+						       surface->font_subsets,
+						       TRUE);
     status = type3_surface->status;
     if (unlikely (status))
 	return status;
@@ -1068,7 +1070,8 @@ _cairo_ps_surface_create_for_stream_internal (cairo_output_stream_t *stream,
     _cairo_pdf_operators_init (&surface->pdf_operators,
 			       surface->stream,
 			       &surface->cairo_to_ps,
-			       surface->font_subsets);
+			       surface->font_subsets,
+			       TRUE);
     surface->num_pages = 0;
 
     cairo_list_init (&surface->document_media);
diff --git a/src/cairo-type3-glyph-surface-private.h b/src/cairo-type3-glyph-surface-private.h
index 6cd37de..6f40f1c 100644
--- a/src/cairo-type3-glyph-surface-private.h
+++ b/src/cairo-type3-glyph-surface-private.h
@@ -65,7 +65,8 @@ cairo_private cairo_surface_t *
 _cairo_type3_glyph_surface_create (cairo_scaled_font_t			 *scaled_font,
 				   cairo_output_stream_t		 *stream,
 				   cairo_type3_glyph_surface_emit_image_t emit_image,
-				   cairo_scaled_font_subsets_t		 *font_subsets);
+				   cairo_scaled_font_subsets_t		 *font_subsets,
+				   cairo_bool_t                           ps_output);
 
 cairo_private void
 _cairo_type3_glyph_surface_set_font_subsets_callback (void				    *abstract_surface,
diff --git a/src/cairo-type3-glyph-surface.c b/src/cairo-type3-glyph-surface.c
index 5bb6bfc..c99d461 100644
--- a/src/cairo-type3-glyph-surface.c
+++ b/src/cairo-type3-glyph-surface.c
@@ -74,7 +74,8 @@ cairo_surface_t *
 _cairo_type3_glyph_surface_create (cairo_scaled_font_t			 *scaled_font,
 				   cairo_output_stream_t		 *stream,
 				   cairo_type3_glyph_surface_emit_image_t emit_image,
-				   cairo_scaled_font_subsets_t		 *font_subsets)
+				   cairo_scaled_font_subsets_t		 *font_subsets,
+				   cairo_bool_t ps)
 {
     cairo_type3_glyph_surface_t *surface;
     cairo_matrix_t invert_y_axis;
@@ -106,7 +107,8 @@ _cairo_type3_glyph_surface_create (cairo_scaled_font_t			 *scaled_font,
     _cairo_pdf_operators_init (&surface->pdf_operators,
 			       surface->stream,
 			       &surface->cairo_to_pdf,
-			       font_subsets);
+			       font_subsets,
+			       ps);
 
     _cairo_surface_clipper_init (&surface->clipper,
 				 _cairo_type3_glyph_surface_clipper_intersect_clip_path);


More information about the cairo-commit mailing list