From d671b2ab3badbcfdbe0ff57f55ff997ba7bcb060 Mon Sep 17 00:00:00 2001 From: Sven Gothel Date: Wed, 15 Jan 2020 08:02:18 +0100 Subject: Bug 1422: Emulate DPI Scaling on non-native DPI autoscale platforms (!MacOS) Bug 1422 shows that it seems to be desired to emulate DPI scaling where the native toolkit does not implmement the same. On GTK, DPIUtil.mapDPIToZoom (int dpi) reads: double zoom = (double) dpi * 100 / 96; int roundedZoom = (int) Math.round (zoom); return roundedZoom; While having dpi calculated as: dpi = 96 * GDK.gdk_monitor_get_scale_factor(monitor); Well, this seems to exist to allow 96 dpi fixed layout to 'look' OK on high-dpi screens. However, you get in trouble if you layout high-dpi aware, i.e. using percentages etc. There is one exception: If DPIUtil.useCairoAutoScale() is true, scalingFactor is 1f and hence the scaling emulation dropped. 'DPIUtil.setUseCairoAutoScale((sx[0]*100) == scaleFactor || OS.isGNOME);' --- .../classes/com/jogamp/newt/swt/NewtCanvasSWT.java | 29 +++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'src/newt/classes/com/jogamp') diff --git a/src/newt/classes/com/jogamp/newt/swt/NewtCanvasSWT.java b/src/newt/classes/com/jogamp/newt/swt/NewtCanvasSWT.java index 2930a4fd3..2615ebbb5 100644 --- a/src/newt/classes/com/jogamp/newt/swt/NewtCanvasSWT.java +++ b/src/newt/classes/com/jogamp/newt/swt/NewtCanvasSWT.java @@ -176,6 +176,29 @@ public class NewtCanvasSWT extends Canvas implements NativeWindowHolder, WindowC addListener (SWT.FocusOut, swtListener); } + /** + * Set's the NEWT {@link Window}'s size using {@link Window#setSize(int, int)}. + *

+ * For all non-native DPI autoscale platforms, it utilizes {@link SWTAccessor#autoScaleUp(Point)} + * by multiplying the given {@link Rectangle} size to emulate DPI scaling, see Bug 1422. + *

+ *

+ * Currently native DPI autoscale platforms are + *

+ * hence the emulated DPI scaling is enabled for all other platforms. + *

+ * @param r containing desired size + */ + private final void setNewtChildSize(final Rectangle r) { + if( !SWTAccessor.isOSX ) { + final Point p = SWTAccessor.autoScaleUp(new Point(r.width, r.height)); + newtChild.setSize(p.getX(), p.getY()); + } else { + newtChild.setSize(r.width, r.height); + } + } private final Listener swtListener = new Listener () { @Override public void handleEvent (final Event event) { @@ -187,7 +210,7 @@ public class NewtCanvasSWT extends Canvas implements NativeWindowHolder, WindowC } if( validateNative() && newtChildReady ) { if( postSetSize ) { - newtChild.setSize(clientAreaWindow.width, clientAreaWindow.height); + setNewtChildSize(clientAreaWindow); postSetSize = false; } if( postSetPos ) { @@ -357,7 +380,7 @@ public class NewtCanvasSWT extends Canvas implements NativeWindowHolder, WindowC } if( sizeChanged ) { if( newtChildReady ) { - newtChild.setSize(nClientAreaWindow.width, nClientAreaWindow.height); + setNewtChildSize(nClientAreaWindow); newtChild.setSurfaceScale(pixelScale); } else { postSetSize = true; @@ -529,7 +552,7 @@ public class NewtCanvasSWT extends Canvas implements NativeWindowHolder, WindowC newtDisplay.setEDTUtil( edtUtil ); } - newtChild.setSize(clientAreaWindow.width, clientAreaWindow.height); + setNewtChildSize(clientAreaWindow); newtChild.reparentWindow(nativeWindow, -1, -1, Window.REPARENT_HINT_BECOMES_VISIBLE); newtChild.setPosition(clientAreaWindow.x, clientAreaWindow.y); newtChild.setVisible(true); -- cgit v1.2.3