[gs-commits] ghostpdl branch, master, updated. jbig2dec-0.14-2013-g5dfca9b

[email protected] (Ray Johnston) Fri, 6 Dec 2019 16:20:24 +0000 (UTC)
Newsgroups gmane.comp.printing.ghostscript.cvs
Message-ID <[email protected]>
The ghostpdl branch, master has been updated
       via  5dfca9b93a17806e11d54068a6e5b9705f3b6bc6 (commit)
      from  fbd776580b26bdf27bcf5778dea94b446c786f67 (commit)

----------------------------------------------------------------------
commit 5dfca9b93a17806e11d54068a6e5b9705f3b6bc6
Author: Ray Johnston <[email protected]>
Date:   Thu Nov 21 09:54:53 2019 -0800

    Fix problem with setup_trans being undone by grestore
    
    Noticed with text from Bug688728.pdf, but the offending method was
    also an issue with 'sh' and 'image' operations where the setup_trans
    invocation was withing a gsave ... grestore. The BlendMode and other
    graphics state parameters would be reset by the grestore.
    
    Also some places could get errors from pathbbox and/or strokepath
    due to a non-invertable matrix, so errors from these now just emit
    an empty bbox [ 0 0 0 0 ].

diff --git a/Resource/Init/pdf_draw.ps b/Resource/Init/pdf_draw.ps
index 099b054..e9d3f82 100644
--- a/Resource/Init/pdf_draw.ps
+++ b/Resource/Init/pdf_draw.ps
@@ -1423,8 +1423,12 @@ drawopdict begin
           } {
             clippath
           } ifelse
-          //null setup_trans
+          % If we get an error, just emit an empty box
+          { pathbbox } stopped { 0 0 0 0 } if
+          4 array astore
           grestore
+          //null
+          setup_trans
           //do_shade exec
           teardown_trans
         } {
@@ -2247,7 +2251,8 @@ currentdict /last-ditch-bpc-csp undef
        % We also need to actually set the current colour space to be the same as the group
        % 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 .begintransparencygroup
+    >> 0 0 1 1
+    .begintransparencygroup
      doimage
     .endtransparencygroup
     % tell the compositor we're done with the SMask.
@@ -2258,7 +2263,8 @@ currentdict /last-ditch-bpc-csp undef
   } {
     .currentSMask //null ne {
       % the image doesn't have an SMask, but the ExtGState does, force a group.
-      << /Subtype /Group /Isolated //true >> 0 0 1 1 .begintransparencygroup
+      << /Subtype /Group /Isolated //true >> 0 0 1 1
+      .begintransparencygroup
       doimage
       .endtransparencygroup
     }
@@ -2339,7 +2345,12 @@ currentdict /last-ditch-bpc-csp undef
       makemaskimage
   } if
                 % Stack: datasource imagemask
-  gsave 1 1 moveto 0 0 lineto /image setup_trans grestore
+  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 setfillstate //true ValidateDecode { imagemask } }
   { ColorSpace setgcolorspace currentdict end setfillblend //false ValidateDecode { image } }
   ifelse
@@ -4236,7 +4247,9 @@ currentdict /set_bc_color undef
         } repeat
         PDFusingtransparency {
           //emptydict
-          pathbbox 2 index add exch 3 index add exch .begintransparencygroup
+          % If we get an error, just emit an empty box
+          { pathbbox } stopped { 0 0 0 0 } if
+          2 index add exch 3 index add exch .begintransparencygroup
           /Multiply .setblendmode
           fill
           .endtransparencygroup
diff --git a/Resource/Init/pdf_main.ps b/Resource/Init/pdf_main.ps
index d771b1e..103b8b3 100644
--- a/Resource/Init/pdf_main.ps
+++ b/Resource/Init/pdf_main.ps
@@ -2784,7 +2784,7 @@ currentdict /PDF2PS_matrix_key undef
     .poppdf14devicefilter	% NB: reset to DefaultQstate will also restore transfer function
     /DefaultQstate qstate store	% device has changed -- reset DefaultQstate
   } {
-    /setup_trans { pop } def    % no-op this if the page doesn't use transparency
+    /setup_trans { pop pop } def    % no-op this if the page doesn't use transparency
                                 % NB: original will be restored from PDFsave
     showpagecontents
   } ifelse
