Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-311 fraction scaling testing #373

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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 @@ -249,12 +249,23 @@ protected void calculatePageSize(Rectangle pageSize, float rotation, float zoom)
}
}

protected static double calculateScaleForDefaultScreen() {
double scale = GraphicsEnvironment.getLocalGraphicsEnvironment()
.getDefaultScreenDevice()
.getDefaultConfiguration()
.getDefaultTransform()
.getScaleX();
System.out.printf("device scale: %f\n", scale);
return scale;
}

@Override
protected void paintComponent(Graphics g) {
// create a copy, so we can set our own state without affecting the parent graphics content.
Graphics2D g2d = (Graphics2D) g.create(0, 0, pageSize.width, pageSize.height);
GraphicsRenderingHints grh = GraphicsRenderingHints.getDefault();
g2d.setRenderingHints(grh.getRenderingHints(GraphicsRenderingHints.SCREEN));

// page location in the entire view.
calculateBufferLocation();

Expand All @@ -274,7 +285,21 @@ protected void paintComponent(Graphics g) {
// force one more paint to make sure we build a new buffer using the current zoom and rotation.
repaint();
}
g2d.drawImage(pageImage, paintingClip.x, paintingClip.y, null);
// get scale which will be > 1.0 on high dpi monitors
double scale = calculateScaleForDefaultScreen();
// g2d.drawImage(pageImage,
// // destination
// paintingClip.x,
// paintingClip.y,
// paintingClip.x + paintingClip.width,
// paintingClip.y + paintingClip.height,
// // source
// paintingClip.x,
// paintingClip.y,
// paintingClip.x + paintingClip.width,
// paintingClip.y + paintingClip.height,
// null);
g2d.drawImage(pageImage, paintingClip.x, paintingClip.y, paintingClip.width, paintingClip.height, null);
}
g2d.dispose();
}
Expand Down Expand Up @@ -412,10 +437,17 @@ public Object call() {
page.init();
pageInitializedCallback(page);

double scale = AbstractPageViewComponent.calculateScaleForDefaultScreen();
BufferedImage pageBufferImage = graphicsConfiguration.createCompatibleImage(
imageLocation.width, imageLocation.height,
(int) (imageLocation.width * scale),
(int) (imageLocation.height * scale),
BufferedImage.TYPE_INT_ARGB);
Graphics g2d = pageBufferImage.createGraphics();
Graphics2D g2d = pageBufferImage.createGraphics();
GraphicsConfiguration gc = g2d.getDeviceConfiguration();
double scaleFactor = gc.getDefaultTransform().getScaleX();
System.out.println("gc scaleFactor: " + scaleFactor);
g2d.scale(scale, scale);


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