Home / Alt manpages / psfxtable(1)

  • psfxtable(1)
  • User command
  • linux

Manage Unicode Tables in Console Fonts with psfxtable

You will use psfxtable to copy a Unicode character table out of a PSF console font, write a font with a table, and deliberately produce a font without one. The workflow uses files in a temporary directory, so the installed font is not changed. Allow about fifteen minutes. You need the kbd package and a PSF font; the examples below use the installed kbd version 2.6.4-2ubuntu2.

Checkpoint

This guide handles the table embedded in a PSF font. It does not install a font, change the active virtual console, or edit a system font directory.

1. Check the installed command

Start with ordinary, read-only checks. No elevated privileges are needed:

$ command -v psfxtable
/usr/bin/psfxtable
$ psfxtable
Usage: psfxtable [-i infont] [-o outfont] [-it intable] [-ot outtable] [-nt]
$ dpkg-query -W -f='${Package} ${Version}\n' kbd
kbd 2.6.4-2ubuntu2

The command reads a font from standard input when -i is absent. It writes nothing unless you request an output font with -o or an output table with -ot. A single dash can stand for standard input or standard output in any filename position.

2. Prepare an uncompressed PSF copy

Console font packages commonly store fonts as .psf.gz. The installed command expects PSF data, not a gzip stream, so make a disposable uncompressed copy before testing:

$ work=$(mktemp -d /tmp/psfxtable.XXXXXX)
$ font_gz=/usr/share/consolefonts/Hebrew-Terminus18x10.psf.gz
$ gzip -dc "$font_gz" > "$work/input.psf"
$ file "$work/input.psf"
/tmp/psfxtable.XXXXXX/input.psf: Linux/i386 PC Screen Font v2 data, 256 characters, Unicode directory, 10x18

Replace font_gz with a readable font that exists on your machine. The path and dimensions above are host-specific. Keep the original compressed file untouched; the redirection creates only the temporary copy.

3. Extract the embedded table

Use -i for the input font and -ot for the table output. The output is a text mapping from glyph positions to Unicode code points:

$ psfxtable -i "$work/input.psf" -ot "$work/input.table"
$ sed -n '1,12p' "$work/input.table"
#
# Character table extracted from font
#
0x000 U+00a4
0x001 U+00a6
0x002 U+00a8
0x003 U+00a9
0x004 U+2666 U+25c8 U+fffd

Exact mappings depend on the font. A line can contain several Unicode values for one glyph. If the command reports a bad magic number, you probably passed a compressed file or a non-PSF file; decompress the font first or choose a different input.

Checkpoint

You have a text table at $work/input.table. Extracting it does not alter the font.

4. Copy a font and its table together

Request both outputs when you want a separate font and table file. An explicit input table overrides a table already embedded in the input font:

$ psfxtable -i "$work/input.psf" -it "$work/input.table" \
    -o "$work/copied.psf" -ot "$work/copied.table"
$ file "$work/copied.psf" "$work/copied.table"
/tmp/psfxtable.XXXXXX/copied.psf: Linux/i386 PC Screen Font v2 data, 256 characters, Unicode directory, 10x18
/tmp/psfxtable.XXXXXX/copied.table: ASCII text

For a simple copy, omit -it; the input font's table is retained by default when it has one. Supplying a hand-edited table is a data change, not a harmless formatting step. Make a backup or write a new destination until you have checked the result.

5. Deliberately remove the table

The -nt option requests an output font without a Unicode table. This is useful when a consumer expects a bare PSF font:

$ psfxtable -i "$work/input.psf" -o "$work/no-table.psf" -nt
$ file "$work/no-table.psf"
/tmp/psfxtable.XXXXXX/no-table.psf: Linux/i386 PC Screen Font v2 data, 256 characters, no directory, 10x18

Do not confuse -nt with deleting the input table: it affects only the output file. If you were about to replace a system font, stop first. A bad font can disrupt a console session, and a direct overwrite is difficult to undo. Write a new file, compare it, then keep the old file as a rollback copy.

6. Use standard input and output when a pipeline helps

A dash makes a file position a stream. This command reads the uncompressed font from standard input and writes a table-free PSF font to standard output:

$ psfxtable -i - -o - -nt < "$work/input.psf" > "$work/stream.psf"
$ file "$work/stream.psf"
/tmp/psfxtable.XXXXXX/stream.psf: Linux/i386 PC Screen Font v2 data, 256 characters, no directory, 10x18

Keep binary output redirected to a file or another binary-safe command. Do not let it mix with diagnostic text in a terminal or text log. The same dash convention applies to -it and -ot, which lets you supply or capture a table through a pipeline.

7. Understand the PSF header choice

When an output font is requested, psfxtable uses a PSF1 header if the input has a PSF1 header and the input table has no sequences. Otherwise it uses a PSF2 header. A sequence is a line with more than one Unicode value for one glyph, such as the example containing U+2666 U+25c8 U+fffd. This is why a table edit can change the output format even when the glyph count stays the same.

If a downstream tool rejects the result, inspect the output with file and compare the table with psfgettable. The related commands psfaddtable, psfgettable and psfstriptable are links to the same program with specialised interfaces, but the option form above makes the input and output paths explicit.

Done means

  • You confirmed the installed kbd version and psfxtable syntax.
  • You used an uncompressed PSF input and left the packaged font unchanged.
  • You extracted a readable Unicode table and checked its mappings.
  • You know that an explicit -it table overrides the input font's table.
  • You verified table presence or absence with file before using an output font.
  • You kept a rollback copy before any future replacement of a live font.