From 3e64d3f614e17cfccd502dcd9b362a07269fd0e3 Mon Sep 17 00:00:00 2001 From: Berenz Date: Fri, 3 Mar 2017 16:43:24 -0500 Subject: [PATCH] Make scale-to-page adjust for changes from web dpi --- src/qz/printer/action/WebApp.java | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/src/qz/printer/action/WebApp.java b/src/qz/printer/action/WebApp.java index e74fa752e..8dd0e4733 100644 --- a/src/qz/printer/action/WebApp.java +++ b/src/qz/printer/action/WebApp.java @@ -45,6 +45,8 @@ public class WebApp extends Application { private static final int SLEEP = 250; private static final int TIMEOUT = 60; //total paused seconds before failing + private static final double WEB_SCALE = 72d / 96d; + private static WebApp instance = null; private static Stage stage; @@ -75,7 +77,7 @@ public class WebApp extends Application { base.getAttributes().setNamedItem(applied); } - //we have to resize the width first, for responsive html, then calculate the best fit height + //width was resized earlier (for responsive html), then calculate the best fit height if (pageHeight <= 0) { String heightText = webView.getEngine().executeScript("Math.max(document.body.offsetHeight, document.body.scrollHeight)").toString(); pageHeight = Double.parseDouble(heightText); @@ -87,16 +89,8 @@ public class WebApp extends Application { webView.autosize(); } - //account for difference in print vs web dpi - double scale = 72d / 96d; - webView.getTransforms().add(new Scale(scale, scale)); - - double increase = 96d / 72d; - log.trace("Setting HTML page width to {}", webView.getWidth() * increase); - webView.setMinWidth(webView.getWidth() * increase); - webView.setPrefWidth(webView.getWidth() * increase); - webView.setMaxWidth(webView.getWidth() * increase); - webView.autosize(); + //scale web dimensions down to print dpi + webView.getTransforms().add(new Scale(WEB_SCALE, WEB_SCALE)); snap.playFromStart(); } @@ -159,10 +153,10 @@ public static synchronized void print(final PrinterJob job, final WebAppModel mo PageLayout layout = job.getJobSettings().getPageLayout(); if (model.isScaled()) { double scale; - if ((webView.getWidth() / webView.getHeight()) >= (layout.getPrintableWidth() / layout.getPrintableHeight())) { - scale = layout.getPrintableWidth() / webView.getWidth(); + if ((webView.getWidth() / webView.getHeight()) / WEB_SCALE >= (layout.getPrintableWidth() / layout.getPrintableHeight())) { + scale = (layout.getPrintableWidth() / webView.getWidth()) / WEB_SCALE; } else { - scale = layout.getPrintableHeight() / webView.getHeight(); + scale = (layout.getPrintableHeight() / webView.getHeight()) / WEB_SCALE; } webView.getTransforms().add(new Scale(scale, scale)); }