xmlgraphics-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sstei...@apache.org
Subject svn commit: r1845492 - in /xmlgraphics/commons/trunk/src: main/java/org/apache/xmlgraphics/java2d/ps/PSGraphics2D.java test/java/org/apache/xmlgraphics/java2d/ps/PSGraphics2DTestCase.java
Date Thu, 01 Nov 2018 15:54:06 GMT
Author: ssteiner
Date: Thu Nov  1 15:54:06 2018
New Revision: 1845492

URL: http://svn.apache.org/viewvc?rev=1845492&view=rev
Log:
XGC-116: Don't draw fully transparent alpha on PS

Modified:
    xmlgraphics/commons/trunk/src/main/java/org/apache/xmlgraphics/java2d/ps/PSGraphics2D.java
    xmlgraphics/commons/trunk/src/test/java/org/apache/xmlgraphics/java2d/ps/PSGraphics2DTestCase.java

Modified: xmlgraphics/commons/trunk/src/main/java/org/apache/xmlgraphics/java2d/ps/PSGraphics2D.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/main/java/org/apache/xmlgraphics/java2d/ps/PSGraphics2D.java?rev=1845492&r1=1845491&r2=1845492&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/src/main/java/org/apache/xmlgraphics/java2d/ps/PSGraphics2D.java
(original)
+++ xmlgraphics/commons/trunk/src/main/java/org/apache/xmlgraphics/java2d/ps/PSGraphics2D.java
Thu Nov  1 15:54:06 2018
@@ -23,6 +23,7 @@ package org.apache.xmlgraphics.java2d.ps
 import java.awt.AlphaComposite;
 import java.awt.BasicStroke;
 import java.awt.Color;
+import java.awt.Composite;
 import java.awt.Dimension;
 import java.awt.GradientPaint;
 import java.awt.Graphics;
@@ -787,35 +788,42 @@ public class PSGraphics2D extends Abstra
      * @see #setClip
      */
     public void fill(Shape s) {
-        preparePainting();
-        try {
-            gen.saveGraphicsState();
+        if (!hasAlpha()) {
+            preparePainting();
+            try {
+                gen.saveGraphicsState();
 
-            AffineTransform trans = getTransform();
-            boolean newTransform = !trans.isIdentity();
+                AffineTransform trans = getTransform();
+                boolean newTransform = !trans.isIdentity();
 
-            if (newTransform) {
-                gen.concatMatrix(trans);
-            }
-            Shape imclip = getClip();
-            if (shouldBeClipped(imclip, s)) {
-                writeClip(imclip);
-            }
+                if (newTransform) {
+                    gen.concatMatrix(trans);
+                }
+                Shape imclip = getClip();
+                if (shouldBeClipped(imclip, s)) {
+                    writeClip(imclip);
+                }
 
-            establishColor(getColor());
+                establishColor(getColor());
 
-            applyPaint(getPaint(), true);
+                applyPaint(getPaint(), true);
 
-            gen.writeln(gen.mapCommand("newpath"));
-            int windingRule = processShape(s, true);
-            doDrawing(true, false,
+                gen.writeln(gen.mapCommand("newpath"));
+                int windingRule = processShape(s, true);
+                doDrawing(true, false,
                     windingRule == PathIterator.WIND_EVEN_ODD);
-            gen.restoreGraphicsState();
-        } catch (IOException ioe) {
-            handleIOException(ioe);
+                gen.restoreGraphicsState();
+            } catch (IOException ioe) {
+                handleIOException(ioe);
+            }
         }
     }
 
+    private boolean hasAlpha() {
+        Composite composite = getComposite();
+        return composite instanceof AlphaComposite && ((AlphaComposite) composite).getAlpha()
== 0f;
+    }
+
     /**
      * Commits a painting operation.
      * @param fill filling

Modified: xmlgraphics/commons/trunk/src/test/java/org/apache/xmlgraphics/java2d/ps/PSGraphics2DTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/test/java/org/apache/xmlgraphics/java2d/ps/PSGraphics2DTestCase.java?rev=1845492&r1=1845491&r2=1845492&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/src/test/java/org/apache/xmlgraphics/java2d/ps/PSGraphics2DTestCase.java
(original)
+++ xmlgraphics/commons/trunk/src/test/java/org/apache/xmlgraphics/java2d/ps/PSGraphics2DTestCase.java
Thu Nov  1 15:54:06 2018
@@ -19,6 +19,7 @@
 
 package org.apache.xmlgraphics.java2d.ps;
 
+import java.awt.AlphaComposite;
 import java.awt.Rectangle;
 import java.awt.Shape;
 import java.awt.TexturePaint;
@@ -161,4 +162,18 @@ public class PSGraphics2DTestCase {
         assertTrue(out.toString().contains("1 1 4 matrix\n{<\nfff\n>} false 3 colorimage"));
         p.dispose();
     }
+
+    @Test
+    public void testFillAlpha() {
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        PSGenerator gen = new PSGenerator(out);
+        PSGraphics2D p = new PSGraphics2D(false, gen);
+        p.setGraphicContext(new GraphicContext());
+        p.setComposite(AlphaComposite.getInstance(3, 0));
+        p.fill(new Rectangle());
+        assertEquals(out.toString(), "");
+        p.setComposite(AlphaComposite.getInstance(3, 0.5f));
+        p.fill(new Rectangle());
+        assertTrue(out.toString().contains("\nN\n"));
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: commits-help@xmlgraphics.apache.org


Mime
View raw message