diff options
author | Sebastian Rasmussen <sebras@gmail.com> | 2018-02-03 02:52:59 +0100 |
---|---|---|
committer | Sebastian Rasmussen <sebras@gmail.com> | 2018-02-14 15:15:44 +0100 |
commit | b2e7d38e845c7d4922d05e6e41f3a2dc1bc1b14a (patch) | |
tree | 3d489f46b718096b24c768841622985a1e4fa9c9 | |
parent | f51836b9732c38d945b87fda0770009a77ba680c (diff) | |
download | mupdf-b2e7d38e845c7d4922d05e6e41f3a2dc1bc1b14a.tar.xz |
Bug 698890: Remember to end groups when showing images.
-rw-r--r-- | source/pdf/pdf-op-run.c | 114 |
1 files changed, 72 insertions, 42 deletions
diff --git a/source/pdf/pdf-op-run.c b/source/pdf/pdf-op-run.c index 355e94d2..f16d228b 100644 --- a/source/pdf/pdf-op-run.c +++ b/source/pdf/pdf-op-run.c @@ -501,12 +501,47 @@ pdf_show_pattern(fz_context *ctx, pdf_run_processor *pr, pdf_pattern *pat, pdf_g } static void +pdf_show_image_imp(fz_context *ctx, pdf_run_processor *pr, fz_image *image, fz_matrix *image_ctm, fz_rect *bbox) +{ + pdf_gstate *gstate = pr->gstate + pr->gtop; + + if (image->colorspace) + { + fz_fill_image(ctx, pr->dev, image, image_ctm, gstate->fill.alpha, &gstate->fill.color_params); + return; + } + + if (gstate->fill.kind == PDF_MAT_COLOR) + fz_fill_image_mask(ctx, pr->dev, image, image_ctm, + gstate->fill.colorspace, gstate->fill.v, gstate->fill.alpha, &gstate->fill.color_params); + else if (gstate->fill.kind == PDF_MAT_PATTERN && gstate->fill.pattern) + { + fz_clip_image_mask(ctx, pr->dev, image, image_ctm, bbox); + fz_try(ctx) + pdf_show_pattern(ctx, pr, gstate->fill.pattern, &pr->gstate[gstate->fill.gstate_num], bbox, PDF_FILL); + fz_always(ctx) + fz_pop_clip(ctx, pr->dev); + fz_catch(ctx) + fz_rethrow(ctx); + } + else if (gstate->fill.kind == PDF_MAT_SHADE && gstate->fill.shade) + { + fz_clip_image_mask(ctx, pr->dev, image, image_ctm, bbox); + fz_try(ctx) + fz_fill_shade(ctx, pr->dev, gstate->fill.shade, &pr->gstate[gstate->fill.gstate_num].ctm, gstate->fill.alpha, &gstate->fill.color_params); + fz_always(ctx) + fz_pop_clip(ctx, pr->dev); + fz_catch(ctx) + fz_rethrow(ctx); + } +} + +static void pdf_show_image(fz_context *ctx, pdf_run_processor *pr, fz_image *image) { pdf_gstate *gstate = pr->gstate + pr->gtop; fz_matrix image_ctm; fz_rect bbox; - softmask_save softmask = { NULL }; if (pr->super.hidden) return; @@ -518,57 +553,52 @@ pdf_show_image(fz_context *ctx, pdf_run_processor *pr, fz_image *image) bbox = fz_unit_rect; fz_transform_rect(&bbox, &image_ctm); - if (image->mask) + if (image->mask && gstate->blendmode) { /* apply blend group even though we skip the soft mask */ - if (gstate->blendmode) - fz_begin_group(ctx, pr->dev, &bbox, NULL, 0, 0, gstate->blendmode, 1); - fz_clip_image_mask(ctx, pr->dev, image->mask, &image_ctm, &bbox); - } - else - gstate = pdf_begin_group(ctx, pr, &bbox, &softmask); + fz_begin_group(ctx, pr->dev, &bbox, NULL, 0, 0, gstate->blendmode, 1); - if (!image->colorspace) - { - switch (gstate->fill.kind) + fz_try(ctx) + fz_clip_image_mask(ctx, pr->dev, image->mask, &image_ctm, &bbox); + fz_catch(ctx) { - case PDF_MAT_NONE: - break; - case PDF_MAT_COLOR: - fz_fill_image_mask(ctx, pr->dev, image, &image_ctm, - gstate->fill.colorspace, gstate->fill.v, gstate->fill.alpha, &gstate->fill.color_params); - break; - case PDF_MAT_PATTERN: - if (gstate->fill.pattern) - { - fz_clip_image_mask(ctx, pr->dev, image, &image_ctm, &bbox); - pdf_show_pattern(ctx, pr, gstate->fill.pattern, &pr->gstate[gstate->fill.gstate_num], &bbox, PDF_FILL); - fz_pop_clip(ctx, pr->dev); - } - break; - case PDF_MAT_SHADE: - if (gstate->fill.shade) - { - fz_clip_image_mask(ctx, pr->dev, image, &image_ctm, &bbox); - fz_fill_shade(ctx, pr->dev, gstate->fill.shade, &pr->gstate[gstate->fill.gstate_num].ctm, gstate->fill.alpha, &gstate->fill.color_params); - fz_pop_clip(ctx, pr->dev); - } - break; + fz_end_group(ctx, pr->dev); + fz_rethrow(ctx); } + + fz_try(ctx) + pdf_show_image_imp(ctx, pr, image, &image_ctm, &bbox); + fz_always(ctx) + { + fz_pop_clip(ctx, pr->dev); + fz_end_group(ctx, pr->dev); + } + fz_catch(ctx) + fz_rethrow(ctx); } - else + else if (image->mask) { - fz_fill_image(ctx, pr->dev, image, &image_ctm, gstate->fill.alpha, &gstate->fill.color_params); + fz_clip_image_mask(ctx, pr->dev, image->mask, &image_ctm, &bbox); + fz_try(ctx) + pdf_show_image_imp(ctx, pr, image, &image_ctm, &bbox); + fz_always(ctx) + fz_pop_clip(ctx, pr->dev); + fz_catch(ctx) + fz_rethrow(ctx); } - - if (image->mask) + else { - fz_pop_clip(ctx, pr->dev); - if (gstate->blendmode) - fz_end_group(ctx, pr->dev); + softmask_save softmask = { NULL }; + + gstate = pdf_begin_group(ctx, pr, &bbox, &softmask); + + fz_try(ctx) + pdf_show_image_imp(ctx, pr, image, &image_ctm, &bbox); + fz_always(ctx) + pdf_end_group(ctx, pr, &softmask); + fz_catch(ctx) + fz_rethrow(ctx); } - else - pdf_end_group(ctx, pr, &softmask); } static void |