diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2018-07-11 14:25:19 +0200 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2018-08-10 14:09:46 +0200 |
commit | f149c37230a5551753d35ab7257d5d31b9e51485 (patch) | |
tree | 388b25cbaad9c18b8f15554c31755012c39fbc3c /source/pdf/pdf-page.c | |
parent | 84c0c62018110e0cbb01d30d4df96b64e0b6899f (diff) | |
download | mupdf-f149c37230a5551753d35ab7257d5d31b9e51485.tar.xz |
Detect cycles in pdf_dict_get_inheritable.
Remove duplicate function pdf_lookup_inherited_page_item.
Diffstat (limited to 'source/pdf/pdf-page.c')
-rw-r--r-- | source/pdf/pdf-page.c | 49 |
1 files changed, 5 insertions, 44 deletions
diff --git a/source/pdf/pdf-page.c b/source/pdf/pdf-page.c index 3d2c46a0..7f9a00e3 100644 --- a/source/pdf/pdf-page.c +++ b/source/pdf/pdf-page.c @@ -343,49 +343,10 @@ pdf_lookup_anchor(fz_context *ctx, pdf_document *doc, const char *name, float *x return fz_atoi(name) - 1; } -static pdf_obj * -pdf_lookup_inherited_page_item(fz_context *ctx, pdf_obj *node, pdf_obj *key) -{ - pdf_obj *node2 = node; - pdf_obj *val = NULL; - - fz_var(node); - fz_try(ctx) - { - do - { - val = pdf_dict_get(ctx, node, key); - if (val) - break; - if (pdf_mark_obj(ctx, node)) - fz_throw(ctx, FZ_ERROR_GENERIC, "cycle in page tree (parents)"); - node = pdf_dict_get(ctx, node, PDF_NAME(Parent)); - } - while (node); - } - fz_always(ctx) - { - do - { - pdf_unmark_obj(ctx, node2); - if (node2 == node) - break; - node2 = pdf_dict_get(ctx, node2, PDF_NAME(Parent)); - } - while (node2); - } - fz_catch(ctx) - { - fz_rethrow(ctx); - } - - return val; -} - static void pdf_flatten_inheritable_page_item(fz_context *ctx, pdf_obj *page, pdf_obj *key) { - pdf_obj *val = pdf_lookup_inherited_page_item(ctx, page, key); + pdf_obj *val = pdf_dict_get_inheritable(ctx, page, key); if (val) pdf_dict_put(ctx, page, key, val); } @@ -641,7 +602,7 @@ pdf_load_links(fz_context *ctx, pdf_page *page) pdf_obj * pdf_page_resources(fz_context *ctx, pdf_page *page) { - return pdf_lookup_inherited_page_item(ctx, page->obj, PDF_NAME(Resources)); + return pdf_dict_get_inheritable(ctx, page->obj, PDF_NAME(Resources)); } pdf_obj * @@ -671,7 +632,7 @@ pdf_page_obj_transform(fz_context *ctx, pdf_obj *pageobj, fz_rect *page_mediabox if (pdf_is_real(ctx, obj)) userunit = pdf_to_real(ctx, obj); - mediabox = pdf_to_rect(ctx, pdf_lookup_inherited_page_item(ctx, pageobj, PDF_NAME(MediaBox))); + mediabox = pdf_to_rect(ctx, pdf_dict_get_inheritable(ctx, pageobj, PDF_NAME(MediaBox))); if (fz_is_empty_rect(mediabox)) { mediabox.x0 = 0; @@ -680,7 +641,7 @@ pdf_page_obj_transform(fz_context *ctx, pdf_obj *pageobj, fz_rect *page_mediabox mediabox.y1 = 792; } - cropbox = pdf_to_rect(ctx, pdf_lookup_inherited_page_item(ctx, pageobj, PDF_NAME(CropBox))); + cropbox = pdf_to_rect(ctx, pdf_dict_get_inheritable(ctx, pageobj, PDF_NAME(CropBox))); if (!fz_is_empty_rect(cropbox)) mediabox = fz_intersect_rect(mediabox, cropbox); @@ -692,7 +653,7 @@ pdf_page_obj_transform(fz_context *ctx, pdf_obj *pageobj, fz_rect *page_mediabox if (page_mediabox->x1 - page_mediabox->x0 < 1 || page_mediabox->y1 - page_mediabox->y0 < 1) *page_mediabox = fz_unit_rect; - rotate = pdf_to_int(ctx, pdf_lookup_inherited_page_item(ctx, pageobj, PDF_NAME(Rotate))); + rotate = pdf_to_int(ctx, pdf_dict_get_inheritable(ctx, pageobj, PDF_NAME(Rotate))); /* Snap page rotation to 0, 90, 180 or 270 */ if (rotate < 0) |