LinuxCommandLibrary

font2c

Convert fonts into C source code

SYNOPSIS

font2c [-v] [-o output.c] fontname

PARAMETERS

-v
    Enable verbose mode, printing font details during conversion.


-o file
    Specify output C file; defaults to stdout if omitted.


DESCRIPTION

font2c is a utility from the X11 font utilities package (xfont-utils) that converts bitmap fonts into C source code for direct embedding in programs. It takes a font specified by its X Logical Font Description (XLFD) name and generates a C file containing glyph bitmaps as data arrays, typically in a structure like XFontStruct or raw bitmaps.

This is useful for standalone applications, embedded systems, or environments without a font server, ensuring fonts are self-contained without runtime dependencies on X fonts. The output C code defines constants for font metrics (width, height, ascent, descent) and per-character bitmap data, allowing compilation into binaries.

Fonts must be bitmap formats like PCF, accessible via the X font path or server. It processes fixed-width fonts best, producing code compatible with Xlib functions like XCreateFontCursor or custom rendering. Verbose mode aids debugging font loading issues.

CAVEATS

Supports only bitmap (PCF/BDF-derived) fonts; scalable or Type1 fonts fail.
Requires fonts in X font path or server. Fixed-width fonts work best; proportional may misalign.
Limited to 8-bit encodings.

EXAMPLE USAGE

font2c -v -o fixedfont.c \
-misc-fixed-medium-r-normal-*-13-*-*-*-*-*-iso8859-1

Generates fixedfont.c with 13px fixed font data.

OUTPUT STRUCTURE

Produces arrays like:
unsigned char font_bits[256][16];
with metrics: charwidth, charheight, etc.

HISTORY

Part of X11 since Release 4 (1980s), maintained in Xorg for legacy bitmap font handling. Usage declined with TrueType/OpenType rise, but persists for retro/minimalist apps.

SEE ALSO

bdf2c(1), pcf2bdf(1), xfontsel(1), xfs(1)

Copied to clipboard