Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get a (Android.Graphics) Path of a String

I cannot find any way to retrieve a Path object representing a string. Does it exist? A list of the necessary points would be enough, but I guess, internally, a path is used.

For example in GDI+ there is:

GraphicsPath p = new GraphicsPath(); 
p.AddString("string");

From there any point of the "drawn string" can be accessed and modified.

PS: I do not mean drawing a text along a path.

like image 383
Mr.Pe Avatar asked Jul 12 '12 11:07

Mr.Pe


1 Answers

I've spent quite a long time solving this problem (to draw vectorized text in OpenGL) and had to dig deep into libSkia sources. And it turned out pretty simple:

Indeed, canvas uses paths internally and it converts text to vector paths using SkPaint's getTextPath() method. Which is, luckily, exposed at Java side in public API as android.graphics.Paint.getTextPath(). After that, you can read Path back with android.graphics.PathMeasure.

Unfortunately, you can't read exact drawing commands, but you can sample the curve pretty closely using something like bisection.

like image 171
Dmitry Avatar answered Nov 16 '22 19:11

Dmitry