linebender / piet

An abstraction for 2D graphics.
Apache License 2.0
1.24k stars 93 forks source link

[How to] How to measure a single character with some font ? #467

Open eric5f3759df opened 2 years ago

eric5f3759df commented 2 years ago

How to do this in druid? like some measure text function in some 2d graphic lib. this feature needed by developing complex rich text app like ms word. return non-mono char width, font height, ascent, descent, baseline etc.

cmyr commented 2 years ago

we don't provide direct access to character information, and the actual visible bounds of a glyph may not correspond to the reported layout metrics.

You can get this information the usual way, though, by creating a TextLayout and then accessing metrics through the methods on that object.