How to Use FontTools Module in Python


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.

To start working with fonts it’s worth to add FontTools library to Python; it will extend your abilities to work with fonts. You can download it from here.

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 build and press enter
  • Write Setup.pyinstall and press enter
Installing FontTools with Command Prompt in Python
Installing FontTools with Command Prompt in Python
Important Note: I first Installed My FontTools and Then take the above photo from my comand prompt so that the command reply may be different for the first time and the second. You just use the mentioned commands instead of considering provided replies by Python

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

[sourcecode language=”python”]
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

[sourcecode language=”python”]
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

[sourcecode language=”python”]

Save a Font As XML with Python FontTools Module
Save a Font As XML with Python FontTools Module

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


What is Python?

In the official Python website they say that

Python is an interpreted, object-oriented, high-level programming language with dynamic semantics. Its high-level built in data structures, combined with dynamic typing and dynamic binding, make it very attractive for Rapid Application Development, as well as for use as a scripting or glue language to connect existing components together. Python’s simple, easy to learn syntax emphasizes readability and therefore reduces the cost of program maintenance. Python supports modules and packages, which encourages program modularity and code reuse. The Python interpreter and the extensive standard library are available in source or binary form without charge for all major platforms, and can be freely distributed.

Often, programmers fall in love with Python because of the increased productivity it provides. Since there is no compilation step, the edit-test-debug cycle is incredibly fast. Debugging Python programs is easy: a bug or bad input will never cause a segmentation fault. Instead, when the interpreter discovers an error, it raises an exception. When the program doesn’t catch the exception, the interpreter prints a stack trace. A source level debugger allows inspection of local and global variables, evaluation of arbitrary expressions, setting breakpoints, stepping through the code a line at a time, and so on. The debugger is written in Python itself, testifying to Python’s introspective power. On the other hand, often the quickest way to debug a program is to add a few print statements to the source: the fast edit-test-debug cycle makes this simple approach very effective.

How to install Python?

Installing Python is as easy as drinking a coffee. Follow these instructions to install Python

  1. At first provide a coffee for yourself
  2. Download the version you like  from the official website (Python 2 or 3)
  3. Run  the setup
  4. Install it the root drive ( for instance C:\Python )
  5. Start drinking your coffee while it is installing on your computer
  6. Setup will finish before your coffee finishes

That’s all about Python installation but I myself rather to use it in command line wherever in windos so that I have to add its path to windows variables. To do this open the Advanced System Settings (former System Properties) and add Python path to it like the following picture

Add Python Path to windows Environment Variables
Add Python Path to windows Environment Variables

How to Write Hello World Application in Python

Python syntax is ridiculously easy to learn. To write your first application in Python you have two options.

          First : use Windows Command Line

          Second : Use Python Editor (IDLE)

To code within the windows command prompt First Open Command Prompt

Write python and press enter

Python command line will appear and you can start coding. To write first command write
print (“Hello World”) // write print in lower case

and press enter then you will see the result in the next line

Python Hello World with Windows Command Prompt
Python Hello World with Windows Command Prompt

To write your application in IDLE you have to open the editor from Start Menu>Python x.x>IDLE
Then again write print (“hello world”) and press enter

Python Hello World Using Python IDLE Editor
Python Hello World Using Python IDLE Editor

As you can see coding in Python is a peace of cake and I strongly recommend you to start programming in Python for your daily usages if you have such a need. It helped me a lot and I learned a lot from its concept in a short time. It worth to try it even once. You can share your experiences with Python or Ruby or other similar tools here.

How to Localize JDK for fa-IR


Atlassian is an Australlian corporation which has some cool products like JIRA, Confluence, Fish Eye, Green Hopper, JIRA Studio and etc. For last 5 years I’m using Jira as an Issue Tracker and I’m really content with it. Attlasian helps Open Source and Free Software and give its software free to the open community. They also help some charities and let their customer help charities by their hand. Actually they pay total price of Standard verions of their products to charity so thatif you buy one, you help charity too. Because of all these good things and these useful application I decided to localize Jira totaly free a year ago.

I was trying to localize Atlassian JIRA because it is really a good issue tracker system. I had started translating it to Persian a year ago. After a while I contacted to JIRA team to include my resource file into JIRA and make it available for the next possible version. It took a month that I get a wondering answer from JIRA team.

Hi Nasser,

There is a problem with Persian (fa_IR), it is not supported by JDK. There is no support for the fa_IR locale.

Do we have the wrong locale? It sounds like we may.

Alternatively, if the locale is correct we will have to postpone the implementation. There are two solutions we can explore, but neither in the short term:

 try to force java to support fa_IR

 refactor TAC so having locale is optional

Thank you Nasser, I appreciate your patience,


I really amazed that JDK doesn’t support fa-IR locale! I’m not a Java man, but if a java geek is reading this, I kindly ask him do a favor to Iranian people. Start localizing JDK for Persian. To start you can go to this page and follow the manual to add Persian to JDK.

I use this blog to thanks Jira team, You guys really rock. I wish you keep on your nice job.