How to get stable layout when zooming text with CanvasKit?

136 views
Skip to first unread message

Yifeng Wang

unread,
May 26, 2021, 1:05:11 AM5/26/21
to skia-discuss
Hi, I'm using CanvasKit to render multi-line text. When user performs zooming, the text width and font size are scaled together. But in this case, the layout result is unstable, jumps in line height or line break can be observed. See online fiddle:


Is this behavior expected (I filed an issue at https://bugs.chromium.org/p/skia/issues/detail?id=12042 but not sure if it's a bug)? Text scaling in browser doesn't have this issue, can we achieve similar result with some workaround? Thanks.

Regards
Yifeng Wang

Shachar Langbeheim

unread,
May 26, 2021, 3:22:01 AM5/26/21
to skia-discuss
You can convert the text to a SkPath at a constant font size, and then scale the path. 
See this discussion:
https://groups.google.com/g/skia-discuss/c/0P6S8gkx3n8/m/Px_6T15tBgAJ?pli=1

--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/skia-discuss/3c5a326c-bf5f-436b-a631-558f0fa372c4n%40googlegroups.com.

Mike Reed

unread,
May 26, 2021, 7:02:05 AM5/26/21
to skia-d...@googlegroups.com
Very nice test case!

Skia has settings (on the SkFont) that can smooth this out, but we may not have exposed them all to CanvasKit yet.

Have you tried font.setSubpixel(true) or font.setLinearMetrics(true) ?

We also have a baseline_snap setting which is not exposed. It may be needed to fixed the vertical snapping...


Ben Wagner

unread,
May 26, 2021, 10:23:42 AM5/26/21
to skia-d...@googlegroups.com
Also "font.setHinting(CanvasKit.FontHinting.None);". Though "Slight"
should also work (it tends to hint in only the vertical direction). If
hinting is Normal or Full then hinting will happen, which expressly
trades off outline scalability for legibility.
> To view this discussion on the web visit https://groups.google.com/d/msgid/skia-discuss/CAERTzqzKiEySWy2gOo%3DCSoe7do%3DBNp2qKn7cp%2B-vEms0aJNzEA%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages