Text resizing isn't linear

113 views
Skip to first unread message

שחר לנגבהיים

unread,
Nov 10, 2019, 11:16:54 AM11/10/19
to skia-discuss
Hi,
As this video shows, some fonts don't scale linearly on all continuous values when drawn using SkTextBlob - there's a subtle jitter when the size "jumps" between some values.
From what I read, this isn't necessarily a bug - some fonts just don't scale linearly. 
I do need linear scaling, and I found a suggestion - to extract the glyph paths for a certain size, and scale them manually.

Has someone tried to tackle such an issue with Skia? I couldn't understand from the API how to extract a glyph run for a combination of font and text, or how to scale a glyph run. If anyone has any pointers, I'd really appreciate the help.
 

Ben Wagner

unread,
Nov 11, 2019, 9:36:08 AM11/11/19
to skia-d...@googlegroups.com
If you want something close to linear scaling for text you'll want to
set hinting to none, set baseline snapping to false, set subpixel to
true, and set linear metrics to true. This will generally give you
something close. In your example, it appears what you are seeing is
the baseline snapping. For full animation you may still see some
wiggle. We're currently working on a way to work around that (it's a
trade-off of performance vs accuracy for animations).
> --
> 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/69b3f098-c44c-48ed-99f2-65ed516ed045%40googlegroups.com.

Ben Wagner

unread,
Nov 11, 2019, 9:37:57 AM11/11/19
to skia-d...@googlegroups.com
Note that there is an issue with trying to draw from paths, which is
that not all glyphs have paths. In particular, color glyphs may be
bitmaps or a set of colored paths (or something even more complex).

Shachar Langbeheim

unread,
Nov 11, 2019, 11:14:34 AM11/11/19
to skia-discuss
Thanks for the help!
Is there a branch in which I can test this thing you're working on?

Ben Wagner

unread,
Nov 11, 2019, 12:45:46 PM11/11/19
to skia-d...@googlegroups.com
Not at the moment, there is
https://skia-review.googlesource.com/c/skia/+/252927 , which is
probably the right API, but we will need to actually implement it
differently.
> To view this discussion on the web visit https://groups.google.com/d/msgid/skia-discuss/CA%2B_KjGa1Dwvg3ENB6S1QhTb5X3S0eCNGqsiWtoLYPDbJwa8J%3Dw%40mail.gmail.com.

Shachar Langbeheim

unread,
Nov 17, 2019, 3:14:48 AM11/17/19
to skia-discuss
Thanks, your suggestion has improved things, but as you predicted it hasn't completely solved the issue.
Compare this to this. The wiggle seems to have disappeared, but the animation still isn't smooth, and also after some point the subpixel edging causes a stroke to appear. 
Are there any other avenues you can think of?

Shawn Riordan

unread,
Nov 17, 2019, 10:19:02 AM11/17/19
to skia-discuss
If the text is not changing, you could just draw the text and shadow once (at highest scale / resolution) into an off-screen surface.  Then grab the image from that surface. Then the animation would be a bunch of calls to SkCanvas::drawImage() using a different matrix each time.
>> > To unsubscribe from this group and stop receiving emails from it, send an email to skia-d...@googlegroups.com.

>> > To view this discussion on the web visit https://groups.google.com/d/msgid/skia-discuss/69b3f098-c44c-48ed-99f2-65ed516ed045%40googlegroups.com.
>>
>> --
>> 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-d...@googlegroups.com.

>> To view this discussion on the web visit https://groups.google.com/d/msgid/skia-discuss/CAE1kqqQ0dDBST3zTN3YQcwhew2E7WKt%3D7K%3DnHGOx59x%3DiBwAJA%40mail.gmail.com.
>
> --
> 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-d...@googlegroups.com.

> To view this discussion on the web visit https://groups.google.com/d/msgid/skia-discuss/CA%2B_KjGa1Dwvg3ENB6S1QhTb5X3S0eCNGqsiWtoLYPDbJwa8J%3Dw%40mail.gmail.com.

--
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-d...@googlegroups.com.

Shachar Langbeheim

unread,
Nov 17, 2019, 1:27:53 PM11/17/19
to skia-discuss
This solution is suboptimal for several reasons - for example, the highest scale / resolution won't necessarily scale well for every smaller resolution, and it means that I need to keep a separate offscreen surface for every single text.
I think that scaling the path is a better way to go, once I understand how to extract the path from a text blob.

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/9bb1520c-2680-48d0-9a39-cf58d5f8e0d6%40googlegroups.com.

Shachar Langbeheim

unread,
Dec 8, 2019, 4:47:29 AM12/8/19
to skia-discuss
If anyone is interested, using SkTextUtils::GetPath and then transforming the path seems to do the trick.
Reply all
Reply to author
Forward
0 new messages