hecrj / wgpu_glyph

A fast text renderer for wgpu (https://github.com/gfx-rs/wgpu)
https://docs.rs/wgpu_glyph
MIT License
443 stars 77 forks source link

Monospaced / fixed width font spacing #42

Closed antonok-edm closed 4 years ago

antonok-edm commented 4 years ago

It appears that the choice of anchor point for text positioning depends on the actual width of the text in pixels rather than the width of the glyphs. In general this is hard to notice, but it definitely causes issues with monospaced/fixed width fonts that are dynamically updated. For instance, consider a simple counter app, where the text of the current count is positioned with the following Layout:

wgpu_glyph::Layout::default_single_line()
    .h_align(wgpu_glyph::HorizontalAlign::Right)
    .v_align(wgpu_glyph::VerticalAlign::Center)

When the rightmost character of the text updates from a wide character (e.g. 0) to a narrow character (e.g. 1) or vice versa, there is a noticeable horizontal shift in the rest of the characters on the left.

hecrj commented 4 years ago

Yes, I have noticed this too.

However, wgpu_glyph doesn't contain any positioning/measurement logic. This logic lives in glyph-brush, a direct dependency.

A new glyph-brush version was released a couple of days ago, and I believe it may fix this. I will try to update the dependency this week. If it doesn't fix the problem, we should file an issue in glyph-brush.

hecrj commented 4 years ago

I tested it and this seems to be fixed by #43. Let me know!

antonok-edm commented 4 years ago

Awesome! I just tried it out and everything appears as expected now :smile: