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.

#!/usr/local/bin/fontforge
# Quick and dirty hack: converts a font to truetype (.ttf)
Print("Opening "+$1);
Open($1);
Print("Saving "+$1:r+".ttf");
Generate($1:r+".ttf");
Quit(0);

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.

#!/bin/bash
#
# 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

done

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 http://www.stuermer.ch/blog/convert-otf-to-ttf-font-on-ubuntu.html 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.

5 comments:

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...

Hi,

Thank you, this is very nice

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

to

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.

Thanks!

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.

https://wiki.ubuntu.com/Fonts for sudo fc-cache -f -v command

bird-general said...

Thanks - this worked great!