Home / Alt manpages / ucs2any(1)

  • ucs2any(1)
  • User command
  • linux

Build Encoded BDF Font Subsets with ucs2any

You will turn one ISO 10646-1 BDF master font into one or more encoded BDF files. The installed ucs2any is from xfonts-utils version 1:7.7+6build3. It reads a mapping table, selects the characters that table names, and writes a BDF subset with the registry and encoding you provide.

Allow about fifteen minutes if you already have a suitable BDF master. You need a shell, a readable ISO 10646-1 encoded BDF file, and one or more mapping tables. This workflow writes new font files in the current directory. It does not install a font, register it with X11, or change system font configuration.

1. Check the installed command

Start with the local binary and its syntax. This is an ordinary read-only check and does not need elevated privileges:

$ command -v ucs2any
/usr/bin/ucs2any
$ ucs2any 2>&1 | sed -n '1,12p'
Usage: ucs2any [+d|-d] <source-name> { <mapping-file> <registry-encoding> }
...

The command has no long option interface in this installed version. Its only switch is the optional +d or -d choice, followed by the source BDF and one or more mapping and registry-encoding pairs.

Checkpoint

Confirm the package version before comparing results with another machine:

$ dpkg-query -W -f='${Package} ${Version}\n' xfonts-utils
xfonts-utils 1:7.7+6build3

2. Find a master BDF and a mapping table

The source must be a BDF file whose character encoding is ISO 10646-1. A PCF file, an already encoded ISO 8859 font, or a font with an unknown encoding is not a safe substitute. Set a shell variable to the actual path you have:

SOURCE_BDF='/path/to/unicode-master.bdf'
test -r "$SOURCE_BDF" && printf 'Readable source: %s\n' "$SOURCE_BDF"

Mapping tables are normally supplied separately from the master font. This package installs tables under /usr/share/fonts/X11/util. List the available names rather than guessing a filename:

$ find /usr/share/fonts/X11/util -maxdepth 1 -type f -name 'map-*' -printf '%f\n' | sort
map-ISO8859-1
map-ISO8859-2
map-ISO8859-15
...

Use the table that describes the target character set. The table is not the same thing as the registry-encoding value: the table supplies the character mapping, while the value becomes part of the target font's XLFD name.

Checkpoint

Inspect the exact table before running a conversion:

$ sed -n '1,12p' /usr/share/fonts/X11/util/map-ISO8859-1

3. Generate one encoded subset

Run ucs2any from a scratch directory or from the directory where the generated BDF belongs. The registry-encoding pair for ISO 8859-1 is iso8859-1 in the documented example:

mkdir -p /tmp/ucs2any-work
cd /tmp/ucs2any-work
ucs2any "$SOURCE_BDF" /usr/share/fonts/X11/util/map-ISO8859-1 iso8859-1

Replace SOURCE_BDF with the real path before running the block. With a master named 6x13.bdf, the documented naming pattern produces 6x13-iso8859-1.bdf. The output is a BDF file in the current working directory, not standard output.

Check the result before moving it anywhere:

$ find . -maxdepth 1 -type f -name '*.bdf' -printf '%f\n'
6x13-iso8859-1.bdf
$ sed -n '1,10p' 6x13-iso8859-1.bdf
STARTFONT 2.1
...

The exact header and font name depend on the source. If the source is absent, unreadable, not an ISO 10646-1 BDF, or the mapping table cannot be read, stop and fix that input rather than interpreting a partial result as a valid font.

4. Generate several subsets in one run

Append another mapping-file and registry-encoding pair to the same command. The program accepts any number of pairs:

ucs2any "$SOURCE_BDF" \
    /usr/share/fonts/X11/util/map-ISO8859-1 iso8859-1 \
    /usr/share/fonts/X11/util/map-ISO8859-2 iso8859-2

For a source named 6x13.bdf, the man page documents these output names:

  • 6x13-iso8859-1.bdf
  • 6x13-iso8859-2.bdf

Use a separate pair for every target. Do not put two values into one mapping-file argument, and do not omit the hyphen between the registry and encoding. A malformed pair shifts the remaining arguments and can produce confusing errors.

Checkpoint

Compare the generated files with the requested target list:

$ for font in ./*.bdf; do
>     test -s "$font" && printf '%s: %s bytes\n' "$font" "$(wc -c < "$font")"
> done
./6x13-iso8859-1.bdf: ... bytes
./6x13-iso8859-2.bdf: ... bytes

5. Choose the DEC VT100 graphics behaviour

For upright, character-cell fonts, the default is +d: DEC VT100 graphics characters are put in the C0 range. For other font types, the default is -d, which omits them. Make the choice explicit when the distinction matters:

ucs2any +d "$SOURCE_BDF" \
    /usr/share/fonts/X11/util/map-ISO8859-1 iso8859-1

Use -d when you need those graphics characters omitted:

ucs2any -d "$SOURCE_BDF" \
    /usr/share/fonts/X11/util/map-ISO8859-1 iso8859-1

These switches affect the generated character set. They do not install the font or alter an existing BDF. If you are unsure which behaviour matches an established font family, generate into a scratch directory and compare the result with the existing files before replacing anything.

6. Avoid overwriting a useful BDF

The output name is derived from the source name and registry-encoding. Treat a repeat run as potentially destructive: an existing file with the same name may be replaced. Inspect the destination first:

OUTPUT='6x13-iso8859-1.bdf'
if test -e "$OUTPUT"; then
    printf 'Refusing to choose existing output: %s\n' "$OUTPUT" >&2
    exit 1
fi
ucs2any "$SOURCE_BDF" /usr/share/fonts/X11/util/map-ISO8859-1 iso8859-1

If you deliberately regenerated a file, keep a backup before the run:

cp -- 6x13-iso8859-1.bdf 6x13-iso8859-1.bdf.backup
ucs2any "$SOURCE_BDF" /usr/share/fonts/X11/util/map-ISO8859-1 iso8859-1

There is no undo option in ucs2any. Restore the backup with mv -- 6x13-iso8859-1.bdf.backup 6x13-iso8859-1.bdf if the new output is wrong. Do not use sudo unless the source or destination directory genuinely requires it. Privilege does not repair a wrong encoding or mapping table.

Done means

  • The source is a readable ISO 10646-1 BDF file.
  • Each target uses the intended installed mapping table and a separate registry-encoding pair.
  • The generated files exist as BDF output in the chosen directory.
  • The +d or -d choice is deliberate for the font type.
  • Existing output was checked or backed up before regeneration.