Expand description
frus-text — text measurement, and in time shaping, on top of
cosmic_text.
At this milestone the API is limited to measure: the natural size of a line
of text, which the layout engine needs in order to size a Text widget.
The FontSystem, which loads the fonts, is expensive: it is initialised
lazily and shared behind a Mutex. That is a pragmatic v1 choice;
unifying it with the renderer’s own FontSystem will come later.
Structs§
- Text
Layout - A text’s shaped layout — a single cosmic-text pass — exposing the geometry an
editing widget needs: caret position by character index, reverse hit-testing, and
selection rectangles. Coordinates are local to the text, with the origin at
its top-left corner. Indices are in characters — frus’s editing convention —
with boundaries
0..=len.
Functions§
- add_
font - Registers a font face from its bytes (TTF/OTF), for the whole process.
- available_
style - The style actually available for the default family. Italic when an oblique
face is loaded, upright when none is — because cosmic-text demands an exact style
match, and asking for one that does not exist sends it to platform fallback lists
that are empty on Android. Turning off
bundled-italicshould cost you slanted text, not text. - available_
weight - The weight actually available in the default family closest to the one
requested. This is essential: cosmic-text demands an exact weight match on the
primary family, and a missing weight (Medium 500 on DejaVu) sends it off to the
platform fallback lists — which do not exist on Android (“no default font found”, a
panic caught on the device). Routing every
Attrsthrough here is what makes rendering deterministic. - baseline
- The alphabetic baseline of a line of text at
size_px: the distance from the top of the line box down to the line the letters sit on. - baseline_
of_ runs - The first baseline of a sequence of styled runs: the largest of their baselines, since they share a line and the tallest ascender sets where it sits.
- family_
for - The font family to use for
text: the bundled Arabic face when the text contains Arabic, otherwise the default sans-serif. - family_
for_ style - The family to draw
textin when a style named one. - font_
loading - How long building the font systems took, all together, and how many were built — one for measuring text, one for drawing it: a part of an application’s time to its first frame (milestone 683, #211). The system’s fonts are read for each.
- line_
box - The height a box needs to hold one line of
stylewithpaddingof room around it:min, unless the reader asked for type that does not fit inmin. - line_
height - The line height for a given font size, in pixels, for a style that says nothing about it.
- line_
spans - The visual lines a piece of text breaks into inside a box
max_widthwide, as byte ranges intotext. - line_
spans_ resolved line_spansunder a whole resolved style: its line height, its family and its letter spacing break the lines as the renderer will (milestone 623).- measure
- Measures a text’s natural size (multiple lines allowed), in pixels, at regular
weight. See
measure_styledfor weight and italics. - measure_
resolved - Measures
textunder a style that has already been resolved — the same thing one step further down, for the code that has done the resolving once and is measuring several times against it. - measure_
runs - Measures a rich text‘s natural size — resolved runs with mixed styles and sizes: the longest line’s width, and the shaped lines’ real height.
- measure_
runs_ wrapped - Measures a rich text under a width constraint: beyond
max_widththe runs wrap.Nonemeans unconstrained. - measure_
style - Measures
textunder aTextStyle, resolving whatever it left open to the framework’s own defaults. - measure_
styled - Measures a styled text’s natural size; weight and italics count, since bold is wider than regular and the layout has to know.
- measure_
wrapped - Measures a styled text under a width constraint: beyond
max_widththe text wraps and the height grows.Nonemeans unconstrained, giving the natural size. This is the measurement wired into taffy’s measure closure for paragraphs. - measure_
wrapped_ resolved - Measures
textunder an already-resolved style, wrapping atmax_width. The resolved counterpart ofmeasure_wrapped, for a paragraph whose style has been settled once and must be measured and painted at the same size. - monospace_
family - The monospaced family, for the widgets that ask for one. When neither the family
named nor the platform’s generic monospace is there — Android without
bundled-mono— it is the default family: text in the wrong face, not none. - new_
font_ system - Builds a ready-to-use
FontSystem: the system fonts, which provide the emoji and script fallbacks, plus the bundled font, set as the default family. Use it everywhere aFontSystemis created — measurement here, rendering infrus-gpu— for consistent text rendering that does not depend on system fonts, which may have no resolvable default at all, as on Android. - runs_
cut_ at - The byte offset at which a rich text runs past
max_linesvisual lines, and how many lines it actually took —Nonewhen it fits. - set_
default_ family - Names the family text uses by default — the one an application ships instead of,
or alongside, the bundled sans. The face itself must be registered with
add_font, or be present on the system. - set_
monospace_ family - Names the family monospaced text uses. See
set_default_family, whose rules for a name that is not loaded apply here too; with nothing to fall back on, monospaced text is drawn in the default family rather than not at all. - spaced
attrswith letter spacing:letter_spacinglogical pixels after every character, which the shaper takes as a fraction of the size (milestone 623). Every place that shapes text goes through this, so a measure and a paint space the same words alike.