diff options
Diffstat (limited to 'source/pdf/pdf-xobject.c')
-rw-r--r-- | source/pdf/pdf-xobject.c | 108 |
1 files changed, 19 insertions, 89 deletions
diff --git a/source/pdf/pdf-xobject.c b/source/pdf/pdf-xobject.c index bac856fd..975b3e76 100644 --- a/source/pdf/pdf-xobject.c +++ b/source/pdf/pdf-xobject.c @@ -1,71 +1,43 @@ #include "mupdf/fitz.h" #include "mupdf/pdf.h" -pdf_xobject * -pdf_keep_xobject(fz_context *ctx, pdf_xobject *xobj) -{ - return fz_keep_storable(ctx, &xobj->storable); -} - -void -pdf_drop_xobject(fz_context *ctx, pdf_xobject *xobj) -{ - fz_drop_storable(ctx, &xobj->storable); -} - -static void -pdf_drop_xobject_imp(fz_context *ctx, fz_storable *xobj_) -{ - pdf_xobject *xobj = (pdf_xobject *)xobj_; - pdf_drop_obj(ctx, xobj->obj); - fz_free(ctx, xobj); -} - -static size_t -pdf_xobject_size(pdf_xobject *xobj) -{ - if (xobj == NULL) - return 0; - return sizeof(*xobj); -} - pdf_obj * -pdf_xobject_resources(fz_context *ctx, pdf_xobject *xobj) +pdf_xobject_resources(fz_context *ctx, pdf_obj *xobj) { - return pdf_dict_get(ctx, xobj->obj, PDF_NAME_Resources); + return pdf_dict_get(ctx, xobj, PDF_NAME_Resources); } fz_rect * -pdf_xobject_bbox(fz_context *ctx, pdf_xobject *xobj, fz_rect *bbox) +pdf_xobject_bbox(fz_context *ctx, pdf_obj *xobj, fz_rect *bbox) { - return pdf_to_rect(ctx, pdf_dict_get(ctx, xobj->obj, PDF_NAME_BBox), bbox); + return pdf_to_rect(ctx, pdf_dict_get(ctx, xobj, PDF_NAME_BBox), bbox); } fz_matrix * -pdf_xobject_matrix(fz_context *ctx, pdf_xobject *xobj, fz_matrix *matrix) +pdf_xobject_matrix(fz_context *ctx, pdf_obj *xobj, fz_matrix *matrix) { - return pdf_to_matrix(ctx, pdf_dict_get(ctx, xobj->obj, PDF_NAME_Matrix), matrix); + return pdf_to_matrix(ctx, pdf_dict_get(ctx, xobj, PDF_NAME_Matrix), matrix); } -int pdf_xobject_isolated(fz_context *ctx, pdf_xobject *xobj) +int pdf_xobject_isolated(fz_context *ctx, pdf_obj *xobj) { - pdf_obj *group = pdf_dict_get(ctx, xobj->obj, PDF_NAME_Group); + pdf_obj *group = pdf_dict_get(ctx, xobj, 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) +int pdf_xobject_knockout(fz_context *ctx, pdf_obj *xobj) { - pdf_obj *group = pdf_dict_get(ctx, xobj->obj, PDF_NAME_Group); + pdf_obj *group = pdf_dict_get(ctx, xobj, 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) +int pdf_xobject_transparency(fz_context *ctx, pdf_obj *xobj) { - pdf_obj *group = pdf_dict_get(ctx, xobj->obj, PDF_NAME_Group); + pdf_obj *group = pdf_dict_get(ctx, xobj, PDF_NAME_Group); if (group) if (pdf_name_eq(ctx, pdf_dict_get(ctx, group, PDF_NAME_S), PDF_NAME_Transparency)) return 1; @@ -73,9 +45,9 @@ int pdf_xobject_transparency(fz_context *ctx, pdf_xobject *xobj) } fz_colorspace * -pdf_xobject_colorspace(fz_context *ctx, pdf_xobject *xobj) +pdf_xobject_colorspace(fz_context *ctx, pdf_obj *xobj) { - pdf_obj *group = pdf_dict_get(ctx, xobj->obj, PDF_NAME_Group); + pdf_obj *group = pdf_dict_get(ctx, xobj, PDF_NAME_Group); if (group) { pdf_obj *cs = pdf_dict_get(ctx, group, PDF_NAME_CS); @@ -92,43 +64,15 @@ pdf_xobject_colorspace(fz_context *ctx, pdf_xobject *xobj) return NULL; } -pdf_xobject * -pdf_load_xobject(fz_context *ctx, pdf_document *doc, pdf_obj *dict) -{ - pdf_xobject *form; - - if (!pdf_is_stream(ctx, dict)) - fz_throw(ctx, FZ_ERROR_SYNTAX, "XObject must be a stream"); - - 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->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)); - - form->obj = pdf_keep_obj(ctx, dict); - - return form; -} - pdf_obj * pdf_new_xobject(fz_context *ctx, pdf_document *doc, const fz_rect *bbox, const fz_matrix *mat) { - int idict_num; - pdf_obj *idict = NULL; + pdf_obj *form = NULL; pdf_obj *dict = NULL; - pdf_xobject *form = NULL; pdf_obj *res = NULL; pdf_obj *procset; - fz_var(idict); fz_var(dict); - fz_var(form); fz_var(res); fz_try(ctx) @@ -150,36 +94,22 @@ pdf_new_xobject(fz_context *ctx, pdf_document *doc, const fz_rect *bbox, const f pdf_dict_put(ctx, dict, PDF_NAME_Subtype, PDF_NAME_Form); pdf_dict_put(ctx, dict, PDF_NAME_Type, PDF_NAME_XObject); - form = fz_malloc_struct(ctx, pdf_xobject); - FZ_INIT_STORABLE(form, 1, pdf_drop_xobject_imp); - form->obj = NULL; - form->iteration = 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); - - pdf_store_item(ctx, idict, form, pdf_xobject_size(form)); - - form->obj = pdf_keep_obj(ctx, idict); + form = pdf_add_object(ctx, doc, dict); } fz_always(ctx) { pdf_drop_obj(ctx, dict); pdf_drop_obj(ctx, res); - pdf_drop_xobject(ctx, form); } fz_catch(ctx) { - pdf_drop_obj(ctx, idict); fz_rethrow(ctx); } - return idict; + return form; } -void pdf_update_xobject_contents(fz_context *ctx, pdf_document *doc, pdf_xobject *form, fz_buffer *buffer) +void pdf_update_xobject_contents(fz_context *ctx, pdf_document *doc, pdf_obj *form, fz_buffer *buffer) { - pdf_update_stream(ctx, doc, form->obj, buffer, 0); - form->iteration ++; + pdf_update_stream(ctx, doc, form, buffer, 0); } |