diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Device.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Device.java index 429bbc71473..05f4157b6b2 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Device.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Device.java @@ -260,9 +260,9 @@ void checkGDIP() { protected void create (DeviceData data) { } -int computePixels(float height) { +int computePixels(float height, int zoom) { long hDC = internal_new_GC (null); - int pixels = -(int)(0.5f + (height * OS.GetDeviceCaps(hDC, OS.LOGPIXELSY) / 72f)); + int pixels = -(int)(0.5f + (height / calculateFontConversionFactor(hDC, zoom))); internal_dispose_GC (hDC, null); return pixels; } @@ -271,9 +271,7 @@ float computePoints(LOGFONT logFont, long hFont) { return computePoints(logFont, hFont, SWT.DEFAULT); } -float computePoints(LOGFONT logFont, long hFont, int zoom) { - long hDC = internal_new_GC (null); - +private float calculateFontConversionFactor(long hDC, int zoom) { float conversionFactor = 72f; if (isAutoScalable() && zoom != SWT.DEFAULT) { // For auto scalable devices we need to use a dynamic @@ -282,6 +280,13 @@ float computePoints(LOGFONT logFont, long hFont, int zoom) { } else { conversionFactor /= OS.GetDeviceCaps(hDC, OS.LOGPIXELSY); } + return conversionFactor; +} + +float computePoints(LOGFONT logFont, long hFont, int zoom) { + long hDC = internal_new_GC (null); + + float conversionFactor = calculateFontConversionFactor(hDC, zoom); int pixels = 0; if (logFont.lfHeight > 0) { /* diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Font.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Font.java index 12cdecdf77c..cd4056de17a 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Font.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Font.java @@ -236,14 +236,7 @@ void init (FontData fd) { if (fd == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); LOGFONT logFont = fd.data; int lfHeight = logFont.lfHeight; - logFont.lfHeight = device.computePixels(fd.height); - - int primaryZoom = extractZoom(device); - if (zoom != primaryZoom) { - float scaleFactor = 1f * zoom / primaryZoom; - logFont.lfHeight *= scaleFactor; - } - + logFont.lfHeight = device.computePixels(fd.height, zoom); handle = OS.CreateFontIndirect(logFont); logFont.lfHeight = lfHeight; if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/ScalingSWTFontRegistry.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/ScalingSWTFontRegistry.java index 1625996f465..06c7f49e106 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/ScalingSWTFontRegistry.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/ScalingSWTFontRegistry.java @@ -54,8 +54,7 @@ private Font getScaledFont(int targetZoom) { private Font scaleFont(int zoom) { FontData fontData = baseFont.getFontData()[0]; int baseZoom = computeZoom(fontData); - int zoomScaleFactor = Math.round(1.0f * zoom / baseZoom); - fontData.data.lfHeight *= zoomScaleFactor; + fontData.data.lfHeight = Math.round(1.0f * fontData.data.lfHeight * zoom / baseZoom); Font scaledFont = Font.win32_new(device, fontData, zoom); addScaledFont(zoom, scaledFont); return scaledFont;