dos-font-utils

Old font utils written in BASIC for DOS (now rewritten in FreeBASIC)

View the Project on GitHub twardoch/dos-font-utils

dos-font-utils

icon

Two small font tools from the DOS age. POLFED32 edits DOS text-mode bitmap fonts pixel by pixel; METRXPRS fixes the metrics of composite glyphs in Adobe .AFM files so an Aacute lines up with its A. Both were written in BASIC in the late 1990s, then rewritten in FreeBasic (2015) so they still compile and run on Windows and Linux today.

Status: archival. These are stable, mature, single-purpose utilities kept here for retrocomputing and legacy font-production work. Expect no new features — bug reports are still welcome.

Published under the Apache 2.0 License.

Author: Adam Twardoch adam@twardoch.com Contributors: Adam Twardoch adam@twardoch.com Homepage: https://github.com/twardoch/dos-font-utils

Table of Contents

Overview

This project provides two main utilities:

POLFED32.EXE - Bitmap Font Editor

POLFED32.EXE is a powerful command-line editor for creating and modifying bitmap screen fonts, primarily those used in DOS text-mode environments. It allows for pixel-level manipulation of glyphs within a font file.

METRXPRS.EXE - AFM Metrics Adjuster

METRXPRS.EXE (Metrics Express) is a “metrics assistance” tool designed to process Adobe Font Metrics (.AFM) files. It corrects the metrics of composite glyphs (e.g., Aacute) to align with their base glyphs (e.g., A) based on user-defined equality tables.

Who is this for?

These tools are primarily for:

Why is it useful?

Installation

Running the Executables

Pre-compiled Windows executables (POLFED32.EXE, METRXPRS.EXE) are provided in their respective subdirectories (POLFED/ and METRXPRS/). These are command-line tools.

No special installation steps are typically needed other than placing the executables in a directory that is in your system’s PATH or navigating to their directory to run them.

Building from Source

The tools are written in FreeBasic and can be compiled using the FreeBasic compiler (fbc).

Usage

POLFED32.EXE

Command Line

POLFED32.EXE INPUT.EXT [OUTPUT.EXT]

Upon execution, POLFED32.EXE opens an interactive text-based user interface (TUI) to edit the font. See the “POLFED32.EXE Internals” section for more on its features.

Example:

POLFED\POLFED32.EXE POLFED\DOSFONT.VGA POLFED\MYFONT.VGA

Programmatic Use

Direct programmatic use of POLFED32.EXE is not its primary design. However, one could automate its execution via shell scripts if batch processing of font files is needed, though interaction with its TUI would be complex to automate. The font file format itself (raw bitmap data) is simple and could be generated or manipulated by other custom programs.

METRXPRS.EXE

Command Line

METRXPRS.EXE <AFM-INFILE> <AFM-OUTFILE> <MEQ-FILE>

Example:

METRXPRS\METRXPRS.EXE METRXPRS\ORIG.AFM METRXPRS\METR_corrected.AFM METRXPRS\ANSI.MEQ

This command will process ORIG.AFM using rules from ANSI.MEQ and save the result to METR_corrected.AFM.

If incorrect arguments are provided, or if /h or /? is used as an argument, the program will display a help message with syntax instructions.

Programmatic Use

METRXPRS.EXE is well-suited for programmatic use in scripts or build processes due to its command-line nature and distinct input/output files. It can be easily integrated into automated font production workflows.

Technical Deep-Dive

POLFED32.EXE Internals

POLFED32.EXE is a sophisticated text-mode application that provides a visual environment for editing bitmap fonts.

Font File Format

POLFED32 works with raw binary font files.

User Interface

The editor presents a Text-based User Interface (TUI):

Key Features

POLFED16.EXE (Historical)

The POLFED directory also contains POLFED16.EXE. This is an older version of the editor, written in Visual Basic for DOS.

METRXPRS.EXE Internals

METRXPRS.EXE processes AFM files based on rules in a MEQ file.

AFM File Processing

The program (METRXPRS.BAS) operates as follows:

  1. Argument Parsing: Reads the input AFM, output AFM, and MEQ file paths from the command line.
  2. MEQ File Parsing:
    • Reads the MEQ-FILE. Each line is parsed into a child glyph name and a parent glyph name.
    • These pairs are stored in an array (e.g., MEQ$).
    • A list of unique parent glyph names is also created (e.g., UNQ$).
  3. Parent Metrics Collection:
    • The AFM-INFILE is read.
    • For each character metric line (C ... N <glyphname> ...), if <glyphname> is in the list of unique parent glyphs, its metrics (character code, width WX, and bounding box B llx lly urx ury) are stored.
  4. Child Metrics Adjustment and Output:
    • The AFM-INFILE is read again, line by line.
    • Non-character metric lines (headers, comments, kerning data) are written to AFM-OUTFILE as-is.
    • For each character metric line:
      • The glyph name is extracted.
      • If this glyph name is found as a “child” in the MEQ$ array:
        • Its corresponding “parent” glyph name is retrieved.
        • The stored metrics (specifically WX, B0 (llx), and B2 (urx)) of the parent glyph are used to replace those of the child glyph. The B1 (lly) and B3 (ury) values, as well as the character code and glyph name, are preserved from the original child glyph entry.
      • The (potentially modified) character metric line is written to AFM-OUTFILE.
  5. Summary: After processing, the program prints the number of glyphs whose metrics were corrected.

The core logic ensures that composite characters like ‘Aacute’ will have the same width and horizontal bounding box extents as their base character ‘A’, if specified in the MEQ file.

MEQ File Format

The Metrics Equality (.MEQ) file is a simple plain text file.

Sample files ANSI.MEQ, ORIG.AFM (input example), and METR.AFM (output example after processing ORIG.AFM with ANSI.MEQ) are provided in the METRXPRS directory.

Coding and Contribution Rules

Coding Conventions

As these tools are written in FreeBasic (with QBasic compatibility - -lang qb), any contributions to the .BAS source files should aim to:

Contributing

This project is maintained by Adam Twardoch. While it’s a relatively small and mature project, contributions in the form of bug reports or feature suggestions are welcome.

Please ensure any contributed code is also licensed under the Apache 2.0 License.