summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKen Sharp <ken.sharp@artifex.com>2015-04-15 17:19:07 +0100
committerKen Sharp <ken.sharp@artifex.com>2015-04-15 17:20:23 +0100
commit4dce3f3cb2ece5795312a85c5ac2693ff8293169 (patch)
tree616bec7f731d298860a4e45f8a4464c04faf4160
parente8142ce7390e2686456894a602df07d8de16a7c7 (diff)
downloadghostpdl-4dce3f3cb2ece5795312a85c5ac2693ff8293169.tar.gz
pdfwrite - Pay attention to /MediaBox pdfmarks
Previously we always emitted a /MediaBox for each page based only on the PostScript media size, even if we had a /MediaBox /Page pdfmark. This in itself is incorrect, but worse we would then emit the MediaBox from the /Page pdfmark as well, leading to a dictionary with duplicate keys.... This commit will use any /MediaBox /Page pdfmark in preference to any PostScript media settings, though it will default to those if no such pdfmark is sent. This exhibits a difference in Bug692502.eps because this file (uniquely in our test suite it seems) does emit a /MediaBox /Page pdfmark, which is different to the media we use in PostScript. Previously it was incorrect, now it is correct, or at least we honour the pdfmark now.....
-rw-r--r--gs/devices/vector/gdevpdf.c30
1 files changed, 26 insertions, 4 deletions
diff --git a/gs/devices/vector/gdevpdf.c b/gs/devices/vector/gdevpdf.c
index 2d8c47127..05e813dc4 100644
--- a/gs/devices/vector/gdevpdf.c
+++ b/gs/devices/vector/gdevpdf.c
@@ -1041,13 +1041,35 @@ pdf_write_page(gx_device_pdf *pdev, int page_num)
pdf_page_t *page = &pdev->pages[page_num - 1];
double mediabox[4] = {0, 0};
stream *s;
+ const cos_value_t *v_mediabox = cos_dict_find_c_key(page->Page, "/MediaBox");
- mediabox[2] = round_box_coord(page->MediaBox.x);
- mediabox[3] = round_box_coord(page->MediaBox.y);
- pdf_open_obj(pdev, page_id, resourcePage);
+ /* If we have not been given a MediaBox overriding pdfmark, use the current media size. */
s = pdev->strm;
- pprintg2(s, "<</Type/Page/MediaBox [0 0 %g %g]\n",
+ pdf_open_obj(pdev, page_id, resourcePage);
+
+ if (v_mediabox == NULL ) {
+ mediabox[2] = round_box_coord(page->MediaBox.x);
+ mediabox[3] = round_box_coord(page->MediaBox.y);
+ pprintg2(s, "<</Type/Page/MediaBox [0 0 %g %g]\n",
mediabox[2], mediabox[3]);
+ } else {
+ const byte *p = v_mediabox->contents.chars.data;
+ char buf[100];
+ int l = min (v_mediabox->contents.chars.size, sizeof(buf) - 1);
+ float temp[4]; /* the type is float for sscanf. */
+
+ temp[0] = temp[1] = 0;
+ temp[2] = round_box_coord(page->MediaBox.x);
+ temp[3] = round_box_coord(page->MediaBox.y);
+ memcpy(buf, p, l);
+ buf[l] = 0;
+ if (sscanf(buf, "[ %g %g %g %g ]",
+ &temp[0], &temp[1], &temp[2], &temp[3]) == 4) {
+ cos_dict_delete_c_key(page->Page, "/MediaBox");
+ }
+ pprintg4(s, "<</Type/Page/MediaBox [%g %g %g %g]\n",
+ temp[0], temp[1], temp[2], temp[3]);
+ }
if (pdev->PDFX) {
const cos_value_t *v_trimbox = cos_dict_find_c_key(page->Page, "/TrimBox");
const cos_value_t *v_artbox = cos_dict_find_c_key(page->Page, "/ArtBox");