Skip to content

Commit dd543d9

Browse files
authored
GH-311 fraction scaling compensation when building and drawing page bufffer (#373)
1 parent 10976ef commit dd543d9

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/AbstractPageViewComponent.java

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,18 @@ protected void calculatePageSize(Rectangle pageSize, float rotation, float zoom)
255255
}
256256
}
257257

258+
protected static double calculateScaleForDefaultScreen() {
259+
try {
260+
return GraphicsEnvironment.getLocalGraphicsEnvironment()
261+
.getDefaultScreenDevice() // could be an issue if multiple screens
262+
.getDefaultConfiguration()
263+
.getDefaultTransform()
264+
.getScaleX();
265+
} catch (Exception e) {
266+
return 1.0;
267+
}
268+
}
269+
258270
@Override
259271
protected void paintComponent(Graphics g) {
260272
// create a copy, so we can set our own state without affecting the parent graphics content.
@@ -280,7 +292,8 @@ protected void paintComponent(Graphics g) {
280292
// force one more paint to make sure we build a new buffer using the current zoom and rotation.
281293
repaint();
282294
}
283-
g2d.drawImage(pageImage, paintingClip.x, paintingClip.y, null);
295+
// will scale buffer to fit the current clip with smooths out any artifacts from screen scale factor
296+
g2d.drawImage(pageImage, paintingClip.x, paintingClip.y, paintingClip.width, paintingClip.height, null);
284297
}
285298
g2d.dispose();
286299
}
@@ -410,18 +423,23 @@ public Object call() {
410423
// paint page.
411424
Page page = pageTree.getPage(pageIndex);
412425
// page loading progress
413-
PageViewLoadingListener pageLoadingListener = new DefaultPageViewLoadingListener(parent, documentViewController);
426+
PageViewLoadingListener pageLoadingListener = new DefaultPageViewLoadingListener(parent,
427+
documentViewController);
414428
boolean isFirstProgressivePaint = false;
415429
try {
416430
if (documentViewController != null) page.addPageProcessingListener(pageLoadingListener);
417431
// page init, interruptible
418432
page.init();
419433
pageInitializedCallback(page);
420434

435+
double scale = AbstractPageViewComponent.calculateScaleForDefaultScreen();
421436
BufferedImage pageBufferImage = graphicsConfiguration.createCompatibleImage(
422-
imageLocation.width, imageLocation.height,
437+
(int) (imageLocation.width * scale),
438+
(int) (imageLocation.height * scale),
423439
BufferedImage.TYPE_INT_ARGB);
424-
Graphics g2d = pageBufferImage.createGraphics();
440+
Graphics2D g2d = pageBufferImage.createGraphics();
441+
g2d.scale(scale, scale);
442+
425443

426444
// if we don't have a soft reference then we are likely on a first clean paint at which
427445
// point we can kick off the animated paint.

0 commit comments

Comments
 (0)