text_fonts

source of text_fonts

1// Font formats and fallback for pkg::alloy::text (REFOCUS.md,2// R6d): CFF and CFF2 outlines, variable fonts (`fvar`, `avar`, `gvar`,3// HVAR, MVAR, CFF2's blends, GDEF's and the feature variations), color4// glyphs (COLR versions 0 and 1, CBDT, sbix, their PNGs), and fallback to5// the system's fonts for characters a style's faces lack: fontconfig,6// DirectWrite, Core Text, and on the web the files a program fetches. A7// program installs them on its fonts before adding any:8//9// ```text10// var fonts = Fonts::create();11// text_fonts::install_into(&var fonts);12// fonts.fetch(&"fonts/NotoSansArabic.ttf"); // for fallback on the web, read now elsewhere13// ```14//15// Without them a face is read for its TrueType outlines alone (a CFF16// face has none, a variable one is at its default), color glyphs are17// drawn as their outlines, and characters the bundled font lacks show as18// boxes (.notdef), the same on every target.19//20// ## How it was built21//22// **R6d as built** (2026-10-22; REFOCUS.md, questions 5A and23// 7B): moved out of `text`, whose F10a, F10d and F14c notes tell how it24// was built: `font/` the formats (`cff.alloy` as text's `Outlines`,25// `variations.alloy`, `gvar.alloy`, `color.alloy`, `bitmaps.alloy`,26// `png.alloy`) with `instances.alloy` giving text's `FontFormats`, which27// each face read after keeps; `fallback.alloy` and `system/` the28// fallback, text's `FontFallback`, which fonts made by29// `Fonts::bundled()` keep from asking the system. Tests: `tests.alloy`30// (PNGs, COLR, CBDT and sbix); `check.alloy` against fontTools' outlines31// and `hb-shape --variations`, fallback through this machine's32// fontconfig, and the color sheets as goldens in33// `tests/golden/text`.3435import std::option;36import std::string;3738import pkg::alloy::text;39import pkg::alloy::text::font::face;40import font::instances;41import fallback;4243// What the fonts read and fall back to from here on: the formats and the44// fallback, the system's fonts too unless they are `Fonts::bundled()`.45exp fn install_into(fonts: &var Fonts) {46    fonts.install_formats(formats(), new Fallback {});47}4849// The formats text reads a face with, for a face read apart from fonts50// (text's `Face::read`).51exp fn font_formats() -> FontFormats => formats();