Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Non-uniform text scaling in Skia (FreeType 2 back-end)

My issue is that during smooth scaling applied to Skia canvas (with concat method) the text appears to scale in "spurts", non-uniformly. The issue is particularly evident on Android platform with FreeType 2 back-end.

I believe this is how general text scaling works in Skia - first apply text size to font engine, then extract glyph bitmap and transform it with "remainder" matrix to achieve the desired final size. But somehow final remaining scaling is not applied which results in such spurts amidst transition between integral values of text size. The same thing with pure Java/Android canvas appears to work impeccably (text scales smoothly).

My question is how can I fix that behavior? Maybe there is some build configuration flag I could tweak, maybe SkPaint runtime flag?

Skia revision is m59.

like image 301
Vsevolod Ganin Avatar asked Sep 19 '17 10:09

Vsevolod Ganin


People also ask

What is non-uniform scaling?

Non-uniform scaling resizes selected objects in a non-uniform manner, allowing you to choose the scaling to be applied for each axis. Arcs are converted to curves and primitive surfaces to power surfaces by default. To non-uniformly scale an object:

Does skiasharp use DirectWrite or FreeType?

SkiaSharp also supports using HarfBuzz to properly shape the text. The current version uses DirectWrite on Windows, as far as I know, Chrome uses Freetype.

Does skiasharp support text hinting?

SkiaSharp also supports using HarfBuzz to properly shape the text. The current version uses DirectWrite on Windows, as far as I know, Chrome uses Freetype. Some shared code might help to investigate this further. Sorry, something went wrong. It might also be that Chrome is making use of some of the text hinting and subpixel things...

How to non-uniformly scale an object in AutoCAD?

To non-uniformly scale an object: Select the objects to scale. Tip: To scale a workplane with the objects, select the workplane after starting selecting the scale option.


1 Answers

I don't know Skia, but generally when I see this behavior with scaling text, it's because you're casting your scaling float to an int.

float scale = someValue;
int someOtherVar = scale;
... some scaling math on someOtherVar...
text.setScale(someOtherVar)

This will cause the described behavior

Never convert any scaling variables to int's until the very last step.

like image 56
NapkinTrout Avatar answered Oct 11 '22 07:10

NapkinTrout