Skip to content

artwork banks fonts

Aisjam edited this page Nov 15, 2026 · 1 revision

Glyph banks, fonts and linked artwork

Home · Section index

Working manual · 0.0.1-alpha · source snapshot 16 November 2026

CTB v1 binary and CTF v1 binary use Core's GlyphCollection, GlyphAsset, SpriteBankData, BinaryReader/BinaryWriter and SaveManager. Neither file references a bitmap, CTG, another bank or a machine path. Both resolve cells against their own embedded monochrome masks. Theme colours remain semantic references to the canonical 32-role catalog.

Ownership and rendering

src/core/graphics/GlyphCollection.* owns collection validation, serialization, document state, import/export, font fallback and revisions. ContciiAsset.hpp owns four-layer cells and frames. SpriteBank.* and GlyphCharacterSet.hpp now live in Core; the Editor headers are forwarding includes for existing tools. Legacy sprite-bank text decoding stays here solely for explicit conversion and existing CTG/bake sources.

src/render/GlyphRenderer.hpp is the existing renderer moved to the shared render boundary. Both the editor and TileFont use it, including the same composeContciiRegion traversal, layer order, quarter-tile offsets, semantic colours and once-only 77/255 shadow alpha. Layer 1 is behind Layer 4. File type does not affect composition. Runtime typography inherits the caller's colour for TextPrimary so selected/disabled text keeps its normal UI semantics; explicit non-primary roles use the current theme.

Masks upload into a nearest-neighbour atlas only when their revision changes. The font and artwork documents have independent storage. No file IO, decoding, texture creation or collection copies occur in runtime text drawing. Sampling policy belongs to the renderer, so later bilinear support needs no file change.

Directories and use

Under the configurable content root:

CONTOUR/
  Glyphs/Default.ctb
  Fonts/Default.ctf
  Artwork/
  Themes/
  Projects/

StoragePaths exposes these directories. The desktop editor accepts --content-root PATH, otherwise using its executable directory. It seeds missing defaults without overwriting existing files. Normal editing writes a complete bank/font, not a file for each glyph. Users can rename, copy and share these files normally. The source defaults are Asset/Glyphs/Default.ctb and Asset/Fonts/Default.ctf; runtime copies live under executable-relative assets.

The optional native ContourBakeGlyphCollections target generates defaults from the existing Bescii atlas into a specified output directory. It refuses to replace files. Build and run it with the atlas and destination root as arguments. Normal builds and H700 cross-builds use the checked-in binaries and do not run the native baker.

Contour accepts --font NAME.ctf, resolved beneath the content root's Fonts, or --font PATH. Without it, a user Fonts/Default.ctf takes precedence over the bundled default. Invalid/missing selection falls back to the bundled CTF; the existing bundled bitmap remains the emergency boot fallback. TileFont::loadTypeface can replace the font during a session without changing text. Unmapped characters use ?; the existing internal down-arrow remains a UI symbol rather than an ASCII font character. Compact text uses a separate 6x6 bitmap with one-pixel spacing.

Editor

Linked CTG artwork

Normal OPEN, file drop and command-line opening of .ctg now edit the file as linked artwork rather than importing a copy. The existing CTG composition stores a relative bank= path to its shared binary CTB and stable sprite IDs. Nested folders can reference ../Default_12.ctb; absolute paths remain rejected. CTG versions 1-4, layers, semantic colours, nine-slice data and all sixteen frames are preserved. No CTB schema change or music-project reference is introduced.

  • SAVE CTG saves the selected composition separately and enters linked mode.
  • SAVE / SAVE AS in linked mode writes CTG, saving dirty shared-bank data first.
  • SAVE BANK writes the shared CTB and editor sidecar without marking CTG edits saved.
  • TO BANK returns to the shared collection, with the existing unsaved-edit guard.
  • NEW while linked creates a new composition using that same bank.
  • OPEN another CTG reloads its referenced bank. Other running editor processes do not live-sync; reopen after another process saves the bank.

Opening linked CTG validates every referenced sprite, including ordinary Unicode IDs. Missing banks/IDs preserve the current document and report an error. Legacy text banks require explicit conversion; no binary CTB is overwritten with text. CTGs without a bank reference use the current saved artwork bank, and acquire an explicit reference on Save. Resolution switching is available after TO BANK.

Sprite SVGs and their associations stay beside the shared bank; editing a linked glyph's sprites uses those same files. SAVE SVG preserves vector source; APPLY PIXELS, followed by bank/glyph Save, publishes the pixels to other linked glyphs when reopened. Layered glyph-to-SVG drafts remain separate, stored as name.ctg.svg beside a linked composition.

--link-ctg <bank.ctb> <artwork-folder> recursively preflights current CTGs. Add --write to back up byte-exact originals in a uniquely named Backup-CTG-before-shared-bank-* folder and update references. Backup folders are excluded. Missing IDs abort preflight; no IDs, geometry, colours or frames are substituted. This is an explicit retarget operation: choose the intended master bank, since matching IDs will use that bank's pixels. CTB/sidecar/SVG files are not changed by this command.

Normal launch edits the complete bank. BANK/FONT switches between independently retained documents. NEW, OPEN, SAVE and SAVE AS act on the current collection. SLOTS selects a glyph/character; BRUSHES selects its cell mask. The font slot grid contains exactly ASCII 32 through 126. TYPE TEXT edits a small live phrase preview. The existing SPRITE view edits embedded mask pixels; edits remain in the active document. Pencil, fill, selection, transforms, layers, extrude, drop, shadow and theme controls retain their implementations. Font animation is disabled; bank animation is capped at 12 frames. Existing standalone CTG tests and the CTG codec retain the previous 16-frame capability.

IMPORT replaces the selected slot after confirmation. It accepts a CTG with its resolved source masks or a single-glyph CTB export. Conflicting mask IDs are remapped within the imported composition instead of altering existing glyphs. Font EXPORT writes a self-contained single-glyph CTB using only referenced masks. Artwork's former EXPORT button is now SAVE CTG for shared-bank authoring. The portable collection export API still explicitly creates a self-contained copy. The existing C++ export remains available for baked UI artwork.

Open validates a replacement before invoking the existing Save/Discard/Cancel transition. Cancel and failed load/save preserve the document. Switching editor modes retains both documents rather than discarding edits; closing warns about the parked document too. Save As confirms existing destinations. SaveManager provides the existing temporary-file/atomic-replacement behavior.

Controlled legacy conversion

Old files called .ctb are textual sprite deltas, not binary CTB v1. Opening one offers explicit conversion using the bundled original masks. The result has no destination until Save As; the source file is never rewritten automatically. Existing CTG and authored dialog/HUD sources remain supported by their existing tools. CTG import rejects more than 12 frames rather than truncating them. The binary reader never guesses an older schema or supplies missing embedded masks.

Binary layout

All integers are unsigned little-endian except the signed cell ink byte. Strings are a u16 byte length followed by UTF-8 bytes, capped at 256 bytes. Records are written field by field; no native struct padding, pointers or platform types.

The existing 12-byte Contour header is:

Offset Type Value
0 4 bytes CTB\0 or CTF\0
4 u16 schema 1
6 u16 reserved flags, zero
8 u32 exact remaining payload size

Payload, in order:

  1. Collection name string; u16 mask width and height (1–64).
  2. u32 mask count (1–8192). Each: u32 stable mask ID followed by ceil(width*height/8) packed row-major monochrome bytes, least-significant bit first. Existing Unicode IDs and custom IDs 0x110000–0x110FFF stay unchanged.
  3. u32 palette-order count and u32 IDs; u32 hidden count and u32 IDs. Entries must exist; duplicates are rejected.
  4. u32 glyph count (1–8192 for CTB, exactly 95 for CTF).
  5. Each glyph: u32 slot/character ID; name string; u16 cell width and height (1–256); u8 nine-slice presence. If present: four u16 values x, y, width, height, with the existing nine-slice bounds rules.
  6. CTB only: u8 frame count (1–12), u8 loop boolean. Each frame begins with u16 duration (10–10000 ms) and state-name string. CTF has one implicit frame and stores no timing, state-name, loop or additional-frame metadata.
  7. Each frame contains exactly four layers, back to front. Each layer: name string, u8 theme role (0–31), u8 visible, u8 locked, then width*height cells. Each cell is u32 mask ID (0xFFFFFFFF means transparent), i8 ink (-1 inherits the layer role, 0–31 overrides it). Literal space remains a real glyph.

CTF v1 requires all 95 unique codepoints 32–126. Identifiers are u32 so a future version can extend to Unicode without changing the cell/character distinction; v1 does not silently accept extra characters. The atlas can include auxiliary masks used by the 95 compositions without adding character slots.

Files are limited to 32 MiB. The reader bounds counts and dimensions before allocation, validates exact payload size, booleans, colour roles, layer counts, references and versions, and rejects trailing/truncated data. Output changes only after complete validation. Writers validate before attempting atomic save.

Linked CTG artwork

The CTB atlas owns tile masks. Linked CTG compositions reference those stable mask IDs and a relative CTB path; a CTG is not published into a bank slot. Same-ID bank compositions remain separate from tile masks. Art Canvas and Glyph Editor share Core's GlyphSerializer and the existing GlyphRenderer/CONTCII traversal. CTG v5 canvas metadata (repository reference: artwork-ctg-v5.md) adds canvas settings without changing CTB/CTF v1. Those binary collections reject canvas-only metadata rather than silently dropping it during export.

What should be here

Documentation still to add
Annotated current-build screenshots and a recorded controller walkthrough for this topic.

Evidence and verification

Repository sources used for this page:

  • docs/file-formats/glyph-bank-font-v1.md

This is a documentation/source review, not a new runtime or hardware test. Physical response, screenshots and listening examples still need verification on a recorded build.

Clone this wiki locally