-
Notifications
You must be signed in to change notification settings - Fork 185
Use font zoom in stringExtent and textExtent #2306
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use font zoom in stringExtent and textExtent #2306
Conversation
Previously, stringExtent calculated the width of a string in pixels using GC.getZoom(), which could lead to inconsistencies if the provided font had a different zoom level. This change ensures that the pixels-to-points conversion uses the zoom of the specified font.
fedejeanne
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the contribution, @arunjose696 !
In general it looks good and I couldn't find any regressions with this PR. I just have a question regarding the necessity of one change.
Also, have you by any chance tried to make the font in the line number ruler smaller so that it has the same size of the code? I assume this would mean that the height of lines in the code would also change, making the code look more compact (which I like) but this is just a thought.
bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/GC.java
Show resolved
Hide resolved
ShahzaibIbrahim
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes looks good to me. I also tested it with quarter autoScale (175% -> 150%). Functionality is as expected.
I tried this, but it turned out to be a bit tricky. The GC used to draw the line number ruler is created from a BufferedImage(which is a Image type), and it inherits the font zoom level from the last requested zoom for the image. This zoom is used by the GC for drawing. I haven’t found a straightforward way to reset the nativeZoom value of a GC that’s created from an image. For experimentation, I was able to make this work on the first draw of the line number ruler by explicitly calling BufferedImage.getImageData(LOWER_ZOOM) just before the GC was created, which as a side effect sets the currentZoom of the image to LOWER_ZOOM. So when the GC is created from that image, it uses the desired zoom. However, later when switching monitors, SWT will request a new image using the zoom specified by swt.autoScale. I feel this route would be much more complicated compared to current approach. |
|
I see. Thank you for the fix and the thorough response, @arunjose696 ! If the size of the font in the line number ruler becomes an issue then we can circle back to the analysis. But I have no strong opinion about it and there are other things in more dire need of attention right now. I accepted your fix. |
Previously, stringExtent calculated the width of a string in pixels using GC.getZoom(), which could lead to inconsistencies if the provided font had a different zoom level. This change ensures that the pixels-to-points conversion uses the zoom of the specified font.
Fixes #2311
Reproduction Steps
On a 100% monitor, set these parameters:
Screenshots
Current Behaviour
With This Change
Have tested the changes on zooms 100,150,200&225 with
-Dswt.autoScale=150 ,100 &200,