diff --git a/Resource/Init/pdf_ops.ps b/Resource/Init/pdf_ops.ps
index 28f2b35..4379ce2 100644
--- a/Resource/Init/pdf_ops.ps
+++ b/Resource/Init/pdf_ops.ps
@@ -701,7 +701,7 @@ end
 % NB: setup_trans is defined as either setupOPtrans (for devices that can support
 %     overprint, or as setupSMtrans which pushes a group for SMask.
 % Also see 'teardown_trans' that pops the group and resets the changed values.
-/setupOPtrans	% <fillop|strokeop> setup_trans
+/setupOPtrans	% [ pathbbox ] <fillop|strokeop> setup_trans
 {  % Check OP and BM in case we need to push a group
   //OPsaveDstack begin
   //Dpush exec			% push the current OPsaveDstack values into 'previous'
@@ -719,41 +719,34 @@ end
   } ifelse
   .currentSMask //null ne or {		% push a group for OP or SMask
     mark /Subtype /Group /Isolated .currentSMask //null ne .dicttomark
-    1 index /stroke eq {
-      % BBox needs to include line width / line join expansion.
-      gsave strokepath pathbbox grestore
-    } {
-      pathbbox     % fill/eofill cases
-    } ifelse
+    2 index aload pop		% pathbbox
     .begintransparencygroup
     % After group pushed, set opacityalpha, shapealpha and blendmode
     /saveOA .currentopacityalpha def
     /saveSA .currentshapealpha def
     1 .setopacityalpha 1 .setshapealpha
     /GroupPushed //true def
-  } if
+  } {
+    /GroupPushed //false def
+  } ifelse
   % we may change to CompatibleOverprint even if we didn't push a group.
   ChangeBM {
     /saveBM .currentblendmode def /CompatibleOverprint .setblendmode
   } if
   pop		% fillop/strokeop
+  pop		% pathbbox array
   end	% OPsaveDstack
 } bind executeonly def
 
 % Also see 'teardown_trans' that pops the group and resets the changed values.
-/setupSMtrans	% <fillop|strokeop> setup_trans
+/setupSMtrans	% [ pathbbox ] <fillop|strokeop> setup_trans
 {
   //OPsaveDstack begin
   //Dpush exec			% push the current OPsaveDstack values into 'previous'
   .currentSMask //null ne 1 index /image ne and		% only push for SMask if not from image
   {
     mark /Subtype /Group /Isolated //true .dicttomark
-    exch /stroke eq {
-    % BBox needs to include line width / line join expansion.
-      gsave strokepath pathbbox grestore
-    } {
-      pathbbox     % fill/eofill cases
-    } ifelse
+    2 index aload pop		% pathbbox
     .begintransparencygroup
     % After group pushed, set opacityalpha, shapealpha and blendmode
     /saveOA .currentopacityalpha def
@@ -762,9 +755,10 @@ end
     /GroupPushed //true def
   } {
     /GroupPushed //false def
-    pop		% fillop/strokeop
   } ifelse
   end	% OPsaveDstack
+  pop	% fillop/strokeop
+  pop	% pathbbox array
 } bind executeonly def
 
 % If a transparency group was pushed, pop it, and reset the settings.
@@ -791,9 +785,23 @@ currentdict dup /Dpush .undef /Dpop .undef
 /fsexec		% <fillop|strokeop> fsexec -
 {
    PDFusingtransparency {
-      dup setup_trans
-      cvx exec
-      teardown_trans
+     dup /stroke eq {
+       % BBox needs to include line width / line join expansion.
+       % strokepath will return empty path (no currentpoint) if nothing is stroked
+       { gsave strokepath pathbbox } stopped grestore {
+         % If we get an error, just emit an empty box
+         0 0 0 0
+       } if
+     } {
+       % If we get an error, just emit an empty box
+       { pathbbox } stopped { 0 0 0 0 } if
+     } ifelse
+     % pathbbox valid -- proceed with drawing
+     4 array astore		% pathbbox
+     1 index
+     setup_trans
+     cvx exec
+     teardown_trans
    } {
       cvx exec
    } ifelse
@@ -924,23 +932,23 @@ currentdict dup /Dpush .undef /Dpop .undef
 
 /B {
   OFFlevels length 0 eq {
-         PDFusingtransparency {
-                % knockout trans group around the filled and stroked object
-                mark
-                /Isolated //true /Knockout //true
-                .dicttomark
-                % strokepath will return empty path (no currentpoint) if nothing is stroked
-                gsave { strokepath pathbbox } stopped grestore not {
-            1 .setopacityalpha
-                        .begintransparencygroup
-                        gsave setfillstate fill grestore
-                        setstrokestate .swapcolors /stroke fsexec .swapcolors
-                        .endtransparencygroup
-                } { newpath pop } ifelse
-         } {
-                gsave setfillstate fill grestore
-                setstrokestate .swapcolors /stroke fsexec .swapcolors
-        } ifelse
+    PDFusingtransparency {
+      % knockout trans group around the filled and stroked object
+      mark
+      /Isolated //true /Knockout //true
+      .dicttomark
+      % strokepath will return empty path (no currentpoint) if nothing is stroked
+      gsave { strokepath pathbbox } stopped grestore not {
+        1 .setopacityalpha
+        .begintransparencygroup
+        gsave setfillstate fill grestore
+        setstrokestate .swapcolors /stroke fsexec .swapcolors
+        .endtransparencygroup
+      } { newpath pop } ifelse
+    } {
+      gsave setfillstate fill grestore
+      setstrokestate .swapcolors /stroke fsexec .swapcolors
+    } ifelse
   } {
     newpath
   } ifelse
@@ -950,23 +958,23 @@ currentdict dup /Dpush .undef /Dpop .undef
 
 /B* {
   OFFlevels length 0 eq {
-         PDFusingtransparency {
-                % knockout trans group around the filled and stroked object
-                mark
-                /Isolated //true /Knockout //true
-                .dicttomark
-                % strokepath will return empty path (no currentpoint) if nothing is stroked
-                gsave { strokepath pathbbox } stopped grestore not {
-            1 .setopacityalpha
-                        .begintransparencygroup
-                        gsave setfillstate eofill grestore
-                        setstrokestate .swapcolors /stroke fsexec .swapcolors
-                        .endtransparencygroup
-                } { newpath pop } ifelse
-         } {
-                gsave setfillstate eofill grestore
-                setstrokestate .swapcolors /stroke fsexec .swapcolors
-        } ifelse
+    PDFusingtransparency {
+      % knockout trans group around the filled and stroked object
+      mark
+      /Isolated //true /Knockout //true
+      .dicttomark
+      % strokepath will return empty path (no currentpoint) if nothing is stroked
+      gsave { strokepath pathbbox } stopped grestore not {
+        1 .setopacityalpha
+        .begintransparencygroup
+        gsave setfillstate eofill grestore
+        setstrokestate .swapcolors /stroke fsexec .swapcolors
+        .endtransparencygroup
+      } { newpath pop } ifelse
+    } {
+      gsave setfillstate eofill grestore
+      setstrokestate .swapcolors /stroke fsexec .swapcolors
+    } ifelse
   } {
     newpath
   } ifelse
@@ -1643,7 +1651,16 @@ end readonly def
 /TextTransSetup {	% showarg path_valid TextTransSetup showarg
                         % showarg path_valid false TextTransSetup showarg
    % NB: if 'show' is used, then we use the clippath, but a smaller bbox is preferred
-   not dup { gsave clippath } if //null setup_trans { grestore } if
+   {
+     % path was (probably) valid (CTM may not be invertable)
+     % Since TR mode may include stroking, expand for stroke
+     % If we get an error, just emit an empty box
+     { gsave strokepath pathbbox } stopped grestore { 0 0 0 0 } if
+   } {
+     gsave clippath pathbbox grestore	% path not valid -- use clippath
+   } ifelse
+   4 array astore //null
+   setup_trans
 } bind executeonly def
 
 /TextTransTeardown {
@@ -1929,7 +1946,9 @@ end readonly def
           1 .setopacityalpha
           % While text will always have a currentpoint, strokepath seems to mess with it.
           % we get the currentpoint, then use moveto to restore it for pathbbox
-          gsave currentpoint strokepath moveto pathbbox grestore
+          { gsave currentpoint strokepath moveto pathbbox } stopped grestore {
+            /tB cvx /undefinedresult signalerror
+          } if
           .begintransparencygroup
           gsave tf grestore tS
           .endtransparencygroup


Summary of changes:
 Resource/Init/pdf_draw.ps |  23 +++++++--
 Resource/Init/pdf_main.ps |   2 +-
 Resource/Init/pdf_ops.ps  | 129 ++++++++++++++++++++++++++--------------------
 3 files changed, 93 insertions(+), 61 deletions(-)