summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKen Sharp <ken.sharp@artifex.com>2022-02-28 16:04:16 +0000
committerChris Liddell <chris.liddell@artifex.com>2022-02-28 16:19:05 +0000
commit60ffb5d0fe3da70799a10a495dea0d9fbc084046 (patch)
tree93beb45ead91deb69964458faa0d5978442de69f
parent21e3b426e869e9961b65526a8a8b1fcbf089dd87 (diff)
downloadghostpdl-60ffb5d0fe3da70799a10a495dea0d9fbc084046.tar.gz
pdfi with Ghostscript - normalise 'Box' arrays before use.
After we retrieve a 'Box' from the PDF file we use it to setup the device PageSize. However we were assuming the Box array was always in the 'normal' format of bottom left corner and top right corner. The spec is quite clear that any opposite pair is acceptable, so in this commit we 'normalise' the two corners before we process the array for the PageSize. Also remove a commented out left over piece of debug printing.
-rw-r--r--Resource/Init/pdf_main.ps25
1 files changed, 24 insertions, 1 deletions
diff --git a/Resource/Init/pdf_main.ps b/Resource/Init/pdf_main.ps
index 4546db016..0841b275f 100644
--- a/Resource/Init/pdf_main.ps
+++ b/Resource/Init/pdf_main.ps
@@ -444,7 +444,6 @@ systemdict /NEWPDF known not {/NEWPDF //true def} if
( Output may be incorrect.\n) newpdf_pdfformaterror
[ 0 0 currentpagedevice /PageSize get aload pop ] //false
} ifelse
-%(newpdf_get_media_box end) == flush
} bind executeonly def
% [llx lly urx ury] newpdf_check_empty_box [llx lly urx ury] true | false
@@ -604,6 +603,30 @@ systemdict /NEWPDF known not {/NEWPDF //true def} if
dup
dup newpdf_get_any_box % Stack: pdfpagedict pdfpagedict /BoxName [box]
+ % Check that the box is 'normal' and make it so if not
+ % Also check the array is 4 elements and if it isn't then use the
+ % current PageSize. The normalise arithmetic assumes the array is a 4
+ % element array.
+ dup length 4 ne {
+ % Invalid size of mediabox
+ pop currentpagedevice /PageSize get
+ } {
+ aload 5 1 roll % array x1 y1 x2 y2
+ exch % array x1 y1 y2 x2
+ 4 -1 roll % array y1 y2 x2 x1
+ 2 copy gt {
+ exch % array y1 y2 xmin xmax
+ } if
+ 4 -2 roll % array xmin xmax y1 y2
+ 2 copy gt {
+ exch % array xmin xmax ymin ymax
+ } if
+ 4 1 roll
+ exch 4 -1 roll
+ 5 -1 roll
+ astore
+ } ifelse
+
//systemdict /PDFFitPage known {
NewPDF_FitPage
} {