Skip to main content

Module font

Module font 

Source
Expand description

CUF (Creative Assembly Unicode Font) file format support.

This module handles .cuf font files used by Total War games to render text. CUF files contain glyph data, metrics, and optional kerning information for bitmap-based font rendering.

§File Format

CUF files use a custom binary format with the signature CUF0. The structure includes:

  • Font properties (line height, baseline, spacing, etc.)
  • Glyph mapping table (character code to glyph index)
  • Glyph dimensions (allocated size, actual size)
  • Glyph bitmap data (8-bit grayscale)
  • Optional kerning data (pair-wise spacing adjustments)

§Testing Status

Currently, only Empire: Total War fonts have been thoroughly tested. Other games may use slight variations of the format.

§Credits

Most of the reverse-engineering work was done by the Europa Barbarorum Team for their CUF tool. Their comments and insights have been ported here for reference.

§Glyph Storage

Glyphs are stored as 8-bit grayscale bitmaps. The format uses a sparse representation where only used character codes (non-0xFFFF values) have associated glyph data.

§Kerning

Kerning support is optional and only present in some font files. When present, kerning data provides spacing adjustments for specific character pairs to improve visual appearance.

§Usage

use rpfm_lib::files::font::Font;
use rpfm_lib::files::Decodeable;

// Decode a font file
let font = Font::decode(&mut data, &None)?;

// Access font properties
println!("Line height: {}", font.properties().line_height());
println!("Supports kerning: {}", font.supports_kerning());

// Access glyphs
for (char_code, glyph) in font.glyphs() {
    println!("Character {}: {}x{}", char_code, glyph.width(), glyph.height());
}

Structs§

CUFProperties
Font properties controlling text layout and rendering.
Font
Represents a CUF font file.
Glyph
Represents a single glyph (character) in a font.

Constants§

EXTENSION
File extension for CUF font files.