summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2012-08-13 19:08:42 +0200
committerRobin Watts <robin.watts@artifex.com>2012-09-04 19:13:07 +0100
commit226fc68a637d6220db6e79269352cbd13e43d93f (patch)
treeff0227febdba1ca4ec07d4322f202a5a5bff6b9e
parentb4419f7378da4c8f2ddbdaeb09cd604ee2d6a340 (diff)
downloadmupdf-226fc68a637d6220db6e79269352cbd13e43d93f.tar.xz
Make pdf resource localisation procedure non-static.
And add a flag in the xref for evey PDF document to say whether it has been localised or not; this will be important for PDF editing to avoid us having to localise on every edit.
-rw-r--r--pdf/mupdf-internal.h3
-rw-r--r--pdf/pdf_write.c17
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));