Converting font formats

Quick Change

© Lead Image © Alphaspirit,

© Lead Image © Alphaspirit,

Article from Issue 198/2017

Perform trouble-free font conversions from the command line with an easy-to-use script.

Ordinarily, few users have to concern themselves with converting file formats for fonts. However, with LibreOffice 5.3 dropping support for Type 1 fonts [1], conversion becomes relevant, especially if other Linux applications do the same. Users are suddenly faced with either finding a solution or losing altogether fonts collected over years, some of which may be irreplaceable if they are from small font designers. Moreover, if support for Type 1 fonts is dropped, in a few years TrueType fonts may also be dropped in favor of OpenType fonts. Fortunately, a number of solutions are available, including a batch script in FontForge [2], a free software font creation tool included in most distributions.

Type 1 fonts (.pfb), also known as PostScript fonts, were first released in 1985. As might be expected with such an old format, they include some major limitations. Information in Type 1 fonts is contained in several files (.pfb, .afm, and, on Windows, .pfm), and older Type 1 fonts are short of accents and other diacritical marks. Moreover, glyphs (characters) are divided into one-thousandths – less than half of the highest-quality TrueType fonts – and are less efficient than TrueType at hinting or rasterizing. All the same, Type 1 fonts are superior to even older font formats and remain good enough for professional uses.

In theory, TrueType fonts, which were introduced a few years after Type 1 fonts, allow more detail. However, in the early 1990s, hastily created TrueType fonts gave the format a bad reputation, causing many designers at the time to avoid it. As a result, small font foundries often chose to use Type 1, which means that many rare fonts are unavailable in TrueType, a fact that has helped to keep the format alive.

In 1996, Microsoft and Adobe released the OpenType format (.otf) and continued developing it over the next 15 years. Built on TrueType, OpenType is an advance on both Type 1 and TrueType, in that it includes support not only for a full range of diacriticals but also for other advanced typographical features, such as ligatures, small capitals, or old style figures in a single file. For the purposes of conversion, OpenType's most important feature is that its vector font outlines can be drawn from either Type 1 or TrueType fonts. With these and other advantages, OpenType has gained steadily in popularity ever since its release, and it has been the font format of choice for well over a decade.

The change in LibreOffice 5.3 is due to the decision to use HarfBuzz [3], a new and advanced font rendering engine that does not include Type 1 support. Under Windows, this decision has little effect, because Microsoft Office 2013 and many other Microsoft products, apparently including at least some recent versions of Windows, have already dropped Type 1 support. However, in Linux, which continues to support the Type 1 format, the effect is more far-reaching. Not only is the dropping of Type 1 support an inadequately announced step backward, but it also places LibreOffice out of sync with other applications, including GIMP, Krita, Inkscape, and Scribus. Consequently, transferring a file from one application to another has become more difficult.

Limited Solutions

Because HarfBuzz shows no signs of adding Type 1 support, users who wish to continue using Type 1 fonts must look elsewhere for solutions. At average prices of $10-75 per typeface for OpenType font versions, replacing a library of Type 1 fonts may be too expensive to be an alternative.

One solution is to set replacements for Type 1 fonts under Tools | Options | LibreOffice (Figure 1). Using free-licensed fonts is especially useful, because they are likely already to be in .otf format. In some cases, the free fonts may be metrical equivalents of Type 1 fonts; characters in the Liberation fonts, for example, occupy the same space as Times Roman, Arial, and Courier, so that no reformatting is necessary. However, many replacements will not be so exact.

Figure 1: Setting up replacements for fonts is one alternative to conversions but may still require reformatting.

Other solutions include switching to Apache OpenOffice, to remain with pre-5.3 version of LibreOffice, or to use Calligra Suite's Writer. However, all these mean abandoning past – and future – improvements in LibreOffice. Moreover, any of these solutions seem temporary at best. Adopting one could mean having to face the same problem again in a few years as backward compatibility ceases, small projects disappear, or HarfBuzz becomes more prevalent.

