Skip to content

Commit fdbb769

Browse files
HeikoKlarefedejeanne
authored andcommitted
[Win32] Use exact selected font size from FontDialog
The FontDialog implementation creates a font handle based on the selection in the dialog to extract information about the font size out of that created font. Due to point/pixel conversion and roundings that depend on the current DPI (affected by the primary monitor zoom), the resulting font size selected differs from what the user has selected. For example, when selecting a 10pt font, the result of the dialog will contain a height of 9.75pt on a 100% monitor and of 10.2pt on a 125% monitor. At the same time, the dialog manages the logically selected size, i.e., in the given scenario the selected 10pt, which could be used instead. This change replaces the complex and imprecise font height extraction logic with a simple read of the actual value selected by the user.
1 parent f878858 commit fdbb769

File tree

1 file changed

+1
-30
lines changed
  • bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets

1 file changed

+1
-30
lines changed

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

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -249,36 +249,7 @@ public FontData open () {
249249
if (success) {
250250
LOGFONT logFont = new LOGFONT();
251251
OS.MoveMemory(logFont, lpLogFont, LOGFONT.sizeof);
252-
253-
/*
254-
* This will not work on multiple screens or for printing. Should use DC for the
255-
* proper device.
256-
*/
257-
int logPixelsY = getDPI();
258-
int pixels = 0;
259-
long hDC = OS.GetDC(0);
260-
if (logFont.lfHeight > 0) {
261-
/*
262-
* Feature in Windows. If the lfHeight of the LOGFONT structure is positive, the
263-
* lfHeight measures the height of the entire cell, including internal leading,
264-
* in logical units. Since the height of a font in points does not include the
265-
* internal leading, we must subtract the internal leading, which requires a
266-
* TEXTMETRIC, which in turn requires font creation.
267-
*/
268-
long hFont = OS.CreateFontIndirect(logFont);
269-
long oldFont = OS.SelectObject(hDC, hFont);
270-
TEXTMETRIC lptm = new TEXTMETRIC();
271-
OS.GetTextMetrics(hDC, lptm);
272-
OS.SelectObject(hDC, oldFont);
273-
OS.DeleteObject(hFont);
274-
pixels = logFont.lfHeight - lptm.tmInternalLeading;
275-
} else {
276-
pixels = -logFont.lfHeight;
277-
}
278-
OS.ReleaseDC(0, hDC);
279-
280-
float points = pixels * 72f / logPixelsY;
281-
fontData = FontData.win32_new(logFont, points);
252+
fontData = FontData.win32_new(logFont, lpcf.iPointSize / 10f);
282253
if (effectsVisible) {
283254
int red = lpcf.rgbColors & 0xFF;
284255
int green = (lpcf.rgbColors >> 8) & 0xFF;

0 commit comments

Comments
 (0)