https://kotlinlang.org logo
Title
p

PHondogo

04/08/2023, 1:18 PM
Hello! Is there multiplatform way to draw text on Canvas?
l

Loney Chou

04/08/2023, 4:40 PM
Not on Canvas, but we have
DrawScope.drawText
extension.
z

Zach Klippenstein (he/him) [MOD]

04/11/2023, 8:58 PM
We recommend using TextMeasurer instead of using (multi)paragraph directly, since it does some more caching. Cc @Halil Ozercan
h

Halil Ozercan

04/13/2023, 1:57 AM
Yes, it could be quite expensive to create a Paragraph/MultiParagraph instance in DrawScope and draw without any kind of caching mechanism in place. TextMeasurer comes with an internal cache so you can call measure in whichever phase you need. Also,
DrawScope.drawText(textMeasurer, "Hello, World!")
is a handy way to merge measure and draw calls. All of this is ofc multiplatform.