You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2020/06/09 18:16:37 UTC

svn commit: r1878671 - /pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java

Author: tilman
Date: Tue Jun  9 18:16:37 2020
New Revision: 1878671

URL: http://svn.apache.org/viewvc?rev=1878671&view=rev
Log:
PDFBOX-4850: , by Jani Pehkonen

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

Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java?rev=1878671&r1=1878670&r2=1878671&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java Tue Jun  9 18:16:37 2020
@@ -1190,18 +1190,23 @@ public class PageDrawer extends PDFGraph
         graphics.setComposite(getGraphicsState().getNonStrokingJavaComposite());
         setClip();
         AffineTransform imageTransform = new AffineTransform(at);
+        int width = image.getWidth();
+        int height = image.getHeight();
+        imageTransform.scale(1.0 / width, -1.0 / height);
+        imageTransform.translate(0, -height);
+
         PDSoftMask softMask = getGraphicsState().getSoftMask();
         if( softMask != null )
         {
-            imageTransform.scale(1, -1);
-            imageTransform.translate(0, -1);
-            Paint awtPaint = new TexturePaint(image,
-                    new Rectangle2D.Double(imageTransform.getTranslateX(), imageTransform.getTranslateY(),
-                            imageTransform.getScaleX(), imageTransform.getScaleY()));
+            Rectangle2D rectangle = new Rectangle2D.Float(0, 0, width, height);
+            Paint awtPaint = new TexturePaint(image, rectangle);
             awtPaint = applySoftMaskToPaint(awtPaint, softMask);
             graphics.setPaint(awtPaint);
-            Rectangle2D unitRect = new Rectangle2D.Float(0, 0, 1, 1);
-            graphics.fill(at.createTransformedShape(unitRect));
+
+            AffineTransform originalTransform = graphics.getTransform();
+            graphics.transform(imageTransform);
+            graphics.fill(rectangle);
+            graphics.setTransform(originalTransform);
         }
         else
         {
@@ -1211,11 +1216,6 @@ public class PageDrawer extends PDFGraph
                 image = applyTransferFunction(image, transfer);
             }
 
-            int width = image.getWidth();
-            int height = image.getHeight();
-            imageTransform.scale(1.0 / width, -1.0 / height);
-            imageTransform.translate(0, -height);
-
             // PDFBOX-4516, PDFBOX-4527, PDFBOX-4815:
             // graphics.drawImage() has terrible quality when scaling down, even when
             // RenderingHints.VALUE_INTERPOLATION_BICUBIC, VALUE_ALPHA_INTERPOLATION_QUALITY,
@@ -1234,15 +1234,6 @@ public class PageDrawer extends PDFGraph
                 RenderingHints.VALUE_RENDER_QUALITY.equals(graphics.getRenderingHint(RenderingHints.KEY_RENDERING)) &&
                 RenderingHints.VALUE_INTERPOLATION_BICUBIC.equals(graphics.getRenderingHint(RenderingHints.KEY_INTERPOLATION)))
             {
-                // PDFBOX-4516, PDFBOX-4527, PDFBOX-4815:
-                // graphics.drawImage() has terrible quality when scaling down, even when
-                // RenderingHints.VALUE_INTERPOLATION_BICUBIC, VALUE_ALPHA_INTERPOLATION_QUALITY,
-                // VALUE_COLOR_RENDER_QUALITY and VALUE_RENDER_QUALITY are all set.
-                // A workaround is to get a pre-scaled image with Image.getScaledInstance()
-                // and then draw that one. To reduce differences in testing
-                // (partly because the method needs integer parameters), only smaller scalings
-                // will trigger the workaround. Because of the slowness we only do it if the user
-                // expects quality rendering and interpolation.
                 int w = Math.round(image.getWidth() * scaleX);
                 int h = Math.round(image.getHeight() * scaleY);
                 if (w < 1)