fonttosfnt Command in Linux



The Linux fonttosfnt command wraps a bitmap font into an SFNT or TrueType wrapper. This conversion makes the bitmap font more portable and easier to use in modern systems.

Bitmap fonts were widely used in earlier displays, such as those found in mobile phones, calculators, and LCDs used in embedded systems. These fonts are designed to display text on displays with limited graphical capabilities. However, modern displays are capable of rendering high-resolution fonts. These fonts are TrueType fonts. These fonts are scalable, cross-platform, and can easily be embedded.

The fonttosfnt command essentially converts the bitmap fonts into the TrueType.

Table of Contents

Here is a comprehensive guide to the options available with the fonttosfnt command −

Syntax of fonttosfnt Command

The syntax of the Linux fonttosfnt command is as follows −

fonttosfnt [options] -o [file.ttf] -- [file.bdf]

The [options] field is used to specify the options to modify the commands behavior. The -o flag is used to specify the output file name. The double dash (--) acts as a delimiter, signaling that anything following it will be treated as arguments, not options. The [file.bdf] is the bitmap font file that is needed to wrap to TrueType.

Common Options with fonttosfnt Command

The options for the fonttosfnt command are listed below −

Options Description
-v It is used to get the verbose output
-c It is used to prevent the glyph cropping (increases the file size)
-b It is used to write byte-aligned glyph data (default is unaligned for smaller files)
-r It is used to skip the font re-encoding (by default fonts are re-encoded to Unicode when possible)
-g n It is used to set the type of scalable glyphs (the default is 2 to work with FreeType, but increases the file size)
-m n It is used to set the type of scalable metrics (default is 1 for partial metrics)
-- It is used to indicate the end of options

Using fonttosfnt Command in Linux

This section demonstrates the usage of the Linux fonttosfnt command through examples −

1. Wrapping a Bitmap Font to TrueType

To wrap the bitmap font type to TrueType, use the command given below −

fonttosfnt -o font.ttf -- myfont.bdf
Wrapping Bitmap Font to TrueType

The bitmap font comes with a .bdf extension, while the TrueType has a .ttf extension. The command converts myfont.bdf to font.ttf in the current directory, as shown in the output image.

2. Wrapping a Bitmap Font to TrueType with Verbose

To make the output verbose use the -v flag −

fonttosfnt -v -o font.ttf -- myfont.bdf
Wrapping Bitmap Font to TrueType with Verbose

3. Wrapping a Bitmap Font to TrueType Preventing the Glyph Cropping

To wrap the bitmap font without cropping the glyphs, use the -c option

fonttosfnt -c -o font.ttf -- myfont.bdf

4. Wrapping a Bitmap Font to TrueType with Byte-Aligned Glyph Data

By default, the glyph data is unaligned to reduce the file size. However, it can be aligned using the -b option −

fonttosfnt -b -o font.ttf -- myfont.bdf

5. Wrapping a Bitmap Font to TrueType Preventing Re-encoding

By default, the fonttosfnt command re-encodes the font with Unicode when possible. However, to prevent it the -r option is used −

fonttosfnt -r -o font.ttf -- myfont.bdf

6. Wrapping a Bitmap Font to TrueType by Combining Multiple Options

Multiple options can also be used to make the custom wrap. For example, in the following command, the bitmap font is wrapped with preserving the glyphs and aligning the glyph data.

fonttosfnt -c -b -o font.ttf -- myfont.bdf

7. Wrapping a Bitmap Font to TrueType by Controlling Scalable Glyph Types

The fonttosfnt command can handle the scalable glyph types using the -g option.

If it is set to 0 then no scalable glyphs are included in the output file. But it can cause the compatibility issues.

fonttosfnt -g 0 -o font.ttf -- myfont.bdf

If it is set to 1 then it will include the scalable glyphs in the output file. But it may trigger an error.

fonttosfnt -g 1 -o font.ttf -- myfont.bdf

If it is set to 2, which is the default, a large number of blank glyphs are included. It essentially satisfies the requirement but increases the file size.

fonttosfnt -g 2 -o font.ttf -- myfont.bdf

8. Wrapping a Bitmap Font to TrueType by Controlling Scalable Metrics

The scalable metrics define the height, width, and spacing of characters of the font. To control it, the -m option is used.

If it is set to 0, then no scalable data will be written to the output file. But it can cause issues when rendering the font.

fonttosfnt -m 0 -o font.ttf -- myfont.bdf

If it is set to 1, then full metrics values will be written for the first glyphs, and only the left sidebearing values will be written for the remaining.

fonttosfnt -m 1 -o font.ttf -- myfont.bdf

If it is 2, all glyphs' scalable metrics values will be written to the output file.

fonttosfnt -m 2 -o font.ttf -- myfont.bdf

Note that, it will increase the size of the file.

Conclusion

The fonttosfnt command in Linux is used to wrap the bitmap font to TrueType. It essentially wraps the .bdf fonts to .ttf fonts. The .bdf fonts are used in earlier mobile phone displays. To make the bdf fonts compatible with modern displays they can be converted to .ttf.

In this tutorial, we explained the fonttosfnt command, its syntax, options, and usage in Linux with examples.

Advertisements