[gs-commits] ghostpdl branch, HEAD, created. jbig2dec-0.14-2006-g26422f1

[email protected] (Ray Johnston) Fri, 29 Nov 2019 16:53:06 +0000 (UTC)
Newsgroups gmane.comp.printing.ghostscript.cvs
Message-ID <[email protected]>
The ghostpdl branch, HEAD has been created
        at  26422f1d0735bb86eedcbaaade32a92d4758561d (commit)


----------------------------------------------------------------------
commit 26422f1d0735bb86eedcbaaade32a92d4758561d
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 2f8b610..650a90f 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
         } {
@@ -2339,7 +2343,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
@@ -4228,7 +4237,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..674d731 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,12 +719,7 @@ 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
@@ -737,23 +732,20 @@ end
     /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
 {
+  pop		% fillop/strokeop
   //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
+    1 index aload pop		% pathbbox
     .begintransparencygroup
     % After group pushed, set opacityalpha, shapealpha and blendmode
     /saveOA .currentopacityalpha def
@@ -762,9 +754,9 @@ end
     /GroupPushed //true def
   } {
     /GroupPushed //false def
-    pop		% fillop/strokeop
   } ifelse
   end	% OPsaveDstack
+  pop	% pathbbox array
 } bind executeonly def
 
 % If a transparency group was pushed, pop it, and reset the settings.
@@ -791,9 +783,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 +930,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 +956,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 +1649,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 +1944,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

----------------------------------------------------------------------
commit c2b492ad627bdcb476fa3cd15a1c31cc3b6b788d
Author: Ray Johnston <[email protected]>
Date:   Fri Nov 29 08:42:15 2019 -0800

    Fix typo (inadvertent paste) in devices/gdevjbig2.c from f63270230 commit

diff --git a/devices/gdevjbig2.c b/devices/gdevjbig2.c
index 0555081..a0dda91 100644
--- a/devices/gdevjbig2.c
+++ b/devices/gdevjbig2.c
@@ -89,7 +89,7 @@ jbig2_print_page(gx_device_printer * pdev, gp_file * prn_stream)
     swrite_file(&fstrm, prn_stream, fbuf, fbuf_size);
     s_init(&cstrm, mem);
     s_std_init(&cstrm, jbuf, jbuf_size, &s_filter_write_procs,
-               s_devices/gdevescp.cmode_write);
+               s_mode_write);
     cstrm.state = (stream_state *) & state;
     cstrm.procs.process = state.templat->process;
     cstrm.strm = &fstrm;