diff options
author | 2021-03-30 10:59:39 +0200 | |
---|---|---|
committer | 2021-04-01 00:04:14 +0200 | |
commit | 5ff1d6955496b3cf9a35042c9ac35db43bc336b1 (patch) | |
tree | 6d470f7eb448f59f53e8df1010aec9dad8ce1f72 /Resource | |
parent | Import Ghostscript 9.53.1 (diff) | |
download | ghostscript-gpl-patches-5ff1d6955496b3cf9a35042c9ac35db43bc336b1.tar.gz ghostscript-gpl-patches-5ff1d6955496b3cf9a35042c9ac35db43bc336b1.tar.bz2 ghostscript-gpl-patches-5ff1d6955496b3cf9a35042c9ac35db43bc336b1.zip |
Import Ghostscript 9.54ghostscript-9.54
Signed-off-by: Thomas Deutschmann <whissi@gentoo.org>
Diffstat (limited to 'Resource')
77 files changed, 859 insertions, 334 deletions
diff --git a/Resource/CIDFont/ArtifexBullet b/Resource/CIDFont/ArtifexBullet Binary files differindex 18c98f16..268d518f 100644 --- a/Resource/CIDFont/ArtifexBullet +++ b/Resource/CIDFont/ArtifexBullet diff --git a/Resource/CMap/Identity-UTF16-H b/Resource/CMap/Identity-UTF16-H index a47413aa..5c1c3eac 100644 --- a/Resource/CMap/Identity-UTF16-H +++ b/Resource/CMap/Identity-UTF16-H @@ -1,4 +1,4 @@ -% Copyright (C) 2003-2018 Artifex Software. All rights reserved. +% Copyright (C) 2003-2021 Artifex Software. All rights reserved. % % This software is provided AS-IS with no warranty, either express or % implied. diff --git a/Resource/ColorSpace/DefaultCMYK b/Resource/ColorSpace/DefaultCMYK index cba9326c..f3d71823 100644 --- a/Resource/ColorSpace/DefaultCMYK +++ b/Resource/ColorSpace/DefaultCMYK @@ -1,4 +1,4 @@ -% Copyright (C) 2001-2020 Artifex Software, Inc. +% Copyright (C) 2001-2021 Artifex Software, Inc. % All Rights Reserved. % % This software is provided AS-IS with no warranty, either express or diff --git a/Resource/ColorSpace/DefaultGray b/Resource/ColorSpace/DefaultGray index 95c9ef41..21a72fd6 100644 --- a/Resource/ColorSpace/DefaultGray +++ b/Resource/ColorSpace/DefaultGray @@ -1,4 +1,4 @@ -% Copyright (C) 2001-2020 Artifex Software, Inc. +% Copyright (C) 2001-2021 Artifex Software, Inc. % All Rights Reserved. % % This software is provided AS-IS with no warranty, either express or diff --git a/Resource/ColorSpace/DefaultRGB b/Resource/ColorSpace/DefaultRGB index 53ddf3ea..d715587b 100644 --- a/Resource/ColorSpace/DefaultRGB +++ b/Resource/ColorSpace/DefaultRGB @@ -1,4 +1,4 @@ -% Copyright (C) 2001-2020 Artifex Software, Inc. +% Copyright (C) 2001-2021 Artifex Software, Inc. % All Rights Reserved. % % This software is provided AS-IS with no warranty, either express or diff --git a/Resource/ColorSpace/TrivialCMYK b/Resource/ColorSpace/TrivialCMYK index b3dec8b8..66776bcd 100644 --- a/Resource/ColorSpace/TrivialCMYK +++ b/Resource/ColorSpace/TrivialCMYK @@ -1,4 +1,4 @@ -% Copyright (C) 2001-2020 Artifex Software, Inc. +% Copyright (C) 2001-2021 Artifex Software, Inc. % All Rights Reserved. % % This software is provided AS-IS with no warranty, either express or diff --git a/Resource/ColorSpace/sGray b/Resource/ColorSpace/sGray index a0997d0b..501ed376 100644 --- a/Resource/ColorSpace/sGray +++ b/Resource/ColorSpace/sGray @@ -1,4 +1,4 @@ -% Copyright (C) 2001-2020 Artifex Software, Inc. +% Copyright (C) 2001-2021 Artifex Software, Inc. % All Rights Reserved. % % This software is provided AS-IS with no warranty, either express or diff --git a/Resource/ColorSpace/sRGB b/Resource/ColorSpace/sRGB index 16f3ecfa..0aadbc01 100644 --- a/Resource/ColorSpace/sRGB +++ b/Resource/ColorSpace/sRGB @@ -1,4 +1,4 @@ -% Copyright (C) 2001-2020 Artifex Software, Inc. +% Copyright (C) 2001-2021 Artifex Software, Inc. % All Rights Reserved. % % This software is provided AS-IS with no warranty, either express or diff --git a/Resource/Decoding/FCO_Dingbats b/Resource/Decoding/FCO_Dingbats index 8da04509..76cd6d1a 100644 --- a/Resource/Decoding/FCO_Dingbats +++ b/Resource/Decoding/FCO_Dingbats @@ -1,4 +1,4 @@ -% Copyright (C) 2001-2020 Artifex Software, Inc. +% Copyright (C) 2001-2021 Artifex Software, Inc. % All Rights Reserved. % % This software is provided AS-IS with no warranty, either express or diff --git a/Resource/Decoding/FCO_Symbol b/Resource/Decoding/FCO_Symbol index c9411a03..4c2dcecb 100644 --- a/Resource/Decoding/FCO_Symbol +++ b/Resource/Decoding/FCO_Symbol @@ -1,4 +1,4 @@ -% Copyright (C) 2001-2020 Artifex Software, Inc. +% Copyright (C) 2001-2021 Artifex Software, Inc. % All Rights Reserved. % % This software is provided AS-IS with no warranty, either express or diff --git a/Resource/Decoding/FCO_Unicode b/Resource/Decoding/FCO_Unicode index 4cdf58a5..acc8e022 100644 --- a/Resource/Decoding/FCO_Unicode +++ b/Resource/Decoding/FCO_Unicode @@ -1,4 +1,4 @@ -% Copyright (C) 2001-2020 Artifex Software, Inc. +% Copyright (C) 2001-2021 Artifex Software, Inc. % All Rights Reserved. % % This software is provided AS-IS with no warranty, either express or diff --git a/Resource/Decoding/FCO_Wingdings b/Resource/Decoding/FCO_Wingdings index a31cefd8..2eaca0df 100644 --- a/Resource/Decoding/FCO_Wingdings +++ b/Resource/Decoding/FCO_Wingdings @@ -1,4 +1,4 @@ -% Copyright (C) 2001-2020 Artifex Software, Inc. +% Copyright (C) 2001-2021 Artifex Software, Inc. % All Rights Reserved. % % This software is provided AS-IS with no warranty, either express or diff --git a/Resource/Decoding/Latin1 b/Resource/Decoding/Latin1 index 8960ab4f..b9dff0f3 100644 --- a/Resource/Decoding/Latin1 +++ b/Resource/Decoding/Latin1 @@ -1,4 +1,4 @@ -% Copyright (C) 2001-2020 Artifex Software, Inc. +% Copyright (C) 2001-2021 Artifex Software, Inc. % All Rights Reserved. % % This software is provided AS-IS with no warranty, either express or diff --git a/Resource/Decoding/StandardEncoding b/Resource/Decoding/StandardEncoding index f2b27a56..5ac6d63c 100644 --- a/Resource/Decoding/StandardEncoding +++ b/Resource/Decoding/StandardEncoding @@ -1,4 +1,4 @@ -% Copyright (C) 2001-2020 Artifex Software, Inc. +% Copyright (C) 2001-2021 Artifex Software, Inc. % All Rights Reserved. % % This software is provided AS-IS with no warranty, either express or diff --git a/Resource/Decoding/Unicode b/Resource/Decoding/Unicode index 7ecd3069..dfc137d9 100644 --- a/Resource/Decoding/Unicode +++ b/Resource/Decoding/Unicode @@ -1,4 +1,4 @@ -% Copyright (C) 2001-2020 Artifex Software, Inc. +% Copyright (C) 2001-2021 Artifex Software, Inc. % All Rights Reserved. % % This software is provided AS-IS with no warranty, either express or diff --git a/Resource/Encoding/CEEncoding b/Resource/Encoding/CEEncoding index bd3f8abb..b2d7e574 100644 --- a/Resource/Encoding/CEEncoding +++ b/Resource/Encoding/CEEncoding @@ -1,4 +1,4 @@ -% Copyright (C) 2001-2020 Artifex Software, Inc. +% Copyright (C) 2001-2021 Artifex Software, Inc. % All Rights Reserved. % % This software is provided AS-IS with no warranty, either express or diff --git a/Resource/Encoding/ExpertEncoding b/Resource/Encoding/ExpertEncoding index fe879bda..97b33213 100644 --- a/Resource/Encoding/ExpertEncoding +++ b/Resource/Encoding/ExpertEncoding @@ -1,4 +1,4 @@ -% Copyright (C) 2001-2020 Artifex Software, Inc. +% Copyright (C) 2001-2021 Artifex Software, Inc. % All Rights Reserved. % % This software is provided AS-IS with no warranty, either express or diff --git a/Resource/Encoding/ExpertSubsetEncoding b/Resource/Encoding/ExpertSubsetEncoding index 6f789bc5..6177adb0 100644 --- a/Resource/Encoding/ExpertSubsetEncoding +++ b/Resource/Encoding/ExpertSubsetEncoding @@ -1,4 +1,4 @@ -% Copyright (C) 2001-2020 Artifex Software, Inc. +% Copyright (C) 2001-2021 Artifex Software, Inc. % All Rights Reserved. % % This software is provided AS-IS with no warranty, either express or diff --git a/Resource/Encoding/NotDefEncoding b/Resource/Encoding/NotDefEncoding index a5e0b8d3..0c810e48 100644 --- a/Resource/Encoding/NotDefEncoding +++ b/Resource/Encoding/NotDefEncoding @@ -1,4 +1,4 @@ -% Copyright (C) 2001-2020 Artifex Software, Inc. +% Copyright (C) 2001-2021 Artifex Software, Inc. % All Rights Reserved. % % This software is provided AS-IS with no warranty, either express or diff --git a/Resource/Encoding/Wingdings b/Resource/Encoding/Wingdings index 4a245571..efb7d3fa 100644 --- a/Resource/Encoding/Wingdings +++ b/Resource/Encoding/Wingdings @@ -1,4 +1,4 @@ -% Copyright (C) 2001-2020 Artifex Software, Inc. +% Copyright (C) 2001-2021 Artifex Software, Inc. % All Rights Reserved. % % This software is provided AS-IS with no warranty, either express or diff --git a/Resource/IdiomSet/PPI_CUtils b/Resource/IdiomSet/PPI_CUtils new file mode 100644 index 00000000..7e6ecb23 --- /dev/null +++ b/Resource/IdiomSet/PPI_CUtils @@ -0,0 +1,24 @@ +%% +%% Idioms for the PPI Media GmbH PPI_ColorUtils ProcSet +%% This appears to be a kind of desktop colour separation utility. If it is +%% used with the pdfwrite PassThroughJPEGImages feature then instead of +%% converting images from colour to gray, we embed the colour image data +%% but with a DeviceGray colour space, which leads to incorrect output. +%% To fix that, turn off the feature if cuForceGray is set to true. This +%% is the first time we've seen this, and more work may be required. +%% + +currentuserparams /IdiomRecognition get +<</IdiomRecognition false>> setuserparams + +/PPI_CUtils +<< +/cuForceGray [ +{/_cuForceGray exch cuPut} bind +{dup //true eq {currentdevice //null //false mark /PassThroughJPEGImages //false .putdeviceparamsonly}if /_cuForceGray exch cuPut} bind +] +>> + +/IdiomSet defineresource pop + +<</IdiomRecognition 3 -1 roll>> setuserparams diff --git a/Resource/Init/FCOfontmap-PCLPS2 b/Resource/Init/FCOfontmap-PCLPS2 index 91bd8f7f..e51db629 100644 --- a/Resource/Init/FCOfontmap-PCLPS2 +++ b/Resource/Init/FCOfontmap-PCLPS2 @@ -1,4 +1,4 @@ -% Copyright (C) 2001-2020 Artifex Software, Inc. +% Copyright (C) 2001-2021 Artifex Software, Inc. % All Rights Reserved. % % This software is provided AS-IS with no warranty, either express or diff --git a/Resource/Init/Fontmap.GS b/Resource/Init/Fontmap.GS index 5f47b6b4..b6fce711 100644 --- a/Resource/Init/Fontmap.GS +++ b/Resource/Init/Fontmap.GS @@ -1,4 +1,4 @@ -% Copyright (C) 2001-2020 Artifex Software, Inc. +% Copyright (C) 2001-2021 Artifex Software, Inc. % All Rights Reserved. % % This software is provided AS-IS with no warranty, either express or diff --git a/Resource/Init/gs_agl.ps b/Resource/Init/gs_agl.ps index 9c1c52d2..ce5ea1ce 100644 --- a/Resource/Init/gs_agl.ps +++ b/Resource/Init/gs_agl.ps @@ -1,4 +1,4 @@ -% Copyright (C) 2001-2020 Artifex Software, Inc. +% Copyright (C) 2001-2021 Artifex Software, Inc. % All Rights Reserved. % % This software is provided AS-IS with no warranty, either express or diff --git a/Resource/Init/gs_btokn.ps b/Resource/Init/gs_btokn.ps index 410b8419..1f63fb5c 100644 --- a/Resource/Init/gs_btokn.ps +++ b/Resource/Init/gs_btokn.ps @@ -1,4 +1,4 @@ -% Copyright (C) 2001-2020 Artifex Software, Inc. +% Copyright (C) 2001-2021 Artifex Software, Inc. % All Rights Reserved. % % This software is provided AS-IS with no warranty, either express or diff --git a/Resource/Init/gs_cff.ps b/Resource/Init/gs_cff.ps index 6cfa1ec1..43cf7d01 100644 --- a/Resource/Init/gs_cff.ps +++ b/Resource/Init/gs_cff.ps @@ -1,4 +1,4 @@ -% Copyright (C) 2001-2020 Artifex Software, Inc. +% Copyright (C) 2001-2021 Artifex Software, Inc. % All Rights Reserved. % % This software is provided AS-IS with no warranty, either express or diff --git a/Resource/Init/gs_cidcm.ps b/Resource/Init/gs_cidcm.ps index 503ec867..1ec03b36 100644 --- a/Resource/Init/gs_cidcm.ps +++ b/Resource/Init/gs_cidcm.ps @@ -1,4 +1,4 @@ -% Copyright (C) 2001-2020 Artifex Software, Inc. +% Copyright (C) 2001-2021 Artifex Software, Inc. % All Rights Reserved. % % This software is provided AS-IS with no warranty, either express or diff --git a/Resource/Init/gs_ciddc.ps b/Resource/Init/gs_ciddc.ps index 6cdba039..9e2ea1ea 100644 --- a/Resource/Init/gs_ciddc.ps +++ b/Resource/Init/gs_ciddc.ps @@ -1,4 +1,4 @@ -% Copyright (C) 2001-2020 Artifex Software, Inc. +% Copyright (C) 2001-2021 Artifex Software, Inc. % All Rights Reserved. % % This software is provided AS-IS with no warranty, either express or diff --git a/Resource/Init/gs_cidfm.ps b/Resource/Init/gs_cidfm.ps index f22e45d6..1a456ab1 100644 --- a/Resource/Init/gs_cidfm.ps +++ b/Resource/Init/gs_cidfm.ps @@ -1,4 +1,4 @@ -% Copyright (C) 2001-2020 Artifex Software, Inc. +% Copyright (C) 2001-2021 Artifex Software, Inc. % All Rights Reserved. % % This software is provided AS-IS with no warranty, either express or diff --git a/Resource/Init/gs_cidfn.ps b/Resource/Init/gs_cidfn.ps index 20af1c87..870a2e11 100644 --- a/Resource/Init/gs_cidfn.ps +++ b/Resource/Init/gs_cidfn.ps @@ -1,4 +1,4 @@ -% Copyright (C) 2001-2020 Artifex Software, Inc. +% Copyright (C) 2001-2021 Artifex Software, Inc. % All Rights Reserved. % % This software is provided AS-IS with no warranty, either express or diff --git a/Resource/Init/gs_cidtt.ps b/Resource/Init/gs_cidtt.ps index e045cfdd..b856ba65 100644 --- a/Resource/Init/gs_cidtt.ps +++ b/Resource/Init/gs_cidtt.ps @@ -1,4 +1,4 @@ -% Copyright (C) 2001-2020 Artifex Software, Inc. +% Copyright (C) 2001-2021 Artifex Software, Inc. % All Rights Reserved. % % This software is provided AS-IS with no warranty, either express or diff --git a/Resource/Init/gs_cmap.ps b/Resource/Init/gs_cmap.ps index 3252089a..0c2e1421 100644 --- a/Resource/Init/gs_cmap.ps +++ b/Resource/Init/gs_cmap.ps @@ -1,4 +1,4 @@ -% Copyright (C) 2001-2020 Artifex Software, Inc. +% Copyright (C) 2001-2021 Artifex Software, Inc. % All Rights Reserved. % % This software is provided AS-IS with no warranty, either express or diff --git a/Resource/Init/gs_cspace.ps b/Resource/Init/gs_cspace.ps index 8aaf6b74..c005cef4 100644 --- a/Resource/Init/gs_cspace.ps +++ b/Resource/Init/gs_cspace.ps @@ -1,4 +1,4 @@ -% Copyright (C) 2001-2020 Artifex Software, Inc. +% Copyright (C) 2001-2021 Artifex Software, Inc. % All Rights Reserved. % % This software is provided AS-IS with no warranty, either express or diff --git a/Resource/Init/gs_dbt_e.ps b/Resource/Init/gs_dbt_e.ps index 2aca0c68..89e24131 100644 --- a/Resource/Init/gs_dbt_e.ps +++ b/Resource/Init/gs_dbt_e.ps @@ -1,4 +1,4 @@ -% Copyright (C) 2001-2020 Artifex Software, Inc. +% Copyright (C) 2001-2021 Artifex Software, Inc. % All Rights Reserved. % % This software is provided AS-IS with no warranty, either express or diff --git a/Resource/Init/gs_diskn.ps b/Resource/Init/gs_diskn.ps index 85ff07e3..825ff8d9 100644 --- a/Resource/Init/gs_diskn.ps +++ b/Resource/Init/gs_diskn.ps @@ -1,4 +1,4 @@ -% Copyright (C) 2001-2020 Artifex Software, Inc. +% Copyright (C) 2001-2021 Artifex Software, Inc. % All Rights Reserved. % % This software is provided AS-IS with no warranty, either express or diff --git a/Resource/Init/gs_dps1.ps b/Resource/Init/gs_dps1.ps index 14cc5d6d..ba5b9b54 100644 --- a/Resource/Init/gs_dps1.ps +++ b/Resource/Init/gs_dps1.ps @@ -1,4 +1,4 @@ -% Copyright (C) 2001-2020 Artifex Software, Inc. +% Copyright (C) 2001-2021 Artifex Software, Inc. % All Rights Reserved. % % This software is provided AS-IS with no warranty, either express or diff --git a/Resource/Init/gs_dps2.ps b/Resource/Init/gs_dps2.ps index 2dfaaa49..03206446 100644 --- a/Resource/Init/gs_dps2.ps +++ b/Resource/Init/gs_dps2.ps @@ -1,4 +1,4 @@ -% Copyright (C) 2001-2020 Artifex Software, Inc. +% Copyright (C) 2001-2021 Artifex Software, Inc. % All Rights Reserved. % % This software is provided AS-IS with no warranty, either express or diff --git a/Resource/Init/gs_dscp.ps b/Resource/Init/gs_dscp.ps index 15764b17..4ea3d454 100644 --- a/Resource/Init/gs_dscp.ps +++ b/Resource/Init/gs_dscp.ps @@ -1,4 +1,4 @@ -% Copyright (C) 2001-2020 Artifex Software, Inc. +% Copyright (C) 2001-2021 Artifex Software, Inc. % All Rights Reserved. % % This software is provided AS-IS with no warranty, either express or diff --git a/Resource/Init/gs_epsf.ps b/Resource/Init/gs_epsf.ps index cf020751..47b68bba 100644 --- a/Resource/Init/gs_epsf.ps +++ b/Resource/Init/gs_epsf.ps @@ -1,4 +1,4 @@ -% Copyright (C) 2001-2020 Artifex Software, Inc. +% Copyright (C) 2001-2021 Artifex Software, Inc. % All Rights Reserved. % % This software is provided AS-IS with no warranty, either express or @@ -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 } { @@ -135,6 +160,25 @@ } ifelse } bind executeonly odef +% Perform anchorsearch on the strings in the array until a match is found. +/anchorsearchforany { % haystack [needle1 ...] --> post needle true + % --> haystack false + false 3 1 roll % false haystack [...] + { % false haystack needle + dup 3 1 roll % false needle haystack needle + anchorsearch { + % false needle post needle + pop % false needle post + 3 1 roll % post false needle + exch not exch % post true needle + exit + } { + % false needle haystack + exch pop % false haystack + } ifelse + } forall + exch % haystack false | post needle true +} bind def /ProcessEPSComment { % file comment -- file comment /EPSBoundingBoxState .systemvar 3 lt { @@ -188,12 +232,23 @@ } ifelse } ifelse } { - (%%EndComments) anchorsearch { - pop pop + {(%%EndComments) (%%BeginProlog) (%%BeginSetup)} anchorsearchforany { + EPSDEBUG { (EPSComment processing finished, encountered: ) print dup = } if + 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 +365,7 @@ end /.runnoepsf /.runEPS /EPSBoundingBoxSetState + /EPSBoundingBoxString /EPSBoundingBoxCrop /EPSBoundingBoxFitPage /EPSBoundingBoxParse diff --git a/Resource/Init/gs_fapi.ps b/Resource/Init/gs_fapi.ps index 0b493c6a..b0f74820 100644 --- a/Resource/Init/gs_fapi.ps +++ b/Resource/Init/gs_fapi.ps @@ -1,4 +1,4 @@ -% Copyright (C) 2001-2020 Artifex Software, Inc. +% Copyright (C) 2001-2021 Artifex Software, Inc. % All Rights Reserved. % % This software is provided AS-IS with no warranty, either express or diff --git a/Resource/Init/gs_fntem.ps b/Resource/Init/gs_fntem.ps index d5ac0bfa..8904352d 100644 --- a/Resource/Init/gs_fntem.ps +++ b/Resource/Init/gs_fntem.ps @@ -1,4 +1,4 @@ -% Copyright (C) 2001-2020 Artifex Software, Inc. +% Copyright (C) 2001-2021 Artifex Software, Inc. % All Rights Reserved. % % This software is provided AS-IS with no warranty, either express or diff --git a/Resource/Init/gs_fonts.ps b/Resource/Init/gs_fonts.ps index 3f4f4af8..f1e26b09 100644 --- a/Resource/Init/gs_fonts.ps +++ b/Resource/Init/gs_fonts.ps @@ -1,4 +1,4 @@ -% Copyright (C) 2001-2020 Artifex Software, Inc. +% Copyright (C) 2001-2021 Artifex Software, Inc. % All Rights Reserved. % % This software is provided AS-IS with no warranty, either express or diff --git a/Resource/Init/gs_frsd.ps b/Resource/Init/gs_frsd.ps index 74c1dd27..80d39910 100644 --- a/Resource/Init/gs_frsd.ps +++ b/Resource/Init/gs_frsd.ps @@ -1,4 +1,4 @@ -% Copyright (C) 2001-2020 Artifex Software, Inc. +% Copyright (C) 2001-2021 Artifex Software, Inc. % All Rights Reserved. % % This software is provided AS-IS with no warranty, either express or @@ -61,13 +61,29 @@ level2dict begin .currentglobal 1 index gcheck .setglobal exch currentpacking //false setpacking exch + 2 dict begin /filelen 0 def % scratch dict for filelen and pos (below). % Stack: dict filters parms CloseSource oldglobal oldpacking file - [ exch { dup 40000 string readstring not { exit } if exch } loop + [ exch { + dup 40000 string readstring + /filelen 2 index length filelen add def % accumulate filelen + not { exit } if exch + } loop exch pop ] - % Stack: dict filters parms CloseSource oldglobal oldpacking [()...] + { filelen string } stopped { % try allocating a single string + pop % couldn't make a string - discard filelen value + } { + % transfer the array-of-strings to the single string. + % stack: ... [() ...] string + /pos 0 def exch { + 1 index exch pos exch putinterval /pos pos 40000 add def + } forall + } ifelse + % top of stack is either array of strings or one string == stream_data + end % done with scratch dict + % Stack: dict filters parms CloseSource oldglobal oldpacking stream_data 3 1 roll setpacking setglobal - % Stack: dict filters parms CloseSource [()...] + % Stack: dict filters parms CloseSource stream_data 1 index .reusablestream } if % We created the stream successfully: clean up. diff --git a/Resource/Init/gs_icc.ps b/Resource/Init/gs_icc.ps index fac0cb25..0bf8313f 100644 --- a/Resource/Init/gs_icc.ps +++ b/Resource/Init/gs_icc.ps @@ -1,4 +1,4 @@ -% Copyright (C) 2001-2020 Artifex Software, Inc. +% Copyright (C) 2001-2021 Artifex Software, Inc. % All Rights Reserved. % % This software is provided AS-IS with no warranty, either express or diff --git a/Resource/Init/gs_il1_e.ps b/Resource/Init/gs_il1_e.ps index f8cfff04..35250233 100644 --- a/Resource/Init/gs_il1_e.ps +++ b/Resource/Init/gs_il1_e.ps @@ -1,4 +1,4 @@ -% Copyright (C) 2001-2020 Artifex Software, Inc. +% Copyright (C) 2001-2021 Artifex Software, Inc. % All Rights Reserved. % % This software is provided AS-IS with no warranty, either express or diff --git a/Resource/Init/gs_img.ps b/Resource/Init/gs_img.ps index 00d79df3..3750ad30 100644 --- a/Resource/Init/gs_img.ps +++ b/Resource/Init/gs_img.ps @@ -1,4 +1,4 @@ -% Copyright (C) 2002-2018 Artifex, Inc. All rights reserved. +% Copyright (C) 2002-2021 Artifex, Inc. All rights reserved. % % This software is provided AS-IS with no warranty, either express or % implied. diff --git a/Resource/Init/gs_init.ps b/Resource/Init/gs_init.ps index f843119a..088c8583 100644 --- a/Resource/Init/gs_init.ps +++ b/Resource/Init/gs_init.ps @@ -1,4 +1,4 @@ -% Copyright (C) 2001-2020 Artifex Software, Inc. +% Copyright (C) 2001-2021 Artifex Software, Inc. % All Rights Reserved. % % This software is provided AS-IS with no warranty, either express or @@ -34,7 +34,7 @@ % Interpreter library version number % NOTE: the interpreter code requires that the first non-comment token % in this file be an integer, and that it match the compiled-in version! -9531 +9540 % Check the interpreter revision. dup revision ne @@ -144,7 +144,8 @@ currentdict /PDFNOCIDFALLBACK known /PDFNOCIDFALLBACK exch def currentdict /BATCH known /BATCH exch def currentdict /DELAYBIND known /DELAYBIND exch def -currentdict /DOINTERPOLATE .knownget { { -1 } { 0 } ifelse /InterpolateControl exch def } if +currentdict /DOINTERPOLATE .knownget { { -1 } { 1 } ifelse /InterpolateControl exch def } if +currentdict /NOINTERPOLATE .knownget { { 0 } { 1 } ifelse /InterpolateControl exch def } if currentdict /ESTACKPRINT known /ESTACKPRINT exch def currentdict /FAKEFONTS known /FAKEFONTS exch def currentdict /FIXEDMEDIA known /FIXEDMEDIA exch def @@ -159,7 +160,6 @@ currentdict /NODISPLAY known not /DISPLAYING exch def currentdict /NOFONTMAP known /NOFONTMAP exch def currentdict /NOFONTPATH known /NOFONTPATH exch def currentdict /NOGC known /NOGC exch def -currentdict /NOINTERPOLATE .knownget { /InterpolateControl 0 def } if currentdict /NOMEDIAATTRS known /NOMEDIAATTRS exch def currentdict /NOOUTERSAVE known /NOOUTERSAVE exch def currentdict /NOPAGEPROMPT known /NOPAGEPROMPT exch def @@ -215,6 +215,13 @@ currentdict /EPSFitPage known { /PSFitPage //true def } if % This is a "convenience" option that sets a combination of EPSFitPage, PDFFitPage and PSFitPage currentdict /FitPage known { /EPSFitPage //true def /PDFFitPage //true def /PSFitPage //true def } if +currentdict /SimulateOverprint known { + (\n**** -dSimulateOverprint={true|false} is no longer supported. ****\n) print + (**** It has been replaced by -dOverprint={enable|disable|simulate} ****\n\n) print + % Set the new variable appropriately. + /Overprint SimulateOverprint { /enable } { /disable } ifelse def +} if + % Acquire environment variables. currentdict /DEVICE known not { (GS_DEVICE) getenv { /DEVICE exch def } if } if diff --git a/Resource/Init/gs_lev2.ps b/Resource/Init/gs_lev2.ps index fefa732b..54849370 100644 --- a/Resource/Init/gs_lev2.ps +++ b/Resource/Init/gs_lev2.ps @@ -1,4 +1,4 @@ -% Copyright (C) 2001-2020 Artifex Software, Inc. +% Copyright (C) 2001-2021 Artifex Software, Inc. % All Rights Reserved. % % This software is provided AS-IS with no warranty, either express or diff --git a/Resource/Init/gs_ll3.ps b/Resource/Init/gs_ll3.ps index f6d98482..98e2a65f 100644 --- a/Resource/Init/gs_ll3.ps +++ b/Resource/Init/gs_ll3.ps @@ -1,4 +1,4 @@ -% Copyright (C) 2001-2020 Artifex Software, Inc. +% Copyright (C) 2001-2021 Artifex Software, Inc. % All Rights Reserved. % % This software is provided AS-IS with no warranty, either express or diff --git a/Resource/Init/gs_mex_e.ps b/Resource/Init/gs_mex_e.ps index dda0675c..cced43b3 100644 --- a/Resource/Init/gs_mex_e.ps +++ b/Resource/Init/gs_mex_e.ps @@ -1,4 +1,4 @@ -% Copyright (C) 2001-2020 Artifex Software, Inc. +% Copyright (C) 2001-2021 Artifex Software, Inc. % All Rights Reserved. % % This software is provided AS-IS with no warranty, either express or diff --git a/Resource/Init/gs_mgl_e.ps b/Resource/Init/gs_mgl_e.ps index e02729b1..b437285b 100644 --- a/Resource/Init/gs_mgl_e.ps +++ b/Resource/Init/gs_mgl_e.ps @@ -1,4 +1,4 @@ -% Copyright (C) 2001-2020 Artifex Software, Inc. +% Copyright (C) 2001-2021 Artifex Software, Inc. % All Rights Reserved. % % This software is provided AS-IS with no warranty, either express or diff --git a/Resource/Init/gs_mro_e.ps b/Resource/Init/gs_mro_e.ps index 7d0e3b7c..e476322b 100644 --- a/Resource/Init/gs_mro_e.ps +++ b/Resource/Init/gs_mro_e.ps @@ -1,4 +1,4 @@ -% Copyright (C) 2001-2020 Artifex Software, Inc. +% Copyright (C) 2001-2021 Artifex Software, Inc. % All Rights Reserved. % % This software is provided AS-IS with no warranty, either express or diff --git a/Resource/Init/gs_pdf_e.ps b/Resource/Init/gs_pdf_e.ps index 172cd72c..2d3ec9ff 100644 --- a/Resource/Init/gs_pdf_e.ps +++ b/Resource/Init/gs_pdf_e.ps @@ -1,4 +1,4 @@ -% Copyright (C) 2001-2020 Artifex Software, Inc. +% Copyright (C) 2001-2021 Artifex Software, Inc. % All Rights Reserved. % % This software is provided AS-IS with no warranty, either express or diff --git a/Resource/Init/gs_pdfwr.ps b/Resource/Init/gs_pdfwr.ps index a53b8c3f..9386339b 100644 --- a/Resource/Init/gs_pdfwr.ps +++ b/Resource/Init/gs_pdfwr.ps @@ -1,4 +1,4 @@ -% Copyright (C) 2001-2020 Artifex Software, Inc. +% Copyright (C) 2001-2021 Artifex Software, Inc. % All Rights Reserved. % % This software is provided AS-IS with no warranty, either express or @@ -278,19 +278,6 @@ languagelevel 2 .setlanguagelevel % ---------------- End of predefined configurations ---------------- % -% Set optimizations for converting PostScript to PDF. -% The ps2pdf* scripts invoke this. -/.setpdfwrite { % - .setpdfwrite - - % Set a large VM threshold to reduce garbage collection. - (\n**** WARNING: The .setpdfwrite operator has been deprecated and will be removed entirely\n) print - ( in the next release of Ghostscript. The functionality of this operator has\n) print - ( been reduced to increasing the size of the VM threshold. If you believe you\n) print - ( have a real need for this then you should replace your call to .setpdfwrite\n) print - ( with:\n\n) print - ( 3000000 setvmthreshold\n\n) print - currentuserparams /VMThreshold get 3000000 .max setvmthreshold -} bind def - % ---------------- pdfmark and DSC processing ---------------- % /.write_small_positive_real % <file> <real> .write_small_positive_real - diff --git a/Resource/Init/gs_res.ps b/Resource/Init/gs_res.ps index 18f63a30..41214bf3 100644 --- a/Resource/Init/gs_res.ps +++ b/Resource/Init/gs_res.ps @@ -1,4 +1,4 @@ -% Copyright (C) 2001-2020 Artifex Software, Inc. +% Copyright (C) 2001-2021 Artifex Software, Inc. % All Rights Reserved. % % This software is provided AS-IS with no warranty, either express or diff --git a/Resource/Init/gs_resmp.ps b/Resource/Init/gs_resmp.ps index 5ba4f43e..a7eb70fc 100644 --- a/Resource/Init/gs_resmp.ps +++ b/Resource/Init/gs_resmp.ps @@ -1,4 +1,4 @@ -% Copyright (C) 2001-2020 Artifex Software, Inc. +% Copyright (C) 2001-2021 Artifex Software, Inc. % All Rights Reserved. % % This software is provided AS-IS with no warranty, either express or diff --git a/Resource/Init/gs_setpd.ps b/Resource/Init/gs_setpd.ps index 51b26899..2a333bf7 100644 --- a/Resource/Init/gs_setpd.ps +++ b/Resource/Init/gs_setpd.ps @@ -1,4 +1,4 @@ -% Copyright (C) 2001-2020 Artifex Software, Inc. +% Copyright (C) 2001-2021 Artifex Software, Inc. % All Rights Reserved. % % This software is provided AS-IS with no warranty, either express or diff --git a/Resource/Init/gs_statd.ps b/Resource/Init/gs_statd.ps index 7b85ef0f..8f01c78c 100644 --- a/Resource/Init/gs_statd.ps +++ b/Resource/Init/gs_statd.ps @@ -1,4 +1,4 @@ -% Copyright (C) 2001-2020 Artifex Software, Inc. +% Copyright (C) 2001-2021 Artifex Software, Inc. % All Rights Reserved. % % This software is provided AS-IS with no warranty, either express or diff --git a/Resource/Init/gs_std_e.ps b/Resource/Init/gs_std_e.ps index 4bfa6c5b..c696b714 100644 --- a/Resource/Init/gs_std_e.ps +++ b/Resource/Init/gs_std_e.ps @@ -1,4 +1,4 @@ -% Copyright (C) 2001-2020 Artifex Software, Inc. +% Copyright (C) 2001-2021 Artifex Software, Inc. % All Rights Reserved. % % This software is provided AS-IS with no warranty, either express or diff --git a/Resource/Init/gs_sym_e.ps b/Resource/Init/gs_sym_e.ps index fb92a299..e6c58f6f 100644 --- a/Resource/Init/gs_sym_e.ps +++ b/Resource/Init/gs_sym_e.ps @@ -1,4 +1,4 @@ -% Copyright (C) 2001-2020 Artifex Software, Inc. +% Copyright (C) 2001-2021 Artifex Software, Inc. % All Rights Reserved. % % This software is provided AS-IS with no warranty, either express or diff --git a/Resource/Init/gs_trap.ps b/Resource/Init/gs_trap.ps index e4d6cafe..9a089eef 100644 --- a/Resource/Init/gs_trap.ps +++ b/Resource/Init/gs_trap.ps @@ -1,4 +1,4 @@ -% Copyright (C) 2001-2020 Artifex Software, Inc. +% Copyright (C) 2001-2021 Artifex Software, Inc. % All Rights Reserved. % % This software is provided AS-IS with no warranty, either express or diff --git a/Resource/Init/gs_ttf.ps b/Resource/Init/gs_ttf.ps index 394cba28..95d50c6b 100644 --- a/Resource/Init/gs_ttf.ps +++ b/Resource/Init/gs_ttf.ps @@ -1,4 +1,4 @@ -% Copyright (C) 2001-2020 Artifex Software, Inc. +% Copyright (C) 2001-2021 Artifex Software, Inc. % All Rights Reserved. % % This software is provided AS-IS with no warranty, either express or @@ -414,7 +414,16 @@ pop /firstcode startc 0 getu16a 16#ff00 and dup 16#f000 ne { pop 0 } if def /putglyph { - glyphs code 3 -1 roll put /code code 1 add def + glyphs code known + { + glyphs /.cmap_warning_issued known not { + (**** Warning: Invalid TTF cmap mapping (overlapping/repeated map)\n) print flush + glyphs /.cmap_warning_issued //true put + } if + pop + } + {glyphs code 3 -1 roll put}ifelse + /code code 1 add def } bind def /glyphs 0 dict def @@ -438,6 +447,10 @@ % Two choices are: drop later repeated/overlapping segments entirely, % or only use codes from later, overlapping segments not already set % by the earlier segment. (Inspired by Bug 700968). + % Revision: bug 703589 has an (invalid) cmap table with overlapping + % (actually repeating) ranges, and requires the *first* range definition + % to be used in order to render correctly. So /putglyph now refuses to + % overwrite existing keys in the "glyphs" dictionary 0 2 nseg2 dup 4 lt {pop 4}if 3 sub { /i2 exch def /scode startc i2 getu16a def @@ -464,7 +477,10 @@ } for } ifelse } if - } for glyphs /glyphs //null def % for GC + } for + % If we've encoutered an invalid table, remove the key before returning + glyphs /.cmap_warning_issued undef + glyphs /glyphs //null def % for GC } .bind 6 { % Single interval lookup. dup 6 getu16a /firstcode exch def diff --git a/Resource/Init/gs_typ32.ps b/Resource/Init/gs_typ32.ps index 2d5fc814..4c2035c7 100644 --- a/Resource/Init/gs_typ32.ps +++ b/Resource/Init/gs_typ32.ps @@ -1,4 +1,4 @@ -% Copyright (C) 2001-2020 Artifex Software, Inc. +% Copyright (C) 2001-2021 Artifex Software, Inc. % All Rights Reserved. % % This software is provided AS-IS with no warranty, either express or diff --git a/Resource/Init/gs_typ42.ps b/Resource/Init/gs_typ42.ps index 654a268c..a3bb9795 100644 --- a/Resource/Init/gs_typ42.ps +++ b/Resource/Init/gs_typ42.ps @@ -1,4 +1,4 @@ -% Copyright (C) 2001-2020 Artifex Software, Inc. +% Copyright (C) 2001-2021 Artifex Software, Inc. % All Rights Reserved. % % This software is provided AS-IS with no warranty, either express or diff --git a/Resource/Init/gs_type1.ps b/Resource/Init/gs_type1.ps index 18488ebe..fa3cdd88 100644 --- a/Resource/Init/gs_type1.ps +++ b/Resource/Init/gs_type1.ps @@ -1,4 +1,4 @@ -% Copyright (C) 2001-2020 Artifex Software, Inc. +% Copyright (C) 2001-2021 Artifex Software, Inc. % All Rights Reserved. % % This software is provided AS-IS with no warranty, either express or diff --git a/Resource/Init/gs_wan_e.ps b/Resource/Init/gs_wan_e.ps index 5d3673cc..fe821352 100644 --- a/Resource/Init/gs_wan_e.ps +++ b/Resource/Init/gs_wan_e.ps @@ -1,4 +1,4 @@ -% Copyright (C) 2001-2020 Artifex Software, Inc. +% Copyright (C) 2001-2021 Artifex Software, Inc. % All Rights Reserved. % % This software is provided AS-IS with no warranty, either express or diff --git a/Resource/Init/pdf_base.ps b/Resource/Init/pdf_base.ps index 2cc18270..2453b6bc 100644 --- a/Resource/Init/pdf_base.ps +++ b/Resource/Init/pdf_base.ps @@ -1,4 +1,4 @@ -% Copyright (C) 2001-2020 Artifex Software, Inc. +% Copyright (C) 2001-2021 Artifex Software, Inc. % All Rights Reserved. % % This software is provided AS-IS with no warranty, either express or @@ -779,17 +779,19 @@ currentdict /token_nofail_dict .undef % Read the data for all objects. We check to see if we get % the number of objects that we expect. % Stack: strm# objstreamdict N objectstream [obj#] PDFDEBUG - mark 3 -1 roll % Get objectstream + /ResolveObjectStreamMark 3 -1 roll count 4 index add % Determine stack depth with objects 3 1 roll resolveobjstreamopdict .pdfrun % Get PDF objects - count counttomark 1 add index ne + count /ResolveObjectStreamMark CountToKey not {0} if + 1 add index + ne { - count counttomark 1 add index gt { + count /ResolveObjectStreamMark CountToKey not {0} if + 1 add index gt { ( **** Error: Incorrect object count in object stream (too many objects).\n) pdfformaterror ( Output may be incorrect.\n) pdfformaterror } if - % Its possible for us to end up here with a valid file. The way we work is to read the % stream and tokenise all the objects, but that assumes there will be delimiters or % whitespace between each object in the stream. We can easily think of cases where @@ -821,13 +823,13 @@ currentdict /token_nofail_dict .undef % the stack, in the right order, preceded by a mark, a count, and an array containing % all the object numbers. - % First, discard everything we read up to now; we can reuse the mark which was placed - % by the preceding code to do this, as long as we remember to replace that mark. + % First, discard everything we read up to now; we can reuse the 'mark' which was placed + % by the preceding code to do this, as long as we remember to replace that 'mark'. % Handily this will leave the count and the array which contains the object numbers in place. - cleartomark + /ResolveObjectStreamMark ClearToKey - % Replace the mark consumed by conttomark above, so that we match what the code following this error handling expects. - mark + % Replace the 'mark' consumed by conttomark above, so that we match what the code following this error handling expects. + /ResolveObjectStreamMark % copy the ObjStm dictionary and then copy the count of objects expected 4 index 4 index @@ -894,14 +896,15 @@ currentdict /token_nofail_dict .undef % but leave count of objects. Check that aginst the number of objects % retrieved. If we got too few then issue a warning. - pop pop exch pop counttomark 1 sub lt { + pop pop exch pop /ResolveObjectStreamMark CountToKey not {1} if + 1 sub lt { ( **** Error: Incorrect object count in object stream (too few objects).\n) pdfformaterror ( Output may be incorrect.\n) pdfformaterror } if } if % We have the object data - counttomark array astore % Put objects into an array + /ResolveObjectStreamMark CountToKey not {0} if array astore exch pop exch pop % Remove mark and count currentdict //no_debug_dict eq { end } if % Restore debug context % Save the objects into Objects @@ -1090,15 +1093,30 @@ currentdict /no_debug_dict undef % Some (bad) PDf files have invalid stream lengths. This causes problems % if we reposition beyond the end of the file. So we compare the given % length to number of bytes left in the file. - dup /Length knownoget { - dup PDFfile bytesavailable lt { % compare to to bytes left in file - PDFfile fileposition % reposition to the end of stream - add PDFfile exch setfileposition - } { - pop % bad stream length - do not reposition. - % This will force a length warning below - } ifelse - } if + dup mark exch /Length {knownoget} stopped { + % Bug 703372 is a PDF file where the XRef stream dictionary has a Length which is an + % indirect object. Clearly we cannot look that up in an xref which we haevn't yet + % read! We catch the error from knownoget and do not reposition the steam. After + % that the normal recovery code kicks in and we will eventually manage to read + % the compressed xref. + cleartomark + } + { + { + dup type /realtype eq { + ( **** Warning: stream length is a real number; converting to integer.\n) pdfformatwarning + cvi 2 copy /Length exch put + } if + dup PDFfile bytesavailable lt { % compare to to bytes left in file + PDFfile fileposition % reposition to the end of stream + add PDFfile exch setfileposition + } { + pop % bad stream length - do not reposition. + % This will force a length warning below + } ifelse + } if + pop % the mark from the Length dereference guard above. + } ifelse } { pop % We're already reading from a stream, which we can't reposition. @@ -1191,7 +1209,7 @@ currentdict /no_debug_dict undef //unabbrevfilterdict 1 index .knownget { exch pop } if dup /Filter resourcestatus { pop pop } { Repaired exch % this error is not the creator's fault - RepiredAnError exch + RepairedAnError exch ( **** ERROR: Unable to process ) pdfformaterror 64 string cvs pdfformaterror ( data. Page will be missing data.\n) pdfformaterror diff --git a/Resource/Init/pdf_draw.ps b/Resource/Init/pdf_draw.ps index a93a526c..8527312c 100644 --- a/Resource/Init/pdf_draw.ps +++ b/Resource/Init/pdf_draw.ps @@ -1,4 +1,4 @@ -% Copyright (C) 2001-2020 Artifex Software, Inc. +% Copyright (C) 2001-2021 Artifex Software, Inc. % All Rights Reserved. % % This software is provided AS-IS with no warranty, either express or @@ -762,6 +762,24 @@ def .pdfruncontext end grestore + + % check for extra garbage on the operand stack and clean it up + count pdfemptycount sub dup 0 ne { + ( **** Error: Transparency Group, Form XObject execution corrupted the stack.\n) pdfformaterror + ( Output may be incorrect.\n) pdfformaterror + PDFSTOPONERROR { + /.execgroup cvx /rangecheck signalerror + } { + dup 0 gt { + { pop } repeat + }{ + pop + } ifelse + } ifelse + } { + pop + } ifelse + /pdfemptycount exch store } bind executeonly def @@ -796,12 +814,22 @@ def %% as arguments to .execgroup mark currentcolor counttomark array astore exch pop currentcolorspace 5 2 roll - - dup /Group oget exch /BBox oget + dup /Group oget dup type /dicttype eq { + exch /BBox oget dup type /arraytype eq { % Stack: resdict stream groupdict bbox - .beginformgroup - .execgroup - .endtransparencygroup + .beginformgroup + .execgroup + .endtransparencygroup + }{ + ( **** Error: Form XObject has a BBox entry with an invalid type.\n) pdfformaterror + ( Ignoring transparency Group, output may be incorrect.\n) pdfformaterror + pop pop pop pop pop pop + } ifelse + } { + ( **** Error: Form XObject has a Group entry with an invalid type.\n) pdfformaterror + ( Ignoring transparency Group, output may be incorrect.\n) pdfformaterror + pop pop pop pop pop pop + } ifelse } bind executeonly def % Make an ImageType 103 (soft-masked) image. @@ -2169,7 +2197,15 @@ currentdict /last-ditch-bpc-csp undef ( Output may be incorrect.\n) pdfformaterror } ifelse } if - 1 index /Mask knownoget { 1 index exch /Mask exch put } if + 1 index /Mask knownoget { + dup type dup /dicttype eq exch /arraytype eq or { % Bug #703681 + 1 index exch /Mask exch put + } { + pop + ( **** Error: Ignoring Mask attribute that is not an array or a dictionary.\n) + pdfformaterror + } ifelse + } if makeimagedict doimagesmask } bind executeonly def /makemaskimage { % <datasource> <imagemask> <Mask> makemaskimage @@ -2287,6 +2323,14 @@ currentdict /last-ditch-bpc-csp undef currentdict /SMask knownoget { % We are doing transparency and SMask is present in the image % stack: <imagemask> <SMask> + % Normalize /Matte attribute for .begintransparencymaskimage + dup /Matte .knownget { + oforce dup //null eq { + pop dup /Matte undef + } { + 1 index /Matte [ 4 -1 roll { oforce } forall ] put + } ifelse + } if .begintransparencymaskimage PDFfile fileposition exch gsave //nodict begin @@ -2308,6 +2352,12 @@ currentdict /last-ditch-bpc-csp undef % code only picks up the current colour space, not the space from the dictionary. currentdict /SMask get /Matte known {/CS currentdict /ColorSpace get dup pdfopdict /cs get exec } if >> 0 0 1 1 + gsave 1 1 moveto 0 0 lineto + % If we get an error, just emit an empty box + { pathbbox } stopped { 0 0 0 0 } if + 4 array astore grestore + /image + setup_trans .begintransparencygroup .currentstrokeconstantalpha .currentfillconstantalpha 3 -1 roll 1 .setfillconstantalpha 1 .setstrokeconstantalpha @@ -2409,12 +2459,6 @@ currentdict /last-ditch-bpc-csp undef makemaskimage } if % Stack: datasource imagemask - gsave 1 1 moveto 0 0 lineto - % If we get an error, just emit an empty box - { pathbbox } stopped { 0 0 0 0 } if - 4 array astore grestore - /image - setup_trans { currentdict end setsmaskstate //true ValidateDecode { imagemask } } { ColorSpace setgcolorspace currentdict end setsmaskstate //false ValidateDecode { image } } ifelse @@ -3008,6 +3052,12 @@ drawopdict begin /File PDFsource def currentdict makeimagekeys OFFlevels length 0 eq { + gsave 1 1 moveto 0 0 lineto + % If we get an error, just emit an empty box + { pathbbox } stopped { 0 0 0 0 } if + 4 array astore grestore + /image + setup_trans doimage } { pop Width @@ -4252,7 +4302,7 @@ currentdict /set_bc_color undef dup annotsetcolor { dup drawborder dup calc_annot_scale 2 copy mul 0 ne - {3 -1 roll drawwidget //false} + {3 -1 roll drawwidget} { pop pop ( **** Error: ignoring annotation with scale factor of 0\n) pdfformaterror @@ -4260,6 +4310,7 @@ currentdict /set_bc_color undef }ifelse } if //endannottransparency exec + //false } bind executeonly def /Ink { % <annot> -> <annot> <true> @@ -5359,14 +5410,9 @@ currentdict /drawannottypes undef /Ink {mark exch loadannot /ANN pdfmark //false} bind executeonly def -/Line { - mark exch dup /L .knownget { - aload 5 1 roll transform 4 -2 roll transform 4 2 roll - 5 -1 roll astore - 1 index /L 3 -1 roll put - } if - loadannot /ANN pdfmark //false -} bind executeonly def +/PolyLine {mark exch loadannot /ANN pdfmark //false} bind executeonly def + +/Line {mark exch loadannot /ANN pdfmark //false} bind executeonly def /Link { /NO_PDFMARK_DESTS where {pop NO_PDFMARK_DESTS not}{//true}ifelse @@ -5456,7 +5502,8 @@ currentdict /drawannottypes undef //false } bind executeonly def -/Movie {mark exch loadannot /ANN pdfmark //false} bind executeonly def +%% We don't handle movies correctly, so don't try to preserve them +%/Movie {mark exch loadannot /ANN pdfmark //false} bind executeonly def /Popup {mark exch loadannot /ANN pdfmark //false} bind executeonly def /Sound {mark exch loadannot /ANN pdfmark //false} bind executeonly def /Square {mark exch loadannot /ANN pdfmark //false} bind executeonly def @@ -5717,22 +5764,25 @@ currentdict end def % The recursive enumeration of the form fields doesn't descend into widget annotations. /draw_form_field { % <field> draw_form_field - - dup /Kids knownoget { % field [] - dup length 0 gt { - dup 0 oget /Parent knownoget { % field [] kid - pop % mon-terminal field % field [] - exch pop % [] - { oforce draw_form_field } forall + dup type /dicttyype eq { % File for Bug692447 has 'null' Fields entries + % This matches what pdf_main process_trailer_attrs + dup /Kids knownoget { % field [] + dup length 0 gt { + dup 0 oget /Parent knownoget { % field [] kid + pop % mon-terminal field % field [] + exch pop % [] + { oforce draw_form_field } forall + } { + pop draw_terminal_field % separate annots % - + } ifelse } { - pop draw_terminal_field % separate annots % - + ( **** Error: Ignoring empty /Kids array in Form field.\n) pdfformaterror + ( Output may be incorrect.\n) pdfformaterror } ifelse } { - ( **** Error: Ignoring empty /Kids array in Form field.\n) pdfformaterror - ( Output may be incorrect.\n) pdfformaterror + draw_terminal_field % merged annotation % - } ifelse - } { - draw_terminal_field % merged annotation % - - } ifelse + } if } bind executeonly def /draw_acro_form { % <form> draw_acro_form - diff --git a/Resource/Init/pdf_font.ps b/Resource/Init/pdf_font.ps index 98a9e3d4..699c14fe 100644 --- a/Resource/Init/pdf_font.ps +++ b/Resource/Init/pdf_font.ps @@ -1,4 +1,4 @@ -% Copyright (C) 2001-2020 Artifex Software, Inc. +% Copyright (C) 2001-2021 Artifex Software, Inc. % All Rights Reserved. % % This software is provided AS-IS with no warranty, either express or @@ -1234,6 +1234,23 @@ setglobal { /undef_proc_warning /missing-type1-procs /readonly-op-dict } { currentdict exch undef } forall + % Bug703454.pdf contains a number of fonts with multiple definitions + % of a given glyph name in the CharStrings dict - i.e. two entries + % for /a - the first of which is "correct" the second is "wrong". + % Normal Postscript behaviour replaces the first value with the second + % for the given key/value pair. + % To handle this, *only* for Type 1 fonts embedded in PDFs, we + % have a special definition of "def" which won't overwrite existing + % values in the CharStrings dict. + /def + { + 3 index /CharStrings eq + currentdict 3 index known and + { pstack flush pop pop } + { systemdict /def get exec } + ifelse + } bind executeonly def + end readonly def currentdict /eexec_pdf_param_dict .undef @@ -1481,7 +1498,9 @@ currentdict /eexec_pdf_param_dict .undef } { % filepos fontres stream 1 index /FontDescriptor oget - /Flags oget 4 and 0 ne { + /Flags oget dup % only believe the symbolic flag if the non-symbolic flag is not also set! + 4 and 0 ne + exch 32 and 0 eq and { //true % symbolic } { 1 index /Encoding oknown not % no encoding => symbolic diff --git a/Resource/Init/pdf_main.ps b/Resource/Init/pdf_main.ps index d7933700..ded2782a 100644 --- a/Resource/Init/pdf_main.ps +++ b/Resource/Init/pdf_main.ps @@ -1,4 +1,4 @@ -% Copyright (C) 2001-2020 Artifex Software, Inc. +% Copyright (C) 2001-2021 Artifex Software, Inc. % All Rights Reserved. % % This software is provided AS-IS with no warranty, either express or @@ -26,10 +26,12 @@ userdict /GS_PDF_ProcSet undef /#? //false def % Test whether the current output device handles pdfmark. -/.writepdfmarkdict 1 dict dup /pdfmark //null put readonly def /.writepdfmarks { % - .writepdfmarks <bool> - currentdevice //.writepdfmarkdict .getdeviceparams - mark eq { //false } { pop pop //true } ifelse + /PdfmarkCapable /GetDeviceParam .special_op { + exch pop + }{ + //false + }ifelse systemdict /DOPDFMARKS known or } bind executeonly def @@ -282,12 +284,22 @@ currentdict /runpdfstring .undef { systemdict /FirstPage known systemdict /LastPage known or - systemdict /Pagelist known or + systemdict /PageList known or { <</DisablePageHandler //true>> setpagedevice } if } bind def +/EnablePageHandlerDevice +{ + systemdict /FirstPage known + systemdict /LastPage known or + systemdict /PageList known or + { + <</DisablePageHandler //false>> setpagedevice + } if +} bind def + /runpdfbegin { % <file> runpdfbegin - userdict begin % It turns out that the PDF interpreter uses memory more @@ -295,20 +307,22 @@ currentdict /runpdfstring .undef % This is counter-intuitive, and we don't understand why it happens, % but the improvement is significant. /PDFTopSave save def - <</ProcessDSCComment //null>> setuserparams - <</ProcessComment //null>> setuserparams - %% Bug #696487, allow dict stack to grow without limit, as these PDF - %% files have stupidly deep gsave nesting and we need a dictionary per gsave - %% at the moment. - %% Remove ths if bug #696511 is ever completed (move ExtGstate parameters into gstate) - <</MaxDictStack -1>> setuserparams - %% Bug #696567, same customer as above. Ths time they have a file with a page whch has - %% 447000 ExtGState references (all of hwch contain no gstate!) Because we allocate - %% these on the stack, allow the stack to grow indefinitely in order to accomodate - %% such stupid files. Also move these lines from the end of the routine, so that - %% the increases are in place before we call odfopen, which will build the - %% resources and needs this definition in place. - <</MaxOpStack -1>> setuserparams + << + /ProcessDSCComment //null + /ProcessComment //null + %% Bug #696487, allow dict stack to grow without limit, as these PDF + %% files have stupidly deep gsave nesting and we need a dictionary per gsave + %% at the moment. + %% Remove ths if bug #696511 is ever completed (move ExtGstate parameters into gstate) + /MaxDictStack -1 + %% Bug #696567, same customer as above. Ths time they have a file with a page whch has + %% 447000 ExtGState references (all of which contain no gstate!) Because we allocate + %% these on the stack, allow the stack to grow indefinitely in order to accomodate + %% such stupid files. Also move these lines from the end of the routine, so that + %% the increases are in place before we call odfopen, which will build the + %% resources and needs this definition in place. + /MaxOpStack -1 + >> setuserparams //DisablePageHandlerDevice exec @@ -323,7 +337,6 @@ currentdict /runpdfstring .undef /CumulativePageCount currentpagedevice /PageCount get def } bind executeonly def -currentdict /DisablePageHandlerDevice undef /runpdfpagerange { % - runpdfpagerange <firstpage#> <lastpage#> /PortfolioPage where { @@ -375,9 +388,8 @@ currentdict /DisablePageHandlerDevice undef 2 2 pdfpagecount { PDFPageList exch 1 put } for - 1 pdfpagecount QUIET not { - (Processing even-numbered pages\n) print + (Processing even-numbered pages\n) print (1 through ) print pdfpagecount =only (.) = flush } if } { @@ -389,9 +401,8 @@ currentdict /DisablePageHandlerDevice undef 1 2 pdfpagecount { PDFPageList exch 1 put } for - 1 pdfpagecount QUIET not { - (Processing odd-numbered pages\n) print 1 index =only ( through ) print dup =only + (Processing odd-numbered pages\n) print (1 through ) print pdfpagecount =only (.) = flush } if } { @@ -525,10 +536,16 @@ currentdict /DisablePageHandlerDevice undef dup /Page# exch store QUIET not { (Page ) print dup //== exec flush } if pdfgetpage - dup //null ne { pdfshowpage } { - ( **** Error: Page #) pdfformaterror Page# 10 string cvs pdfformaterror - ( not found.\n) pdfformaterror - /dopdfpages cvx /syntaxerror signalerror + dup //null ne { + pdfshowpage + } { + PDFSTOPONERROR { + /dopdfpages cvx /syntaxerror signalerror + } { + pop + ( **** Error: Page #) pdfformaterror Page# 10 string cvs pdfformaterror + ( not found.\n) pdfformaterror + } ifelse } ifelse }{ pop @@ -554,9 +571,12 @@ currentdict /DisablePageHandlerDevice undef PDFTopSave restore end % userdict 2 vmreclaim % couldn't hurt - <</DisablePageHandler //false>> setpagedevice + //EnablePageHandlerDevice exec } bind executeonly def +currentdict /DisablePageHandlerDevice undef +currentdict /EnablePageHandlerDevice undef + % Copy stream to an external temporary file and % return the file name as PS name. /copy_embedded_file { @@ -890,7 +910,25 @@ pdfdict begin { % xref line tag was not /n /f ne % verify that the tag was /f { /setxrefentry cvx /syntaxerror signalerror - } if + } { + % Bug #703214 has a invalid initial xref table. The table entries are correct + % but the subsection begins 1 7 instead of 0 7, which means the initial entry is + % declared as object 1 instead of object 0. The file is incrementally updated + % many times and every object *except* object 1 is redefined. Object 1 is + % therefore defined as free and having an offset of 0. Acrobat can open this + % without complaint! Because the PDF header is a comment line it is skipped + % so Acrobat must simply be ignoring the free flag. We can't easily detect + % this, but we can check for the generation number being the canonical + % head of the free list. If it is, and the object number we have is not + % zero, then pretend its not free....... + dup 65535 eq { + 2 index 0 ne { + 0 3 1 roll + //false setxrefentry + 3 -1 roll pop + } if + }if + }ifelse } ifelse pop pop % pop <obj location> and <gen num> % stack: <err count> <obj num> @@ -1254,26 +1292,26 @@ currentdict /xref-char-dict undef % to the parent field. Trailer /Root knownoget { /AcroForm knownoget { - %% If we don't have a NeedAppearances entry, treat as if true. - %% We know Acrobat always regenerates all annotait - dup /NeedAppearances knownoget not { //true } if { - /NeedAppearances //true def - dup - /Fields knownoget { - { oforce - %% Make sure the entry from the Fields array is a dictionary - %% Bug #692447.pdf has an array of nulls. - dup type /dicttype eq { - link_widget_annots - }if - pop - } forall - } if - pop - } { - pop - } ifelse - } if + %% If we don't have a NeedAppearances entry, treat as if true. + %% We know Acrobat always regenerates all annotations. + dup /NeedAppearances knownoget not { //true } if { + /NeedAppearances //true def + dup + /Fields knownoget { + { oforce + %% Make sure the entry from the Fields array is a dictionary + %% Bug #692447.pdf has an array of nulls. + dup type /dicttype eq { + link_widget_annots + }if + pop + } forall + } if + pop + } { + pop + } ifelse + } if } if % Use OutputIntent ICC profile @@ -1427,14 +1465,15 @@ currentdict /xref-char-dict undef % Guess whether the output device is a printer. /Printed currentpagedevice /OutputFile known def } ifelse - currentpagedevice /OutputFile known { - currentpagedevice /OutputFile get (%d) search { - pop pop pop + % If the file name has an odd number of '%', it is either a request for + % separate pages, or is invalid. In either case some marks can be omitted. + currentpagedevice /OutputFile .knownget { + //false exch { + 37 eq xor + } forall { /NO_PDFMARK_OUTLINES //true def /NO_PDFMARK_DESTS //true def - } { - pop - }ifelse + } if } if /PSLevel1 where { pop } { /PSLevel1 //false def } ifelse % NB: PDFfile is used outside of the PDF code to determine that a @@ -1579,10 +1618,9 @@ currentdict /xref-char-dict undef % Check for recursion in the page tree. Bug 689954, MOAB-06-01-2007 % Make sure that the operand stack is cleaned up in case there's % an error and we ignore it (bug #700953) - mark + /StackMarkVerifyPageTree verify_page_tree - cleartomark - + /StackMarkVerifyPageTree ClearToKey currentdict end } bind executeonly def @@ -1923,7 +1961,6 @@ currentdict /xref-char-dict undef }ifelse }{ % No Page Resources, recursively try ParentResources as a last resort - pop % page Resources LocalResources parent_obj_get } ifelse } { @@ -1971,7 +2008,8 @@ currentdict /xref-char-dict undef % Get the total number of pages in the document. /pdfpagecount % - pdfpagecount <int> - { Trailer /Root knownoget { + { + Trailer /Root knownoget { /Pages knownoget { dup /Count knownoget { dup type /integertype eq { dup 0 le } { //true } ifelse { @@ -2078,10 +2116,20 @@ currentdict /xref-char-dict undef exch pop //null 0 1 3 index length 1 sub { 2 index exch get - dup oforce dup /Kids known { /Count oget } { pop 1 } ifelse + dup oforce + dup //null eq { + PDFSTOPONERROR { + /pdffindpage? cvx /syntaxerror signalerror + } { + ( **** Error: Ignoring a null node in the Page tree.\n) pdfformaterror + pop pop + } ifelse + } { + dup /Kids known { /Count oget } { pop 1 } ifelse % Stack: index kids null noderef count - dup 5 index ge { pop exch pop exit } if - 5 -1 roll exch sub 4 1 roll pop + dup 5 index ge { pop exch pop exit } if + 5 -1 roll exch sub 4 1 roll pop + } ifelse } for exch pop % Stack: index null|noderef dup //null eq { pop pop 1 //null exit } if @@ -2511,7 +2559,7 @@ end readonly def 2 index sub exch 3 index sub exch 4 2 roll pop pop % stack: savedCTM <pdfpagedict> [Box] XImageable YImageable 2 index aload pop 2 index sub exch 3 index sub exch 4 2 roll pop pop - 5 index /Rotate pget not { 0 } if 90 cvi idiv 1 and 0 ne { exch } if + 5 index /Rotate pget not { 0 } if cvi 90 idiv 1 and 0 ne { exch } if % stack: savedCTM <pdfpagedict> [Box] XImageable YImageable XBox YBox 4 copy 3 -1 roll exch div 3 1 roll div .min @@ -2647,7 +2695,11 @@ currentdict /PDF2PS_matrix_key undef % Determine the number of spot colors used on the page. Note: This searches % the pages resources. It may be high if a spot color is in a resource but % is not actually used on the page. - currentpagedevice /PageSpotColors known { /PageSpotColors 2 index countspotcolors def } if + currentpagedevice /PageSpotColors known { + /PageSpotColors 2 index countspotcolors + userdict /PageSpotColors 2 index put + def + } if % If the user told us to use a named OutputIntent systemdict /UseOutputIntent .knownget { @@ -2701,6 +2753,30 @@ currentdict /PDF2PS_matrix_key undef % Stack: pagedict currentpagedict installproc /Install exch def % Stack: pagedict currentpagedict + % If the Overprint device flag is not /disable, check usage of OP/op + /PageUsesOverprint //false def % assume we don't need OP simulation + dup /Overprint get /disable ne + % If the device suppports SpotColors (DeviceN device) we don't need simulation + 1 index /PageSpotColors known + not and + /HighLevelDevice /GetDeviceParam .special_op { + exch pop + }{ + //false + }ifelse + not and % Only if not HighLevelDevice + { + % Overprint is /enable, so the device might need the overprint compositor + % if it does not support spot colors, thus check if overprint is used so + % overprint simulation can be done with the pdf14 compositor + 1 index countspotcolors userdict exch /PageSpotColors exch put % save it in a known place + 1 index pageusesoverprint + 1 index /ProcessColorModel get /DeviceCMYK eq { + PageSpotColors 0 gt % count of colorants NOT including CMYK + and + } if + /PageUsesOverprint exch def % the page needs OP simulation so set device param. + } if pop currentdict end setpagedevice } bind executeonly def @@ -2769,18 +2845,46 @@ currentdict /PDF2PS_matrix_key undef % and the result was set in the pagedevice dictionary. Use it rather than % scanning again IF it is present. If the pdfshowpage_setup was not called % (eg GSView 5) then it will not be present, so we must rescan. - currentpagedevice /PageUsesTransparency .knownget not {dup pageusestransparency} if + currentdict /PageUsesTransparency .knownget not {dup pageusestransparency} if dup /PDFusingtransparency exch def { - % If the current device isn't CMYK, or if it is a device that (currently) supports transparency + % If the current device isn't CMYK, or if it is a device that supports transparency % we don't need the special handling of Overprint transparency, so disable the checking. - currentpagedevice dup /Colors get 4 lt 1 index /SimulateOverprint get not or - exch /HaveTransparency .knownget not { //false } if or - % device needs special Oveprint handling + + 4 dict begin % working directory to simplify + currentpagedevice dup /Colors get + /devColors exch def % put into our convenience dict + dup /HaveTransparency .knownget not { //false } if + /devSupportsTrans exch def % put into our convenience dict + dup /Overprint get + /SimOP exch def % put into our convenience dict + SimOP /simulate eq + exch /PageUsesOverprint .knownget not { //false } if + and % both Overprint==/simulate and PageUsesOverprint + { + % Determine if the device needs the special pdf14 compositor push + devColors 4 eq PageSpotColors 0 gt and % CMYK device, but device has spot colors + devColors 4 lt % RGB or Gray device + or + } { + //false % Overprint is not /simulate or PageUseOverprint is false + } ifelse + % Determine if the device needs SMask for Overprint + SimOP /simulate eq { + //true % we will need setupOPrtans for Compatible BM + } { + SimOP /enable eq + devColors 4 ge % CMYK device + and + } ifelse + devSupportsTrans not and % If device supports transparency (e.g. pdfwrite) then no setupOPtrans + end % pop the convenience dict /setup_trans exch - { /setupSMtrans } { /setupOPtrans } ifelse + { /setupOPtrans } { /setupSMtrans } ifelse load def + % Show the page within a PDF 1.4 device filter. - 0 .pushpdf14devicefilter { + { -1 } { 0 } ifelse + .pushpdf14devicefilter { /DefaultQstate qstate store % device has changed -- reset DefaultQstate % If the page has a Group, enclose contents in transparency group. % (Adobe Tech Note 5407, sec 9.2) @@ -2808,7 +2912,31 @@ currentdict /PDF2PS_matrix_key undef } { /setup_trans { pop pop } def % no-op this if the page doesn't use transparency % NB: original will be restored from PDFsave - showpagecontents + % The page doesn't use transparency, but if Overprint is /simulate, we may need to + % push a pdf14devicefilter to handle the overprint simulation using the pdf14 device. + currentpagedevice + dup /Overprint get /simulate eq + 1 index /PageSpotColors known + not and + exch /PageUsesOverprint .knownget not { //false } if + and + { + % Show the page within a PDF 1.4 device filter for overprint_simulation. + -1 .pushpdf14devicefilter { + /DefaultQstate qstate store % device has changed -- reset DefaultQstate + showpagecontents + } stopped { + % abort the transparency device + .abortpdf14devicefilter + /DefaultQstate qstate store % device has changed -- reset DefaultQstate + stop + } if + { } settransfer % identity transfer during popdevice (put_image) + .poppdf14devicefilter % NB: reset to DefaultQstate will also restore transfer function + /DefaultQstate qstate store % device has changed -- reset DefaultQstate + } { + showpagecontents + } ifelse } ifelse .free_page_resources % todo: mixing drawing ops outside the device filter could cause @@ -2967,7 +3095,8 @@ currentdict /PDF2PS_matrix_key undef } ifelse } if } if - //systemdict /ShowAcroForm .knownget { //true eq } { //false } ifelse { + % default AcroForm to true to match Acrobat. + //systemdict /ShowAcroForm .knownget { //true eq } { //true } ifelse { Trailer /Root oget /AcroForm knownoget { draw_acro_form } if } if } bind executeonly def @@ -2980,6 +3109,112 @@ currentdict /PDF2PS_matrix_key undef dup { setcolorspace } //.internalstopped exec { pop /DeviceRGB } if } bind executeonly def +% returns true if OP or op is true in an ExtGState +/pageusesoverprint { % <pagedict> pageusesoverprint <bool> + dup //false exch { + 4 dict 1 index resourceusesoverprint { pop not exit } if + %% Check the current dictionary and its Parent (if any) to see + %% if they both have stored object numbers. If they do then + %% check the numbers, don't allow self-references. + dup /Parent knownoget not { pop exit } + { + exch /.gs.pdfobj# .knownget + { + 1 index /.gs.pdfobj# .knownget { + eq { + pop exit + }if + }{ + pop + }ifelse + }if + } ifelse + } loop + % Also check for transparency in the annotation (if not in resources). + { pop //true } { annotsuseoverprint } ifelse +} bind def + +% Check if Overprint (OP/op) is specified in an ExtGState dict +/extgstateusesoverprint { % <gstate dict> extgstateusesoverprint <bool> + //false exch % Assume no overprint + dup //null eq { + pop % bug 692050 + } { + { % establish loop context + dup /OP knownoget { { pop not exit } if } if + dup /op knownoget { { pop not exit } if } if + pop exit + } loop + } ifelse +} bind def + +% Check if overprint is used in a Pattern +/patternusesoverprint { % <Pattern dict> patternusesoverprint <bool> + //false exch % Assume no overprint + { + 4 dict 1 index resourceusesoverprint { pop not exit } if + dup /ExtGState knownoget { extgstateusesoverprint { pop not exit } if } if + pop exit + } loop +} bind def + +% Check the Resources of a page or Form. Check for loops in the resource chain. +/resourceusesoverprint { % <dict> <dict> resourceusesoverprint <bool> + { % Use loop to provide an exitable context. + /Resources knownoget not { 0 dict } if + 2 copy .knownget { + { % Some circular references may be missed because scanning stops + % when the 1st overprint is found. + ( **** File has circular references in resource dictionaries.\n) + pdfformaterror + } if + pop //false exit + } if + 2 copy //true put % In the current chain. + dup /ExtGState knownoget { + //false exch + { exch pop oforce extgstateusesoverprint { pop //true exit } if + } forall + { pop //true exit } if + } if + dup /Pattern knownoget { + //false exch + { exch pop oforce patternusesoverprint { pop //true exit } if + } forall + { pop //true exit } if + } if + 2 copy //false put % Visited but not in the current chain. + pop //false exit + } loop + exch pop +} bind def + +% Check if the annotations on a page use overprint +/annotsuseoverprint { % <page dict> annotsuseoverprint <bool> + //false exch % Assume no overprint + /Annots knownoget { % Get Annots array + dup type /arraytype eq { + { + oforce + dup //null ne { + /AP knownoget { % Get appearance dict for the annoation + /N knownogetdict { % Get the /N (i.e. normal) appearance stream + 4 dict exch resourceusesoverprint { pop pop //true exit } if + } if + } if % If AP dict known + } { + pop + } ifelse + } forall % For all annots on the page + } { + ( **** Error: Annotation array is not an array, ignoring it.\n) pdfformaterror + ( Output may be incorrect.\n) pdfformaterror + pop + } + ifelse + } if +} bind def + % ------ Transparency support ------ % % Determine whether a page might invoke any transparency features: @@ -3162,31 +3397,37 @@ currentdict /PDF2PS_matrix_key undef } { exch pop % remove the 'on error' marker - dup //null ne { - dup /Subtype knownoget { - /Highlight eq { % Highlight annotation is always implemented - pop pop //true exit % as transparency. + dup type /dicttype eq { + dup //null ne { + dup /Subtype knownoget { + /Highlight eq { % Highlight annotation is always implemented + pop pop //true exit % as transparency. + } if } if - } if - dup /AP knownoget { % Get appearance dict for the annoation - /N knownogetdict { % Get the /N (i.e. normal) appearance stream - 4 dict exch resourceusestransparency { pop pop //true exit } if + dup /AP knownoget { % Get appearance dict for the annoation + /N knownogetdict { % Get the /N (i.e. normal) appearance stream + 4 dict exch resourceusestransparency { pop pop //true exit } if + } if + } if % If AP dict known + dup /BM knownoget { + pop pop pop //true exit } if - } if % If AP dict known - dup /BM knownoget { - pop pop pop //true exit - } if - dup /CA knownoget { - 1 le { - pop pop //true exit + dup /CA knownoget { + 1 le { + pop pop //true exit + } if } if - } if - /ca knownoget { - 1 le { - pop //true exit + /ca knownoget { + 1 le { + pop //true exit + } if } if - } if + } { + pop + } ifelse } { + ( **** Error: Annotation entry is not a dictionary, ignoring it.\n) pdfformaterror + ( Output may be incorrect.\n) pdfformaterror pop } ifelse } ifelse @@ -3213,21 +3454,32 @@ currentdict /PDF2PS_matrix_key undef % Thus it may include Cyan, Magenta, Yellow, and Black. % <colorspace> <spotcolordict> colorspacespotcolors - /colorspacespotcolors { - exch dup type /arraytype eq { + % Make sure we have an array, and that it is has enough info + exch dup type /arraytype eq + { % If we have an Indexed color space then get the base space. dup 0 oget % <<>> [csp] /Type dup /Indexed eq { pop 1 oget % <<>> [base] 2 copy exch colorspacespotcolors } { - % Stack: <spotcolordict> <colorspace> <colorspacetype> - dup /Separation eq exch /DeviceN eq or { - dup 1 oget dup type /arraytype eq { - { oforce 2 index putspotcolor } forall + dup /Pattern eq { + 1 index length 1 gt { % only uncolored patterns have colorspace + pop 1 oget % <<>> [base] + 2 copy exch colorspacespotcolors } { - 2 index putspotcolor + pop } ifelse - } if + } { + % Stack: <spotcolordict> <colorspace> <colorspacetype> + dup /Separation eq exch /DeviceN eq or { + dup 1 oget dup type /arraytype eq { + { oforce 2 index putspotcolor } forall + } { + 2 index putspotcolor + } ifelse + } if + } ifelse } ifelse } if pop pop @@ -3647,6 +3899,70 @@ currentdict /PDF2PS_matrix_key undef } if } bind executeonly def +% These functions can be used in error handling. It is not always possible to +% use the PostScript sequence 'mark ..... cleartomark' to clean up behind a +% sequence of operations, because processing the PDF might leave a mark +% object on the stack. There are a number of ways to address that problem; one +% is to count the objects on the stack at the time and store that value in a +% convenient dictionary, presented here is an alternative. Instead of using a +% mark object, we can use a specific name object as if it were a mark object +% and use the two routines below to count the number of objects on the stack +% up to a specific key, and to clear the stack back to a named key. + +% +% /key CountToKey false | int true +% +% Counts the operand stack backwards until it encounters +% a specific name key on the stack. Returns true and the count +% of objects on the stack after that key, or false if the key +% was not found on the stack. Consumes the key passed +% to CountToKey. Throws a typecheck if the operand is not +% a name type. +% +/CountToKey +{ + dup type /nametype eq { + //false + 0 1 count 5 sub + { + dup 3 add index + 3 index eq + { + 3 1 roll pop pop //true exit + } + {pop} ifelse + } for + + { + //true + } + { + pop //false + } ifelse + } + { + /CountToKey cvx /typecheck signalerror + }ifelse +}bind readonly def + +% +% /key ClearToKey - +% +% Clears the operand stack backwards until it encounters +% the name object passed as an operand. If the name object +% is not present on the stack then it will clear the entire +% stack. Like cleartomark this removes the 'key' from the stack. +% +/ClearToKey +{ + 0 1 count 4 sub + { + pop + dup 3 1 roll eq {exit} if + } for + pop +}bind readonly def + end % pdfdict diff --git a/Resource/Init/pdf_ops.ps b/Resource/Init/pdf_ops.ps index 47ff512d..fe61b12d 100644 --- a/Resource/Init/pdf_ops.ps +++ b/Resource/Init/pdf_ops.ps @@ -1,4 +1,4 @@ -% Copyright (C) 2001-2020 Artifex Software, Inc. +% Copyright (C) 2001-2021 Artifex Software, Inc. % All Rights Reserved. % % This software is provided AS-IS with no warranty, either express or @@ -695,10 +695,11 @@ end { % Check OP and BM in case we need to push a group //OPsaveDstack begin //Dpush exec % push the current OPsaveDstack values into 'previous' + /SupportsDevn .special_op okOPcs currentcolorspace 0 get dup /Indexed eq { pop currentcolorspace 1 get % use the base space } if - known { + known or { 1 index /stroke ne { .currentfilloverprint } { .currentstrokeoverprint } ifelse % Change BM to CompatibleOverprint if this has overprint true dup /ChangeBM exch def @@ -1478,19 +1479,8 @@ currentdict /clip_if_required .undef % width under pdfwrite. Pdfwrite uses (in text mode) an identity % CTM, so we need to calculate the stroke width which would result % if the CTM had been unity. - currentlinewidth dup - currentdict /qTextSaveMatrix known { - matrix defaultmatrix idtransform qTextSaveMatrix dtransform - }{ - matrix defaultmatrix idtransform TextSaveMatrix dtransform - } ifelse - abs 2 copy exch abs eq { - pop - }{ - % non-square scaling reduces to Text matrix in pdfwrite , so - % we can ignore it. (wrong answer, but consistent) - pop pop currentlinewidth - }ifelse setlinewidth + calc_text_linewidth + setlinewidth show setlinewidth} bind executeonly % Tr 2 - Fill then Stroke { currentlinewidth exch setsmaskstate @@ -1498,19 +1488,8 @@ currentdict /clip_if_required .undef % width under pdfwrite. Pdfwrite uses (in text mode) an identity % CTM, so we need to calculate the stroke width which would result % if the CTM had been unity. - currentlinewidth dup - currentdict /qTextSaveMatrix known { - matrix defaultmatrix idtransform qTextSaveMatrix dtransform - }{ - matrix defaultmatrix idtransform TextSaveMatrix dtransform - } ifelse - abs 2 copy exch abs eq { - pop - }{ - % non-square scaling reduces to Text matrix in pdfwrite , so - % we can ignore it. (wrong answer, but consistent) - pop pop currentlinewidth - }ifelse setlinewidth + calc_text_linewidth + setlinewidth setsmaskstate show setlinewidth} bind executeonly % Tr 3 - Neither fill nor stroke { setsmaskstate show } bind executeonly @@ -1525,38 +1504,50 @@ currentdict /clip_if_required .undef setsmaskstate dup show grestore //true charpath } bind executeonly % Tr 5 - Stroke, add to clip { gsave 1 .settextrenderingmode - currentlinewidth dup - matrix defaultmatrix idtransform TextSaveMatrix dtransform - abs 2 copy exch abs eq { - pop - }{ - % non-square scaling reduces to Text matrix in pdfwrite , so - % we can ignore it. (wrong answer, but consistent) - pop pop currentlinewidth - }ifelse setlinewidth + calc_text_linewidth + setlinewidth setsmaskstate dup show grestore //true charpath} bind executeonly % Tr 6 - Fill, stroke, add to clip { gsave 2 .settextrenderingmode - currentlinewidth dup - currentdict /qTextSaveMatrix known { - matrix defaultmatrix idtransform qTextSaveMatrix dtransform - }{ - matrix defaultmatrix idtransform TextSaveMatrix dtransform - } ifelse - abs 2 copy exch abs eq { - pop - }{ - % non-square scaling reduces to Text matrix in pdfwrite , so - % we can ignore it. (wrong answer, but consistent) - pop pop currentlinewidth - }ifelse setlinewidth + calc_text_linewidth + setlinewidth setsmaskstate dup show grestore //true charpath} bind executeonly % Tr 7 - Add to clip { //true charpath} bind executeonly ] readonly def +% - calc_text_linewidth calculated_width +% This calculates the required linewidth for stroke for *pdfwrite*, it must not be +% used for rendering. Because pdfwrite writes text scaled into a 72 dpi resolution +% we cannot use the current linewidth for it, it will be too large. Instead we must +% re-calculate the original linewidth (removing the default CTM) and then apply the +% TextSaveMatrix to find the appropriate new linewidth. +% We check to see if the x and y scaling are approximately the same, if they are not +% then we calculate a linewidth based on a right triangle with the x and y values +% of the current linewidth in each direction and then calculate the hypotenuse, which +% we then use as an approximation to the required width. +% The 'approximation' of 0.01 is just a guess. +/calc_text_linewidth +{ + currentlinewidth dup + currentdict /qTextSaveMatrix known { + matrix defaultmatrix idtransform qTextSaveMatrix dtransform + }{ + matrix defaultmatrix idtransform TextSaveMatrix dtransform + } ifelse + abs 2 copy exch abs sub abs 0.01 le { + pop + }{ + % We used to leave the linewidth alone for non-square resolutions, + % claiming it reduced to the text matrix in pdfwrite. This is not + % true. So handle it the same way we usually do, the hypotenuse of + % the unit square transformed through the TextSaveMatrix. + dup mul exch dup mul add sqrt 2 div + }ifelse +} bind executeonly def + /setstrokeforTrpreservation { % Check to see if the current device supports Tr /PreserveTrMode /GetDeviceParam .special_op { @@ -1573,15 +1564,7 @@ currentdict /clip_if_required .undef % CTM, so we need to calculate the stroke width which would result % if the CTM had been unity. NOTE! Only interested in magnitudes, % not signs. - currentlinewidth dup - matrix defaultmatrix idtransform TextSaveMatrix dtransform - abs 2 copy exch abs eq { - pop - }{ - % non-square scaling reduces to Text matrix in pdfwrite , so - % we can ignore it. (wrong answer, but consistent) - pop pop currentlinewidth - }ifelse + calc_text_linewidth setlinewidth } if } if diff --git a/Resource/Init/pdf_rbld.ps b/Resource/Init/pdf_rbld.ps index 037f10b7..6eeb6085 100644 --- a/Resource/Init/pdf_rbld.ps +++ b/Resource/Init/pdf_rbld.ps @@ -1,4 +1,4 @@ -% Copyright (C) 2001-2020 Artifex Software, Inc. +% Copyright (C) 2001-2021 Artifex Software, Inc. % All Rights Reserved. % % This software is provided AS-IS with no warranty, either express or @@ -142,13 +142,28 @@ PDFfile token pop % get starting entry - or 'trailer' (trailer) ne { % if we do not already have 'trailer' PDFfile token pop % get number of entries - PDFfile token pop pop % this moves us into the middle of the first entry - 25 string exch % define working string for readline - { PDFfile 1 index readline pop pop - } repeat % skip entries - pop % pop working string - PDFfile token pop pop % get 'trailer' - PDFfile fileposition % get file position + % The following check could be more efficient + % but broken file..... + dup + PDFfile fileposition + PDFfile 0 setfileposition + PDFfile bytesavailable + exch PDFfile exch setfileposition + % On the basis it requires at least 15 bytes to define an object + % in PDF, if the claimed number of objects is more than the number + % of bytes in the file, then it is clearly bogus, and we just give up + 15 idiv + lt { + PDFfile token pop pop % this moves us into the middle of the first entry + 25 string exch % define working string for readline + { PDFfile 1 index readline pop pop + } repeat % skip entries + pop % pop working string + PDFfile token pop pop % get 'trailer' + PDFfile fileposition % get file position + } + { pop 0} + ifelse } if } { pop 0 % no xref, should not happen, report it upstrem diff --git a/Resource/Init/pdf_sec.ps b/Resource/Init/pdf_sec.ps index b6f2bfce..9e6c1c0f 100644 --- a/Resource/Init/pdf_sec.ps +++ b/Resource/Init/pdf_sec.ps @@ -1,4 +1,4 @@ -% Copyright (C) 2001-2020 Artifex Software, Inc. +% Copyright (C) 2001-2021 Artifex Software, Inc. % All Rights Reserved. % % This software is provided AS-IS with no warranty, either express or @@ -481,15 +481,33 @@ systemdict /check_r6_password .forceundef % Even if StmF and StrF are Identity, if the StdCF is missing AuthEvent % or it is DocOpen, we require the password. Check for that. 1 index /CF .knownget { - /StdCF .knownget { - /AuthEvent .knownget { - /DocOpen eq - or + oforce dup type /dicttype eq { + /StdCF .knownget { + oforce dup type /dicttype eq { + /AuthEvent .knownget { + oforce dup type /nametype eq { + /DocOpen eq + or + }{ + ( **** Error: AuthEvent has wrong type.\n) pdfformaterror + ( Cannot decrypt PDF file.\n) pdfformaterror + /pdf_process_Encrypt cvx /invalidfileaccess signalerror + } ifelse + } { + pop true % no AuthEvent, default is DocOpen, require password + } ifelse + }{ + ( **** Error: StdCF has wrong type.\n) pdfformaterror + ( Cannot decrypt PDF file.\n) pdfformaterror + /pdf_process_Encrypt cvx /invalidfileaccess signalerror + } ifelse } { - pop true % no AuthEvent, default is DocOpen, require password + pop true % no StdCF, require password } ifelse - } { - pop true % no StdCF, require password + }{ + ( **** Error: CF has wrong type.\n) pdfformaterror + ( Cannot decrypt PDF file.\n) pdfformaterror + /pdf_process_Encrypt cvx /invalidfileaccess signalerror } ifelse } { pop true % no CF, require password diff --git a/Resource/SubstCID/CNS1-WMode b/Resource/SubstCID/CNS1-WMode index cc0e9bbd..9b3939fa 100644 --- a/Resource/SubstCID/CNS1-WMode +++ b/Resource/SubstCID/CNS1-WMode @@ -1,4 +1,4 @@ -% Copyright (C) 2001-2020 Artifex Software, Inc. +% Copyright (C) 2001-2021 Artifex Software, Inc. % All Rights Reserved. % % This software is provided AS-IS with no warranty, either express or diff --git a/Resource/SubstCID/GB1-WMode b/Resource/SubstCID/GB1-WMode index 22da0829..7d022f85 100644 --- a/Resource/SubstCID/GB1-WMode +++ b/Resource/SubstCID/GB1-WMode @@ -1,4 +1,4 @@ -% Copyright (C) 2001-2020 Artifex Software, Inc. +% Copyright (C) 2001-2021 Artifex Software, Inc. % All Rights Reserved. % % This software is provided AS-IS with no warranty, either express or diff --git a/Resource/SubstCID/Japan1-WMode b/Resource/SubstCID/Japan1-WMode index 9f85a86e..f2110449 100644 --- a/Resource/SubstCID/Japan1-WMode +++ b/Resource/SubstCID/Japan1-WMode @@ -1,4 +1,4 @@ -% Copyright (C) 2001-2020 Artifex Software, Inc. +% Copyright (C) 2001-2021 Artifex Software, Inc. % All Rights Reserved. % % This software is provided AS-IS with no warranty, either express or diff --git a/Resource/SubstCID/Korea1-WMode b/Resource/SubstCID/Korea1-WMode index ff59b9dc..8832bbe4 100644 --- a/Resource/SubstCID/Korea1-WMode +++ b/Resource/SubstCID/Korea1-WMode @@ -1,4 +1,4 @@ -% Copyright (C) 2001-2020 Artifex Software, Inc. +% Copyright (C) 2001-2021 Artifex Software, Inc. % All Rights Reserved. % % This software is provided AS-IS with no warranty, either express or |