[Win32] Use exact selected font size from FontDialog #2435
+1
−30
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Note that this will not have any visible impact, as font sizes are rounded anyway, such that all the imprecise values (such as 9.75pt or 10.2pt) will still lead to a 10pt font.
How to reproduce
The behavior can be reproduced by any FontDialog, such as in
Snippet133
:System.out.println(fontData.height)
) of Snippet 133 after opening the dialog:eclipse.platform.swt/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet133.java
Line 140 in 93a484e
Snippet133
and open "Font" in the "File" menuWithout the change you will see 9.75pt on a 100% monitor, with the change you will see 10pt on a 100% (and any other) monitor.