Considering all those vector graphics available in a font file, we should be able to extract word glyph outlines and translate them into SVG format. Do we need to read TTF or OTF specification before we start extracting? Not really, there are some utilities and libraries can help us to achieve this goal.
Library | Language | Description |
---|---|---|
Apache™ Batik | Java | Batik is a SVG toolkit which include a utility called ttf2svg: lets you convert a range of characters from a TrueType Font into the SVG font format. |
FreeType Project | C/C++ | FreeType is a freely available software library to render fonts. |
ttf2svg example can be found here: https://xmlgraphics.apache.org/batik/tools/font-converter.html
FreeType supplies a example to extract vector glyph and translate into SVG: https://www.freetype.org/freetype2/docs/tutorial/example5.cpp
The example from FreeType is too simple and available for one English letter. But it can be easily modified to achieve other purpose, such as handling Chinese words and reading from text file and writing vector information into JSON or SVG file. You can find this modified version here: font2svg.cpp. This program need a word.txt as input and gonna generate a word.json and a word.svg at the same directory after running. You can has any words you want to extract in word.txt and make sure words are available in the TTF or OTF file you supplied to the program.
g++ -o font2svg.exe font2svg.cpp -I/usr/include/freetype2 -I/usr/include -L/lib -lfreetype.dll -lz
If you are working in Windows environment, Cygwin can help you to compile and link the example. Just remember to install Devel at least.
Please remember, some fonts come from open source projects and some fonts have their own copyrights or licence requirements. Make sure you are using libraries to treat them in a correct and respectful way.
没有评论:
发表评论