Author: ssteiner
Date: Mon Sep 18 15:02:56 2017
New Revision: 1808727

URL: http://svn.apache.org/viewvc?rev=1808727&view=rev
Log:
FOP-2739: Avoid rastering PDF with Smask to image

Added:
    xmlgraphics/fop-pdf-images/trunk/test/resources/smask.pdf   (with props)
Modified:
    xmlgraphics/fop-pdf-images/trunk/lib/xmlgraphics-commons-svn-trunk.jar
    
xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/ImageConverterPDF2G2D.java
    
xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/PSPDFGraphics2D.java
    
xmlgraphics/fop-pdf-images/trunk/test/java/org/apache/fop/render/pdf/PDFBoxAdapterTestCase.java

Modified: xmlgraphics/fop-pdf-images/trunk/lib/xmlgraphics-commons-svn-trunk.jar
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/trunk/lib/xmlgraphics-commons-svn-trunk.jar?rev=1808727&r1=1808726&r2=1808727&view=diff
==============================================================================
Binary files - no diff available.

Modified: 
xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/ImageConverterPDF2G2D.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/ImageConverterPDF2G2D.java?rev=1808727&r1=1808726&r2=1808727&view=diff
==============================================================================
--- 
xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/ImageConverterPDF2G2D.java
 (original)
+++ 
xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/ImageConverterPDF2G2D.java
 Mon Sep 18 15:02:56 2017
@@ -39,7 +39,6 @@ import org.apache.pdfbox.pdmodel.PDResou
 import org.apache.pdfbox.pdmodel.common.PDRectangle;
 import org.apache.pdfbox.pdmodel.graphics.PDXObject;
 import org.apache.pdfbox.pdmodel.graphics.form.PDFormXObject;
-import org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject;
 import org.apache.pdfbox.pdmodel.graphics.shading.PDShading;
 import org.apache.pdfbox.rendering.PDFRenderer;
 
@@ -202,11 +201,6 @@ public class ImageConverterPDF2G2D exten
                                     && pageHasTransparency(formRes)) {
                                 return true;
                             }
-                        } else if (pdxObject instanceof PDImageXObject) {
-                            if 
(pdxObject.getCOSStream().containsKey(COSName.SMASK)
-                                    || ((PDImageXObject) 
pdxObject).isStencil()) {
-                                return true;
-                            }
                         }
                     }
                 }

Modified: 
xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/PSPDFGraphics2D.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/PSPDFGraphics2D.java?rev=1808727&r1=1808726&r2=1808727&view=diff
==============================================================================
--- 
xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/PSPDFGraphics2D.java
 (original)
+++ 
xmlgraphics/fop-pdf-images/trunk/src/java/org/apache/fop/render/pdf/pdfbox/PSPDFGraphics2D.java
 Mon Sep 18 15:02:56 2017
@@ -27,7 +27,10 @@ import java.awt.Image;
 import java.awt.Paint;
 import java.awt.PaintContext;
 import java.awt.Rectangle;
+import java.awt.TexturePaint;
 import java.awt.geom.AffineTransform;
+import java.awt.geom.Point2D;
+import java.awt.geom.Rectangle2D;
 import java.awt.image.BufferedImage;
 import java.awt.image.ColorModel;
 import java.awt.image.DataBufferInt;
@@ -148,9 +151,43 @@ public class PSPDFGraphics2D extends PSG
                     handleIOException(ioe);
                 }
             }
+        } else if (paint.getClass().getSimpleName().equals("TilingPaint")) {
+            try {
+                Field f = paint.getClass().getDeclaredField("paint");
+                f.setAccessible(true);
+                TexturePaint texturePaint = (TexturePaint) f.get(paint);
+                f = paint.getClass().getDeclaredField("patternMatrix");
+                f.setAccessible(true);
+                Matrix matrix = (Matrix) f.get(paint);
+                Rectangle2D rect = getTransformedRect(matrix, 
texturePaint.getAnchorRect());
+                texturePaint = new TexturePaint(texturePaint.getImage(), rect);
+                super.applyPaint(texturePaint, fill);
+            } catch (NoSuchFieldException e) {
+                throw new RuntimeException(e);
+            } catch (IllegalAccessException e) {
+                throw new RuntimeException(e);
+            }
         }
     }
 
