Module gui::gui_text
GUI: TrueType/OpenType fonts and text layout.
GuiTypeface parses a font file in memory — a from-scratch reader for the sfnt tables a renderer needs (head, hhea, hmtx, maxp, cmap formats 0/4/6/12, loca, glyf with simple and composite glyphs, kern format 0, GPOS pair-adjustment kerning formats 1 and 2, OS/2, name) — and hands out glyph outlines as GuiPaths (quadratic curves), metrics and kerning. GuiCanvas::fill_text() (gui_canvas.h) rasterizes them anti-aliased and caches the result per glyph, size and subpixel position.
Scope: TrueType outlines ('glyf'). OpenType fonts with CFF/CFF2 (cubic, PostScript-flavored) outlines load for their metrics but have no glyph shapes — load_* returns 0 for them unless allowed with GUI_FONT_ALLOW_NO_OUTLINES. No hinting (glyphs are drawn unhinted, like macOS and most modern renderers), no color glyphs, no variable-font axes (the default instance is used). Shaping is "simple": one glyph per codepoint through the cmap, pair kerning, no ligatures or complex-script reordering — right for Latin, Greek, Cyrillic, CJK and symbols; not for Arabic or Indic scripts.
struct GuiTypeface face;
if (!face.load_file("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf")) { ... }
float w = face.measure("Hello", 16.0f); // pixels at 16 px
canvas.set_font(&face, 16.0f);
canvas.fill_text("Hello", 10.0f, 30.0f);
face.free();
GuiTypeface::fallback() is always available: a sans-serif face compiled into the library (a subset of DejaVu Sans — printable ASCII, Latin-1, and common punctuation such as curly quotes, dashes, ellipsis and bullet; see gui_text_fallback.sc for its license), so text renders even with no font files at all (bare metal, a minimal container). GuiTypeface::system() looks for a system font by family name in the usual places on Linux, macOS and Windows.
Sizes are in pixels (the em height), so a size-16 face is 16 px tall from ascender-ish to descender-ish, depending on the font's design.
Structs
| GuiGlyphBitmap | One cached anti-aliased glyph image (owned by its typeface's cache). |
| GuiTypeface | |
| GuiTextGlyph | One positioned glyph of a GuiTextLayout. |
| GuiTextLine | |
| GuiTextLayout | Text broken into lines and positioned: word wrap at spaces and hyphens (anywhere for CJK, and inside words too long for a line), hard breaks at '\n', tabs to 4-space stops, alignment within maxWidth. Also maps between positions and byte offsets for carets/selection. |
Macros
| GUI_FONT_COPY | load_* flags |
| GUI_FONT_ALLOW_NO_OUTLINES | accept CFF-outline fonts (metrics only) |
| GUI_TEXT_LEFT | Text alignment (GuiTextLayout, GuiCanvas::set_text_align) |
| GUI_TEXT_CENTER | |
| GUI_TEXT_RIGHT |