Python comes with the great modules which you can use them to improve your application functionalities. Recently I felt in love with Python and trying to implement some of my daily usages with it. I was always interested in Unicode and Fonts so that I had a glance at Python abilities in these fields and I have to say that Python has a lot to say when it comes to these areas. It is really fantastic and powerful and you have access to whatever you want just a a peace of a cake. In this Article I show you how to use python abilities to save a font as an XML document. It may be wierd for you but sometimes it is necessary to check font tables and the rest of its information.
Each Python module has its own way for installation. Some of them only needs a simple copy to the appropriate folders and some of them should be installed. FontTools uses the second approach so that you have to follow the following instruction to install it in your Python.
- Open Windows Command Prompt
- Go to the folder you download FontTools
- Write Setup.py build and press enter
- Write Setup.pyinstall and press enter
Some lines will appear in your command prompt and then installation will complete within a minute. Now, to use this module in your application you have to load ( or import or use ) this module in your application, so write the following command in your Python application just like other commands
from fontTools.ttLib import ttfont
Note that commands are case sensitive so write it in the exact mentioned way.
Till now you are able to use FontTools abilities in your application so that to test it we create a font object and then get a simple export from it.
To create a font object in Python write the below command in your application; just note that you have to use for slash instead (/) of back slash (\) for addressing
font = TTFont("d:/fontname.ttf")
Till now you created a new object of your font in the object named font. It’s time to use it in our application so that I save the font as an XML document just like
You can find the rest of the FontTools commands in the documentation. Share your experiences with me if you know another good library to work with fonts.
- How to Start Programming with Python (hajloo.wordpress.com)