Skip to content

Commit

Permalink
ps: merge emit_recording surface and emit_recording_subsurface into o…
Browse files Browse the repository at this point in the history
…ne function

Most of each function was identical.
  • Loading branch information
Adrian Johnson committed Oct 5, 2015
1 parent e5d4f52 commit 0537479
Showing 1 changed file with 31 additions and 99 deletions.
130 changes: 31 additions & 99 deletions src/cairo-ps-surface.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand All @@ -2953,103 +2973,15 @@ _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);
_cairo_pdf_operators_set_cairo_to_pdf_matrix (&surface->pdf_operators,
&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,
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 0537479

Please sign in to comment.