Compile a BDF X Font into PCF with bdftopcf
An X server cannot read a BDF font directly, so bdftopcf compiles that source into a Portable Compiled Format file it can load. The examples use bdftopcf 1.1 from the Debian package xfonts-utils version 1:7.7+6build3. Allow about ten minutes if the BDF file is ready and you only need a standard conversion.
The route
Jump straight to the step you need, or tick off Done means at the end.
- This is a file conversion, not an installation.
- You need: a shell, a readable file named like
fontfile.bdf, and write access to a separate output directory. - Privilege: the commands normally run as your ordinary user. Do not use
sudounless your input or destination permissions genuinely require it.
1. Check the installed compiler
$ command -v bdftopcf
/usr/bin/bdftopcf
$ bdftopcf -v
bdftopcf 1.1
The installed manual describes this as a font compiler for the X server and font server. PCF files are portable between architectures, although a file can be read more quickly when its layout suits the host. The version check matters when a build script or an old font archive has to be reproduced later.
Checkpoint
If the command is missing, stop here and install the distribution package that provides bdftopcf through your normal package-management process. Do not download a random executable into a font directory.
2. Convert one BDF file without changing the source
$ bdftopcf -o ./output-font.pcf ./fontfile.bdf
$ printf 'status=%s\n' "$?"
status=0
$ ls -l ./output-font.pcf
fontfile.bdfis the positional input. With-o, the compiled PCF is written to the named file.- Without
-o,bdftopcfwrites the PCF bytes to standard output, useful for a deliberate redirection but easy to mistake for a missing output file. - The source is never edited. The command reads the BDF and writes the PCF; check the exit status immediately after conversion and confirm the destination exists. Exact byte count depends on the font and the selected format settings.
Checkpoint
Use file ./output-font.pcf or the font inspection tool available on your system for a second check. A successful exit status means the compiler completed; it does not prove the glyph design is what you intended, so keep the BDF until the PCF has been tested by the consumer.
3. Avoid accidental truncation
$ bdftopcf -o ./output-font.pcf.new ./fontfile.bdf
$ test -s ./output-font.pcf.new
$ mv ./output-font.pcf.new ./output-font.pcf
-o names an output file, but it is still safer to use a fresh temporary name when replacing an existing PCF. This protects the old file if the conversion fails or you decide the result is wrong. Run the mv only after the conversion and the non-empty-file check succeed; if conversion fails, inspect the diagnostic and leave the old PCF alone. To recover an unwanted replacement before another process uses it, restore your own backup or regenerate the known-good PCF from the original BDF. The mv example changes state in the current directory, so review both names before running it.
If you deliberately want standard output instead, use an explicit new file:
$ bdftopcf ./fontfile.bdf > ./output-font.pcf
$ printf 'status=%s\n' "$?"
status=0
Warning
Shell redirection opens the destination before the program runs. Never use this form with the only copy of a useful PCF unless you have a backup. The -o workflow with a .new name makes the replacement boundary easier to see.
4. Select glyph padding when a consumer needs it
$ bdftopcf -p 4 -o ./output-font-p4.pcf ./fontfile.bdf
-psets glyph scanline padding to 1, 2, 4 or 8 bytes. This changes how each glyph scanline is padded in the compiled font: a format and consumer-compatibility choice, not a visual resize.- Match an existing requirement if an X font setup specifies particular padding; otherwise leave the option out and use the installed program's normal default rather than guessing a value from the font name.
-uis different: it sets the scanline unit to 1, 2 or 4 bytes for byte swapping when font bit order differs from byte order:$ bdftopcf -u 4 -o ./output-font-u4.pcf ./fontfile.bdf
Only add these options when the target X implementation or an existing reproducible build requires them. If the option value is outside the documented set, the installed compiler rejects it; correcting an invalid value is safer than trying several combinations against a production font directory.
5. Set bit and byte order only for a known target
The default conversion does not require you to choose an order manually. The explicit switches are:
-mwrites glyph bits most significant bit first.-lwrites glyph bits least significant bit first.-Mwrites multi-byte data most significant byte first.-Lwrites multi-byte data least significant byte first.
These are different choices: bit order controls the position of bits within each unit, while byte order controls multi-byte values such as metrics and bitmap data. Do not add all four flags to make a conversion seem more portable. Select the documented combination for the X server or font tooling that will consume the PCF, and keep that choice in the build command so it can be reproduced.
6. Use terminal optimisation with a clear reason
$ bdftopcf -t -o ./terminal-font.pcf ./fontfile.bdf
-tasksbdftopcfto convert the font into terminal form when possible. Terminal fonts pad each glyph image to the same size, which can let an X server render them more quickly. This is an output-layout optimisation, not a guarantee every font becomes a terminal font.- It also inhibits ink-metric computation. When glyph images do not fill their metric bitmap, the ordinary conversion computes actual ink metrics and stores them in the PCF;
-tinhibits that. -iinhibits the normal ink-metric computation on its own, without asking for terminal conversion:$ bdftopcf -i -o ./no-ink-metrics.pcf ./fontfile.bdf
These flags can change spacing or the way glyph extents are understood by software. Test the resulting font with the actual application. If you only need a normal PCF, omit both options.
7. Diagnose a failed conversion
$ ls -l ./fontfile.bdf
$ test -r ./fontfile.bdf && echo readable
$ test -w . && echo destination-writable
Check the input path and permissions first, without changing the font archive. If the compiler reports it cannot open the BDF source, correct the path or read permission. If it cannot create the PCF, choose a writable destination or fix the destination permission according to your system policy. Running the whole conversion as root can hide an ownership problem and can leave root-owned output behind, so it should not be the first remedy.
For an option error, compare the command with the local manual. The documented values are narrow: -p accepts 1, 2, 4 or 8, and -u accepts 1, 2 or 4. The compiler has no documented input-directory mode, font installation mode or automatic overwrite safeguard. Keep conversion and installation as separate, reviewable operations.
Done means
- Version confirmed:
bdftopcf -vreported the installed compiler version. - Conversion succeeded: a readable BDF source produced a PCF with exit status 0.
- Source preserved: the BDF remains available for recovery and later recompilation.
- Replacement made safe: a fresh or temporary output name prevented an unreviewed overwrite.
- Options used deliberately: padding, byte order, terminal conversion and ink-metric options set only for a known consumer requirement.
- Result checked: the PCF was checked with a file or font tool and tested by its intended X application.