diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/DPIUtil.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/DPIUtil.java index bc55a3aac1..eff027fa77 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/DPIUtil.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/DPIUtil.java @@ -125,6 +125,12 @@ public static float pixelToPoint(float size, int zoom) { return (size / scaleFactor); } +public static double pixelToPoint(double size, int zoom) { + if (zoom == 100 || size == SWT.DEFAULT) return size; + double scaleFactor = getScalingFactorD (zoom, 100); + return (size / scaleFactor); +} + /** * Auto-scale image with ImageData @@ -208,6 +214,13 @@ public static float getScalingFactor(int zoom) { } +public static double getScalingFactorD(int targetZoom, int currentZoom) { + if (targetZoom <= 0) { + targetZoom = deviceZoom; + } + return targetZoom / (double) currentZoom; +} + public static float getScalingFactor(int targetZoom, int currentZoom) { if (targetZoom <= 0) { targetZoom = deviceZoom; diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/FontMetrics.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/FontMetrics.java index ae6298be4c..5eeb08b765 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/FontMetrics.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/FontMetrics.java @@ -108,7 +108,7 @@ public int getAscent() { * @since 3.107 */ public double getAverageCharacterWidth() { - return getAverageCharWidth(); + return DPIUtil.pixelToPoint((double)handle.tmAveCharWidth, getZoom()); } /**