Skip to content

Commit 9ce68ae

Browse files
akoch-yattaHeikoKlare
authored andcommitted
[win32] fix to use zoom dpi for fonts via display
With commit cd8bb13 we adapted the calcuation how to scale up fonts to fix the calculation for fonts used by the Printer. This introduced an issue if monitor-specific scaling is active and the primary monitor zoom is changed, because two different calculation were mixed now. This commit fixes this inconsistency.
1 parent df1c412 commit 9ce68ae

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Device.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,9 @@ void checkGDIP() {
260260
protected void create (DeviceData data) {
261261
}
262262

263-
int computePixels(float height) {
263+
int computePixels(float height, int zoom) {
264264
long hDC = internal_new_GC (null);
265-
int pixels = -(int)(0.5f + (height * OS.GetDeviceCaps(hDC, OS.LOGPIXELSY) / 72f));
265+
int pixels = -(int)(0.5f + (height / calculateFontConversionFactor(hDC, zoom)));
266266
internal_dispose_GC (hDC, null);
267267
return pixels;
268268
}
@@ -271,9 +271,7 @@ float computePoints(LOGFONT logFont, long hFont) {
271271
return computePoints(logFont, hFont, SWT.DEFAULT);
272272
}
273273

274-
float computePoints(LOGFONT logFont, long hFont, int zoom) {
275-
long hDC = internal_new_GC (null);
276-
274+
private float calculateFontConversionFactor(long hDC, int zoom) {
277275
float conversionFactor = 72f;
278276
if (isAutoScalable() && zoom != SWT.DEFAULT) {
279277
// For auto scalable devices we need to use a dynamic
@@ -282,6 +280,13 @@ float computePoints(LOGFONT logFont, long hFont, int zoom) {
282280
} else {
283281
conversionFactor /= OS.GetDeviceCaps(hDC, OS.LOGPIXELSY);
284282
}
283+
return conversionFactor;
284+
}
285+
286+
float computePoints(LOGFONT logFont, long hFont, int zoom) {
287+
long hDC = internal_new_GC (null);
288+
289+
float conversionFactor = calculateFontConversionFactor(hDC, zoom);
285290
int pixels = 0;
286291
if (logFont.lfHeight > 0) {
287292
/*

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Font.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -236,14 +236,7 @@ void init (FontData fd) {
236236
if (fd == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
237237
LOGFONT logFont = fd.data;
238238
int lfHeight = logFont.lfHeight;
239-
logFont.lfHeight = device.computePixels(fd.height);
240-
241-
int primaryZoom = extractZoom(device);
242-
if (zoom != primaryZoom) {
243-
float scaleFactor = 1f * zoom / primaryZoom;
244-
logFont.lfHeight *= scaleFactor;
245-
}
246-
239+
logFont.lfHeight = device.computePixels(fd.height, zoom);
247240
handle = OS.CreateFontIndirect(logFont);
248241
logFont.lfHeight = lfHeight;
249242
if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);

0 commit comments

Comments
 (0)