xmlgraphics-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sstei...@apache.org
Subject svn commit: r1809627 - in /xmlgraphics/commons/trunk/src: main/java/org/apache/xmlgraphics/java2d/ps/ main/java/org/apache/xmlgraphics/ps/ test/java/org/apache/xmlgraphics/java2d/ps/
Date Mon, 25 Sep 2017 13:42:08 GMT
Author: ssteiner
Date: Mon Sep 25 13:42:08 2017
New Revision: 1809627

URL: http://svn.apache.org/viewvc?rev=1809627&view=rev
Log:
FOP-2740: PDF to PostScript tiling pattern error in Acrobat

Modified:
    xmlgraphics/commons/trunk/src/main/java/org/apache/xmlgraphics/java2d/ps/PSGraphics2D.java
    xmlgraphics/commons/trunk/src/main/java/org/apache/xmlgraphics/java2d/ps/PSTilingPattern.java
    xmlgraphics/commons/trunk/src/main/java/org/apache/xmlgraphics/ps/PSGenerator.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=1809627&r1=1809626&r2=1809627&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
Mon Sep 25 13:42:08 2017
@@ -568,7 +568,7 @@ public class PSGraphics2D extends Abstra
                     // create pattern with texture and use it for filling of a graphics object
                     PSTilingPattern psTilingPattern = new PSTilingPattern("Pattern1",
                             (TexturePaint)paint, 0, 0, 3, null);
