[cairo-commit] 4 commits - src/cairo-pdf-surface.c
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Tue Apr 26 12:58:43 UTC 2022
src/cairo-pdf-surface.c | 38 ++++++++++++++++++++++++++------------
1 file changed, 26 insertions(+), 12 deletions(-)
New commits:
commit f07d539c07488edccd0bea241073572bc20c8ed1
Merge: fafbfcda9 e37afffd5
Author: Adrian Johnson <ajohnson at redneon.com>
Date: Tue Apr 26 12:58:41 2022 +0000
Merge branch 'issue-514' into 'master'
pdf: reset current operator when resetting clip
Closes #514
See merge request cairo/cairo!256
commit e37afffd50a3f8f2becc943824d33aac36fae9ec
Merge: 059f044e6 b63dc83c8
Author: Adrian Johnson <ajohnson at redneon.com>
Date: Mon Oct 4 14:47:15 2021 +1030
Merge branch 'master' into issue-514
commit 059f044e6224696dc41b6ec4331d1bca72410191
Author: Adrian Johnson <ajohnson at redneon.com>
Date: Mon Oct 4 14:30:33 2021 +1030
pdf: reset gstate in groups
diff --git a/src/cairo-pdf-surface.c b/src/cairo-pdf-surface.c
index e51c36156..e3d104228 100644
--- a/src/cairo-pdf-surface.c
+++ b/src/cairo-pdf-surface.c
@@ -1239,7 +1239,8 @@ _cairo_operator_to_pdf_blend_mode (cairo_operator_t op)
static void
_cairo_pdf_surface_emit_group_resources (cairo_pdf_surface_t *surface,
- cairo_pdf_group_resources_t *res)
+ cairo_pdf_group_resources_t *res,
+ cairo_bool_t gs0)
{
int num_alphas, num_smasks, num_resources, i;
double alpha;
@@ -1254,6 +1255,11 @@ _cairo_pdf_surface_emit_group_resources (cairo_pdf_surface_t *surface,
_cairo_output_stream_printf (surface->output,
" /ExtGState <<\n");
+ if (gs0) {
+ _cairo_output_stream_printf (surface->output,
+ " /gs0 << /BM /Normal /SMask /None /CA 1.0 /ca 1.0 >>\n");
+ }
+
for (i = 0; i < CAIRO_NUM_OPERATORS; i++) {
if (res->operators[i]) {
_cairo_output_stream_printf (surface->output,
@@ -2055,7 +2061,7 @@ _cairo_pdf_surface_write_memory_stream (cairo_pdf_surface_t *surface,
_cairo_output_stream_printf (surface->output,
" >>\n"
" /Resources\n");
- _cairo_pdf_surface_emit_group_resources (surface, resources);
+ _cairo_pdf_surface_emit_group_resources (surface, resources, TRUE);
_cairo_output_stream_printf (surface->output,
">>\n"
"stream\n");
@@ -2076,9 +2082,6 @@ _cairo_pdf_surface_open_group (cairo_pdf_surface_t *surface,
assert (surface->group_stream.active == FALSE);
surface->group_stream.active = TRUE;
- surface->current_pattern_is_solid_color = FALSE;
- surface->current_operator = CAIRO_OPERATOR_OVER;
- _cairo_pdf_operators_reset (&surface->pdf_operators);
surface->group_stream.mem_stream = _cairo_memory_stream_create ();
@@ -2105,6 +2108,12 @@ _cairo_pdf_surface_open_group (cairo_pdf_surface_t *surface,
surface->group_stream.is_knockout = FALSE;
surface->group_stream.bbox = *bbox;
+ /* Reset gstate */
+ _cairo_output_stream_printf (surface->output, "/gs0 gs\n");
+ surface->current_pattern_is_solid_color = FALSE;
+ surface->current_operator = CAIRO_OPERATOR_OVER;
+ _cairo_pdf_operators_reset (&surface->pdf_operators);
+
return status;
}
@@ -2417,7 +2426,8 @@ _cairo_pdf_surface_open_content_stream (cairo_pdf_surface_t *surface,
}
static cairo_int_status_t
-_cairo_pdf_surface_close_content_stream (cairo_pdf_surface_t *surface)
+_cairo_pdf_surface_close_content_stream (cairo_pdf_surface_t *surface,
+ cairo_bool_t is_form)
{
cairo_int_status_t status;
@@ -2437,7 +2447,7 @@ _cairo_pdf_surface_close_content_stream (cairo_pdf_surface_t *surface)
_cairo_output_stream_printf (surface->output,
"%d 0 obj\n",
surface->content_resources.id);
- _cairo_pdf_surface_emit_group_resources (surface, &surface->resources);
+ _cairo_pdf_surface_emit_group_resources (surface, &surface->resources, is_form);
_cairo_output_stream_printf (surface->output,
"endobj\n");
@@ -3681,6 +3691,9 @@ _cairo_pdf_surface_emit_recording_surface (cairo_pdf_surface_t *surface,
if (unlikely (status))
goto err;
+ /* Reset gstate */
+ _cairo_output_stream_printf (surface->output, "/gs0 gs\n");
+
if (source->content == CAIRO_CONTENT_COLOR) {
status = _cairo_pdf_surface_add_alpha (surface, 1.0, &alpha);
if (unlikely (status))
@@ -3703,7 +3716,7 @@ _cairo_pdf_surface_emit_recording_surface (cairo_pdf_surface_t *surface,
if (unlikely (status))
goto err;
- status = _cairo_pdf_surface_close_content_stream (surface);
+ status = _cairo_pdf_surface_close_content_stream (surface, TRUE);
_cairo_surface_clipper_reset (&surface->clipper);
surface->clipper = old_clipper;
@@ -5371,7 +5384,7 @@ _cairo_pdf_surface_show_page (void *abstract_surface)
if (unlikely (status))
return status;
- status = _cairo_pdf_surface_close_content_stream (surface);
+ status = _cairo_pdf_surface_close_content_stream (surface, FALSE);
if (unlikely (status))
return status;
@@ -6628,7 +6641,7 @@ _cairo_pdf_surface_emit_type3_font_subset (cairo_pdf_surface_t *surface,
_cairo_output_stream_printf (surface->output,
" /Resources\n");
- _cairo_pdf_surface_emit_group_resources (surface, &surface->resources);
+ _cairo_pdf_surface_emit_group_resources (surface, &surface->resources, FALSE);
if (to_unicode_stream.id != 0)
_cairo_output_stream_printf (surface->output,
@@ -7363,7 +7376,7 @@ _cairo_pdf_surface_write_page (cairo_pdf_surface_t *surface)
if (unlikely (status))
return status;
- status = _cairo_pdf_surface_close_content_stream (surface);
+ status = _cairo_pdf_surface_close_content_stream (surface, FALSE);
if (unlikely (status))
return status;
}
@@ -7662,7 +7675,7 @@ _cairo_pdf_surface_start_fallback (cairo_pdf_surface_t *surface)
cairo_box_double_t bbox;
cairo_int_status_t status;
- status = _cairo_pdf_surface_close_content_stream (surface);
+ status = _cairo_pdf_surface_close_content_stream (surface, FALSE);
if (unlikely (status))
return status;
commit 58aadd1481421d3c3e3189b4de0f640404ecaaab
Author: Adrian Johnson <ajohnson at redneon.com>
Date: Sun Oct 3 14:39:22 2021 +1030
pdf: reset current operator when resetting clip
PDF output uses q/Q operators to reset the clip path. This also resets
the PDF graphics state including the current blend mode.
When resetting the clip path, reset the current blend mode tracked by
the PDF surface so that if a non-default blend mode is required, the
surface will emit the correct blend mode.
Fixes #514
diff --git a/src/cairo-pdf-surface.c b/src/cairo-pdf-surface.c
index 07fe5dffc..e51c36156 100644
--- a/src/cairo-pdf-surface.c
+++ b/src/cairo-pdf-surface.c
@@ -417,6 +417,7 @@ _cairo_pdf_surface_clipper_intersect_clip_path (cairo_surface_clipper_t *clipper
_cairo_output_stream_printf (surface->output, "Q q\n");
surface->current_pattern_is_solid_color = FALSE;
+ surface->current_operator = CAIRO_OPERATOR_OVER;
_cairo_pdf_operators_reset (&surface->pdf_operators);
return CAIRO_STATUS_SUCCESS;
More information about the cairo-commit
mailing list