From 837bf73f082f3bb0158b57cf7c456380531853b3 Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Tue, 8 Jul 2008 22:00:15 +0930 Subject: [PATCH] Add PDF operators function to reset any remembered state --- src/cairo-pdf-operators-private.h | 3 +++ src/cairo-pdf-operators.c | 15 +++++++++++++++ src/cairo-pdf-surface.c | 4 ++++ src/cairo-ps-surface.c | 5 +++++ 4 files changed, 27 insertions(+) diff --git a/src/cairo-pdf-operators-private.h b/src/cairo-pdf-operators-private.h index b48233513..089404732 100644 --- a/src/cairo-pdf-operators-private.h +++ b/src/cairo-pdf-operators-private.h @@ -110,6 +110,9 @@ _cairo_pdf_operators_set_cairo_to_pdf_matrix (cairo_pdf_operators_t *pdf_operato cairo_private cairo_status_t _cairo_pdf_operators_flush (cairo_pdf_operators_t *pdf_operators); +cairo_private void +_cairo_pdf_operators_reset (cairo_pdf_operators_t *pdf_operators); + cairo_private cairo_int_status_t _cairo_pdf_operators_clip (cairo_pdf_operators_t *pdf_operators, cairo_path_fixed_t *path, diff --git a/src/cairo-pdf-operators.c b/src/cairo-pdf-operators.c index da0191972..4fd15a795 100644 --- a/src/cairo-pdf-operators.c +++ b/src/cairo-pdf-operators.c @@ -121,6 +121,21 @@ _cairo_pdf_operators_flush (cairo_pdf_operators_t *pdf_operators) return status; } +/* Reset the known graphics state of the PDF consumer. ie no + * assumptions will be made about the state. The next time a + * particular graphics state is required (eg line width) the state + * operator is always emitted and then remembered for subsequent + * operatations. + * + * This should be called when starting a new stream or after emitting + * the 'Q' operator (where pdf-operators functions were called inside + * the q/Q pair). + */ +void +_cairo_pdf_operators_reset (cairo_pdf_operators_t *pdf_operators) +{ +} + /* A word wrap stream can be used as a filter to do word wrapping on * top of an existing output stream. The word wrapping is quite * simple, using isspace to determine characters that separate diff --git a/src/cairo-pdf-surface.c b/src/cairo-pdf-surface.c index f68b69660..1d1407c95 100644 --- a/src/cairo-pdf-surface.c +++ b/src/cairo-pdf-surface.c @@ -870,6 +870,7 @@ _cairo_pdf_surface_open_stream (cairo_pdf_surface_t *surface, surface->pdf_stream.length = length; surface->pdf_stream.compressed = compressed; surface->current_pattern_is_solid_color = FALSE; + _cairo_pdf_operators_reset (&surface->pdf_operators); _cairo_output_stream_printf (surface->output, "%d 0 obj\n" @@ -1006,6 +1007,7 @@ _cairo_pdf_surface_open_group (cairo_pdf_surface_t *surface, surface->group_stream.active = TRUE; surface->current_pattern_is_solid_color = FALSE; + _cairo_pdf_operators_reset (&surface->pdf_operators); surface->group_stream.mem_stream = _cairo_memory_stream_create (); @@ -2722,6 +2724,7 @@ _cairo_pdf_surface_unselect_pattern (cairo_pdf_surface_t *surface) return status; _cairo_output_stream_printf (surface->output, "Q\n"); + _cairo_pdf_operators_reset (&surface->pdf_operators); } surface->select_pattern_gstate_saved = FALSE; @@ -2783,6 +2786,7 @@ _cairo_pdf_surface_intersect_clip_path (void *abstract_surface, _cairo_output_stream_printf (surface->output, "Q q\n"); surface->current_pattern_is_solid_color = FALSE; + _cairo_pdf_operators_reset (&surface->pdf_operators); return CAIRO_STATUS_SUCCESS; } diff --git a/src/cairo-ps-surface.c b/src/cairo-ps-surface.c index aa93f1e25..e6ce3f30a 100644 --- a/src/cairo-ps-surface.c +++ b/src/cairo-ps-surface.c @@ -2031,6 +2031,7 @@ _cairo_ps_surface_emit_meta_surface (cairo_ps_surface_t *surface, surface->width = meta_extents.width; surface->height = meta_extents.height; surface->current_pattern_is_solid_color = FALSE; + _cairo_pdf_operators_reset (&surface->pdf_operators); 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); @@ -2064,6 +2065,7 @@ _cairo_ps_surface_emit_meta_surface (cairo_ps_surface_t *surface, surface->width = old_width; surface->height = old_height; surface->current_pattern_is_solid_color = FALSE; + _cairo_pdf_operators_reset (&surface->pdf_operators); surface->cairo_to_ps = old_cairo_to_ps; status = _cairo_surface_set_clip (&surface->base, old_clip); if (status) @@ -2901,6 +2903,7 @@ _cairo_ps_surface_intersect_clip_path (void *abstract_surface, _cairo_output_stream_printf (stream, "Q q\n"); surface->current_pattern_is_solid_color = FALSE; + _cairo_pdf_operators_reset (&surface->pdf_operators); return CAIRO_STATUS_SUCCESS; } @@ -3079,6 +3082,7 @@ _cairo_ps_surface_fill (void *abstract_surface, return status; _cairo_output_stream_printf (surface->stream, "Q\n"); + _cairo_pdf_operators_reset (&surface->pdf_operators); } else { status = _cairo_ps_surface_emit_pattern (surface, source, op); if (status == CAIRO_INT_STATUS_NOTHING_TO_DO) @@ -3207,6 +3211,7 @@ _cairo_ps_surface_set_bounding_box (void *abstract_surface, surface->bbox_y2 = y2; } surface->current_pattern_is_solid_color = FALSE; + _cairo_pdf_operators_reset (&surface->pdf_operators); return _cairo_output_stream_get_status (surface->stream); }