diff options
-rw-r--r-- | include/mupdf/pdf/resource.h | 6 | ||||
-rw-r--r-- | source/pdf/pdf-op-run.c | 11 | ||||
-rw-r--r-- | source/pdf/pdf-xobject.c | 40 |
3 files changed, 36 insertions, 21 deletions
diff --git a/include/mupdf/pdf/resource.h b/include/mupdf/pdf/resource.h index 727c6b89..d25fbb44 100644 --- a/include/mupdf/pdf/resource.h +++ b/include/mupdf/pdf/resource.h @@ -93,9 +93,6 @@ struct pdf_xobject_s pdf_obj *obj; pdf_document *document; - int isolated; - int knockout; - int transparency; fz_colorspace *colorspace; int iteration; }; @@ -111,5 +108,8 @@ void pdf_update_appearance(fz_context *ctx, pdf_document *doc, pdf_annot *annot) pdf_obj *pdf_xobject_resources(fz_context *ctx, pdf_xobject *xobj); fz_rect *pdf_xobject_bbox(fz_context *ctx, pdf_xobject *xobj, fz_rect *bbox); fz_matrix *pdf_xobject_matrix(fz_context *ctx, pdf_xobject *xobj, fz_matrix *matrix); +int pdf_xobject_isolated(fz_context *ctx, pdf_xobject *xobj); +int pdf_xobject_knockout(fz_context *ctx, pdf_xobject *xobj); +int pdf_xobject_transparency(fz_context *ctx, pdf_xobject *xobj); #endif diff --git a/source/pdf/pdf-op-run.c b/source/pdf/pdf-op-run.c index a2b9e35c..02005b57 100644 --- a/source/pdf/pdf-op-run.c +++ b/source/pdf/pdf-op-run.c @@ -1222,6 +1222,7 @@ pdf_run_xobject(fz_context *ctx, pdf_run_processor *proc, pdf_xobject *xobj, pdf pdf_obj *resources; fz_rect xobj_bbox; fz_matrix xobj_matrix; + int transparency; /* Avoid infinite recursion */ if (xobj == NULL || pdf_mark_obj(ctx, xobj->obj)) @@ -1229,6 +1230,7 @@ pdf_run_xobject(fz_context *ctx, pdf_run_processor *proc, pdf_xobject *xobj, pdf pdf_xobject_bbox(ctx, xobj, &xobj_bbox); pdf_xobject_matrix(ctx, xobj, &xobj_matrix); + transparency = pdf_xobject_transparency(ctx, xobj); fz_var(cleanup_state); fz_var(gstate); @@ -1253,7 +1255,7 @@ pdf_run_xobject(fz_context *ctx, pdf_run_processor *proc, pdf_xobject *xobj, pdf pr->gstate[pr->gparent].ctm = gstate->ctm; /* apply soft mask, create transparency group and reset state */ - if (xobj->transparency) + if (transparency) { fz_rect bbox; bbox = xobj_bbox; @@ -1267,7 +1269,10 @@ pdf_run_xobject(fz_context *ctx, pdf_run_processor *proc, pdf_xobject *xobj, pdf /* Remember that we tried to call fz_begin_group. Even * if it throws an error, we must call fz_end_group. */ cleanup_state = 2; - fz_begin_group(ctx, pr->dev, &bbox, xobj->isolated, xobj->knockout, gstate->blendmode, gstate->fill.alpha); + fz_begin_group(ctx, pr->dev, &bbox, + pdf_xobject_isolated(ctx, xobj), + pdf_xobject_knockout(ctx, xobj), + gstate->blendmode, gstate->fill.alpha); gstate->blendmode = 0; gstate->stroke.alpha = 1; @@ -1302,7 +1307,7 @@ pdf_run_xobject(fz_context *ctx, pdf_run_processor *proc, pdf_xobject *xobj, pdf pdf_grestore(ctx, pr); /* Remove the clippath */ /* wrap up transparency stacks */ - if (xobj->transparency) + if (transparency) { if (cleanup_state >= 2) { diff --git a/source/pdf/pdf-xobject.c b/source/pdf/pdf-xobject.c index e921f47f..7eb4552f 100644 --- a/source/pdf/pdf-xobject.c +++ b/source/pdf/pdf-xobject.c @@ -49,6 +49,31 @@ pdf_xobject_matrix(fz_context *ctx, pdf_xobject *xobj, fz_matrix *matrix) return pdf_to_matrix(ctx, pdf_dict_get(ctx, xobj->obj, PDF_NAME_Matrix), matrix); } +int pdf_xobject_isolated(fz_context *ctx, pdf_xobject *xobj) +{ + pdf_obj *group = pdf_dict_get(ctx, xobj->obj, PDF_NAME_Group); + if (group) + return pdf_to_bool(ctx, pdf_dict_get(ctx, group, PDF_NAME_I)); + return 0; +} + +int pdf_xobject_knockout(fz_context *ctx, pdf_xobject *xobj) +{ + pdf_obj *group = pdf_dict_get(ctx, xobj->obj, PDF_NAME_Group); + if (group) + return pdf_to_bool(ctx, pdf_dict_get(ctx, group, PDF_NAME_K)); + return 0; +} + +int pdf_xobject_transparency(fz_context *ctx, pdf_xobject *xobj) +{ + pdf_obj *group = pdf_dict_get(ctx, xobj->obj, PDF_NAME_Group); + if (group) + if (pdf_name_eq(ctx, pdf_dict_get(ctx, group, PDF_NAME_S), PDF_NAME_Transparency)) + return 1; + return 0; +} + pdf_xobject * pdf_load_xobject(fz_context *ctx, pdf_document *doc, pdf_obj *dict) { @@ -72,22 +97,11 @@ pdf_load_xobject(fz_context *ctx, pdf_document *doc, pdf_obj *dict) fz_try(ctx) { - form->isolated = 0; - form->knockout = 0; - form->transparency = 0; - obj = pdf_dict_get(ctx, dict, PDF_NAME_Group); if (obj) { pdf_obj *attrs = obj; - form->isolated = pdf_to_bool(ctx, pdf_dict_get(ctx, attrs, PDF_NAME_I)); - form->knockout = pdf_to_bool(ctx, pdf_dict_get(ctx, attrs, PDF_NAME_K)); - - obj = pdf_dict_get(ctx, attrs, PDF_NAME_S); - if (pdf_name_eq(ctx, obj, PDF_NAME_Transparency)) - form->transparency = 1; - obj = pdf_dict_get(ctx, attrs, PDF_NAME_CS); if (obj) { @@ -155,10 +169,6 @@ pdf_new_xobject(fz_context *ctx, pdf_document *doc, const fz_rect *bbox, const f form->obj = NULL; form->iteration = 0; - form->isolated = 0; - form->knockout = 0; - form->transparency = 0; - idict_num = pdf_create_object(ctx, doc); pdf_update_object(ctx, doc, idict_num, dict); idict = pdf_new_indirect(ctx, doc, idict_num, 0); |