Why is there no `drawText` on the `Canvas` interface?
m
Why is there no
drawText
on the
Canvas
interface?
j
Seems like a layering problem. Drawing would then have to involve knowledge of the entire text stack. Ultimately text and a font bottom out in drawing commands. It's like asking why there is no drawJpeg or drawSvg. You want something at a higher level of abstraction to handle the high-level semantics of the thing, and then issue low-level drawing calls to the canvas.
m
Hmm, I guess so. I noticed there’s a
drawText
extension function on
DrawScope
so was just wondering why there wouldn’t also be a
Canvas.drawText
extension function.
j
DrawScope is at a much higher level of abstraction since you're above the layout system now which would be required for a text engine to do things like wrapping
m
I’ve got some custom drawing logic (mostly `Path`s but also some shapes and text). Should I be building that on top of
Canvas
or
DrawScope
? It’s certainly a lot easier to do the latter, since I no longer need to deal with
Paint
(and especially not Android-only
TextPaint
) and no longer need to dip into
Canvas.nativeCanvas
. OTOH, for the caller,
DrawScope
, I guess, is more tricky to set up being a higher level of abstraction. BTW, I don’t need to do things like text wrapping. The only text is always one or two digits placed in a circle.
z
feel free to file a feature request