summaryrefslogtreecommitdiff
path: root/source/tools/pdfposter.c
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2015-10-01 19:39:59 +0100
committerRobin Watts <robin.watts@artifex.com>2015-10-02 15:53:20 +0100
commitf810f1dba5da32f00cd11142eaa31b1a736d1aa0 (patch)
tree6f98e6ca286c09e79bf6a1ebd555977d099fb0b9 /source/tools/pdfposter.c
parent1acaaf2b40614401378aa697de47093be9f390fe (diff)
downloadmupdf-f810f1dba5da32f00cd11142eaa31b1a736d1aa0.tar.xz
Bug 696078: Improve box handling in poster tool.
The poster tool worked by rewriting the mediabox, but left the other boxes (crop, bleed, trim, art) unchanged. This could cause problems with viewers that didn't intersect such boxes. This update makes the poster tool write intersected boxes for all boxes.
Diffstat (limited to 'source/tools/pdfposter.c')
-rw-r--r--source/tools/pdfposter.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/source/tools/pdfposter.c b/source/tools/pdfposter.c
index 1fa077c2..9a58909e 100644
--- a/source/tools/pdfposter.c
+++ b/source/tools/pdfposter.c
@@ -17,6 +17,38 @@ static void usage(void)
exit(1);
}
+static void
+intersect_box(fz_context *ctx, pdf_document *doc, pdf_obj *page, pdf_obj *box_name, const fz_rect *mb)
+{
+ pdf_obj *box = pdf_dict_get(ctx, page, box_name);
+ pdf_obj *newbox;
+ fz_rect old_rect;
+
+ if (box == NULL)
+ return;
+
+ old_rect.x0 = pdf_to_real(ctx, pdf_array_get(ctx, box, 0));
+ old_rect.y0 = pdf_to_real(ctx, pdf_array_get(ctx, box, 1));
+ old_rect.x1 = pdf_to_real(ctx, pdf_array_get(ctx, box, 2));
+ old_rect.y1 = pdf_to_real(ctx, pdf_array_get(ctx, box, 3));
+
+ if (old_rect.x0 < mb->x0)
+ old_rect.x0 = mb->x0;
+ if (old_rect.y0 < mb->y0)
+ old_rect.y0 = mb->y0;
+ if (old_rect.x1 > mb->x1)
+ old_rect.x1 = mb->x1;
+ if (old_rect.y1 > mb->y1)
+ old_rect.y1 = mb->y1;
+
+ newbox = pdf_new_array(ctx, doc, 4);
+ pdf_array_push(ctx, newbox, pdf_new_real(ctx, doc, old_rect.x0));
+ pdf_array_push(ctx, newbox, pdf_new_real(ctx, doc, old_rect.y0));
+ pdf_array_push(ctx, newbox, pdf_new_real(ctx, doc, old_rect.x1));
+ pdf_array_push(ctx, newbox, pdf_new_real(ctx, doc, old_rect.y1));
+ pdf_dict_put(ctx, page, box_name, newbox);
+}
+
/*
* Recreate page tree with our posterised pages in.
*/
@@ -98,6 +130,11 @@ static void decimatepages(fz_context *ctx, pdf_document *doc)
pdf_dict_put(ctx, newpageobj, PDF_NAME_Parent, parent);
pdf_dict_put(ctx, newpageobj, PDF_NAME_MediaBox, newmediabox);
+ intersect_box(ctx, doc, newpageobj, PDF_NAME_CropBox, &mb);
+ intersect_box(ctx, doc, newpageobj, PDF_NAME_BleedBox, &mb);
+ intersect_box(ctx, doc, newpageobj, PDF_NAME_TrimBox, &mb);
+ intersect_box(ctx, doc, newpageobj, PDF_NAME_ArtBox, &mb);
+
/* Store page object in new kids array */
pdf_array_push(ctx, kids, newpageref);