summaryrefslogtreecommitdiff
path: root/source/pdf
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2016-06-30 15:09:59 +0200
committerTor Andersson <tor.andersson@artifex.com>2016-07-06 13:34:37 +0200
commit74627fe0ccb279638f82472048311097b39741d5 (patch)
tree94859ba3a1319bea0f02bee6d0b6795f7814d21a /source/pdf
parent944a6aff121475d1db07423fe97a72fa1ded3f40 (diff)
downloadmupdf-74627fe0ccb279638f82472048311097b39741d5.tar.xz
pdf: Flatten inheritable page properties when copying pages.
Affects pdfclean, pdfmerge, and pdfposter.
Diffstat (limited to 'source/pdf')
-rw-r--r--source/pdf/pdf-clean-file.c11
-rw-r--r--source/pdf/pdf-page.c17
2 files changed, 22 insertions, 6 deletions
diff --git a/source/pdf/pdf-clean-file.c b/source/pdf/pdf-clean-file.c
index e886dc5f..94433eb2 100644
--- a/source/pdf/pdf-clean-file.c
+++ b/source/pdf/pdf-clean-file.c
@@ -30,6 +30,8 @@ static void retainpage(fz_context *ctx, pdf_document *doc, pdf_obj *parent, pdf_
pdf_obj *pageref = pdf_lookup_page_obj(ctx, doc, page-1);
pdf_obj *pageobj = pdf_resolve_indirect(ctx, pageref);
+ pdf_flatten_inheritable_page_items(ctx, doc, pageobj);
+
pdf_dict_put(ctx, pageobj, PDF_NAME_Parent, parent);
/* Store page object in new kids array */
@@ -170,7 +172,7 @@ static int strip_outlines(fz_context *ctx, pdf_document *doc, pdf_obj *outlines,
static void retainpages(fz_context *ctx, globals *glo, int argc, char **argv)
{
- pdf_obj *oldroot, *root, *pages, *kids, *countobj, *parent, *olddests;
+ pdf_obj *oldroot, *root, *pages, *kids, *countobj, *olddests;
pdf_document *doc = glo->doc;
int argidx = 0;
pdf_obj *names_list = NULL;
@@ -199,7 +201,6 @@ static void retainpages(fz_context *ctx, globals *glo, int argc, char **argv)
pdf_update_object(ctx, doc, pdf_to_num(ctx, oldroot), root);
/* Create a new kids array with only the pages we want to keep */
- parent = pdf_new_indirect(ctx, doc, pdf_to_num(ctx, pages), pdf_to_gen(ctx, pages));
kids = pdf_new_array(ctx, doc, 1);
/* Retain pages specified */
@@ -214,17 +215,15 @@ static void retainpages(fz_context *ctx, globals *glo, int argc, char **argv)
{
if (spage < epage)
for (page = spage; page <= epage; ++page)
- retainpage(ctx, doc, parent, kids, page);
+ retainpage(ctx, doc, pages, kids, page);
else
for (page = spage; page >= epage; --page)
- retainpage(ctx, doc, parent, kids, page);
+ retainpage(ctx, doc, pages, kids, page);
}
argidx++;
}
- pdf_drop_obj(ctx, parent);
-
/* Update page count and kids array */
countobj = pdf_new_int(ctx, doc, pdf_array_len(ctx, kids));
pdf_dict_put(ctx, pages, PDF_NAME_Count, countobj);
diff --git a/source/pdf/pdf-page.c b/source/pdf/pdf-page.c
index 9fa96261..8ba02562 100644
--- a/source/pdf/pdf-page.c
+++ b/source/pdf/pdf-page.c
@@ -258,6 +258,23 @@ pdf_lookup_inherited_page_item(fz_context *ctx, pdf_document *doc, pdf_obj *node
return val;
}
+static void
+pdf_flatten_inheritable_page_item(fz_context *ctx, pdf_document *doc, pdf_obj *page, pdf_obj *key)
+{
+ pdf_obj *val = pdf_lookup_inherited_page_item(ctx, doc, page, key);
+ if (val)
+ pdf_dict_put(ctx, page, key, val);
+}
+
+void
+pdf_flatten_inheritable_page_items(fz_context *ctx, pdf_document *doc, pdf_obj *page)
+{
+ pdf_flatten_inheritable_page_item(ctx, doc, page, PDF_NAME_MediaBox);
+ pdf_flatten_inheritable_page_item(ctx, doc, page, PDF_NAME_CropBox);
+ pdf_flatten_inheritable_page_item(ctx, doc, page, PDF_NAME_Rotate);
+ pdf_flatten_inheritable_page_item(ctx, doc, page, PDF_NAME_Resources);
+}
+
/* We need to know whether to install a page-level transparency group */
static int pdf_resources_use_blending(fz_context *ctx, pdf_document *doc, pdf_obj *rdb);