Reputation: 10806
I am working with vector images in Android and I need access to the actual glyph data. Like the Bezier curves that make up the font. Is there any way to access this data? I've debated converting fonts to SVG and reading those because I already have that ability. Or coding up a custom TTF parser. But, these solutions would also require a download or adding a bunch of extra TTF or SVG assets. And a perhaps a lot of work that might not be needed.
Is there some way to get access to the glyph data of a given font?
That failing, is there some way to get access to the actual ttf (or whatever font type Android uses) files?
I am working directly with vector images and manipulating the actual curves used to build vector images. Which means need actual access to the curves. Which curve goes where in order to build this particular letter. I don't want a bitmap or what harfbuzz within Android finally comes up with and pushes into GL, I want access to the actual curves used to make the font. Which means I can write my own font parser and include my own font assets, but all of that is built into Android but at the C level.
I would like to not have to include a font parser or a bunch of fonts. Android has both of those things included, are they just unreachable from the java level or is there perchance some trick?
I need the vector image from the font. Like the vector image of a letter A. The lines and curves used to build the letter. I don't need any of the kerning or em data, or missing glyphs info. And I'd like access to that without having to import an entire parser into my program and a bunch of font assets just to get the vector images the letters of the fonts are made out of.
Upvotes: 1
Views: 1472
Reputation: 347
Here is solution for your requirement. Please read on.
Fonts are mostly outlines only. That is say in the letter "H" in your post above the dotted line is the path of the glyph. If you give a color to the strokes then you see the outline of the letter in that color. If you fill it then the letter appears in that color solidly.
You can use "font editor" of fontforge organisation to get the path data. The software of fontforge is freeware.(They accept donations). If you want center-line and not outline then you have to draw the centre-line and then export it as SVG file. You will be exporting single letter at a time. You can open the SVG file in wordpad and take the pathdata of your centre-line. However curved the glyph is you can easily draw the centre-line. Sometimes you can even improve the shape of the glyph in your centre-line. If it is centre-line then the strokes when you draw again will be of uniform thickness. Not like the original glyph with gradually varying thickness of the line(centre-line). You can master the font editor just in a couple of days.
See the glyph below. Copy and paste the code below in an xml file in Android Studio and see the glyph drawn in blue color.That is centreline of thickness 32dp and not outline and fill.
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="600dp"
android:height="600dp"
android:viewportWidth="800.0"
android:viewportHeight="800.0">
<path
android:pathData="M 162 8
q -07 00 -41 26
q -34 27 -50 64
q -25 59 -19 117
q 07 70 53 121
q 57 63 151 62
q 87 -01 140 -66
q 46 -55 48 -142
q 01 -56 -34 -105
q -38 -52 -77 -70
l -29 -11
q 16 -01 31 -02
q 59 -01 119 -02 "
android:strokeLineCap="round"
android:strokeColor="#f00f"
android:fillColor="#00000000"
android:strokeWidth="32"/>
</vector>
Upvotes: 1