Skip to content

Commit

Permalink
Only call updatepeer on vector prints
Browse files Browse the repository at this point in the history
  • Loading branch information
Berenz committed May 21, 2020
1 parent aef8d0c commit 12c3ca0
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions src/qz/printer/action/WebApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public class WebApp extends Application {
private static double pageWidth;
private static double pageHeight;
private static double pageZoom;
private static boolean raster;
private static boolean headless;

private static CountDownLatch startupLatch;
Expand Down Expand Up @@ -225,6 +226,7 @@ public void start(Stage st) throws Exception {
*/
public static synchronized void print(final PrinterJob job, final WebAppModel model) throws Throwable {
model.setZoom(1); //vector prints do not need to use zoom
raster = false;

load(model, (int frames) -> {
try {
Expand Down Expand Up @@ -302,6 +304,8 @@ public static synchronized BufferedImage raster(final WebAppModel model) throws
model.setWebWidth(model.getWebWidth() * increase);
model.setWebHeight(model.getWebHeight() * increase);

raster = true;

load(model, (int frames) -> {
if (frames == 2) {
log.debug("Attempting image capture");
Expand Down Expand Up @@ -381,23 +385,25 @@ private static synchronized void load(WebAppModel model, IntPredicate action) {
public static void autosize(WebView webView) {
webView.autosize();

// Call updatePeer; fixes a bug with webView resizing
// Can be avoided by calling stage.show() but breaks headless environments
// See: https://github.com/qzind/tray/issues/513
String[] methods = {"impl_updatePeer" /*jfx8*/, "doUpdatePeer" /*jfx11*/};
try {
for(Method m : webView.getClass().getDeclaredMethods()) {
for(String method : methods) {
if (m.getName().equals(method)) {
m.setAccessible(true);
m.invoke(webView);
return;
if (!raster) {
// Call updatePeer; fixes a bug with webView resizing
// Can be avoided by calling stage.show() but breaks headless environments
// See: https://github.com/qzind/tray/issues/513
String[] methods = {"impl_updatePeer" /*jfx8*/, "doUpdatePeer" /*jfx11*/};
try {
for(Method m : webView.getClass().getDeclaredMethods()) {
for(String method : methods) {
if (m.getName().equals(method)) {
m.setAccessible(true);
m.invoke(webView);
return;
}
}
}
}
}
catch(SecurityException | ReflectiveOperationException e) {
log.warn("Unable to update peer; Blank pages may occur.", e);
catch(SecurityException | ReflectiveOperationException e) {
log.warn("Unable to update peer; Blank pages may occur.", e);
}
}
}

Expand Down

0 comments on commit 12c3ca0

Please sign in to comment.