summaryrefslogtreecommitdiff
path: root/Resource
diff options
context:
space:
mode:
authorKen Sharp <ken.sharp@artifex.com>2022-11-07 17:09:03 +0000
committerKen Sharp <ken.sharp@artifex.com>2022-11-07 17:10:19 +0000
commit6badab86a997e33e9db7381b86f86188d722be73 (patch)
tree4abdd33c4643f28a59cf00c94bc92014665125a6 /Resource
parentcb46ea041582033e874e1e7b7149e9a9370e3b2f (diff)
downloadghostpdl-6badab86a997e33e9db7381b86f86188d722be73.tar.gz
GhostPDF - Preserve UserUnit when the output device supports it
Bug #706059 "PDF interpreter does not preserve UserUnit with pdfwrite" The bug report is in two parts; the first is that pdfwrite does not automagically insert UserUnit and alter the scaling of files when the media size exceeds the Acrobat architectural limitation of 14,400. We do not regard this as a Ghostscript bug, since the PDF format does not limit the MediaBox, this is a limitation of Acrobat. The second part correctly noted that the new PDF interpreter was not preserving any UserUnit from the input file when the output device was pdfwrite (the only device which supports preserving UserUnit). This commit preserves any extant UserUnit (and does not scale either the media or the content) when the output device supports UserUnit and the -dNoUserUnit switch isn't set. This now works for the case when the PDF interpreter is built into Ghostscript and when it is a stand-alone binary. A couple of files in the test suite show very slight (pixel level) changes now, because we preserve the UserUnit and so the scaling is not quite the same.
Diffstat (limited to 'Resource')
-rw-r--r--Resource/Init/pdf_main.ps49
1 files changed, 34 insertions, 15 deletions
diff --git a/Resource/Init/pdf_main.ps b/Resource/Init/pdf_main.ps
index 207105f85..4830f7edf 100644
--- a/Resource/Init/pdf_main.ps
+++ b/Resource/Init/pdf_main.ps
@@ -673,18 +673,27 @@ systemdict /NEWPDF known not {/NEWPDF //true def} if
}
{
2 index /UserUnit get
- % The PageSize needs to be multiplied too
- exch aload 5 1 roll % UserUnit box llx lly urx ury
- 2 index sub exch % UserUnit box llx lly (ury - lly) urx
- 3 index sub % UserUnit box llx lly boxheight boxwidth
- 5 index mul % UserUnit box llx lly boxheight (Boxwidth*UserUnit)
- exch
- 5 index mul % UserUnit box llx lly (Boxwidth*UserUnit) (boxheight*UserUnit)
- 4 -2 roll
- 5 index mul exch % UserUnit box (Boxwidth*UserUnit) (boxheight*UserUnit) (lly*UserUnit) llx
- 5 index mul exch % UserUnit box (Boxwidth*UserUnit) (boxheight*UserUnit) (llx*UserUnit) (lly*UserUnit)
- 4 2 roll % UserUnit box (llx*UserUnit) (lly*UserUnit) (Boxwidth*UserUnit) (boxheight*UserUnit)
- 6 -1 roll pop % box (llx*UserUnit) (lly*UserUnit) (Boxwidth*UserUnit) (boxheight*UserUnit)
+ /PassUserUnit /GetDeviceParam .special_op {exch pop} {//false} ifelse {
+ [ /UserUnit 3 -1 roll .pdfputparams pop pop
+ % No media scaling required, calculate PageSize as the width and height of the box
+ aload 5 1 roll % box llx lly urx ury
+ 2 index sub % box llx lly urx (ury - lly)
+ exch 3 index sub % box llx lly (ury - lly) (urx - llx)
+ exch
+ }{
+ % The PageSize needs to be multiplied too
+ exch aload 5 1 roll % UserUnit box llx lly urx ury
+ 2 index sub exch % UserUnit box llx lly (ury - lly) urx
+ 3 index sub % UserUnit box llx lly boxheight boxwidth
+ 5 index mul % UserUnit box llx lly boxheight (Boxwidth*UserUnit)
+ exch
+ 5 index mul % UserUnit box llx lly (Boxwidth*UserUnit) (boxheight*UserUnit)
+ 4 -2 roll
+ 5 index mul exch % UserUnit box (Boxwidth*UserUnit) (boxheight*UserUnit) (lly*UserUnit) llx
+ 5 index mul exch % UserUnit box (Boxwidth*UserUnit) (boxheight*UserUnit) (llx*UserUnit) (lly*UserUnit)
+ 4 2 roll % UserUnit box (llx*UserUnit) (lly*UserUnit) (Boxwidth*UserUnit) (boxheight*UserUnit)
+ 6 -1 roll pop % box (llx*UserUnit) (lly*UserUnit) (Boxwidth*UserUnit) (boxheight*UserUnit)
+ } ifelse
} ifelse
}
{
@@ -768,8 +777,18 @@ systemdict /NEWPDF known not {/NEWPDF //true def} if
//systemdict /NoUserUnit .knownget not { //false } if not
{
2 index /UserUnit known {
- 2 index /UserUnit get
- dup scale
+ /PassUserUnit /GetDeviceParam .special_op {
+ exch pop not
+ } {
+ true
+ }ifelse
+
+ % If PassUserUnit isn't handled by the device, or it returns 'false'
+ % then scale the content by the UserUnit. Otherwise do not scale.
+ {
+ 2 index /UserUnit get
+ dup scale
+ } if
} if
} if
} ifelse
@@ -777,7 +796,7 @@ systemdict /NEWPDF known not {/NEWPDF //true def} if
pop % The box
% If we are using the MediaBox (and only the MediaBox) then we
- % want to clip to the CropBox, if there s one present
+ % want to clip to the CropBox, if there is one present
/MediaBox eq {
dup /CropBox known {