library text_fonts
Modules
fallbackFallback to the system's fonts (decisions/F10.md, question 1A): the platform names the font for a character the style's face lacks,
textreads 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 byFonts::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::bitmapsBitmap 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::cffGlyph outlines from a
CFForCFF2table: 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'sblendtaking the face's position on its axes. Hints are read past,seacaccents and the arithmetic operators left out, as they are from modern fonts.font::colorColor 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::gvarTrueType 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::instancesThe formats beyond TrueType's outlines, as text's
FontFormatscalls 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 orgvar's phantom points, GPOS's device tables by GDEF's store.font::pngPNG 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::variationsItem 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::browserFallback 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::coretextFallback 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::directwriteFallback 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::fontconfigFallback 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
emojifamily in color), and the first font covering the character is the one read.text_fontsFont 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::comCOM on Windows, the package
pkg::alloy::com(PLAN.md, F6b; a package of its own since F10, whichwindowandtextshare): 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 bytests/windows/com_layout.sh.pkg::alloy::objcObjective-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 isobjc_msgSendread as the method's exact C prototype (F0 question 4), so arguments pass as the method declares them:pkg::alloy::textText 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::drawdraws 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::faceA 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::outlineGlyph 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::rasterOutlines 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::readerBig-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::paragraphsLaying 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::applyApplying 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
atare those already done, HarfBuzz's output buffer, the rest its input.pkg::alloy::text::shaping::bufferThe 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::contextContextual 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::fallbackMarks 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::gposGlyph 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::gsubGlyph substitution (GSUB): single, multiple, alternate, ligature, contextual, chained contextual and reverse chained lookups, through extensions, applied as HarfBuzz applies them.
pkg::alloy::text::shaping::normalizeNormalizing 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::opentypeWhat 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::planWhat 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::shaperShaping 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::shapersThe 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
ComplexShapertheir plan keeps, the default shaper's done here.pkg::alloy::text::shaping::tagsOpenType'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::graphemesExtended grapheme clusters, by UAX #29's rules (Unicode 16.0): what a caret steps over and a selection takes whole.
pkg::alloy::text::unicode::linesLine break opportunities, by UAX #14's rules (Unicode 16.0) with LB1's default resolution of classes.
pkg::alloy::text::unicode::propertiesA code point's Unicode properties, from the generated tables, and UTF-8 decoding.
pkg::alloy::text::unicode::runsText 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::tablesGenerated 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::wordsWord 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::deflateDeflate (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::disposeValues that must be released by a call, not only freed.
std::equalEquality: the Equal interface.
std::ffiValues C holds for Alloy (LANGUAGE_SPEC.md section 6.3): a C library that calls back through an
extern (...) -> Rfunction often passes along avoid *its caller gave it.c_pointeris that pointer: made from a reference, read back as one by the callback, which names the type it was made from.std::float_digitsThe 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::formatFormatting values as text: the Format interface.
std::fsThe file system: directories, paths and what is at them.
std::hashHashing: the Key interface of hash map keys.
std::ioConsole and file input/output.
std::iterableThe iteration interfaces driving
forloops.std::macrosThe built-in compile-time macros (LANGUAGE_SPEC.md section 7.4).
std::mapThe hash map.
std::mathMathematics over floats (LANGUAGE_SPEC.md section 6.1a).
std::numberThe numeric constraint interface.
std::optionThe optional value: a payload (
Some) or its absence (None).std::processThe running process's environment.
std::resultThe outcome of something that may fail: a value (
Ok) or the error that took its place (Err).std::sortSorting in place.
std::stringThe owned, growable byte string.
std::syncWhat tasks share (LANGUAGE_SPEC.md section 5.6).
std::vectorThe growable array.