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/20 08:27:04 UTC
svn commit: r1879028 -
/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/rendering/PageDrawer.java
Author: tilman
Date: Sat Jun 20 08:27:03 2020
New Revision: 1879028
URL: http://svn.apache.org/viewvc?rev=1879028&view=rev
Log:
PDFBOX-4863: also consider the graphics device transform when deciding whether to use getScaledInstance() for smooth scaling, use classic method when w or h < 1
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=1879028&r1=1879027&r2=1879028&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 Sat Jun 20 08:27:03 2020
@@ -1216,7 +1216,7 @@ public class PageDrawer extends PDFGraph
image = applyTransferFunction(image, transfer);
}
- // PDFBOX-4516, PDFBOX-4527, PDFBOX-4815:
+ // PDFBOX-4516, PDFBOX-4527, PDFBOX-4815, PDFBOX-4886, PDFBOX-4863:
// 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.
@@ -1225,32 +1225,37 @@ public class PageDrawer extends PDFGraph
// (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.
- Matrix m = new Matrix(imageTransform);
- float scaleX = Math.abs(m.getScalingFactorX());
- float scaleY = Math.abs(m.getScalingFactorY());
- Image imageToDraw = image;
+ Matrix imageTransformMatrix = new Matrix(imageTransform);
+ AffineTransform graphicsTransformA = graphics.getTransform();
+ Matrix graphicsTransformMatrix = new Matrix(graphicsTransformA);
+ float scaleX = Math.abs(imageTransformMatrix.getScalingFactorX() * graphicsTransformMatrix.getScalingFactorX());
+ float scaleY = Math.abs(imageTransformMatrix.getScalingFactorY() * graphicsTransformMatrix.getScalingFactorY());
- if ((scaleX < 0.25f || scaleY < 0.25f) &&
+ if ((scaleX < 0.5 || scaleY < 0.5) &&
RenderingHints.VALUE_RENDER_QUALITY.equals(graphics.getRenderingHint(RenderingHints.KEY_RENDERING)) &&
RenderingHints.VALUE_INTERPOLATION_BICUBIC.equals(graphics.getRenderingHint(RenderingHints.KEY_INTERPOLATION)))
{
int w = Math.round(image.getWidth() * scaleX);
int h = Math.round(image.getHeight() * scaleY);
- if (w < 1)
+ if (w < 1 || h < 1)
{
- w = 1;
+ graphics.drawImage(image, imageTransform, null);
+ return;
}
- if (h < 1)
- {
- h = 1;
- }
- imageToDraw = image.getScaledInstance(
- w,
- h,
- Image.SCALE_SMOOTH);
- imageTransform.scale(1 / scaleX, 1 / scaleY); // remove the scale
+ Image imageToDraw = image.getScaledInstance(w, h, Image.SCALE_SMOOTH);
+ // remove the scale (extracted from w and h, to have it from the rounded values
+ // hoping to reverse the rounding: without this, we get an horizontal line
+ // when rendering PDFJS-8860-Pattern-Size1.pdf at 100% )
+ imageTransform.scale(1f / w * image.getWidth(), 1f / h * image.getHeight());
+ imageTransform.preConcatenate(graphicsTransformA);
+ graphics.setTransform(new AffineTransform());
+ graphics.drawImage(imageToDraw, imageTransform, null);
+ graphics.setTransform(graphicsTransformA);
+ }
+ else
+ {
+ graphics.drawImage(image, imageTransform, null);
}
- graphics.drawImage(imageToDraw, imageTransform, null);
}
}