text_fonts

library text_fonts

Modules

fallback

Fallback to the system's fonts (decisions/F10.md, question 1A): the platform names the font for a character the style's face lacks, text reads it. Linux asks fontconfig, Windows DirectWrite's system font fallback, macOS Core Text; a web page is given no fonts, so a program names files to fetch (fonts.fetch), served beside it. Fonts made by Fonts::bundled() never ask the system. A font picked is read whole from its file the first time and kept for the program's life, a family of its own whose face is placed at the style's weight and size as any variable face is; answers are cached per script, language, weight and block of 256 characters (and per character where a block's answer lacks one), and a font picked for a script is tried first for that script's next characters.

font::bitmaps

Bitmap color glyphs (decisions/F10.md, "Color emoji"): PNGs in CBDT, found through CBLC's strikes, and in sbix, Apple's; the strike nearest a size is decoded (png.alloy), premultiplied and resampled to the size, a box filter shrinking and bilinear interpolation growing.

font::cff

Glyph outlines from a CFF or CFF2 table: Type 2 charstrings with their global and local subroutines, run into contours of lines and cubic curves; name-keyed fonts with one private dictionary, CID-keyed ones (as Noto Sans CJK is) and CFF2 fonts choosing one per glyph through FDSelect, and CFF2's blend taking the face's position on its axes. Hints are read past, seac accents and the arithmetic operators left out, as they are from modern fonts.

font::color

Color glyphs from COLR and CPAL (decisions/F10.md, "Color emoji"): version 0's layers of plain colors and version 1's graphs of paints (solid colors, linear, radial and sweep gradients, transforms, clips by glyphs and boxes, and composite modes), varied at a variable face's position, drawn on the CPU into premultiplied RGBA as outlines are into coverage. Palette 0 gives the colors; an entry 0xFFFF takes the text's color.

font::gvar

TrueType outlines at a position on a variable face's axes: gvar's tuples of deltas, each weighted by its scalar there, moving a glyph's points (a composite's component offsets) and its four phantom points; points a tuple leaves out moved as their touched neighbours are (interpolation of untouched points, IUP).

font::instances

The formats beyond TrueType's outlines, as text's FontFormats calls them on a face: its CFF or CFF2 outlines, color tables and a variable face's axes read with it; instances at a position on the axes, whose variation stores give their scalars, MVAR their metrics and feature variations their lookups; advances moved by HVAR or gvar's phantom points, GPOS's device tables by GDEF's store.

font::png

PNG images, the bitmap glyphs of CBDT and sbix are kept as (decisions/F10.md, "Color emoji"): 8-bit images (gray, gray and alpha, RGB, RGBA, palettes of 1 to 8 bits; 16-bit samples keep their high byte; not interlaced) read into RGBA, the zlib stream (RFC 1950) inflated by std::deflate.

font::variations

Item variation stores, which CFF2, HVAR, MVAR and GDEF keep their deltas in: regions of the axes' space, each with a scalar at the face's position, and rows of deltas weighted by them.

system::browser

Fallback on the web (decisions/F10.md, question 1A): a page is given no font files, so a program names fonts to fetch, served beside it (fonts.fetch); browser.web.js fetches them and keeps those that arrive until the fonts take them, as fallback faces for any script.

system::coretext

Fallback on macOS (decisions/F10.md, question 1A): Core Text picks the font for a character from the system UI font's cascade for the run's language, and gives its file's URL and PostScript name, by which a collection's face is found. Core Text and Core Foundation are loaded while running, through pkg::alloy::objc's helpers.

system::directwrite

Fallback on Windows (decisions/F10.md, question 1A): DirectWrite's system font fallback maps a character, in the run's language (the user's when it has none), to a font of the system's collection, whose file is local; its path and face index are read through the font's face and file loader. DirectWrite is loaded while running, and its objects reached through pkg::alloy::com; the slots are checked against MinGW's headers (tests/windows/com_layout.c).

system::fontconfig

Fallback on Linux (decisions/F10.md, question 1A): fontconfig, loaded while running as window loads libwayland-client, sorts the system's fonts for a character, the run's language and weight (and, for emoji, its emoji family in color), and the first font covering the character is the one read.

text_fonts

Font formats and fallback for pkg::alloy::text (REFOCUS.md, R6d): CFF and CFF2 outlines, variable fonts (fvar, avar, gvar, HVAR, MVAR, CFF2's blends, GDEF's and the feature variations), color glyphs (COLR versions 0 and 1, CBDT, sbix, their PNGs), and fallback to the system's fonts for characters a style's faces lack: fontconfig, DirectWrite, Core Text, and on the web the files a program fetches. A program installs them on its fonts before adding any:

Dependencies

pkg::alloy::com

COM on Windows, the package pkg::alloy::com (PLAN.md, F6b; a package of its own since F10, which window and text share): interface ids, calls through another object's table of functions, and the strings, arrays and variants UI Automation, the file dialogs, drops and DirectWrite pass, with UTF-16 text both ways. The tables' slots each user reads are checked against MinGW's headers by tests/windows/com_layout.sh.

pkg::alloy::objc

Objective-C from Alloy (PLAN.md, F7), the package pkg::alloy::objc: the runtime's C functions, loaded while running, for AppKit and Metal on Apple systems. Every message is objc_msgSend read as the method's exact C prototype (F0 question 4), so arguments pass as the method declares them:

pkg::alloy::text

Text in pure Alloy (PLAN.md, stages F4 and F10): TrueType faces, text split into runs by script and emoji presentation, shaping by the faces' OpenType features, line breaking by UAX #14 with carets on grapheme clusters by UAX #29, and glyphs rasterized into coverage masks. It knows nothing of the GPU: pkg::alloy::draw draws a layout. Text is shaped as HarfBuzz shapes it. The bundled font is Inter Regular, made bold by thickening it. Two packages install more on the fonts (REFOCUS.md, R6d): pkg::alloy::text_scripts the complex scripts' shapers and both directions mixed by UAX #9, pkg::alloy::text_fonts CFF, variable and color faces (COLR, CBDT, sbix, as premultiplied RGBA) and fallback to the system's fonts. Without them every run is shaped by the default shaper, left to right, and characters Inter lacks show as boxes, the same on every target.

pkg::alloy::text::font::face

A font face read from TrueType data: where its tables are, its metrics, characters to glyphs, advances and outlines. Its bytes are kept as given, read in place.

pkg::alloy::text::font::outline

Glyph outlines: from glyf, contours of on- and off-curve points (quadratic curves), composite glyphs assembled from their components; from CFF and CFF2 (text_fonts' cff.alloy), lines and cubic curves.

pkg::alloy::text::font::raster

Outlines into coverage masks (PLAN.md, F4 question 2): every line's signed area accumulated per pixel, then summed along each row, as font-rs does; curves are flattened into lines first. Grayscale, unhinted.

pkg::alloy::text::font::reader

Big-endian numbers read out of font data, 0 past its end, so a truncated or malformed font reads as zeros rather than faulting.

pkg::alloy::text::paragraphs

Laying text out: paragraphs between mandatory breaks, each given its direction and levels by UAX #9 (text_scripts' bidi, else left to right) and shaped in runs of one style and level, then filled into lines in the text's order at UAX #14's opportunities (spaces at a line's end hang past it; a word wider than a line breaks between clusters, and with text_scripts words of Thai, Lao, Khmer and Myanmar between any two graphemes), each line's glyphs put in visual order by their levels (L1, L2), lines stacked by their faces' metrics and aligned on their paragraph's side.

pkg::alloy::text::shaping::apply

Applying GSUB's and GPOS's lookups to a buffer, as HarfBuzz's apply context does (hb-ot-layout-gsubgpos.hh): each lookup over the glyphs its feature's mask selects, skipping those its flags ignore and the default ignorables; sequences matched by glyph, class or coverage, ligatures formed with the marks between their components kept apart, and the lookups a contextual rule names applied at positions within its match. The buffer is one array: the glyphs before at are those already done, HarfBuzz's output buffer, the rest its input.

pkg::alloy::text::shaping::buffer

The glyphs being shaped, as HarfBuzz's buffer keeps them: each with its cluster, the features it takes (a mask), what Unicode says of its character, what GDEF and substitutions say of its glyph, the ligature it belongs to, its syllable and what its script's shaper found; and their positions, with what each is attached to. Glyphs stay in the text's order, right to left too.

pkg::alloy::text::shaping::context

Contextual lookups, GSUB's 5 and 6 and GPOS's 7 and 8: a sequence of glyphs matched by glyph, class or coverage, with what comes before and after it, then other lookups applied at positions within it.

pkg::alloy::text::shaping::fallback

Marks placed without GPOS, around their base's ink box by their combining class, as HarfBuzz places them (hb-ot-shape-fallback.cc).

pkg::alloy::text::shaping::gpos

Glyph positioning (GPOS): single and pair adjustments, cursive attachment, marks attached to bases, ligatures and other marks, contextual and chained contextual lookups, through extensions, applied as HarfBuzz applies them. Attached glyphs keep what they attach to, resolved into offsets once every lookup ran (resolve_attachments).

pkg::alloy::text::shaping::gsub

Glyph substitution (GSUB): single, multiple, alternate, ligature, contextual, chained contextual and reverse chained lookups, through extensions, applied as HarfBuzz applies them.

pkg::alloy::text::shaping::normalize

Normalizing a run's characters as HarfBuzz does for the face (hb-ot-shape-normalize.cc): each character decomposed where the face lacks it and has its parts (or always, for some shapers), marks put in canonical order, then each mark composed with its base where the face has the result; every character given the glyph the face maps it to.

pkg::alloy::text::shaping::opentype

What GSUB and GPOS share: the script, language and feature lists that pick lookups, coverage and class tables, lookup flags and GDEF's glyph classes.

pkg::alloy::text::shaping::plan

What shaping a run applies, compiled once for a face, script, language, direction and set of features (HarfBuzz's shape plan and feature map, hb-ot-map.cc and hb-ot-shape.cc): the script's shaper, the language system its features are read from, each feature's mask, and the lookups of GSUB and GPOS in stages, each stage ending in what the shaper does between them.

pkg::alloy::text::shaping::shaper

Shaping a run of text in one face, in one direction, as HarfBuzz's OpenType shaper does (hb-ot-shape.cc): characters given their Unicode props and grapheme clusters, prepared by their script's shaper, mirrored right to left, normalized and mapped to glyphs, then substituted and positioned by the plan's lookups in stages, default ignorables hidden at the end.

pkg::alloy::text::shaping::shapers

The script shapers HarfBuzz chooses between (hb-ot-shaper.hh): what each asks of normalization and positioning; the complex ones (pkg::alloy::text_scripts) add steps of shaping through a ComplexShaper their plan keeps, the default shaper's done here.

pkg::alloy::text::shaping::tags

OpenType's script tags for a run, as HarfBuzz gives them (hb-ot-tag.cc): a script's new tags (dev3, dev2) before its old one (deva). The language systems a BCP 47 tag names are text_scripts'.

pkg::alloy::text::unicode::graphemes

Extended grapheme clusters, by UAX #29's rules (Unicode 16.0): what a caret steps over and a selection takes whole.

pkg::alloy::text::unicode::lines

Line break opportunities, by UAX #14's rules (Unicode 16.0) with LB1's default resolution of classes.

pkg::alloy::text::unicode::properties

A code point's Unicode properties, from the generated tables, and UTF-8 decoding.

pkg::alloy::text::unicode::runs

Text split into runs a face shapes whole (decisions/F10.md, question 1): by script, each character's Script and Script_Extensions (UAX #24) resolved as HarfBuzz and ICU resolve them, Common and Inherited characters joining the run around them and a closing bracket the run of its opening one; and by emoji presentation (UTS #51), a grapheme cluster at a time, so a run never splits one.

pkg::alloy::text::unicode::tables

Generated by unicode/generate.alloy from the Unicode Character Database 16.0.0: do not edit. A code point's value is VALUES[BLOCKS[MIDDLE[TOP[c >> 9] * 32 + (c >> 4 & 31)] * 16 + (c & 15)]].

pkg::alloy::text::unicode::words

Word boundaries, by UAX #29's rules (Unicode 16.0): where a screen reader's and the caret's words start and end. Thai, Lao, Khmer and Myanmar have no dictionary here, so a run of them is one word.

std::deflate

Deflate (RFC 1951) and gzip (RFC 1952): inflating what a server or a PNG compressed, its Huffman codes looked up nine bits at a time, and compressing what a program writes about as zlib's best level does (repeats found through chains of hashes and looked for again a byte on, blocks of their own Huffman codes).

std::dispose

Values that must be released by a call, not only freed.

std::equal

Equality: the Equal interface.

std::ffi

Values C holds for Alloy (LANGUAGE_SPEC.md section 6.3): a C library that calls back through an extern (...) -> R function often passes along a void * its caller gave it. c_pointer is that pointer: made from a reference, read back as one by the callback, which names the type it was made from.

std::float_digits

The shortest decimal digits of a float that read back to the same value, by Ryu (Ulf Adams, "Ryu: fast float-to-string conversion", PLDI 2018), which std::format writes floats with (LANGUAGE_SPEC.md section 6.5). Integer arithmetic only, so compile-time code formats floats too.

std::format

Formatting values as text: the Format interface.

std::fs

The file system: directories, paths and what is at them.

std::hash

Hashing: the Key interface of hash map keys.

std::io

Console and file input/output.

std::iterable

The iteration interfaces driving for loops.

std::macros

The built-in compile-time macros (LANGUAGE_SPEC.md section 7.4).

std::map

The hash map.

std::math

Mathematics over floats (LANGUAGE_SPEC.md section 6.1a).

std::number

The numeric constraint interface.

std::option

The optional value: a payload (Some) or its absence (None).

std::process

The running process's environment.

std::result

The outcome of something that may fail: a value (Ok) or the error that took its place (Err).

std::sort

Sorting in place.

std::string

The owned, growable byte string.

std::sync

What tasks share (LANGUAGE_SPEC.md section 5.6).

std::vector

The growable array.