[cairo-commit] src/cairo-ps-surface.c
Adrian Johnson
ajohnson at kemper.freedesktop.org
Mon Oct 5 04:46:28 PDT 2015
src/cairo-ps-surface.c | 130 +++++++++++--------------------------------------
1 file changed, 31 insertions(+), 99 deletions(-)
New commits:
commit 0537479bd1d4c5a3bc0f6f41dec4deb98481f34a
Author: Adrian Johnson <ajohnson at redneon.com>
Date: Mon Oct 5 16:10:02 2015 +1030
ps: merge emit_recording surface and emit_recording_subsurface into one function
Most of each function was identical.
diff --git a/src/cairo-ps-surface.c b/src/cairo-ps-surface.c
index 03eba62..12b682b 100644
--- a/src/cairo-ps-surface.c
+++ b/src/cairo-ps-surface.c
@@ -2914,8 +2914,10 @@ _cairo_ps_surface_emit_jpeg_image (cairo_ps_surface_t *surface,
}
static cairo_status_t
-_cairo_ps_surface_emit_recording_surface (cairo_ps_surface_t *surface,
- cairo_surface_t *recording_surface)
+_cairo_ps_surface_emit_recording_surface (cairo_ps_surface_t *surface,
+ cairo_surface_t *recording_surface,
+ cairo_bool_t subsurface,
+ const cairo_rectangle_int_t *extents)
{
double old_width, old_height;
cairo_matrix_t old_cairo_to_ps;
@@ -2938,12 +2940,30 @@ _cairo_ps_surface_emit_recording_surface (cairo_ps_surface_t *surface,
if (_cairo_surface_is_snapshot (recording_surface))
free_me = recording_surface = _cairo_surface_snapshot_get_target (recording_surface);
- status =
- _cairo_recording_surface_get_bbox ((cairo_recording_surface_t *) recording_surface,
- &bbox,
- NULL);
- if (unlikely (status))
- goto err;
+ if (subsurface) {
+ surface->page_bbox.x = surface->page_bbox.y = 0;
+ surface->page_bbox.width = surface->width = extents->width;
+ surface->page_bbox.height = surface->height = extents->height;
+
+#if DEBUG_PS
+ _cairo_output_stream_printf (surface->stream,
+ "%% _cairo_ps_surface_emit_recording_subsurface"
+ " (%d, %d), (%d, %d)\n",
+ extents->x, extents->y,
+ extents->width, extents->height);
+#endif
+
+ } else {
+ status =
+ _cairo_recording_surface_get_bbox ((cairo_recording_surface_t *) recording_surface,
+ &bbox,
+ NULL);
+ if (unlikely (status))
+ goto err;
+
+ surface->width = _cairo_fixed_to_double (bbox.p2.x - bbox.p1.x);
+ surface->height = _cairo_fixed_to_double (bbox.p2.y - bbox.p1.y);
+ _cairo_box_round_to_rectangle (&bbox, &surface->page_bbox);
#if DEBUG_PS
_cairo_output_stream_printf (surface->stream,
@@ -2953,93 +2973,8 @@ _cairo_ps_surface_emit_recording_surface (cairo_ps_surface_t *surface,
_cairo_fixed_to_double (bbox.p2.x),
_cairo_fixed_to_double (bbox.p2.y));
#endif
-
- surface->width = _cairo_fixed_to_double (bbox.p2.x - bbox.p1.x);
- surface->height = _cairo_fixed_to_double (bbox.p2.y - bbox.p1.y);
- _cairo_box_round_to_rectangle (&bbox, &surface->page_bbox);
-
- 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);
- _cairo_output_stream_printf (surface->stream, " q\n");
-
- if (recording_surface->content == CAIRO_CONTENT_COLOR) {
- surface->content = CAIRO_CONTENT_COLOR;
- _cairo_output_stream_printf (surface->stream,
- " 0 g %d %d %d %d rectfill\n",
- surface->page_bbox.x,
- surface->page_bbox.y,
- surface->page_bbox.width,
- surface->page_bbox.height);
}
- status = _cairo_recording_surface_replay_region (recording_surface,
- NULL,
- &surface->base,
- CAIRO_RECORDING_REGION_NATIVE);
- assert (status != CAIRO_INT_STATUS_UNSUPPORTED);
- if (unlikely (status))
- goto err;
-
- status = _cairo_pdf_operators_flush (&surface->pdf_operators);
- if (unlikely (status))
- goto err;
-
- _cairo_output_stream_printf (surface->stream, " Q\n");
-
- _cairo_surface_clipper_reset (&surface->clipper);
- surface->clipper = old_clipper;
- surface->content = old_content;
- surface->width = old_width;
- surface->height = old_height;
- surface->page_bbox = old_page_bbox;
- surface->current_pattern_is_solid_color = FALSE;
- _cairo_pdf_operators_reset (&surface->pdf_operators);
- surface->cairo_to_ps = old_cairo_to_ps;
-
- _cairo_pdf_operators_set_cairo_to_pdf_matrix (&surface->pdf_operators,
- &surface->cairo_to_ps);
-
-err:
- cairo_surface_destroy (free_me);
- return status;
-}
-
-static cairo_int_status_t
-_cairo_ps_surface_emit_recording_subsurface (cairo_ps_surface_t *surface,
- cairo_surface_t *recording_surface,
- const cairo_rectangle_int_t *extents)
-{
- double old_width, old_height;
- cairo_matrix_t old_cairo_to_ps;
- cairo_content_t old_content;
- cairo_rectangle_int_t old_page_bbox;
- cairo_surface_clipper_t old_clipper;
- cairo_surface_t *free_me = NULL;
- cairo_int_status_t status;
-
- old_content = surface->content;
- old_width = surface->width;
- old_height = surface->height;
- old_page_bbox = surface->page_bbox;
- old_cairo_to_ps = surface->cairo_to_ps;
- old_clipper = surface->clipper;
- _cairo_surface_clipper_init (&surface->clipper,
- _cairo_ps_surface_clipper_intersect_clip_path);
-
-#if DEBUG_PS
- _cairo_output_stream_printf (surface->stream,
- "%% _cairo_ps_surface_emit_recording_subsurface (%d, %d), (%d, %d)\n",
- extents->x, extents->y,
- extents->width, extents->height);
-#endif
-
- surface->page_bbox.x = surface->page_bbox.y = 0;
- surface->page_bbox.width = surface->width = extents->width;
- surface->page_bbox.height = surface->height = 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);
@@ -3047,9 +2982,6 @@ _cairo_ps_surface_emit_recording_subsurface (cairo_ps_surface_t *surface,
&surface->cairo_to_ps);
_cairo_output_stream_printf (surface->stream, " q\n");
- if (_cairo_surface_is_snapshot (recording_surface))
- free_me = recording_surface = _cairo_surface_snapshot_get_target (recording_surface);
-
if (recording_surface->content == CAIRO_CONTENT_COLOR) {
surface->content = CAIRO_CONTENT_COLOR;
_cairo_output_stream_printf (surface->stream,
@@ -3061,7 +2993,7 @@ _cairo_ps_surface_emit_recording_subsurface (cairo_ps_surface_t *surface,
}
status = _cairo_recording_surface_replay_region (recording_surface,
- extents,
+ subsurface ? extents : NULL,
&surface->base,
CAIRO_RECORDING_REGION_NATIVE);
assert (status != CAIRO_INT_STATUS_UNSUPPORTED);
@@ -3158,9 +3090,9 @@ _cairo_ps_surface_emit_surface (cairo_ps_surface_t *surface,
if (source_surface->type == CAIRO_SURFACE_TYPE_RECORDING) {
if (source_surface->backend->type == CAIRO_SURFACE_TYPE_SUBSURFACE) {
cairo_surface_subsurface_t *sub = (cairo_surface_subsurface_t *) source_surface;
- status = _cairo_ps_surface_emit_recording_subsurface (surface, sub->target, &sub->extents);
+ status = _cairo_ps_surface_emit_recording_surface (surface, sub->target, TRUE, &sub->extents);
} else {
- status = _cairo_ps_surface_emit_recording_surface (surface, source_surface);
+ status = _cairo_ps_surface_emit_recording_surface (surface, source_surface, FALSE, NULL);
}
} else {
cairo_image_surface_t *image = (cairo_image_surface_t *) source_surface;
More information about the cairo-commit
mailing list