summaryrefslogtreecommitdiff
path: root/Resource
diff options
context:
space:
mode:
authorKen Sharp <ken.sharp@artifex.com>2022-09-13 12:19:53 +0100
committerKen Sharp <ken.sharp@artifex.com>2022-09-13 12:19:53 +0100
commit54ace5ddb3c9af2dd11b9f7ffa001b055284775c (patch)
tree5e297fe99433b0e9e62f0a54b5032ae3002bd178 /Resource
parent65a0c7a46d1156b8927e9951e1ca21e320828b30 (diff)
downloadghostpdl-54ace5ddb3c9af2dd11b9f7ffa001b055284775c.tar.gz
GhostPDF + GS - Centre contents on media when using PDFFitPage
Bug #705861 "Regression: image not centered when forcing A4 output" The old PDF interpreter apparently centres the content on the scaled page when using PDFFitPage, whereas we were maintaining the origin at 0,0. Add code to duplicate this.
Diffstat (limited to 'Resource')
-rw-r--r--Resource/Init/pdf_main.ps36
1 files changed, 27 insertions, 9 deletions
diff --git a/Resource/Init/pdf_main.ps b/Resource/Init/pdf_main.ps
index be151d110..4aa2595f9 100644
--- a/Resource/Init/pdf_main.ps
+++ b/Resource/Init/pdf_main.ps
@@ -417,15 +417,33 @@ systemdict /NEWPDF known not {/NEWPDF //true def} if
translate
% Now use the box and media values to calculate the required x/y scale factors
- 3 -1 roll div % box boxwidth mediawidth (mediaheight / boxheight)
- 3 1 roll % box (mediaheight / boxheight) boxwidth mediawidth
- exch % box (mediaheight / boxheight) mediawidth boxwidth
- div % box (mediaheight / boxheight) (mediawidth / boxwidth)
-
- 2 copy % box Yscale Xscale Yscale Xscale
- gt {exch} if % select smallest scale factor
- pop %
- dup scale % and scale page isomorphically
+ 4 copy % Stack - box boxwidth boxheight mediawidth mediaheight boxwidth boxheight mediawidth mediaheight
+ 3 -1 roll div % box boxwidth boxheight mediawidth mediaheight boxwidth mediawidth (mediaheight / boxheight)
+ 3 1 roll % box boxwidth boxheight mediawidth mediaheight (mediaheight / boxheight) boxwidth mediawidth
+ exch % box boxwidth boxheight mediawidth mediaheight (mediaheight / boxheight) mediawidth boxwidth
+ div % box boxwidth boxheight mediawidth mediaheight (mediaheight / boxheight) (mediawidth / boxwidth)
+
+ % Stack - box boxwidth boxheight mediawidth mediaheight Yscale Xscale
+
+ % Centre the output on the media
+ 2 copy % box boxwidth boxheight mediawidth mediaheight Yscale Xscale Yscale Xscale
+ gt {
+ exch pop % box boxwidth boxheight mediawidth mediaheight Xscale
+ dup 4 index mul % box boxwidth boxheight mediawidth mediaheight Xscale (boxheight * Xscale)
+ 3 -1 roll sub dup
+ 0 lt {-1 mul} if % box boxwidth boxheight mediawidth Xscale ((boxheight * Xscale) - mediaheight)
+ dup 0 ne {2 div} if % box boxwidth boxheight mediawidth Xscale (heightdiff / 2)
+ 0 exch translate % box boxwidth boxheight mediawidth Xscale
+ } {
+ pop % box boxwidth boxheight mediawidth mediaheight Yscale
+ dup 5 index mul % box boxwidth boxheight mediawidth mediaheight Yscale (boxwidth * Yscale)
+ 4 -1 roll sub dup
+ 0 lt {-1 mul} if % box boxwidth boxheight mediaheight Yscale ((boxwidth * Yscale) - mediawidth)
+ dup 0 ne {2 div} if % box boxwidth boxheight mediawidth Yscale (widthdiff / 2)
+ 0 translate % box boxwidth boxheight mediawidth Yscale
+ } ifelse
+ dup scale % scale both axes the same
+ pop pop pop % remove the leftover boxwidth, boxheight and mediawidth/height
} bind def
/newpdf_get_media_box { % <pagedict> get_media_box <box> <bool>