From 14a052d269e6a72890bb6762c093ef5f7a375b78 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Thu, 7 Jul 2016 15:34:04 +0200 Subject: Slim pdf_xobject struct: remove cached bbox field. --- source/pdf/pdf-annot.c | 3 ++- source/pdf/pdf-appearance.c | 12 ++++++------ source/pdf/pdf-op-run.c | 16 ++++++++++------ source/pdf/pdf-xobject.c | 10 ++++++---- 4 files changed, 24 insertions(+), 17 deletions(-) (limited to 'source/pdf') diff --git a/source/pdf/pdf-annot.c b/source/pdf/pdf-annot.c index b456f2b0..1f6e3c5e 100644 --- a/source/pdf/pdf-annot.c +++ b/source/pdf/pdf-annot.c @@ -406,11 +406,12 @@ pdf_drop_annots(fz_context *ctx, pdf_annot *annot) void pdf_annot_transform(fz_context *ctx, pdf_annot *annot, fz_matrix *annot_ctm) { - fz_rect bbox = annot->ap->bbox; + fz_rect bbox; fz_rect rect; float w, h, x, y; pdf_to_rect(ctx, pdf_dict_get(ctx, annot->obj, PDF_NAME_Rect), &rect); + pdf_xobject_bbox(ctx, annot->ap, &bbox); fz_transform_rect(&bbox, &annot->ap->matrix); if (bbox.x1 == bbox.x0) diff --git a/source/pdf/pdf-appearance.c b/source/pdf/pdf-appearance.c index 6e03cb2b..43095351 100644 --- a/source/pdf/pdf-appearance.c +++ b/source/pdf/pdf-appearance.c @@ -1135,7 +1135,7 @@ void pdf_update_text_appearance(fz_context *ctx, pdf_document *doc, pdf_obj *obj pdf_xobject *form = NULL; fz_buffer *fzbuf = NULL; fz_matrix tm; - fz_rect rect; + fz_rect rect, form_bbox; int has_tm; char *text = NULL; @@ -1156,9 +1156,9 @@ void pdf_update_text_appearance(fz_context *ctx, pdf_document *doc, pdf_obj *obj form = load_or_create_form(ctx, doc, obj, &rect); + pdf_xobject_bbox(ctx, form, &form_bbox); has_tm = get_matrix(ctx, doc, form, info.q, &tm); - fzbuf = create_text_appearance(ctx, doc, &form->bbox, has_tm ? &tm : NULL, &info, - text?text:""); + fzbuf = create_text_appearance(ctx, doc, &form_bbox, has_tm ? &tm : NULL, &info, text?text:""); update_marked_content(ctx, doc, form, fzbuf); } fz_always(ctx) @@ -1377,7 +1377,7 @@ void pdf_update_combobox_appearance(fz_context *ctx, pdf_document *doc, pdf_obj pdf_xobject *form = NULL; fz_buffer *fzbuf = NULL; fz_matrix tm; - fz_rect rect; + fz_rect rect, form_bbox; int has_tm; pdf_obj *val; char *text; @@ -1403,8 +1403,9 @@ void pdf_update_combobox_appearance(fz_context *ctx, pdf_document *doc, pdf_obj form = load_or_create_form(ctx, doc, obj, &rect); + pdf_xobject_bbox(ctx, form, &form_bbox); has_tm = get_matrix(ctx, doc, form, info.q, &tm); - fzbuf = create_text_appearance(ctx, doc, &form->bbox, has_tm ? &tm : NULL, &info, + fzbuf = create_text_appearance(ctx, doc, &form_bbox, has_tm ? &tm : NULL, &info, text?text:""); update_marked_content(ctx, doc, form, fzbuf); } @@ -1621,7 +1622,6 @@ void pdf_set_annot_appearance(fz_context *ctx, pdf_document *doc, pdf_annot *ann if (xobj) { /* Update bounding box and matrix also in the xobject structure */ - xobj->bbox = trect; xobj->matrix = fz_identity; xobj->iteration++; pdf_drop_xobject(ctx, xobj); diff --git a/source/pdf/pdf-op-run.c b/source/pdf/pdf-op-run.c index b529125a..3d82699f 100644 --- a/source/pdf/pdf-op-run.c +++ b/source/pdf/pdf-op-run.c @@ -118,7 +118,7 @@ begin_softmask(fz_context *ctx, pdf_run_processor *pr, softmask_save *save) save->ctm = gstate->softmask_ctm; save_ctm = gstate->ctm; - mask_bbox = softmask->bbox; + pdf_xobject_bbox(ctx, softmask, &mask_bbox); save_tm = pr->tm; save_tlm = pr->tlm; @@ -1218,11 +1218,14 @@ pdf_run_xobject(fz_context *ctx, pdf_run_processor *proc, pdf_xobject *xobj, pdf int cleanup_state = 0; char errmess[256] = ""; pdf_obj *resources; + fz_rect xobj_bbox; /* Avoid infinite recursion */ if (xobj == NULL || pdf_mark_obj(ctx, xobj->obj)) return; + pdf_xobject_bbox(ctx, xobj, &xobj_bbox); + fz_var(cleanup_state); fz_var(gstate); fz_var(oldtop); @@ -1248,7 +1251,8 @@ pdf_run_xobject(fz_context *ctx, pdf_run_processor *proc, pdf_xobject *xobj, pdf /* apply soft mask, create transparency group and reset state */ if (xobj->transparency) { - fz_rect bbox = xobj->bbox; + fz_rect bbox; + bbox = xobj_bbox; fz_transform_rect(&bbox, &gstate->ctm); /* Remember that we tried to call begin_softmask. Even @@ -1272,10 +1276,10 @@ pdf_run_xobject(fz_context *ctx, pdf_run_processor *proc, pdf_xobject *xobj, pdf pdf_gsave(ctx, pr); /* Save here so the clippath doesn't persist */ /* clip to the bounds */ - fz_moveto(ctx, pr->path, xobj->bbox.x0, xobj->bbox.y0); - fz_lineto(ctx, pr->path, xobj->bbox.x1, xobj->bbox.y0); - fz_lineto(ctx, pr->path, xobj->bbox.x1, xobj->bbox.y1); - fz_lineto(ctx, pr->path, xobj->bbox.x0, xobj->bbox.y1); + fz_moveto(ctx, pr->path, xobj_bbox.x0, xobj_bbox.y0); + fz_lineto(ctx, pr->path, xobj_bbox.x1, xobj_bbox.y0); + fz_lineto(ctx, pr->path, xobj_bbox.x1, xobj_bbox.y1); + fz_lineto(ctx, pr->path, xobj_bbox.x0, xobj_bbox.y1); fz_closepath(ctx, pr->path); pr->clip = 1; pdf_show_path(ctx, pr, 0, 0, 0, 0); diff --git a/source/pdf/pdf-xobject.c b/source/pdf/pdf-xobject.c index 78d736e2..ad2abe09 100644 --- a/source/pdf/pdf-xobject.c +++ b/source/pdf/pdf-xobject.c @@ -37,6 +37,12 @@ pdf_xobject_resources(fz_context *ctx, pdf_xobject *xobj) return pdf_dict_get(ctx, xobj->obj, PDF_NAME_Resources); } +fz_rect * +pdf_xobject_bbox(fz_context *ctx, pdf_xobject *xobj, fz_rect *bbox) +{ + return pdf_to_rect(ctx, pdf_dict_get(ctx, xobj->obj, PDF_NAME_BBox), bbox); +} + pdf_xobject * pdf_load_xobject(fz_context *ctx, pdf_document *doc, pdf_obj *dict) { @@ -60,8 +66,6 @@ pdf_load_xobject(fz_context *ctx, pdf_document *doc, pdf_obj *dict) fz_try(ctx) { - obj = pdf_dict_get(ctx, dict, PDF_NAME_BBox); - pdf_to_rect(ctx, obj, &form->bbox); obj = pdf_dict_get(ctx, dict, PDF_NAME_Matrix); if (obj) @@ -152,8 +156,6 @@ pdf_new_xobject(fz_context *ctx, pdf_document *doc, const fz_rect *bbox, const f form->obj = NULL; form->iteration = 0; - form->bbox = *bbox; - form->matrix = *mat; form->isolated = 0; -- cgit v1.2.3