diff options
Diffstat (limited to 'source/pdf')
-rw-r--r-- | source/pdf/pdf-interpret.c | 14 | ||||
-rw-r--r-- | source/pdf/pdf-op-run.c | 21 | ||||
-rw-r--r-- | source/pdf/pdf-xobject.c | 58 |
3 files changed, 45 insertions, 48 deletions
diff --git a/source/pdf/pdf-interpret.c b/source/pdf/pdf-interpret.c index c4dfaf88..c895478f 100644 --- a/source/pdf/pdf-interpret.c +++ b/source/pdf/pdf-interpret.c @@ -431,6 +431,7 @@ pdf_process_extgstate(fz_context *ctx, pdf_processor *proc, pdf_csi *csi, pdf_ob pdf_obj *group, *s, *bc, *tr; float softmask_bc[FZ_MAX_COLORS]; fz_colorspace *colorspace; + int colorspace_n = 1; int k, luminosity; fz_var(xobj); @@ -442,17 +443,20 @@ pdf_process_extgstate(fz_context *ctx, pdf_processor *proc, pdf_csi *csi, pdf_ob fz_try(ctx) { - colorspace = xobj->colorspace; - if (!colorspace) - colorspace = fz_device_gray(ctx); + colorspace = pdf_xobject_colorspace(ctx, xobj); + if (colorspace) + { + colorspace_n = colorspace->n; + fz_drop_colorspace(ctx, colorspace); + } - for (k = 0; k < colorspace->n; k++) + for (k = 0; k < colorspace_n; k++) softmask_bc[k] = 0; bc = pdf_dict_get(ctx, obj, PDF_NAME_BC); if (pdf_is_array(ctx, bc)) { - for (k = 0; k < colorspace->n; k++) + for (k = 0; k < colorspace_n; k++) softmask_bc[k] = pdf_to_real(ctx, pdf_array_get(ctx, bc, k)); } diff --git a/source/pdf/pdf-op-run.c b/source/pdf/pdf-op-run.c index e74d08f4..a0f28008 100644 --- a/source/pdf/pdf-op-run.c +++ b/source/pdf/pdf-op-run.c @@ -111,6 +111,7 @@ begin_softmask(fz_context *ctx, pdf_run_processor *pr, softmask_save *save) fz_rect mask_bbox; fz_matrix save_tm, save_tlm, save_ctm; fz_matrix mask_matrix; + fz_colorspace *mask_colorspace; save->softmask = softmask; if (softmask == NULL) @@ -121,6 +122,7 @@ begin_softmask(fz_context *ctx, pdf_run_processor *pr, softmask_save *save) pdf_xobject_bbox(ctx, softmask, &mask_bbox); pdf_xobject_matrix(ctx, softmask, &mask_matrix); + save_tm = pr->tm; save_tlm = pr->tlm; @@ -135,12 +137,14 @@ begin_softmask(fz_context *ctx, pdf_run_processor *pr, softmask_save *save) gstate->softmask_resources = NULL; gstate->ctm = gstate->softmask_ctm; - fz_begin_mask(ctx, pr->dev, &mask_bbox, gstate->luminosity, - softmask->colorspace, gstate->softmask_bc); + mask_colorspace = pdf_xobject_colorspace(ctx, softmask); fz_try(ctx) { + fz_begin_mask(ctx, pr->dev, &mask_bbox, gstate->luminosity, mask_colorspace, gstate->softmask_bc); pdf_run_xobject(ctx, pr, softmask, save->page_resources, &fz_identity); } + fz_always(ctx) + fz_drop_colorspace(ctx, mask_colorspace); fz_catch(ctx) { fz_rethrow_if(ctx, FZ_ERROR_TRYLATER); @@ -1474,15 +1478,20 @@ static void pdf_run_gs_SMask(fz_context *ctx, pdf_processor *proc, pdf_xobject * if (smask) { - fz_colorspace *cs = smask->colorspace; - if (!cs) - cs = fz_device_gray(ctx); + fz_colorspace *cs = pdf_xobject_colorspace(ctx, smask); + int cs_n = 1; + if (cs) + { + cs_n = cs->n; + fz_drop_colorspace(ctx, cs); + } gstate->softmask_ctm = gstate->ctm; gstate->softmask = pdf_keep_xobject(ctx, smask); gstate->softmask_resources = pdf_keep_obj(ctx, page_resources); - for (i = 0; i < cs->n; ++i) + for (i = 0; i < cs_n; ++i) gstate->softmask_bc[i] = bc[i]; gstate->luminosity = luminosity; + fz_drop_colorspace(ctx, cs); } } diff --git a/source/pdf/pdf-xobject.c b/source/pdf/pdf-xobject.c index e38be70e..4fcea897 100644 --- a/source/pdf/pdf-xobject.c +++ b/source/pdf/pdf-xobject.c @@ -16,9 +16,6 @@ static void pdf_drop_xobject_imp(fz_context *ctx, fz_storable *xobj_) { pdf_xobject *xobj = (pdf_xobject *)xobj_; - - if (xobj->colorspace) - fz_drop_colorspace(ctx, xobj->colorspace); pdf_drop_obj(ctx, xobj->obj); fz_free(ctx, xobj); } @@ -28,7 +25,7 @@ pdf_xobject_size(pdf_xobject *xobj) { if (xobj == NULL) return 0; - return sizeof(*xobj) + (xobj->colorspace ? xobj->colorspace->size : 0); + return sizeof(*xobj); } pdf_obj * @@ -74,54 +71,42 @@ int pdf_xobject_transparency(fz_context *ctx, pdf_xobject *xobj) return 0; } +fz_colorspace * +pdf_xobject_colorspace(fz_context *ctx, pdf_xobject *xobj) +{ + pdf_obj *group = pdf_dict_get(ctx, xobj->obj, PDF_NAME_Group); + if (group) + { + pdf_obj *cs = pdf_dict_get(ctx, group, PDF_NAME_CS); + if (cs) + { + fz_colorspace *colorspace = NULL; + fz_try(ctx) + colorspace = pdf_load_colorspace(ctx, pdf_get_bound_document(ctx, xobj->obj), cs); + fz_catch(ctx) + fz_warn(ctx, "cannot load xobject colorspace"); + return colorspace; + } + } + return NULL; +} + pdf_xobject * pdf_load_xobject(fz_context *ctx, pdf_document *doc, pdf_obj *dict) { pdf_xobject *form; - pdf_obj *obj; if ((form = pdf_find_item(ctx, pdf_drop_xobject_imp, dict)) != NULL) - { return form; - } form = fz_malloc_struct(ctx, pdf_xobject); FZ_INIT_STORABLE(form, 1, pdf_drop_xobject_imp); - form->colorspace = NULL; form->obj = NULL; form->iteration = 0; /* Store item immediately, to avoid possible recursion if objects refer back to this one */ pdf_store_item(ctx, dict, form, pdf_xobject_size(form)); - fz_try(ctx) - { - obj = pdf_dict_get(ctx, dict, PDF_NAME_Group); - if (obj) - { - pdf_obj *attrs = obj; - - obj = pdf_dict_get(ctx, attrs, PDF_NAME_CS); - if (obj) - { - fz_try(ctx) - { - form->colorspace = pdf_load_colorspace(ctx, doc, obj); - } - fz_catch(ctx) - { - fz_warn(ctx, "cannot load xobject colorspace"); - } - } - } - } - fz_catch(ctx) - { - pdf_remove_item(ctx, pdf_drop_xobject_imp, dict); - pdf_drop_xobject(ctx, form); - fz_rethrow(ctx); - } - form->obj = pdf_keep_obj(ctx, dict); return form; @@ -163,7 +148,6 @@ pdf_new_xobject(fz_context *ctx, pdf_document *doc, const fz_rect *bbox, const f form = fz_malloc_struct(ctx, pdf_xobject); FZ_INIT_STORABLE(form, 1, pdf_drop_xobject_imp); - form->colorspace = NULL; form->obj = NULL; form->iteration = 0; |