Skip to main content

Module font_atlas

Module font_atlas 

Source
Expand description

font-atlas [--no-text] [--wide [<set>=]<wide.bdf>]... <font.bdf>... <out-dir>: turns a BDF bitmap font into a font atlas (atlas.png + atlas.ron, read as shuyi_assets::font::FontAtlasDef) and its one-bit copy for a one-bit screen (atlas_1bit.bin). It keeps the glyphs the font has of ATLAS_RANGES, of the characters the game’s text uses and of the glyphs the project requires (AtlasChars): when shuyi.ron names a game tool program, font-atlas runs in it and reads the game’s text (--no-text: the ranges and the required glyphs only). Further BDF files add glyphs the first lacks (a game’s own, e.g. controller button shapes). The atlas must have the glyphs the project requires (crate::project::FontAtlas::required_glyphs); a character the text uses that the fonts lack is named, and check fails on it.

--wide adds a wide font (Japanese, Chinese), its cells twice as wide as the narrow font’s: the atlas keeps its glyphs of the characters the text uses that the narrow fonts lack, and of the project’s wide_glyphs, each over two cells after the narrow glyphs. A BDF font in JIS X 0208 (CHARSET_REGISTRY "JISX0208...") is read as Unicode, with the crate’s jis feature (without it, such a font is refused).

--wide <set>=<wide.bdf> makes a named wide set instead, and may be given once per set (WideFont): the set keeps the wide characters of the languages that name it (a pack’s lang.ron’s wide_font, the source’s SourceLang::wide_font), their wide punctuation if they have it wide, and the project’s wide_set_glyphs for it. An unnamed --wide keeps those of the languages that name no set. The sets are laid out one after another, in the order given, after the narrow glyphs.

Structs§

Atlas
The atlas: the glyph map, plus its picture (white where the glyph is set, transparent elsewhere).
AtlasChars
The characters an atlas keeps, of those its font has: every one of ATLAS_RANGES, every character the game’s text uses, and the glyphs the project requires; never a combining mark or a control character. Its wide sets keep the characters of the languages that draw from them (wants_wide). AtlasChars::default is the ranges alone.
BitmapFont
A bitmap font: fixed cell size, each glyph an on/off pixel grid placed inside the cell (row-major, cell_w × cell_h).
WideFont
A wide font font-atlas reads: the set it makes and its BDF file.

Constants§

ATLAS_RANGES
Unicode ranges copied into the atlas (whatever the font has of them).
COLUMNS
Atlas cells per row.
ONE_BIT_FILE
The one-bit atlas’s file name, next to atlas.png.

Functions§

atlas_ron
The atlas.ron text for def, with a generated-file header naming the tool as command and pointing at readme, if there is one.
build_atlas
Lays out every glyph of font that chars wants, in codepoint order, COLUMNS per row.
build_atlas_with_sets
build_atlas, and after the narrow glyphs each wide set of wides (None: the unnamed one) in turn: the glyphs of its font that chars wants in it (AtlasChars::wants_wide), in codepoint order, each over two cells of one row. A wide font’s cells must be twice as wide as font’s and as tall (check_wide).
build_wide_atlas
build_atlas, and after the narrow glyphs the glyphs of wide that chars wants wide (AtlasChars::wants_wide), in codepoint order, each over two cells of one row: the unnamed wide set. build_atlas_with_sets says more.
check_wide
Whether wide fits beside font as its wide font: its cells twice as wide and as tall.
one_bit
The one-bit atlas (ONE_BIT_FILE) of the atlas picture image laid out as def: each glyph in cell index order, one byte per pixel row, the highest bit the left pixel, set where the picture isn’t see-through; a wide glyph’s two halves are two cells like any other. Fails for cells wider than 8 pixels.
parse_bdf
Parses a BDF font. Glyph bitmaps are positioned in the cell using the font and glyph bounding boxes; pixels outside the cell are dropped. A font whose CHARSET_REGISTRY is JIS X 0208’s has its codes read as Unicode (with the jis feature; refused without it); a code with no Unicode character is left out.
read_font
Reads and parses the BDF font at path.
run
Runs the command: reads the fonts at font_paths (the first is the font; the rest add glyphs to it) and the wide fonts wides, each its own set (one set once), and writes the glyphs chars wants to atlas.png, atlas.ron and atlas_1bit.bin in out_dir. Fails if the result lacks a glyph rules require; a character the text uses that the fonts lack is named in the summary, not a failure. command is what atlas.ron’s header calls the tool.