Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get vectors from font

I am looking for a way to get vector form (points and curves) from characters, similar to what is described in this SO question but in Python instead of java. Anyone knows of a way?

like image 595
Tamar Avatar asked Dec 13 '25 01:12

Tamar


1 Answers

UPDATE

I just found-out a rather complete Python wrapper for the FreeType library:

  • docs: https://freetype-py.readthedocs.io/en/latest/
  • repo: https://github.com/rougier/freetype-py/

It is ctypes based, and pretty low level - but the examples bundled show clearly how it can be used including ways to get glyphs geometry described in lines and arcs and so on. FreeType itself can deal with any font file format you need.

original answer

I don know if people on the Java question actually got what they wanted - but this is something definetly non-trivial.

It may be possible that in Java as the font-rendering engine itself runs as a Java object inside the JVM. That is not the philosophy of Python - were low level things like renderign to screen is performed in native code, not by Python objects inside the interpreter VM.

So, while in Java one could hook up to the classes doing the actual renderign of characters and extract data from them, in Python this is separated from your actual code by several layers of code.

That difference explained, there is not y enough information on your question to give you any meaningful answer: What kind of font files?? There are tens of types! :-)

In what context will you use this font-path information? I mean - which libraries will you use to render the graphics - or maybe you are just dumping the data to a readable file? That is relevant because depending on the library you intend to use to render the graphics there may be ways of accessing character information by using that library eco-system (say Qt, Cairo, pango, windows native, pygame, and so on)

That said, there is at least one font file format from which it would be fairly easy to get the information you want: SVG fonts wherein the points and curves will be represented as XML data.

Also, another thing for you to look is the fontforge project - it can deal with fonts - several formats - and it is scriptable in Python. But that is just about what I know. (http://fontforge.org)

like image 164
jsbueno Avatar answered Dec 14 '25 20:12

jsbueno



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!