Friday, 7 August 2009

How to use OTF fonts in Ubuntu

It isn't possible to use OTF fonts directly in Ubuntu without converting them into TTF's.

If we spend just a few minutes and install FontForge and make a very small script it becomes almost trivial to do.

sudo apt-get install fontforge

Now we should make the scripts, well it is two actually but one is a small config script for FontForge and the other is just a script to convert many OTF files in one go, rather than individually. First the FontForge settings file.

cd ~/bin
touch otf2ttf.conf

Then open otf2ttf.conf in your favourite text editor and paste the following into it.

# Quick and dirty hack: converts a font to truetype (.ttf)
Print("Opening "+$1);
Print("Saving "+$1:r+".ttf");

Save the file, and now lets make the script to convert many fonts in one swoop.

cd ~/bin
touch otf2ttf
chmod +x otf2ttf

Again, open this file with your prefered text editor and paste the following in.

# had to enable extglob
shopt -s extglob

# this uses globbing to match fiels ending in otf/OTF
for i in +(*.otf|*.OTF)

do fontforge -script /home/subbass/bin/otf2ttf.conf $i


To use this now (provided that your ~/bin folder is in your path) just open a terminal where your OTF files are, and issue the command otf2ttf. It will convert 20 files in just a couple of seconds to give you an idea of speed, you can then move all the resulting TTF files into ~/.fonts

Credit to where I found the script before re-typing the instructions. I put it here so I don't lose it next time I need it.


Anonymous said...

Nice article, very useful, thanks!

Tista said...

In the line:
do fontforge -script /home/subbass/bi...

should put your actual username.

Other than that... great!

Anonymous said...


Thank you, this is very nice

Personally I had to change
do fontforge -script /home/subbass/bin/otf2ttf.conf $i


do fontforge -script /home/subbass/bin/otf2ttf.conf "$i"

(add the quotes) because my otf files had spaces in them and the script would fail.


Darren said...

Thanks from me too!

I'm pretty much a rank amateur so please consider my experience carefully but I had to use:

do fontforge -script /bin/otf2ttf.conf "$i"

instead of

do fontforge -script /home/subbass/bin/otf2ttf.conf $i

Also I think I found it easier to work with /tmp for GUI work as /bin was locked. Then copied it to the /bin directory with the terminal:

$ sudo cp /tmp/windowsfonts/otf2ttf .
(when in the directory to be copied to)

Also only the .dir file seemed to be created. Couldn't find the other one, but didn't seem to need it.

Converted output didn't seem to go to .fonts but ended up amongst the .otf files they came from. Sorting by date made finding them easy. for sudo fc-cache -f -v command

Anonymous said...

Thanks - this worked great!