Font rendering broken
Kirottu opened this issue · comments
What OS are you on?
I use linux, and wayland if that is relevant.
IFAIK Raqote generally delegates text rendering to the developer. I've encountered this a few times. Here's the approach I used
Would it be fairly easy to integrate cosmic-text
with raqote to get better text support?
At least as a proof-of-concept, my colleague got it working in a few minutes:
https://github.com/Foundation-Devices/raqote-cosmic-text/blob/main/src/main.rs
I was playing around with raqote on linux, and I noticed this issue on the various fonts I tried. And when I dug deeper, I found that it seems like that the advance width for the glyphs in draw_text
has the wrong scaling factor.
Per the font-kit documentation, font.advance(id)
returns a distance in font units, and this TrueType documentation says that the scaling factor to turn font units into pixels is point_size * resolution / (72 * units_per_em)
. units_per_em
is a font-specific value, which you can get from font-kit with font.metrics().units_per_em
. The display resolution isn't available to raqote, but at least one piece of code in font-kit always uses 72 dpi. Fixing this results in text that does appear properly rendered.
No part of this scaling factor is platform-specific, or specific to the underlying font technology (i.e. FreeType vs Core Text), so I wonder why this comment implies that it does work on some platforms. If it's related to the screen resolution, I wonder why font-kit hardcodes 72 dpi. Otherwise, I can only conclude that if the current scaling factor really does work on some platforms, then font-kit might be buggy in those platforms.
I was playing around with raqote on linux, and I noticed this issue on the various fonts I tried. And when I dug deeper, I found that it seems like that the advance width for the glyphs in
draw_text
has the wrong scaling factor.Per the font-kit documentation,
font.advance(id)
returns a distance in font units, and this TrueType documentation says that the scaling factor to turn font units into pixels ispoint_size * resolution / (72 * units_per_em)
.units_per_em
is a font-specific value, which you can get from font-kit withfont.metrics().units_per_em
. The display resolution isn't available to raqote, but at least one piece of code in font-kit always uses 72 dpi. Fixing this results in text that does appear properly rendered.No part of this scaling factor is platform-specific, or specific to the underlying font technology (i.e. FreeType vs Core Text), so I wonder why this comment implies that it does work on some platforms. If it's related to the screen resolution, I wonder why font-kit hardcodes 72 dpi. Otherwise, I can only conclude that if the current scaling factor really does work on some platforms, then font-kit might be buggy in those platforms.
To reiterate, draw_text
is not meant to be used. It's meant to do the bare minimum