font2c
Convert fonts into C source code
SYNOPSIS
font2c [options] fontfile
PARAMETERS
-b
Generate byte-order independent output for font data (typically big-endian).
-c column
Specify the number of characters per line when outputting bitmap data arrays.
-g
Generate glyph tables for the font, including character mappings.
-h
Generate only a header file (.h) with font declarations, without the full C source.
-o outputfile
Specify the name of the output C source file. If not provided, output goes to standard output.
-p prefix
Specify a string to be used as a prefix for all font symbol names in the generated code.
-r
Output raw bitmap data only, without including font structures or metadata.
-s
Include character size information within the generated font data structures.
-t
Use tab characters for indentation in the generated C code instead of spaces.
-u
Assume that the input BDF file uses UTF-8 character encoding.
-v
Enable verbose output, showing progress and additional information during conversion.
-y
Output bitmap data in Y-major (vertical scanline first) order rather than X-major.
DESCRIPTION
font2c is a utility that converts font files, specifically those in the Bitmap Distribution Format (BDF), into C source code.
This C code typically defines data structures and arrays representing the font's characters (glyphs) and their raw bitmap data.
Its primary use case is embedding font data directly into applications, especially in environments where dynamic font loading is not feasible or desired, such as embedded systems, graphics libraries, or bootloaders.
By compiling the font data directly into the executable, it eliminates the need for external font files at runtime and ensures consistent font availability.
The generated C code can then be compiled alongside the application's source, providing a static, portable, and efficient way to integrate fonts into software projects.
The tool offers various options to control the output format, naming conventions, and specific data inclusions like character sizes or byte order.
CAVEATS
font2c primarily supports the Bitmap Distribution Format (BDF) as its input; it cannot directly convert other modern font formats like TrueType (TTF) or OpenType (OTF).
The specific structure and contents of the generated C code can vary slightly between different implementations or versions of font2c (e.g., the X.Org version often named xfnt2c versus other embedded-specific tools).
Embedding font data directly into an executable, while convenient, will increase the overall size of the compiled binary.
INPUT FONT FORMAT
The utility exclusively uses the Bitmap Distribution Format (BDF) as its input. BDF is a plain-text format for bitmap fonts, describing glyphs as an array of pixels. This makes it suitable for tools like font2c to parse and convert directly into structured C data.
OUTPUT STRUCTURE
The generated C code typically includes a structure (e.g., FontRec
) containing metadata about the font (like character metrics, default character, first/last character) and arrays holding the raw bitmap data for each glyph. This allows applications to directly access pixel data for rendering without external font files.
HISTORY
The concept of converting font bitmaps into C code has a long history, particularly in the context of early graphical user interfaces and the X Window System. The font2c utility, often implemented as xfnt2c as part of the X.Org font utilities, emerged to address the need for embedding font data directly into X server modules or applications requiring static font resources. Its design reflects the bitmap-centric approach to fonts prevalent in earlier graphical environments, providing a means to compile font resources directly into executable code for efficiency and portability.
SEE ALSO
bdftopcf(1), mkfontdir(1), mkfontscale(1), gcc(1)