All things considered, converting fonts to OpenType format seems the most practical solution --especially if the tedium of conversion can be alleviated by running batch scripts. The Adobe Font Development Kit for OpenType includes the tx script for Type 1 to OpenType conversion [4], but installation instructions for Linux are obscure and require a knowledge of how to add paths to an environment, making them difficult for many to use. Similarly, although FontForge supports Python scripts as well as its own scripting language, so far no one seems to have written one for conversion.

FontForge Solutions

FontForge is a powerful but slow application with a primitive-looking interface that, in the best free software tradition, is the result of one developer's enthusiasms – in this case, the enthusiasm of George Williams, who developed FontForge as a retirement hobby before passing its development on to other hands in 2012. Although it's less sophisticated-looking than proprietary font design applications, FontForge remains a full-featured tool, and, according to Wikipedia, it was used to develop such free-licensed fonts as Cantarell, DejaVu, Inconsolata, and Linux Libertine. Most major Linux distributions include FontForge in their repositories [5].

FontForge offers two solutions for converting single fonts. First, from the FontForge interface, you can open a .pfb or .ttf file, and then select Font | Generate Font (Figure 2), and set the export format to OpenType (CFF). Second, FontForge maintains an Online Font Converter [6], in which you select the export format and then drag and drop files to the window (Figure 3).

Figure 2: Single font conversions can be done from the FontForge interface.
Figure 3: Another way to convert only a few fonts is from FontForge's online tool.

These solutions are practical if you have only a few fonts to convert or else are content to convert files only as needed. However, if you have dozens or hundreds of Type 1 files and want to get the entire process over and done with, the most practical solution is to run a headless batch script – one that calls upon FontForge without opening the graphical interface. Happily, the FontForge website includes an example of such a script that describes its construction, adding complexity step by step [7]. With one or two minor modifications, the script samples remain usable today (Listing 1). Table 1 parses the file to show what each element does.

Table 1

Explanation of Script




This comment calls on FontForge to execute the script. The location of the FontForge binary may be in a different place in your distribution, such as /usr/share/bin/fontforge.


Creates a local variable called i with a value of 1.


Sets a default conversion format of OpenType. This format can be changed by setting the format option when running the command (see below).


Variable for the number of arguments passed to the script.


The array containing the argument passed to the script.

( $argv[i]=="-format" || $argv[i]=="--format" )

Creates a format option. Notice that the both -format and --format (one or two hyphens) are valid options.

if ..else

If -format or --format is specified, then that format is used. If neither -format or --format is used, then the default set in format= is used.

Listing 1

Sample Script


To run a batch file, run

chmod +x

to give it the necessary permissions to run. Place all the files you want to convert in the same directory, and then switch to the directory and run: --format "EXPORT-FORMAT" *.ORIGINAL-FORMAT-FILES

For instance, to convert Type 1 fonts to OpenFace, you would run: --format ".otf" *.pfb.

FontForge does not have a verbose mode, so the only evidence of success is the appearance of the converted files in the directory.

The FontForge site also gives a version of this script for converting TrueType fonts to Type 1, but, these days, few people are likely to want that variant. Similarly, the same page describes how to add more accented characters to a Type 1 font, but if you have survived without the extra accents in the past, you probably can continue to do without them. Besides, the newest Type 1 fonts already have a reasonable array of accented characters for Western European languages.

After Conversion

This script runs without problems from a command line (Figure 4). However, if you are working from the FontForge interface, you can click File | Preferences | Scripts to add a script menu and then add the script as a menu item.

Figure 4: You can run the conversion script from a command line or from the FontForge interface.

No matter how you run the script, the conversion should be trouble-free. You will have to add the converted versions of the font to your system or to LibreOffice to use them, and, if LibreOffice is open, close, and reopen it to gain access to the files.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

comments powered by Disqus
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters

Support Our Work

Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.

Learn More