+    private static Rectangle2D getTransformedRect(Matrix matrix, Rectangle2D 
anchorRect) {
+        double x = anchorRect.getX();
+        double y = anchorRect.getY();
+        double width = anchorRect.getWidth();
+        double height = anchorRect.getHeight();
+        AffineTransform at = matrix.createAffineTransform();
+        Point2D p1 = new Point2D.Double(x, y);
+        Point2D p2 = new Point2D.Double(x + width, y + height);
+        at.transform(p1, p1);
+        at.transform(p2, p2);
+        Rectangle2D rectangle = new Rectangle2D.Float(
+                (float) Math.min(p1.getX(), p2.getX()),
+                (float) Math.min(p1.getY(), p2.getY()),
+                (float) Math.abs(width),
+                (float) Math.abs(height));
+        return rectangle;
+    }
+
     private void transformCoords(float[] coords, Paint paint, boolean 
axialShading) {
         try {
             Field f = paint.getClass().getDeclaredField("matrix");

Modified: 
xmlgraphics/fop-pdf-images/trunk/test/java/org/apache/fop/render/pdf/PDFBoxAdapterTestCase.java
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/trunk/test/java/org/apache/fop/render/pdf/PDFBoxAdapterTestCase.java?rev=1808727&r1=1808726&r2=1808727&view=diff
==============================================================================
--- 
xmlgraphics/fop-pdf-images/trunk/test/java/org/apache/fop/render/pdf/PDFBoxAdapterTestCase.java
 (original)
+++ 
xmlgraphics/fop-pdf-images/trunk/test/java/org/apache/fop/render/pdf/PDFBoxAdapterTestCase.java
 Mon Sep 18 15:02:56 2017
@@ -112,6 +112,7 @@ public class PDFBoxAdapterTestCase {
     private static final String LOOP = "test/resources/loop.pdf";
     private static final String ERROR = "test/resources/error.pdf";
     private static final String LIBREOFFICE = "test/resources/libreoffice.pdf";
+    private static final String SMASK = "test/resources/smask.pdf";
 
     private static PDFPage getPDFPage(PDFDocument doc) {
         final Rectangle2D r = new Rectangle2D.Double();
@@ -299,7 +300,7 @@ public class PDFBoxAdapterTestCase {
         pdfToPS(TTSubset3);
         pdfToPS(TTSubset5);
         stream = pdfToPS(CFFCID1);
-        Assert.assertEquals(countString(stream.toString("UTF-8"), 
"%AXGBeginBitmap:"), 1);
+        Assert.assertEquals(countString(stream.toString("UTF-8"), 
"%AXGBeginBitmap:"), 2);
         pdfToPS(CFFCID2);
         pdfToPS(Type1Subset1);
         pdfToPS(Type1Subset2);
@@ -360,6 +361,13 @@ public class PDFBoxAdapterTestCase {
     }
 
     @Test
+    public void testSmask() throws IOException, ImageException {
+        ByteArrayOutputStream ps = pdfToPS(SMASK);
+        Assert.assertTrue(ps.toString("UTF-8").contains("/Pattern"));
+        Assert.assertTrue(ps.toString("UTF-8").contains("{<\nf1f1f1"));
+    }
+
+    @Test
     public void testPCL() throws IOException, ImageException {
         String ex = "";
         try {

Added: xmlgraphics/fop-pdf-images/trunk/test/resources/smask.pdf
URL: 
http://svn.apache.org/viewvc/xmlgraphics/fop-pdf-images/trunk/test/resources/smask.pdf?rev=1808727&view=auto
==============================================================================
Binary file - no diff available.

Propchange: xmlgraphics/fop-pdf-images/trunk/test/resources/smask.pdf
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



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

Reply via email to