egui icon indicating copy to clipboard operation
egui copied to clipboard

Fix some monospace fonts spacing being non-monospace

Open alphaqu opened this issue 1 year ago • 4 comments

On fonts like Jetbrains Mono the rounding to the closest pixel after every glyph made the spacing between the characters non-monospace. This fixes that issue by rounding the glyph location instead of the cursor x position which affects the future characters in a non-expected way.

alphaqu avatar Oct 18 '22 14:10 alphaqu

I tried this out with the default font with pixels_per_point = 1.15.

Before:

old-rounding

After:

new-rounding

The new code produces some bad kerning in many places: Screen Shot 2022-10-18 at 17 17 37

Screen Shot 2022-10-18 at 17 18 44

Screen Shot 2022-10-18 at 17 18 53

emilk avatar Oct 18 '22 15:10 emilk

A possible fix might be to only apply this fix on monospace fonts as those are the ones which need this fix to be quote on quote "monospaced".

alphaqu avatar Oct 18 '22 15:10 alphaqu

Another solution to this problem is to provide the glyph width correctly in the first place. Rendering rounds the glyph_width which makes it be different than the application (for example a cursor drawer). Just rounding the glyph_width on the getter makes the behavior consistent across the codebase.

I originally missjudged my issue. I thought the drawer was messing up the spacings but it was just using a different glyph width to fix the spacing.

alphaqu avatar Oct 18 '22 16:10 alphaqu

@alphaqu could you try the patch in #2490? I don't have an app using Jetbrains Mono, and I'm not exactly sure what I should be looking for to compare between actual and expected rasterization because there are no screenshots here.

The linked patch may address the issue you had if your pixels_per_point is greater than 1.0. (I.e. on a high DPI display.)

parasyte avatar Dec 21 '22 21:12 parasyte