diff -r c734b008e3e8 modules/javafx.swt/src/main/java/javafx/embed/swt/FXCanvas.java --- a/modules/javafx.swt/src/main/java/javafx/embed/swt/FXCanvas.java Mon Jul 31 04:14:09 2017 -0700 +++ b/modules/javafx.swt/src/main/java/javafx/embed/swt/FXCanvas.java Tue Nov 21 21:25:45 2017 +0100 @@ -184,6 +184,17 @@ } catch (Exception e) { // FAIL silently should the reflection fail } + } else if( SWT.getPlatform().equals("win32") ) { + if( swtDPIUtilMethod == null ) { + return 1.0; + } + + try { + Integer value = (Integer) swtDPIUtilMethod.invoke(null); + return value.intValue() / 100.0; + } catch (Exception e) { + // FAIL silently should the reflection fail + } } return 1.0; } @@ -226,6 +237,8 @@ private static Method screenMethod; private static Method backingScaleFactorMethod; + private static Method swtDPIUtilMethod; + static { if (SWT.getPlatform().equals("cocoa")) { try { @@ -246,6 +259,15 @@ } catch (Exception e) { //Fail silently. If we can't get the methods, then the current version of SWT has no retina support } + } else if( SWT.getPlatform().equals("win32") ) { + try { + if( System.getProperty("swt.autoScale") == null || ! "false".equalsIgnoreCase(System.getProperty("swt.autoScale"))) { + Class dpiUtilClass = Class.forName("org.eclipse.swt.internal.DPIUtil"); + swtDPIUtilMethod = dpiUtilClass.getMethod("getDeviceZoom"); + } + } catch (Exception e) { + //Fail silently. If we can't get the methods, then the current version of SWT has no retina support + } } initFx(); } @@ -311,8 +333,19 @@ AccessController.doPrivileged((PrivilegedAction) () -> { System.setProperty("com.sun.javafx.application.type", "FXCanvas"); System.setProperty("javafx.embed.isEventThread", "true"); - System.setProperty("glass.win.uiScale", "100%"); - System.setProperty("glass.win.renderScale", "100%"); + if( swtDPIUtilMethod == null ) { + System.setProperty("glass.win.uiScale", "100%"); + System.setProperty("glass.win.renderScale", "100%"); + } else { + Integer scale = 100; + try { + scale = (Integer) swtDPIUtilMethod.invoke(null); + } catch (Exception e) { + //Fail silently + } + System.setProperty("glass.win.uiScale", scale + "%"); + System.setProperty("glass.win.renderScale", scale + "%"); + } System.setProperty("javafx.embed.eventProc", eventProcStr); return null; });