Is there a way to get the real, physical, bounding...
# compose
a
Is there a way to get the real, physical, bounding box of a character or a line from a
TextLayoutResult
?
getBoundingBox
returns
Copy code
Rect.fromLTRB(0.0, 0.0, 15.4, 33.0)
Rect.fromLTRB(15.4, 0.0, 32.6, 33.0)
Rect.fromLTRB(32.6, 0.0, 48.3, 33.0)
on a string like
abc
, but obviously the real bounding box’s top of these charaters is not 0.
r
To get pixel-level bounding boxes you have to go through the graphics APIs but I don’t know if the necessary APIs have been exposed in Compose. On Android you’d use a Paint object to measure the text or turn it into a Path and then get the path’s bounds.
Having a text -> Path API in Compose would make sense as it can be used for many things including your use case
a
I see, thanks.
z
Something that could potentially be added to TextMeasurer or TextLayoutResult APIs, worth a feature request