From 68506f420925035927e40f2db36f706ce2e10e74 Mon Sep 17 00:00:00 2001 From: Shahzaib Ibrahim Date: Wed, 10 Dec 2025 14:32:07 +0100 Subject: [PATCH] [GTK] Replaceing usages of Display#getDPI from gtk Having the scale factor being based on the screen DPI leads to unexpected result e.g. Image too big/small. Having a screen dpi independent factor leads to consistent results. --- .../gtk/org/eclipse/swt/graphics/Font.java | 11 ++++++----- .../gtk/org/eclipse/swt/widgets/Display.java | 3 ++- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Font.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Font.java index a394f1090ae..fc0e0a2a3e4 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Font.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Font.java @@ -184,15 +184,15 @@ public boolean equals(Object object) { */ public FontData[] getFontData() { if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - + final int DOTS_PER_INCH = 96; long family = OS.pango_font_description_get_family(handle); int length = C.strlen(family); byte[] buffer = new byte[length]; C.memmove(buffer, family, length); String name = new String(Converter.mbcsToWcs(buffer)); float height = (float)OS.pango_font_description_get_size(handle) / OS.PANGO_SCALE; - Point dpi = device.dpi, screenDPI = device.getScreenDPI(); - float size = height * screenDPI.y / dpi.y; + Point dpi = device.dpi; + float size = height * DOTS_PER_INCH / dpi.y; int pangoStyle = OS.pango_font_description_get_style(handle); int pangoWeight = OS.pango_font_description_get_weight(handle); int style = SWT.NORMAL; @@ -254,8 +254,9 @@ public int hashCode() { void init(String name, float height, int style, byte[] fontString) { if (name == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); if (height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - Point dpi = device.dpi, screenDPI = device.getScreenDPI(); - float size = height * dpi.y / screenDPI.y; + final int DOTS_PER_INCH = 96; + Point dpi = device.dpi; + float size = height * dpi.y / DOTS_PER_INCH; if (fontString != null) { handle = OS.pango_font_description_from_string (fontString); if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java index 132f293b132..7e04d318710 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java @@ -5053,7 +5053,8 @@ String debugInfoForIndex(long index) { } void dpiChanged(int newScaleFactor) { - DPIUtil.setDeviceZoom (DPIUtil.mapDPIToZoom(getDPI().x * newScaleFactor)); + final int DOTS_PER_INCH = 96; + DPIUtil.setDeviceZoom (DPIUtil.mapDPIToZoom(DOTS_PER_INCH * newScaleFactor)); Shell[] shells = getShells(); for (int i = 0; i < shells.length; i++) { shells[i].layout(true, true);