From 503ddc187360eff6f4d13e708e0f6349f0a035dd Mon Sep 17 00:00:00 2001 From: Patrick Corless Date: Sun, 15 Oct 2023 22:43:12 -0600 Subject: [PATCH 1/4] GH-311 apply static 1.0 scale factor to avoid rendering issues when painting the page buffer at higher scale factors. --- .../org/icepdf/ri/common/views/AbstractPageViewComponent.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/AbstractPageViewComponent.java b/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/AbstractPageViewComponent.java index 3cead268a..9ef7e16f7 100644 --- a/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/AbstractPageViewComponent.java +++ b/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/AbstractPageViewComponent.java @@ -255,6 +255,9 @@ protected void paintComponent(Graphics g) { Graphics2D g2d = (Graphics2D) g.create(0, 0, pageSize.width, pageSize.height); GraphicsRenderingHints grh = GraphicsRenderingHints.getDefault(); g2d.setRenderingHints(grh.getRenderingHints(GraphicsRenderingHints.SCREEN)); + // force a 1.0 scale to avoid blurring the Page buffer with system scaling for HiDPI displays + // JRE will automatically scale the Graphics context, 125% fractional scaling would result in a scale of 1.25 + g2d.scale(1.0, 1.0); // page location in the entire view. calculateBufferLocation(); From eb7c69fe544262b8f84637c78338dbf81f7a33d1 Mon Sep 17 00:00:00 2001 From: folkfreund Date: Tue, 17 Oct 2023 08:04:41 +0200 Subject: [PATCH 2/4] consider system scaling to avoid blurred output --- .../ri/common/views/AbstractDocumentView.java | 2 ++ .../ri/common/views/AbstractDocumentViewModel.java | 13 +++++++++++++ .../ri/common/views/AbstractPageViewComponent.java | 12 +++++++++--- .../icepdf/ri/common/views/DocumentViewModel.java | 3 +++ .../icepdf/ri/common/views/OneColumnPageView.java | 5 +++-- .../org/icepdf/ri/common/views/OnePageView.java | 5 +++-- .../icepdf/ri/common/views/PageViewDecorator.java | 7 +++++++ .../icepdf/ri/common/views/TwoColumnPageView.java | 5 +++-- .../org/icepdf/ri/common/views/TwoPageView.java | 5 +++-- 9 files changed, 46 insertions(+), 11 deletions(-) diff --git a/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/AbstractDocumentView.java b/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/AbstractDocumentView.java index 58b9aa846..0a92ab891 100644 --- a/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/AbstractDocumentView.java +++ b/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/AbstractDocumentView.java @@ -295,6 +295,8 @@ public void paintComponent(Graphics g) { if (currentTool != null) { currentTool.paintTool(g); } + Graphics2D g2d = (Graphics2D) g; + documentViewModel.setSystemScaling(g2d.getDeviceConfiguration().getDefaultTransform().getScaleX()); } public void adjustmentValueChanged(AdjustmentEvent e) { diff --git a/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/AbstractDocumentViewModel.java b/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/AbstractDocumentViewModel.java index 237eafd45..937cb810c 100644 --- a/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/AbstractDocumentViewModel.java +++ b/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/AbstractDocumentViewModel.java @@ -70,6 +70,8 @@ public abstract class AbstractDocumentViewModel implements DocumentViewModel { protected int pageBoundary = Page.BOUNDARY_CROPBOX; // page tool settings protected int userToolModeFlag, oldUserToolModeFlag; + + protected double systemScaling; // 10 pages doesn't take to long to look at, anymore and people will notice // the rest of the page sizes will be figured out later. @@ -388,4 +390,15 @@ public UndoCaretaker getAnnotationCareTaker() { public void addMemento(Memento oldMementoState, Memento newMementoState) { undoCaretaker.addState(oldMementoState, newMementoState); } + + public void setSystemScaling(double scaling) + { + systemScaling = scaling; + } + + public double getSystemScaling() + { + return systemScaling; + } + } diff --git a/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/AbstractPageViewComponent.java b/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/AbstractPageViewComponent.java index 9ef7e16f7..23a11205f 100644 --- a/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/AbstractPageViewComponent.java +++ b/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/AbstractPageViewComponent.java @@ -255,9 +255,15 @@ protected void paintComponent(Graphics g) { Graphics2D g2d = (Graphics2D) g.create(0, 0, pageSize.width, pageSize.height); GraphicsRenderingHints grh = GraphicsRenderingHints.getDefault(); g2d.setRenderingHints(grh.getRenderingHints(GraphicsRenderingHints.SCREEN)); - // force a 1.0 scale to avoid blurring the Page buffer with system scaling for HiDPI displays - // JRE will automatically scale the Graphics context, 125% fractional scaling would result in a scale of 1.25 - g2d.scale(1.0, 1.0); + + // revert system scaling, which will blur the image + // JRE automatically scales the Graphics context, 125% fractional scaling would result in a scale of 1.25 + double systemScaling = (documentViewModel != null) ? documentViewModel.getSystemScaling() : 1.0; + if (systemScaling != 1.0) + { + g2d.scale(1.0/systemScaling, 1.0/systemScaling); + } + // page location in the entire view. calculateBufferLocation(); diff --git a/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/DocumentViewModel.java b/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/DocumentViewModel.java index eef703a2b..fa8700f43 100644 --- a/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/DocumentViewModel.java +++ b/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/DocumentViewModel.java @@ -321,4 +321,7 @@ void addMemento(Memento oldMementoState, void setDocumentViewScrollPane(JScrollPane documentViewScrollPane); + void setSystemScaling(double scaling); + + double getSystemScaling(); } diff --git a/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/OneColumnPageView.java b/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/OneColumnPageView.java index 131939b5e..2ceb0f36e 100644 --- a/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/OneColumnPageView.java +++ b/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/OneColumnPageView.java @@ -135,8 +135,9 @@ public Dimension getDocumentSize() { } // normalize the dimensions to a zoom level of zero. float currentZoom = documentViewController.getDocumentViewModel().getViewZoom(); - pageViewWidth = Math.abs(pageViewWidth / currentZoom); - pageViewHeight = Math.abs(pageViewHeight / currentZoom); + float systemScaling = (float)documentViewController.getDocumentViewModel().getSystemScaling(); + pageViewWidth = Math.abs(pageViewWidth / currentZoom / systemScaling); + pageViewHeight = Math.abs(pageViewHeight / currentZoom / systemScaling); // add any horizontal padding from layout manager pageViewWidth += PAGE_SPACING_HORIZONTAL; diff --git a/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/OnePageView.java b/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/OnePageView.java index f426bd1ff..70782fde6 100644 --- a/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/OnePageView.java +++ b/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/OnePageView.java @@ -142,8 +142,9 @@ public Dimension getDocumentSize() { } // normalize the dimensions to a zoom level of zero. float currentZoom = documentViewController.getDocumentViewModel().getViewZoom(); - pageViewWidth = Math.abs(pageViewWidth / currentZoom); - pageViewHeight = Math.abs(pageViewHeight / currentZoom); + float systemScaling = (float)documentViewController.getDocumentViewModel().getSystemScaling(); + pageViewWidth = Math.abs(pageViewWidth / currentZoom / systemScaling); + pageViewHeight = Math.abs(pageViewHeight / currentZoom / systemScaling); // add any horizontal padding from layout manager pageViewWidth += PAGE_SPACING_HORIZONTAL; diff --git a/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/PageViewDecorator.java b/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/PageViewDecorator.java index f333c7cce..1adf5dd1e 100644 --- a/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/PageViewDecorator.java +++ b/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/PageViewDecorator.java @@ -127,6 +127,13 @@ public void paint(Graphics g) { Graphics2D g2d = (Graphics2D) g; Dimension size = pageViewComponent.getPreferredSize(); + double scale = g2d.getDeviceConfiguration().getDefaultTransform().getScaleX(); + if (scale != 1.0) + { + size.width = (int)Math.round(size.width/scale); + size.height = (int)Math.round(size.height/scale); + } + // paper g2d.setColor(pageColor); g2d.fillRect(0, 0, size.width, size.height); diff --git a/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/TwoColumnPageView.java b/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/TwoColumnPageView.java index 036769b4b..5f4d8a4ba 100644 --- a/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/TwoColumnPageView.java +++ b/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/TwoColumnPageView.java @@ -189,8 +189,9 @@ public Dimension getDocumentSize() { // normalize the dimensions to a zoom level of zero. float currentZoom = documentViewController.getDocumentViewModel().getViewZoom(); - pageViewWidth = Math.abs(pageViewWidth / currentZoom); - pageViewHeight = Math.abs(pageViewHeight / currentZoom); + float systemScaling = (float)documentViewController.getDocumentViewModel().getSystemScaling(); + pageViewWidth = Math.abs(pageViewWidth / currentZoom / systemScaling); + pageViewHeight = Math.abs(pageViewHeight / currentZoom / systemScaling); // two pages wide, generalization, pages are usually the same size we // don't bother to look at the second pages size for the time being. diff --git a/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/TwoPageView.java b/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/TwoPageView.java index 9021c79fa..c722d6db7 100644 --- a/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/TwoPageView.java +++ b/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/TwoPageView.java @@ -188,8 +188,9 @@ public Dimension getDocumentSize() { } // normalize the dimensions to a zoom level of zero. float currentZoom = documentViewController.getDocumentViewModel().getViewZoom(); - pageViewWidth = Math.abs(pageViewWidth / currentZoom); - pageViewHeight = Math.abs(pageViewHeight / currentZoom); + float systemScaling = (float)documentViewController.getDocumentViewModel().getSystemScaling(); + pageViewWidth = Math.abs(pageViewWidth / systemScaling / currentZoom); + pageViewHeight = Math.abs(pageViewHeight / systemScaling / currentZoom); // two pages wide, generalization, pages are usually the same size we // don't bother to look at the second pages size for the time being. From 7c0b9dfc57b16bc0081f09cf1877b9badf048e79 Mon Sep 17 00:00:00 2001 From: folkfreund Date: Thu, 19 Oct 2023 13:36:41 +0200 Subject: [PATCH 3/4] consider system scaling for layouts, too --- .../ri/common/views/AbstractDocumentView.java | 2 -- .../views/AbstractPageViewComponent.java | 29 ++++++++++++------- .../ri/common/views/OneColumnPageView.java | 15 ++++++++-- .../common/views/OneColumnPageViewLayout.java | 10 ++++++- .../icepdf/ri/common/views/OnePageView.java | 17 ++++++++--- .../ri/common/views/OnePageViewLayout.java | 18 +++++++++--- .../ri/common/views/PageViewDecorator.java | 8 ++--- .../ri/common/views/TwoColumnPageView.java | 18 ++++++++++-- .../common/views/TwoColumnPageViewLayout.java | 18 ++++++++++-- .../icepdf/ri/common/views/TwoPageView.java | 9 ++++++ .../ri/common/views/TwoPageViewLayout.java | 16 +++++++++- 11 files changed, 124 insertions(+), 36 deletions(-) diff --git a/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/AbstractDocumentView.java b/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/AbstractDocumentView.java index 0a92ab891..58b9aa846 100644 --- a/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/AbstractDocumentView.java +++ b/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/AbstractDocumentView.java @@ -295,8 +295,6 @@ public void paintComponent(Graphics g) { if (currentTool != null) { currentTool.paintTool(g); } - Graphics2D g2d = (Graphics2D) g; - documentViewModel.setSystemScaling(g2d.getDeviceConfiguration().getDefaultTransform().getScaleX()); } public void adjustmentValueChanged(AdjustmentEvent e) { diff --git a/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/AbstractPageViewComponent.java b/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/AbstractPageViewComponent.java index 23a11205f..2683e3c8c 100644 --- a/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/AbstractPageViewComponent.java +++ b/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/AbstractPageViewComponent.java @@ -124,7 +124,13 @@ public AbstractPageViewComponent(DocumentViewModel documentViewModel, PageTree p } public Dimension getPreferredSize() { - return pageSize.getSize(); + Dimension preferredSize = pageSize.getSize(); + double systemScaling = documentViewModel.getSystemScaling(); + if (systemScaling != 1.0) { + preferredSize.width = (int)Math.round(preferredSize.width / systemScaling); + preferredSize.height = (int)Math.round(preferredSize.height / systemScaling); + } + return preferredSize; } public Dimension getSize() { @@ -243,8 +249,9 @@ protected void calculatePageSize(Rectangle pageSize, float rotation, float zoom) if (pageTree != null) { Page currentPage = pageTree.getPage(pageIndex); if (currentPage != null) { + double systemScaling = (documentViewModel != null) ? documentViewModel.getSystemScaling() : 1.0; pageSize.setSize(currentPage.getSize(pageBoundaryBox, - rotation, zoom).toDimension()); + rotation, (float)(zoom * systemScaling)).toDimension()); } } } @@ -255,15 +262,15 @@ protected void paintComponent(Graphics g) { Graphics2D g2d = (Graphics2D) g.create(0, 0, pageSize.width, pageSize.height); GraphicsRenderingHints grh = GraphicsRenderingHints.getDefault(); g2d.setRenderingHints(grh.getRenderingHints(GraphicsRenderingHints.SCREEN)); - - // revert system scaling, which will blur the image - // JRE automatically scales the Graphics context, 125% fractional scaling would result in a scale of 1.25 - double systemScaling = (documentViewModel != null) ? documentViewModel.getSystemScaling() : 1.0; - if (systemScaling != 1.0) - { - g2d.scale(1.0/systemScaling, 1.0/systemScaling); - } - +// +// // revert system scaling, which will blur the image +// // JRE automatically scales the Graphics context, 125% fractional scaling would result in a scale of 1.25 +// double systemScaling = (documentViewModel != null) ? documentViewModel.getSystemScaling() : 1.0; +// if (systemScaling != 1.0) +// { +// g2d.scale(1.0/systemScaling, 1.0/systemScaling); +// } +// // page location in the entire view. calculateBufferLocation(); diff --git a/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/OneColumnPageView.java b/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/OneColumnPageView.java index 2ceb0f36e..94c50badf 100644 --- a/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/OneColumnPageView.java +++ b/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/OneColumnPageView.java @@ -22,6 +22,7 @@ import javax.swing.border.EmptyBorder; import java.awt.*; import java.util.List; +import org.icepdf.core.util.PropertyConstants; import static org.icepdf.ri.common.views.BasePageViewLayout.PAGE_SPACING_HORIZONTAL; @@ -134,10 +135,10 @@ public Dimension getDocumentSize() { pageViewHeight = bounds.height; } // normalize the dimensions to a zoom level of zero. - float currentZoom = documentViewController.getDocumentViewModel().getViewZoom(); float systemScaling = (float)documentViewController.getDocumentViewModel().getSystemScaling(); - pageViewWidth = Math.abs(pageViewWidth / currentZoom / systemScaling); - pageViewHeight = Math.abs(pageViewHeight / currentZoom / systemScaling); + float currentZoom = documentViewController.getDocumentViewModel().getViewZoom() * systemScaling; + pageViewWidth = Math.abs(pageViewWidth / currentZoom); + pageViewHeight = Math.abs(pageViewHeight / currentZoom); // add any horizontal padding from layout manager pageViewWidth += PAGE_SPACING_HORIZONTAL; @@ -146,6 +147,14 @@ public Dimension getDocumentSize() { } public void paintComponent(Graphics g) { + Graphics2D g2d = (Graphics2D)g; + double scale = g2d.getDeviceConfiguration().getDefaultTransform().getScaleX(); + double dpiScaling = documentViewModel.getSystemScaling(); + if (scale != dpiScaling) { + documentViewModel.setSystemScaling(scale); + java.util.List pageComponents = documentViewController.getDocumentViewModel().getPageComponents(); + pageComponents.forEach(page -> page.updateView(PropertyConstants.DOCUMENT_VIEW_REFRESH_CHANGE, 1, 0)); + } Rectangle clipBounds = g.getClipBounds(); // paint background gray g.setColor(backgroundColour); diff --git a/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/OneColumnPageViewLayout.java b/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/OneColumnPageViewLayout.java index 44e497a32..c2f5233f2 100644 --- a/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/OneColumnPageViewLayout.java +++ b/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/OneColumnPageViewLayout.java @@ -20,6 +20,8 @@ public void layoutContainer(Container parent) { setSizes(parent); } + double systemScaling = documentViewModel.getSystemScaling(); + PageViewDecorator[] pages = Arrays.stream(parent.getComponents()) .filter(component -> component instanceof PageViewDecorator && component.isVisible()) .toArray(PageViewDecorator[]::new); @@ -27,6 +29,12 @@ public void layoutContainer(Container parent) { int index = 0; for (PageViewDecorator pageViewDecorator : pages) { Dimension d = pageViewDecorator.getPreferredSize(); + int boundsWidth = d.width; + int boundsHeight = d.height; + + d.width = (int)Math.round(d.width / systemScaling); + d.height = (int)Math.round(d.height / systemScaling); + // set starting position for page, everything else flows from there if(index == 0){ // detect if we should be centering @@ -48,7 +56,7 @@ public void layoutContainer(Container parent) { index++; xCord += insets.left; - pageViewDecorator.setBounds(xCord, yCord, d.width, d.height); + pageViewDecorator.setBounds(xCord, yCord, boundsWidth, boundsHeight); updatePopupAnnotationComponents(pageViewDecorator); } } diff --git a/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/OnePageView.java b/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/OnePageView.java index 70782fde6..e25dbbe03 100644 --- a/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/OnePageView.java +++ b/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/OnePageView.java @@ -21,6 +21,7 @@ import javax.swing.*; import javax.swing.border.EmptyBorder; import java.awt.*; +import org.icepdf.core.util.PropertyConstants; import static org.icepdf.ri.common.views.BasePageViewLayout.PAGE_SPACING_HORIZONTAL; @@ -140,11 +141,11 @@ public Dimension getDocumentSize() { pageViewWidth = bounds.width; pageViewHeight = bounds.height; } - // normalize the dimensions to a zoom level of zero. - float currentZoom = documentViewController.getDocumentViewModel().getViewZoom(); + // normalize the dimensions to a zoom level of zero and apply system scaling float systemScaling = (float)documentViewController.getDocumentViewModel().getSystemScaling(); - pageViewWidth = Math.abs(pageViewWidth / currentZoom / systemScaling); - pageViewHeight = Math.abs(pageViewHeight / currentZoom / systemScaling); + float currentZoom = documentViewController.getDocumentViewModel().getViewZoom() * systemScaling; + pageViewWidth = Math.abs(pageViewWidth / currentZoom); + pageViewHeight = Math.abs(pageViewHeight / currentZoom); // add any horizontal padding from layout manager pageViewWidth += PAGE_SPACING_HORIZONTAL; @@ -153,6 +154,14 @@ public Dimension getDocumentSize() { } public void paintComponent(Graphics g) { + Graphics2D g2d = (Graphics2D)g; + double scale = g2d.getDeviceConfiguration().getDefaultTransform().getScaleX(); + double dpiScaling = documentViewModel.getSystemScaling(); + if (scale != dpiScaling) { + documentViewModel.setSystemScaling(scale); + java.util.List pageComponents = documentViewController.getDocumentViewModel().getPageComponents(); + pageComponents.forEach(page -> page.updateView(PropertyConstants.DOCUMENT_VIEW_REFRESH_CHANGE, 1, 0)); + } Rectangle clipBounds = g.getClipBounds(); // paint background gray g.setColor(backgroundColour); diff --git a/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/OnePageViewLayout.java b/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/OnePageViewLayout.java index f33beb9e0..491f7b00f 100644 --- a/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/OnePageViewLayout.java +++ b/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/OnePageViewLayout.java @@ -23,11 +23,13 @@ public void layoutContainer(Container parent) { Insets insets = parent.getInsets(); int maxWidth = parent.getWidth() - (insets.left + insets.right); int maxHeight = parent.getHeight() - (insets.top + insets.bottom); - + if (sizeUnknown) { setSizes(parent); } + double systemScaling = documentViewModel.getSystemScaling(); + PageViewDecorator[] pages = Arrays.stream(parent.getComponents()) .filter(component -> component instanceof PageViewDecorator && component.isVisible()) .toArray(PageViewDecorator[]::new); @@ -35,8 +37,8 @@ public void layoutContainer(Container parent) { for (PageViewDecorator pageViewDecorator : pages) { Dimension d = pageViewDecorator.getPreferredSize(); // center the page or pagesPanel - int xCord = (maxWidth - d.width) / 2; - int yCord = (maxHeight - d.height) / 2; + int xCord = (int)Math.round((maxWidth - d.width / systemScaling) / 2); + int yCord = (int)Math.round((maxHeight - d.height / systemScaling) / 2); if (xCord < 0) xCord = 0; if (yCord < 0) yCord = 0; @@ -125,8 +127,16 @@ protected void setSizes(Container parent) { preferredHeight += dimension.height + PAGE_SPACING_VERTICAL; minWidth = Math.max(pageViewDecorator.getMinimumSize().width, minWidth); - minHeight = preferredHeight; } + + preferredHeight += pages.length * PAGE_SPACING_VERTICAL; + minHeight = preferredHeight; + + double systemScaling = documentViewModel.getSystemScaling(); + minWidth = (int)Math.round(minWidth / systemScaling); + minHeight = (int)Math.round(minHeight / systemScaling); + preferredWidth = (int)Math.round(preferredWidth / systemScaling); + preferredHeight = (int)Math.round(preferredHeight / systemScaling); } public String toString() { diff --git a/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/PageViewDecorator.java b/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/PageViewDecorator.java index 1adf5dd1e..e8a233895 100644 --- a/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/PageViewDecorator.java +++ b/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/PageViewDecorator.java @@ -128,10 +128,8 @@ public void paint(Graphics g) { Dimension size = pageViewComponent.getPreferredSize(); double scale = g2d.getDeviceConfiguration().getDefaultTransform().getScaleX(); - if (scale != 1.0) - { - size.width = (int)Math.round(size.width/scale); - size.height = (int)Math.round(size.height/scale); + if (scale != 1.0) { + g2d.scale(1.0 / scale, 1.0 / scale); } // paper @@ -144,7 +142,7 @@ public void paint(Graphics g) { // paper shadow paintShadow(g2d, size); - super.paint(g); + super.paint(g2d); } protected void paintBorder(Graphics2D g2d, Dimension size){ diff --git a/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/TwoColumnPageView.java b/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/TwoColumnPageView.java index 5f4d8a4ba..5e3004e2b 100644 --- a/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/TwoColumnPageView.java +++ b/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/TwoColumnPageView.java @@ -22,6 +22,7 @@ import javax.swing.border.EmptyBorder; import java.awt.*; import java.awt.event.MouseEvent; +import org.icepdf.core.util.PropertyConstants; /** *

Constructs a two column page view as defined in the PDF specification. @@ -189,9 +190,8 @@ public Dimension getDocumentSize() { // normalize the dimensions to a zoom level of zero. float currentZoom = documentViewController.getDocumentViewModel().getViewZoom(); - float systemScaling = (float)documentViewController.getDocumentViewModel().getSystemScaling(); - pageViewWidth = Math.abs(pageViewWidth / currentZoom / systemScaling); - pageViewHeight = Math.abs(pageViewHeight / currentZoom / systemScaling); + pageViewWidth = pageViewWidth / currentZoom; + pageViewHeight = pageViewHeight / currentZoom; // two pages wide, generalization, pages are usually the same size we // don't bother to look at the second pages size for the time being. @@ -201,11 +201,23 @@ public Dimension getDocumentSize() { pageViewWidth += AbstractDocumentView.horizontalSpace * 4; pageViewHeight += AbstractDocumentView.verticalSpace * 2; + float systemScaling = (float)documentViewController.getDocumentViewModel().getSystemScaling(); + pageViewWidth = Math.abs(pageViewWidth / systemScaling); + pageViewHeight = Math.abs(pageViewHeight / systemScaling); + return new Dimension((int) pageViewWidth, (int) pageViewHeight); } public void paintComponent(Graphics g) { + Graphics2D g2d = (Graphics2D)g; + double scale = g2d.getDeviceConfiguration().getDefaultTransform().getScaleX(); + double dpiScaling = documentViewModel.getSystemScaling(); + if (scale != dpiScaling) { + documentViewModel.setSystemScaling(scale); + java.util.List pageComponents = documentViewController.getDocumentViewModel().getPageComponents(); + pageComponents.forEach(page -> page.updateView(PropertyConstants.DOCUMENT_VIEW_REFRESH_CHANGE, 1, 0)); + } Rectangle clipBounds = g.getClipBounds(); g.setColor(backgroundColour); g.fillRect(clipBounds.x, clipBounds.y, clipBounds.width, clipBounds.height); diff --git a/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/TwoColumnPageViewLayout.java b/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/TwoColumnPageViewLayout.java index 3050599e3..5dba3148f 100644 --- a/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/TwoColumnPageViewLayout.java +++ b/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/TwoColumnPageViewLayout.java @@ -22,6 +22,8 @@ public void layoutContainer(Container parent) { setSizes(parent); } + double systemScaling = documentViewModel.getSystemScaling(); + PageViewDecorator[] pages = Arrays.stream(parent.getComponents()) .filter(component -> component instanceof PageViewDecorator && component.isVisible()) .toArray(PageViewDecorator[]::new); @@ -31,11 +33,17 @@ public void layoutContainer(Container parent) { for (PageViewDecorator pageViewDecorator : pages) { int pageIndex = pageViewDecorator.getPageViewComponent().getPageIndex(); Dimension d = pageViewDecorator.getPreferredSize(); + int boundsWidth = d.width; + int boundsHeight = d.height; + + d.width = (int)Math.round(d.width / systemScaling); + d.height = (int)Math.round(d.height / systemScaling); + // apply left to right reading if (viewType == DocumentView.RIGHT_VIEW && pageIndex == 0 && (pages.length != 2)) { // offset to the right side - xCord = ((maxWidth - preferredWidth) / 2) + d.width + PAGE_SPACING_HORIZONTAL + insets.left; + xCord = ((maxWidth - preferredWidth) / 2) + d.width + PAGE_SPACING_HORIZONTAL; if (preferredHeight < maxHeight) { yCord = (maxHeight - preferredHeight) / 2; } @@ -54,7 +62,7 @@ public void layoutContainer(Container parent) { xCord += previousDimension.width + PAGE_SPACING_HORIZONTAL; } previousDimension = d; - pageViewDecorator.setBounds(xCord, yCord, d.width, d.height); + pageViewDecorator.setBounds(xCord, yCord, boundsWidth, boundsHeight); updatePopupAnnotationComponents(pageViewDecorator); } } @@ -85,5 +93,11 @@ protected void setSizes(Container parent) { preferredHeight += pages[0].getPreferredSize().height + PAGE_SPACING_VERTICAL; minHeight += preferredHeight; } + + double systemScaling = documentViewModel.getSystemScaling(); + minWidth = (int)Math.round(minWidth / systemScaling); + minHeight = (int)Math.round(minHeight / systemScaling); + preferredWidth = (int)Math.round(preferredWidth / systemScaling); + preferredHeight = (int)Math.round(preferredHeight / systemScaling); } } diff --git a/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/TwoPageView.java b/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/TwoPageView.java index c722d6db7..afaf4742d 100644 --- a/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/TwoPageView.java +++ b/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/TwoPageView.java @@ -22,6 +22,7 @@ import javax.swing.*; import javax.swing.border.EmptyBorder; import java.awt.*; +import org.icepdf.core.util.PropertyConstants; import static org.icepdf.ri.common.views.TwoPageViewLayout.PAGE_SPACING_HORIZONTAL; @@ -204,6 +205,14 @@ public Dimension getDocumentSize() { } public void paintComponent(Graphics g) { + Graphics2D g2d = (Graphics2D)g; + double scale = g2d.getDeviceConfiguration().getDefaultTransform().getScaleX(); + double dpiScaling = documentViewModel.getSystemScaling(); + if (scale != dpiScaling) { + documentViewModel.setSystemScaling(scale); + java.util.List pageComponents = documentViewController.getDocumentViewModel().getPageComponents(); + pageComponents.forEach(page -> page.updateView(PropertyConstants.DOCUMENT_VIEW_REFRESH_CHANGE, 1, 0)); + } Rectangle clipBounds = g.getClipBounds(); g.setColor(backgroundColour); g.fillRect(clipBounds.x, clipBounds.y, clipBounds.width, clipBounds.height); diff --git a/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/TwoPageViewLayout.java b/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/TwoPageViewLayout.java index 3ad402cfa..0d18b2646 100644 --- a/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/TwoPageViewLayout.java +++ b/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/TwoPageViewLayout.java @@ -37,11 +37,19 @@ public void layoutContainer(Container parent) { .filter(component -> component instanceof PageViewDecorator && component.isVisible()) .toArray(PageViewDecorator[]::new); + double systemScaling = documentViewModel.getSystemScaling(); + int count = 0; int previousWidth = 0; for (PageViewDecorator pageViewDecorator : pages) { int pageIndex = pageViewDecorator.getPageViewComponent().getPageIndex(); Dimension d = pageViewDecorator.getPreferredSize(); + int boundsWidth = d.width; + int boundsHeight = d.height; + + d.width = (int)Math.round(d.width / systemScaling); + d.height = (int)Math.round(d.height / systemScaling); + // apply odd pages right offset if (viewType == DocumentView.RIGHT_VIEW && pageIndex == 0 && pages.length == 1) { @@ -64,7 +72,7 @@ public void layoutContainer(Container parent) { yCord += insets.top; - pageViewDecorator.setBounds(xCord, yCord, d.width, d.height); + pageViewDecorator.setBounds(xCord, yCord, boundsWidth, boundsHeight); updatePopupAnnotationComponents(pageViewDecorator); } } @@ -148,6 +156,12 @@ protected void setSizes(Container parent) { minWidth = Math.max(component.getMinimumSize().width * 2, minWidth); minHeight = preferredHeight; } + + double systemScaling = documentViewModel.getSystemScaling(); + minWidth = (int)Math.round(minWidth / systemScaling); + minHeight = (int)Math.round(minHeight / systemScaling); + preferredWidth = (int)Math.round(preferredWidth / systemScaling); + preferredHeight = (int)Math.round(preferredHeight / systemScaling); } public String toString() { From 5a2cae16a6feed20f724accbd56aa5e1b27be41a Mon Sep 17 00:00:00 2001 From: folkfreund Date: Thu, 19 Oct 2023 14:24:10 +0200 Subject: [PATCH 4/4] consider system scaling for markupGlue Fixed possible NPE, if search is called via shortkey --- .../java/org/icepdf/ri/common/SwingController.java | 14 ++++++++------ .../views/annotations/MarkupGlueComponent.java | 7 +++++++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/SwingController.java b/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/SwingController.java index 566e175c6..d9c0f697a 100644 --- a/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/SwingController.java +++ b/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/SwingController.java @@ -4547,17 +4547,19 @@ public void showSearch() { * @see #setUtilityPaneVisible(boolean) */ public void showSearchPanel() { - final String selectedText = documentViewController.getSelectedText(); - if (selectedText != null && !selectedText.trim().isEmpty()) { - showSearchPanel(selectedText.trim()); - } else { - showSearchPanel(searchPanel.getSearchPhrase()); + if (searchPanel != null) { + final String selectedText = documentViewController.getSelectedText(); + if (selectedText != null && !selectedText.trim().isEmpty()) { + showSearchPanel(selectedText.trim()); + } else { + showSearchPanel(searchPanel.getSearchPhrase()); + } } } public void showSearchPanel(final String searchPhrase) { - searchPanel.setSearchPhrase(searchPhrase); if (utilityTabbedPane != null && searchPanel != null) { + searchPanel.setSearchPhrase(searchPhrase); // make sure the utility pane is visible if (!utilityTabbedPane.isVisible()) { setUtilityPaneVisible(true); diff --git a/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/annotations/MarkupGlueComponent.java b/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/annotations/MarkupGlueComponent.java index 4a5a6baf8..86565b04c 100644 --- a/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/annotations/MarkupGlueComponent.java +++ b/viewer/viewer-awt/src/main/java/org/icepdf/ri/common/views/annotations/MarkupGlueComponent.java @@ -92,6 +92,13 @@ public void refreshDirtyBounds() { @Override public void paintComponent(Graphics g) { + Graphics2D g2d = (Graphics2D) g; + + double scale = g2d.getDeviceConfiguration().getDefaultTransform().getScaleX(); + if (scale != 1.0) { + g2d.scale(1.0 / scale, 1.0 / scale); + } + if (popupAnnotationComponent.isVisible()) { Rectangle popupBounds = popupAnnotationComponent.getBounds(); Rectangle markupBounds = adjustedMarkupAnnotationBounds;