diff options
-rw-r--r-- | pdf/mupdf-internal.h | 3 | ||||
-rw-r--r-- | pdf/pdf_write.c | 17 |
2 files changed, 14 insertions, 6 deletions
diff --git a/pdf/mupdf-internal.h b/pdf/mupdf-internal.h index eca0b67f..347f74b5 100644 --- a/pdf/mupdf-internal.h +++ b/pdf/mupdf-internal.h @@ -218,6 +218,7 @@ struct pdf_document_s int page_cap; pdf_obj **page_objs; pdf_obj **page_refs; + int resources_localised; pdf_lexbuf_large lexbuf; @@ -232,6 +233,8 @@ struct pdf_document_s pdf_document *pdf_open_document_no_run(fz_context *ctx, const char *filename); pdf_document *pdf_open_document_no_run_with_stream(fz_context *ctx, fz_stream *file); +void pdf_localise_page_resources(pdf_document *xref); + void pdf_cache_object(pdf_document *doc, int num, int gen); fz_stream *pdf_open_inline_stream(pdf_document *doc, pdf_obj *stmobj, int length, fz_stream *chain, pdf_image_params *params); diff --git a/pdf/pdf_write.c b/pdf/pdf_write.c index 24d328d6..4d33770c 100644 --- a/pdf/pdf_write.c +++ b/pdf/pdf_write.c @@ -1165,7 +1165,7 @@ lpr_inherit(fz_context *ctx, pdf_obj *node, char *text, int depth) } static int -lpr(fz_context *ctx, pdf_write_options *opts, pdf_obj *node, int depth, int page) +lpr(fz_context *ctx, pdf_obj *node, int depth, int page) { pdf_obj *kids; pdf_obj *o = NULL; @@ -1216,7 +1216,7 @@ lpr(fz_context *ctx, pdf_write_options *opts, pdf_obj *node, int depth, int page n = pdf_array_len(kids); for(i = 0; i < n; i++) { - page = lpr(ctx, opts, pdf_array_get(kids, i), depth+1, page); + page = lpr(ctx, pdf_array_get(kids, i), depth+1, page); } pdf_dict_dels(node, "Resources"); pdf_dict_dels(node, "MediaBox"); @@ -1241,12 +1241,17 @@ lpr(fz_context *ctx, pdf_write_options *opts, pdf_obj *node, int depth, int page return page; } -static void -linearize_page_resources(pdf_document *xref, pdf_write_options *opts) +void +pdf_localise_page_resources(pdf_document *xref) { fz_context *ctx = xref->ctx; - lpr(ctx, opts, pdf_dict_gets(pdf_dict_gets(xref->trailer, "Root"), "Pages"), 0, 0); + if (xref->resources_localised) + return; + + lpr(ctx, pdf_dict_getp(xref->trailer, "Root/Pages"), 0, 0); + + xref->resources_localised = 1; } static void @@ -1265,7 +1270,7 @@ linearize(pdf_document *xref, pdf_write_options *opts) /* FIXME: We could 'thin' the resources according to what is actually * required for each page, but this would require us to run the page * content streams. */ - linearize_page_resources(xref, opts); + pdf_localise_page_resources(xref); /* Walk the objects for each page, marking which ones are used, where */ memset(opts->use_list, 0, n * sizeof(int)); |