Converting font formats
Quick Change
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.
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).
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
Excerpt | Description |
---|---|
#!/usr/bin/fontforge |
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. |
i=1 |
Creates a local variable called i with a value of 1. |
format=".otf" |
Sets a default conversion format of OpenType. This format can be changed by setting the format option when running the command (see below). |
$argc |
Variable for the number of arguments passed to the script. |
$argv[i] |
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 convert.pe
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:
convert.pe --format "EXPORT-FORMAT" *.ORIGINAL-FORMAT-FILES
For instance, to convert Type 1 fonts to OpenFace, you would run:
convert.pe --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.
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.
Infos
- Type 1 fonts in LibreOffice: https://bugs.documentfoundation.org/show_bug.cgi?id=104701
- FontForge: https://fontforge.github.io/en-US/
- HarfBuzz: https://freedesktop.org/wiki/Software/HarfBuzz/
- Type 1 to OpenType conversion script: https://www.adobe.com/devnet/opentype/afdko/topic_overview.html#a_programs
- FontForge distros: https://en.wikipedia.org/wiki/FontForge
- Online Font Converter: https://onlinefontconverter.com/
- Script tutorial: https://fontforge.github.io/scripting-tutorial.html
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
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.
News
-
New Steam Client Ups the Ante for Linux
The latest release from Steam has some pretty cool tricks up its sleeve.
-
Gnome OS Transitioning Toward a General-Purpose Distro
If you're looking for the perfectly vanilla take on the Gnome desktop, Gnome OS might be for you.
-
Fedora 41 Released with New Features
If you're a Fedora fan or just looking for a Linux distribution to help you migrate from Windows, Fedora 41 might be just the ticket.
-
AlmaLinux OS Kitten 10 Gives Power Users a Sneak Preview
If you're looking to kick the tires of AlmaLinux's upstream version, the developers have a purrfect solution.
-
Gnome 47.1 Released with a Few Fixes
The latest release of the Gnome desktop is all about fixing a few nagging issues and not about bringing new features into the mix.
-
System76 Unveils an Ampere-Powered Thelio Desktop
If you're looking for a new desktop system for developing autonomous driving and software-defined vehicle solutions. System76 has you covered.
-
VirtualBox 7.1.4 Includes Initial Support for Linux kernel 6.12
The latest version of VirtualBox has arrived and it not only adds initial support for kernel 6.12 but another feature that will make using the virtual machine tool much easier.
-
New Slimbook EVO with Raw AMD Ryzen Power
If you're looking for serious power in a 14" ultrabook that is powered by Linux, Slimbook has just the thing for you.
-
The Gnome Foundation Struggling to Stay Afloat
The foundation behind the Gnome desktop environment is having to go through some serious belt-tightening due to continued financial problems.
-
Thousands of Linux Servers Infected with Stealth Malware Since 2021
Perfctl is capable of remaining undetected, which makes it dangerous and hard to mitigate.