-                    gen.write(psTilingPattern.toString());
+                    gen.write(psTilingPattern.toString(gen.isAcrobatDownsample()));
                     gen.writeln("/Pattern " + gen.mapCommand("setcolorspace"));
                     gen.writeln(psTilingPattern.getName() + " " + gen.mapCommand("setcolor"));
                 } catch (IOException ioe) {

Modified: xmlgraphics/commons/trunk/src/main/java/org/apache/xmlgraphics/java2d/ps/PSTilingPattern.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/main/java/org/apache/xmlgraphics/java2d/ps/PSTilingPattern.java?rev=1809627&r1=1809626&r2=1809627&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/src/main/java/org/apache/xmlgraphics/java2d/ps/PSTilingPattern.java
(original)
+++ xmlgraphics/commons/trunk/src/main/java/org/apache/xmlgraphics/java2d/ps/PSTilingPattern.java
Mon Sep 25 13:42:08 2017
@@ -365,7 +365,7 @@ public class PSTilingPattern {
      *
      * @return The string which contains postscript code of pattern definition
      */
-    public String toString() {
+    public String toString(boolean acrobatDownsample) {
         StringBuffer sb = new StringBuffer("<<\n");
         sb.append("/PatternType " + this.patternType + "\n");
         sb.append("/PaintType " + paintType + "\n");
@@ -397,26 +397,18 @@ public class PSTilingPattern {
 
             // define color image: width height bits/comp matrix
             //                        datasrc0 datasrcncomp-1 multi ncomp colorimage
-            sb.append(width + " " + height + " 8 " + "matrix\n");   // width height bits/comp
matrix
+            // width height bits/comp matrix
+            int bits = 8;
+            if (acrobatDownsample) {
+                bits = 4;
+            }
+            sb.append(width).append(" ").append(height).append(" ").append(bits).append("
").append("matrix\n");
             int [] argb = new int[width * height];                  // datasrc0 datasrcncomp-1
-            sb.append("{<");
             getAsRGB().getRGB(0, 0, width, height, argb, 0, width);
-            int count = 0;
-            for (int i = 0; i < argb.length; i++) {
-                if ((i % width == 0) || (count > 249)) {
-                    sb.append("\n");
-                    count = 0;  // line should not be longer than 255 characters
-                }
-                // delete alpha canal and write to output
-                StringBuffer sRGB = new StringBuffer(Integer.toHexString(argb[i] & 0x00ffffff));
-                if (sRGB.length() != 6) {
-                    sRGB.insert(0, "000000");   // zero padding
-                    sRGB = new StringBuffer(sRGB.substring(sRGB.length() - 6));
-                }
-                sb.append(sRGB);
-                count += 6;
-            }
-            sb.append("\n>} false 3 colorimage");                   //  multi ncomp colorimage
+
+            writeImage(sb, argb, width, bits);
+
+            sb.append(" false 3 colorimage");                   //  multi ncomp colorimage
         } else {
             sb.append(paintProc);
         }
@@ -433,6 +425,43 @@ public class PSTilingPattern {
         return sb.toString();
     }
 
+    private void writeImage(StringBuffer sb, int[] argb, int width, int bits) {
+        int count = 0;
+        sb.append("{<");
+        for (int i = 0; i < argb.length; i++) {
+            if ((i % width == 0) || (count > 249)) {
+                sb.append('\n');
+                count = 0;  // line should not be longer than 255 characters
+            }
+            if (bits == 4) {
+                Color c = new Color(argb[i]);
+                int v = c.getRed() / 16;
+                String s = Integer.toHexString(v);
+                sb.append(s);
+
+                v = c.getGreen() / 16;
+                s = Integer.toHexString(v);
+                sb.append(s);
+
+                v = c.getBlue() / 16;
+                s = Integer.toHexString(v);
+                sb.append(s);
+
+                count += 3;
+            } else {
+                // delete alpha canal and write to output
+                StringBuffer sRGB = new StringBuffer(Integer.toHexString(argb[i] & 0x00ffffff));
+                if (sRGB.length() != 6) {
+                    sRGB.insert(0, "000000");   // zero padding
+                    sRGB = new StringBuffer(sRGB.substring(sRGB.length() - 6));
+                }
+                sb.append(sRGB);
+                count += 6;
+            }
+        }
+        sb.append("\n>}");
+    }
+
     private BufferedImage getAsRGB() {
         BufferedImage img = texture.getImage();
         if (img.getType() != BufferedImage.TYPE_INT_RGB) {

Modified: xmlgraphics/commons/trunk/src/main/java/org/apache/xmlgraphics/ps/PSGenerator.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/main/java/org/apache/xmlgraphics/ps/PSGenerator.java?rev=1809627&r1=1809626&r2=1809627&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/src/main/java/org/apache/xmlgraphics/ps/PSGenerator.java (original)
+++ xmlgraphics/commons/trunk/src/main/java/org/apache/xmlgraphics/ps/PSGenerator.java Mon
Sep 25 13:42:08 2017
@@ -71,6 +71,7 @@ public class PSGenerator implements PSCo
     private Log log = LogFactory.getLog(getClass());
     private OutputStream out;
     private int psLevel = DEFAULT_LANGUAGE_LEVEL;
+    private boolean acrobatDownsample;
     private boolean commentsEnabled = true;
     private boolean compactMode = true;
     private PSCommandMap commandMap = PSProcSets.STD_COMMAND_MAP;
@@ -166,6 +167,14 @@ public class PSGenerator implements PSCo
         this.psLevel = level;
     }
 
+    public boolean isAcrobatDownsample() {
+        return acrobatDownsample;
+    }
+
+    public void setAcrobatDownsample(boolean b) {
+        acrobatDownsample = b;
+    }
+
     /**
      * Attempts to resolve the given URI. PSGenerator should be subclasses to provide more
      * sophisticated URI resolution.

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=1809627&r1=1809626&r2=1809627&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
Mon Sep 25 13:42:08 2017
@@ -142,4 +142,23 @@ public class PSGraphics2DTestCase {
 
         p.dispose();
     }
+
+    @Test
+    public void testAcrobatDownsample() {
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        PSGenerator gen = new PSGenerator(out);
+        PSGraphics2D p = new PSGraphics2D(false, gen);
+        p.setGraphicContext(new GraphicContext());
+        BufferedImage img = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
+        TexturePaint tp = new TexturePaint(img, new Rectangle());
+        p.setPaint(tp);
+        p.fill(new Rectangle());
+        assertTrue(out.toString().contains("1 1 8 matrix\n{<\nffffff\n>} false 3 colorimage"));
+        out.reset();
+
+        gen.setAcrobatDownsample(true);
+        p.fill(new Rectangle());
+        assertTrue(out.toString().contains("1 1 4 matrix\n{<\nfff\n>} false 3 colorimage"));
+        p.dispose();
+    }
 }



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


Mime
View raw message