Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 974E1200D06 for ; Mon, 25 Sep 2017 15:42:14 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 95B9C1609C4; Mon, 25 Sep 2017 13:42:14 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id B4C641609BB for ; Mon, 25 Sep 2017 15:42:13 +0200 (CEST) Received: (qmail 75501 invoked by uid 500); 25 Sep 2017 13:42:12 -0000 Mailing-List: contact commits-help@xmlgraphics.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: general@xmlgraphics.apache.org Delivered-To: mailing list commits@xmlgraphics.apache.org Received: (qmail 75492 invoked by uid 99); 25 Sep 2017 13:42:12 -0000 Received: from Unknown (HELO svn01-us-west.apache.org) (209.188.14.144) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 25 Sep 2017 13:42:12 +0000 Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id B16933A028F for ; Mon, 25 Sep 2017 13:42:10 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@xmlgraphics.apache.org From: ssteiner@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20170925134211.B16933A028F@svn01-us-west.apache.org> archived-at: Mon, 25 Sep 2017 13:42:14 -0000 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