Skip to content

Phobos-developers/ra2fnt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ra2fnt

This program was created entirely using GPT-5.3-Codex without writing code by hand.

CLI utility for converting Westwood Unicode BitFont (game.fnt, fonT), a font format used in Command & Conquer: Red Alert 2, to a PNG set and back.

Build

go build ./src/cmd/ra2fnt

Local multi-platform release build scripts:

./scripts/build-release.sh
./scripts/build-release.sh v1.0.0
powershell -ExecutionPolicy Bypass -File .\scripts\build-release.ps1
powershell -ExecutionPolicy Bypass -File .\scripts\build-release.ps1 -Version v1.0.0
scripts\build-release.bat
scripts\build-release.bat v1.0.0

Usage

Export .fnt to PNG set:

./ra2fnt export -in game.fnt -out out_font

Export with integer pixel scaling (for easier editing):

./ra2fnt export -in game.fnt -out out_font --scale 3

Non-interactive overwrite for scripts/CI:

./ra2fnt export -in game.fnt -out out_font --force

Create .fnt from PNG set:

./ra2fnt create -in out_font -out rebuilt.fnt

Create without glyph deduplication:

./ra2fnt create -in out_font -out rebuilt.fnt --no-dedup

Validate PNG set and metadata without writing .fnt:

./ra2fnt validate -in out_font

Show CLI version:

./ra2fnt version
./ra2fnt --version

export and create show a progress bar in stderr. If out directory already exists, export asks for confirmation before deleting it.

  • Use --force to skip confirmation and overwrite out.

Export format

export writes only PNG files grouped by Unicode ranges:

out_font/
  metadata.json
  0x0020-0x007F (Basic Latin)/
    0x0041.png
    0x0042.png
  0x0400-0x04FF (Cyrillic)/
    0x0451.png

In this tree, only non-zero-width glyphs are shown as PNG files. Zero-width glyphs are listed only in metadata.json (symbol_width).

  • One PNG is exported per mapped Unicode codepoint from the .fnt unicode table.
  • PNG filename is fixed-length hex codepoint: 0xXXXX.png.
  • metadata.json stores:
    • symbol_width (only zero-width glyphs, as 0)
    • symbol_stride
    • font_height
    • ideograph_width
    • scale (integer export scale, default 1)
  • Zero-width glyphs are not exported as PNG files and are restored via metadata.json (symbol_width=0).
  • PNG height is symbol_height.
  • No unicode_table.bin or tail.bin is produced.

Create behavior

create reconstructs a .fnt from PNG files in the input directory:

  • PNG files are discovered recursively (subdirectory names are ignored by parser).
  • Files must be named as fixed-length hex codepoints (for example 0x0041.png, 0x30A1.png).
  • Zero-width glyphs are restored from metadata.json (symbol_width=0).
  • Codepoints with symbol_width=0 must not have PNG files.
  • All PNG files must have the same height.
  • symbol_width contains only zero-width entries and is used to restore width 0; otherwise width is taken from PNG width.
  • symbol_stride is taken from metadata.json when present; otherwise it is auto-calculated as ceil(max_symbol_width / 8).
  • font_height is taken from metadata.json.
  • ideograph_width is taken from metadata.json.
  • scale is taken from metadata.json; when scale > 1, PNG dimensions are downscaled by this factor during create (back to normal font size).
  • Identical glyphs are deduplicated, so multiple codepoints can reference the same symbol index.
  • Use --no-dedup to disable deduplication.
  • Unicode table is rebuilt from filenames (0xXXXX -> symbol index in sorted codepoint order).

Because unicode mapping order/tail bytes are rebuilt, the resulting .fnt is not expected to be byte-identical to the original input file.

Validate behavior

validate runs the same checks as create without writing output .fnt, and prints a summary:

  • total codepoints
  • number of PNG files
  • number of zero-width codepoints from metadata
  • resulting symbol count
  • number of deduplicated symbols

Limitations

  • Output .fnt is not byte-identical to source game.fnt.
  • At least one non-zero-width PNG is required to infer symbol_height.
  • Zero-width glyphs are represented only in metadata.json and have no PNG files.
  • Unicode table order is rebuilt from sorted codepoints.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors