diff options
author | Ken Sharp <ken.sharp@artifex.com> | 2022-10-26 13:25:13 +0100 |
---|---|---|
committer | Ken Sharp <ken.sharp@artifex.com> | 2022-10-26 13:25:37 +0100 |
commit | 048bc2918ba0b07471d12c0090d5ca737f38a339 (patch) | |
tree | 0b8d48f196ec7cbf6f6e951725cfc06e6914d0e7 /Resource | |
parent | 28a4b16ec292d181b7227040dd47925e3b0949d9 (diff) | |
download | ghostpdl-048bc2918ba0b07471d12c0090d5ca737f38a339.tar.gz |
GhostPDF + GS - Fix negative llx and lly Box with FitPage
Bug #705992 "Converting PDF to TIFF with ghostscript causes offset output when using -dFitPage and -sPAPERSIZE options"
The files supplied with the report all have a MediaBox (and other Boxes)
where the origin is not only not 0,0 but is in fact negative. A
possibility I had overlooked previously.
This commit fixes that.
This does lead to some changes in behaviour when compared to the old
PDF interpreter.
The output from the old interpreter was inconsistent with 'landscape'
pages, as evidenced in the bug report. In fact these pages are not
landscape at all, in the sense that the media and content is all defined
in portrait. The reason they are displayed landscape is because the page
contains a /Rotate key with a value of 270.
When the output was to a rendering device, such as TIFF, the landscape
files were sized to fit on Legal media (to satisfy -sPAPERSIZE=legal and
-dFitPage) BUT the output was then rotated, resulting in a landscape
bitmap.
When the output was a high level device, such as pdfwrite, then the
landscape files were written as portrait files, sized for Legal media
and rotated so that the content is 'upside down'.
This also happened with the rendering devices when using
-dDEVICEWIDTHPOINTS and -dDEVICEHEIGHTPOINTS to set the media size to
Legal.
When using -dDEVICEHEIGHTPOINTS and -dDEVICEWIDTHPOINTS to set true
landscape media, and fitting the page to that, the rendering devices
coped correctly, but the pdfwrite output has a badly sized CropBox
leading to the files displaying totally incorrectly in Acrobat.
The new code is consistent across all devices, rotations, orientations
of both actual media and requested media.
The requested media in the bug report is Legal, and Legal media is
portrait, not landscape, so it seems to me that producing a landscape
bitmap is wrong. We now produce portrait legal output. The pdfwrite
device also produces portrait media output (as before) but the content
is the correct way up, not rotated.
To achieve landscape output, you need to specify landscape media (which
can't be done with -sPAPERSIZE as only 11x17 has a defined landscape
version), by using -sDEVICEWIDTHPOINTS and -dDEVICEWIDTHPOINTS and
setting -dFIXEDMEDIA to prevent the media size being changed to match
the requested input.
Diffstat (limited to 'Resource')
-rw-r--r-- | Resource/Init/pdf_main.ps | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/Resource/Init/pdf_main.ps b/Resource/Init/pdf_main.ps index e40883c39..3f848e21a 100644 --- a/Resource/Init/pdf_main.ps +++ b/Resource/Init/pdf_main.ps @@ -411,11 +411,6 @@ systemdict /NEWPDF known not {/NEWPDF //true def} if exch % swap media width/height for scaling calculation }if - % Stack - box boxwidth boxheight mediawidth mediaheight - % Incorporate up any offset from 0,0 - 4 index aload pop pop pop neg exch neg - translate - % Now use the box and media values to calculate the required x/y scale factors 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) @@ -442,6 +437,14 @@ systemdict /NEWPDF known not {/NEWPDF //true def} if dup 0 ne {2 div} if % box boxwidth boxheight mediawidth Yscale (widthdiff / 2) 0 translate % box boxwidth boxheight mediawidth Yscale } ifelse + + % Apply any 'offset' in the Box. Tht is, if the llx and lly are not 0, then we need to + % shift the origin of the content so that they become 0,0. We need to take into + % account the scaling from above. + 4 index aload pop pop pop + neg 2 index mul exch neg 2 index mul exch + translate + dup scale % scale both axes the same pop pop pop % remove the leftover boxwidth, boxheight and mediawidth/height } bind def |