Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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());
}
}
}
Expand All @@ -255,6 +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);
// }
//
// page location in the entire view.
calculateBufferLocation();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,4 +321,7 @@ void addMemento(Memento oldMementoState,

void setDocumentViewScrollPane(JScrollPane documentViewScrollPane);

void setSystemScaling(double scaling);

double getSystemScaling();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -134,7 +135,8 @@ 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();
float currentZoom = documentViewController.getDocumentViewModel().getViewZoom() * systemScaling;
pageViewWidth = Math.abs(pageViewWidth / currentZoom);
pageViewHeight = Math.abs(pageViewHeight / currentZoom);

Expand All @@ -145,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<AbstractPageViewComponent> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,21 @@ 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);

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
Expand All @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -140,8 +141,9 @@ 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();
float currentZoom = documentViewController.getDocumentViewModel().getViewZoom() * systemScaling;
pageViewWidth = Math.abs(pageViewWidth / currentZoom);
pageViewHeight = Math.abs(pageViewHeight / currentZoom);

Expand All @@ -152,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<AbstractPageViewComponent> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,22 @@ 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);

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;
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ public void paint(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
Dimension size = pageViewComponent.getPreferredSize();

double scale = g2d.getDeviceConfiguration().getDefaultTransform().getScaleX();
if (scale != 1.0) {
g2d.scale(1.0 / scale, 1.0 / scale);
}

// paper
g2d.setColor(pageColor);
g2d.fillRect(0, 0, size.width, size.height);
Expand All @@ -137,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){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.awt.event.MouseEvent;
import org.icepdf.core.util.PropertyConstants;

/**
* <p>Constructs a two column page view as defined in the PDF specification.
Expand Down Expand Up @@ -189,8 +190,8 @@ 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);
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.
Expand All @@ -200,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<AbstractPageViewComponent> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}
Expand All @@ -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);
}
}
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -188,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 / 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.
Expand All @@ -203,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<AbstractPageViewComponent> 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);
Expand Down
Loading