Extract Selected Glyphs from a Linux Console Font with splitfont
You will finish with one small file per selected character, extracted from a raw Linux console font. The installed splitfont comes from kbd 2.6.4-2ubuntu2. It accepts a font file and one or more character ranges, then writes files named after the requested character values.
The route
Jump straight to the step you need, or tick off Done means at the end.
Allow about fifteen minutes. You need a shell, the kbd package, and a font in the format this old utility expects: no PSF header and exactly 256 characters. The examples use a temporary copy. They do not require sudo, do not load a font, and do not change the console.
1. Check the installed command
Confirm the binary and its short usage message:
$ command -v splitfont
/usr/bin/splitfont
$ dpkg-query -W -f='${Package} ${Version}\n' kbd
kbd 2.6.4-2ubuntu2
$ splitfont
call: splitfont fontfile 17,23-30,...
The syntax is splitfont FONTFILE RANGE.... A range is a comma-separated list of decimal character numbers and inclusive ranges, such as 17,23-30. The manual describes the input as an ISO-type font with 256 characters and no PSF header.
Checkpoint: if the file you have is a .psf font, do not pass it directly. A PSF header makes it the wrong input format for this utility. Make a headerless working copy only when you understand the source format and glyph size.
2. Prepare a safe working copy
Do not experiment on the only copy of a font. The following example takes the 4,096 glyph bytes from an installed 8 by 16, 256-character PSF font after its 32-byte PSF2 header. It is a test fixture for splitfont, not a general PSF conversion recipe:
$ workdir=$(mktemp -d /tmp/splitfont.XXXXXX)
$ dd if=/usr/share/consolefonts/UbuntuMono-R-8x16.psf \
of="$workdir/font.raw" bs=1 skip=32 count=4096 status=none
$ stat -c '%n: %s bytes' "$workdir/font.raw"
/tmp/splitfont.XXXXXX/font.raw: 4096 bytes
A 256-character font with 16 bytes per glyph is 4,096 bytes. Your font may use a different glyph height, so use the actual raw size rather than copying these numbers blindly. If you already have a headerless font, copy it into a temporary directory with a new name and work there.
Do not use sudo for this preparation unless the source is unreadable to your account. If you need elevated access, copy the source to a directory you own first, then run splitfont on that copy.
3. Extract individual characters
Choose character numbers and run the command from the directory containing the working copy:
$ cd "$workdir"
$ splitfont font.raw 65,66-67
$ printf 'status: %s\n' "$?"
status: 0
$ ls -l font.raw.41 font.raw.42 font.raw.43
-rw-r--r-- 1 you you 16 ... font.raw.41
-rw-r--r-- 1 you you 16 ... font.raw.42
-rw-r--r-- 1 you you 16 ... font.raw.43
The decimal values 65, 66 and 67 are the character numbers for the requested glyphs. The generated suffixes are hexadecimal: 65 becomes .41, 66 becomes .42, and 67 becomes .43. Each output contains one glyph, so the file size is the font's glyph height, 16 bytes in this example.
Ranges are inclusive. For example, 23-30 requests eight consecutive characters. Keep the range list explicit in scripts, and quote the font path if it contains spaces:
$ splitfont '/path/to/raw font' 32,48-57,65-90
$ printf 'status: %s\n' "$?"
status: 0
4. Verify the result and source
Check that the extracted files have the expected size and that the source was not altered:
$ sha256sum font.raw > before.sha256
$ splitfont font.raw 65
$ sha256sum -c before.sha256
font.raw: OK
$ stat -c '%n: %s bytes' font.raw.41
font.raw.41: 16 bytes
splitfont writes extracted files beside the input; it does not replace the input in this test. Treat that as an observed property of the installed command, not permission to skip backups when using important font data. If an output file with the same name already exists, stop and inspect it before rerunning. The command may overwrite that extracted output.
To compare a glyph with its position in the raw source, use a byte offset equal to the character number multiplied by the glyph height. For character 65 in this 16-byte font:
$ dd if=font.raw bs=16 skip=65 count=1 status=none | cmp - font.raw.41
$ printf 'compare status: %s\n' "$?"
compare status: 0
A zero status means the extracted file matches the corresponding 16-byte slice. This is a byte check, not a visual preview.
5. Handle the common input errors
If you see file unexpectedly large, the input is not the required 256-glyph, headerless size. Check its size and format before changing anything:
$ file /path/to/font
$ stat -c '%s bytes' /path/to/font
The installed program also rejects a file whose size is not a multiple of 256. That check does not identify a PSF header for you, and a file that passes the size check can still contain the wrong data. Use a known font format and a deliberate conversion step.
If a range is mistyped, the command returns a non-zero status and reports a bad argument. Do not infer the output name from a decimal suffix: the observed names use hexadecimal. If the command cannot open the file, fix the path or read permission rather than using root to conceal the mistake.
Done means
- You checked that kbd and
splitfontare installed. - You used a headerless, 256-character working font.
- You requested characters with explicit decimal values or ranges.
- You found one glyph file per request, with hexadecimal suffixes.
- You verified an output size and compared at least one glyph with its source slice.
- You kept the original font safe and did not change the active console font.