pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1777684 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java
Date Fri, 06 Jan 2017 18:27:16 GMT
Author: tilman
Date: Fri Jan  6 18:27:16 2017
New Revision: 1777684

URL: http://svn.apache.org/viewvc?rev=1777684&view=rev
Log:
PDFBOX-3000: fill with /bc color for Luminosity soft masks

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java?rev=1777684&r1=1777683&r2=1777684&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java Fri Jan
 6 18:27:16 2017
@@ -428,7 +428,18 @@ public class PageDrawer extends PDFGraph
         {
             return parentPaint;
         }
-        TransparencyGroup transparencyGroup = new TransparencyGroup(softMask.getGroup(),
true, softMask.getInitialTransformationMatrix());
+        PDColor backdropColor = null;
+        if (COSName.LUMINOSITY.equals(softMask.getSubType()))
+        {
+            COSArray backdropColorArray = softMask.getBackdropColor();
+            PDColorSpace colorSpace = softMask.getGroup().getGroup().getColorSpace();
+            if (colorSpace != null && backdropColorArray != null)
+            {
+                backdropColor = new PDColor(backdropColorArray, colorSpace);
+            }
+        }
+        TransparencyGroup transparencyGroup = new TransparencyGroup(softMask.getGroup(),
true, 
+                softMask.getInitialTransformationMatrix(), backdropColor);
         BufferedImage image = transparencyGroup.getImage();
         if (image == null)
         {
@@ -437,7 +448,6 @@ public class PageDrawer extends PDFGraph
             return parentPaint;
         }
         BufferedImage gray = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_BYTE_GRAY);
-        PDColor backdropColor = null;
         if (COSName.ALPHA.equals(softMask.getSubType()))
         {
             gray.setData(image.getAlphaRaster());
@@ -447,13 +457,6 @@ public class PageDrawer extends PDFGraph
             Graphics g = gray.getGraphics();
             g.drawImage(image, 0, 0, null);
             g.dispose();
-            
-            COSArray backdropColorArray = softMask.getBackdropColor();
-            PDColorSpace colorSpace = softMask.getGroup().getGroup().getColorSpace();
-            if (colorSpace != null && backdropColorArray != null)
-            {
-                backdropColor = new PDColor(backdropColorArray, colorSpace);
-            }
         }
         else
         {
@@ -1072,7 +1075,7 @@ public class PageDrawer extends PDFGraph
     public void showTransparencyGroup(PDTransparencyGroup form) throws IOException
     {
         TransparencyGroup group =
-                new TransparencyGroup(form, false, getGraphicsState().getCurrentTransformationMatrix());
+                new TransparencyGroup(form, false, getGraphicsState().getCurrentTransformationMatrix(),
null);
         BufferedImage image = group.getImage();
         if (image == null)
         {
@@ -1149,8 +1152,18 @@ public class PageDrawer extends PDFGraph
 
         /**
          * Creates a buffered image for a transparency group result.
+         *
+         * @param form the transparency group of the form or soft mask.
+         * @param isSoftMask true if this is a soft mask.
+         * @param ctm the relevant current transformation matrix. For soft masks, this is
the CTM at
+         * the time the soft mask is set (not at the time the soft mask is used for fill/stroke!),
+         * for forms, this is the CTM at the time the form is invoked.
+         * @param backdropColor the color according to the /bc entry to be used for luminosity
soft
+         * masks.
+         * @throws IOException
          */
-        private TransparencyGroup(PDTransparencyGroup form, boolean isSoftMask, Matrix ctm)
throws IOException
+        private TransparencyGroup(PDTransparencyGroup form, boolean isSoftMask, Matrix ctm,

+                PDColor backdropColor) throws IOException
         {
             Graphics2D g2dOriginal = graphics;
             Area lastClipOriginal = lastClip;
@@ -1201,6 +1214,14 @@ public class PageDrawer extends PDFGraph
                 image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
             }
             Graphics2D g = image.createGraphics();
+            if (isSoftMask && backdropColor != null)
+            {
+                // "If the subtype is Luminosity, the transparency group XObject G shall
be 
+                // composited with a fully opaque backdrop whose colour is everywhere defined

+                // by the soft-mask dictionary’s BC entry."
+                g.setBackground(new Color(backdropColor.toRGB()));
+                g.clearRect(0, 0, width, height);
+            }
 
             // flip y-axis
             g.translate(0, image.getHeight());



Mime
View raw message