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 2017/01/31 16:09:44 UTC
svn commit: r1781111 -
/pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/pagepane/PagePane.java
Author: tilman
Date: Tue Jan 31 16:09:44 2017
New Revision: 1781111
URL: http://svn.apache.org/viewvc?rev=1781111&view=rev
Log:
PDFBOX-3665: prevent blurry display on JDK9, thanks Alexandr Scherbatiy
Modified:
pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/pagepane/PagePane.java
Modified: pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/pagepane/PagePane.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/pagepane/PagePane.java?rev=1781111&r1=1781110&r2=1781111&view=diff
==============================================================================
--- pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/pagepane/PagePane.java (original)
+++ pdfbox/branches/2.0/debugger/src/main/java/org/apache/pdfbox/debugger/pagepane/PagePane.java Tue Jan 31 16:09:44 2017
@@ -19,16 +19,18 @@ package org.apache.pdfbox.debugger.pagep
import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
+import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
+import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.concurrent.ExecutionException;
import javax.swing.BoxLayout;
-import javax.swing.ImageIcon;
+import javax.swing.Icon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingWorker;
@@ -252,7 +254,17 @@ public class PagePane implements ActionL
{
try
{
- label.setIcon(new ImageIcon(get()));
+ BufferedImage image = get();
+
+ // We cannot use "label.setIcon(new ImageIcon(get()))" here
+ // because of blurry upscaling in JDK9. Instead, the label is now created with
+ // a smaller size than the image to compensate that the
+ // image is scaled up with some screen configurations (e.g. 125% on windows).
+ // See PDFBOX-3665 for more sample code and discussion.
+ AffineTransform tx = panel.getGraphicsConfiguration().getDefaultTransform();
+ label.setSize((int) Math.ceil(image.getWidth() / tx.getScaleX()),
+ (int) Math.ceil(image.getHeight() / tx.getScaleY()));
+ label.setIcon(new HighResolutionImageIcon(image, label.getWidth(), label.getHeight()));
label.setText(null);
}
catch (InterruptedException e)
@@ -266,5 +278,37 @@ public class PagePane implements ActionL
throw new RuntimeException(e);
}
}
+
+ private class HighResolutionImageIcon implements Icon
+ {
+ private final BufferedImage image;
+ private final int baseWidth;
+ private final int baseHeight;
+
+ private HighResolutionImageIcon(BufferedImage image, int baseWidth, int baseHeight)
+ {
+ this.image = image;
+ this.baseWidth = baseWidth;
+ this.baseHeight = baseHeight;
+ }
+
+ @Override
+ public void paintIcon(Component c, Graphics g, int x, int y)
+ {
+ g.drawImage(image, x, y, getIconWidth(), getIconHeight(), null);
+ }
+
+ @Override
+ public int getIconWidth()
+ {
+ return baseWidth;
+ }
+
+ @Override
+ public int getIconHeight()
+ {
+ return baseHeight;
+ }
+ }
}
}