Skip to content

Commit bc5cdb9

Browse files
committed
Removal for OS.LOGPIXELS* usage where possible #62
This commit removes the usage of OS.LOGPIXELS* in a few places in the code wherever these values can be obtained using other means as the OS.LOGPIXELS provides the dpi values of the primary monitor at the app-startup time. It's usage have been either removed completely (wherever possible) or have been replaced by DPI-Aware OS.GetDpiForMonitor calls. contributes to #62 and #127
1 parent df1c412 commit bc5cdb9

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/ScalingSWTFontRegistry.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ private void addScaledFont(int targetZoom, Font scaledFont) {
7777

7878
@Override
7979
public Font getSystemFont(int zoom) {
80-
ScaledFontContainer container = getOrCreateBaseSystemFontContainer(device);
80+
ScaledFontContainer container = getOrCreateBaseSystemFontContainer(device, zoom);
8181

8282
Font systemFont = container.getScaledFont(zoom);
8383
if (systemFont != null) {
@@ -89,16 +89,12 @@ public Font getSystemFont(int zoom) {
8989
return systemFont;
9090
}
9191

92-
private ScaledFontContainer getOrCreateBaseSystemFontContainer(Device device) {
92+
private ScaledFontContainer getOrCreateBaseSystemFontContainer(Device device, int zoom) {
9393
ScaledFontContainer systemFontContainer = fontKeyMap.get(KEY_SYSTEM_FONTS);
9494
if (systemFontContainer == null) {
95-
long hDC = device.internal_new_GC (null);
96-
int dpiX = OS.GetDeviceCaps (hDC, OS.LOGPIXELSX);
97-
device.internal_dispose_GC (hDC, null);
98-
int primaryZoom = DPIUtil.mapDPIToZoom(dpiX);
99-
long systemFontHandle = createSystemFont(primaryZoom);
100-
Font systemFont = Font.win32_new(device, systemFontHandle, primaryZoom);
101-
systemFontContainer = new ScaledFontContainer(systemFont, primaryZoom);
95+
long systemFontHandle = createSystemFont(zoom);
96+
Font systemFont = Font.win32_new(device, systemFontHandle, zoom);
97+
systemFontContainer = new ScaledFontContainer(systemFont, zoom);
10298
fontHandleMap.put(systemFont.handle, systemFontContainer);
10399
fontKeyMap.put(KEY_SYSTEM_FONTS, systemFontContainer);
104100
}

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/FontDialog.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,14 +195,15 @@ public FontData open () {
195195
if (effectsVisible) {
196196
lpcf.Flags |= OS.CF_EFFECTS;
197197
}
198+
int [] dpiX = new int[1];
199+
int [] dpiY = new int[1];
200+
OS.GetDpiForMonitor(getParent().getMonitor().handle, OS.MDT_EFFECTIVE_DPI, dpiX, dpiY);
198201

199202
long lpLogFont = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, LOGFONT.sizeof);
200203
if (fontData != null && fontData.data != null) {
201204
LOGFONT logFont = fontData.data;
202205
int lfHeight = logFont.lfHeight;
203-
long hDC = OS.GetDC (0);
204-
int pixels = -(int)(0.5f + (fontData.height * OS.GetDeviceCaps(hDC, OS.LOGPIXELSY) / 72));
205-
OS.ReleaseDC (0, hDC);
206+
int pixels = -(int)(0.5f + (fontData.height * dpiY[0] / 72));
206207
logFont.lfHeight = pixels;
207208
lpcf.Flags |= OS.CF_INITTOLOGFONTSTRUCT;
208209
OS.MoveMemory (lpLogFont, logFont, LOGFONT.sizeof);
@@ -257,7 +258,7 @@ public FontData open () {
257258
* proper device.
258259
*/
259260
long hDC = OS.GetDC(0);
260-
int logPixelsY = OS.GetDeviceCaps(hDC, OS.LOGPIXELSY);
261+
int logPixelsY = dpiY[0];
261262
int pixels = 0;
262263
if (logFont.lfHeight > 0) {
263264
/*

0 commit comments

Comments
 (0)