summaryrefslogtreecommitdiff
path: root/Resource/Init/gs_epsf.ps
diff options
context:
space:
mode:
authorRay Johnston <ray.johnston@artifex.com>2020-10-17 12:52:36 -0700
committerRay Johnston <ray.johnston@artifex.com>2020-10-23 09:09:17 -0700
commit8313e4f30bef7c50711cd503c3037184a7850d51 (patch)
tree2a707eaaa6e0c72b4d78174c2b2a8c9f4dff1251 /Resource/Init/gs_epsf.ps
parent76359f0c03e8b4d8db7359d521865894ac7a4592 (diff)
downloadghostpdl-8313e4f30bef7c50711cd503c3037184a7850d51.tar.gz
Fix Bug702995: Inconsistent auto-rotation of EPS with EPSFitPage.
We need to defer the EPSFitPage scaling, centering and rotation until after both the the %%BoundingBox and/or the %%HiResBoundingBox have been processed. Doing one after the other results in slight rounding diffs depending on the resolution. Change to save the value (prefering the HiResBoundingBox) and do the scaling/translate/rotate only once when %%EndComments is processed.
Diffstat (limited to 'Resource/Init/gs_epsf.ps')
-rw-r--r--Resource/Init/gs_epsf.ps52
1 files changed, 44 insertions, 8 deletions
diff --git a/Resource/Init/gs_epsf.ps b/Resource/Init/gs_epsf.ps
index cf020751a..0e4e3c8cd 100644
--- a/Resource/Init/gs_epsf.ps
+++ b/Resource/Init/gs_epsf.ps
@@ -29,6 +29,7 @@
% After %%HiResBoundingBox processed, state is 3 if OK or 4 if cropped.
% After %%EndComments processed, state is 5.
/EPSBoundingBoxState 5 def
+/EPSBoundingBoxString () def % set if either BoundingBox is seen (even if invalid)
/EPSBoundingBoxSetState {
//systemdict /EPSBoundingBoxState 3 -1 roll .forceput
} .bind executeonly odef % .forceput must be bound and hidden
@@ -60,7 +61,10 @@
/EPSBoundingBoxFitPage { % llx lly urx ury --
EPSDEBUG { (gs_epsf.ps: Rescaling EPS to fit page\n) print flush } if
clippath pathbbox newpath % ellx elly eurx eury pllx plly purx pury
-
+ EPSDEBUG {
+ (Page Coordinates: LLX: ) print 3 index =print (, LLY: ) print
+ 2 index =print (, URX: ) print 1 index =print (, URY: ) print dup = flush
+ } if
% Convert box corners to coordinates of the center and box sizes
2 { % loop doing the page coordinates, the the EPS bbox coordinates
3 -1 roll exch % ... llx urx lly ury
@@ -82,7 +86,19 @@
% Find orientation of the best fit. Square pages or files don't rotate.
2 copy sub % edx ecx edy ecy pdx pdy pdx-pdy
- 6 index 5 index sub mul % edx ecx edy ecy pdx pdy (pdx-pdy)*(edx-edy)
+ EPSDEBUG {
+ (pdx: ) print 2 index =print (, pdy: ) print 1 index =print
+ (, pdx-pdy: ) print dup = flush
+ } if
+ 6 index 5 index sub
+ EPSDEBUG {
+ (edx: ) print 7 index =print (, edy: ) print 5 index =print
+ (, edx-edy: ) print dup = flush
+ } if
+ mul % edx ecx edy ecy pdx pdy (pdx-pdy)*(edx-edy)
+ EPSDEBUG {
+ (product: ) print dup = flush
+ } if
0 lt {
90 rotate
exch
@@ -100,15 +116,17 @@
} bind executeonly odef
/EPSBoundingBoxProcess { % (llx lly urx ury) state --
+ % The following 'lt' check prioritzies HiResBoundingBox over BoundingBox
+ % even if HiResBoundingBox occurs first in the EPS file.
//systemdict /EPSBoundingBoxState get 1 index lt {
- exch EPSBoundingBoxParse
+ % save the BBoxString for possible FitPage when EndComments is seen
+ exch dup //systemdict /EPSBoundingBoxString 3 -1 roll .forceput
+ EPSBoundingBoxParse
{
//systemdict /EPSCrop known {
EPSBoundingBoxCrop
} {
- //systemdict /EPSFitPage known {
- EPSBoundingBoxFitPage
- } {
+ //systemdict /EPSFitPage known not {
% Warn if some of the EPS file will be clipped
clippath pathbbox newpath
{ % context for exit
@@ -124,10 +142,17 @@
flush
1 add
} if
+ } {
+ pop pop pop pop
} ifelse
} ifelse
EPSBoundingBoxSetState
} {
+ % improperly formed BoundingBox string.
+ QUIET not {
+ (\n **** Warning: BoundingBox values are invalid and will be ignored: ') print
+ EPSBoundBoxString print (') = flush
+ } if
pop % state
} ifelse
} {
@@ -189,11 +214,21 @@
} ifelse
} {
(%%EndComments) anchorsearch {
- pop pop
+ pop pop % discard the strings from the anchorsearch
+ % We may have seen BoundingBox or HiResBounfingBox. If so and if EPSFitPage
+ % is set, then we do the transformation here to scale and center the page,
+ % rotating if needed (and AllowFitPageRotation is true -- the default.)
+ //systemdict /EPSFitPage known
+ //systemdict /EPSBoundingBoxState get 0 gt
+ and {
+ EPSBoundingBoxString EPSBoundingBoxParse {
+ EPSBoundingBoxFitPage
+ } if
+ } if
% Ignore any following comments
5 EPSBoundingBoxSetState
} {
- pop
+ pop % Not %%EndComments -- ignore it
} ifelse
} ifelse
} if
@@ -310,6 +345,7 @@ end
/.runnoepsf
/.runEPS
/EPSBoundingBoxSetState
+ /EPSBoundingBoxString
/EPSBoundingBoxCrop
/EPSBoundingBoxFitPage
/EPSBoundingBoxParse