Skip to main content

Crate frus_text

Crate frus_text 

Source
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§

TextLayout
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-italic should 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 Attrs through 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 text in 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 style with padding of room around it: min, unless the reader asked for type that does not fit in min.
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_width wide, as byte ranges into text.
line_spans_resolved
line_spans under 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_styled for weight and italics.
measure_resolved
Measures text under 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_width the runs wrap. None means unconstrained.
measure_style
Measures text under a TextStyle, 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_width the text wraps and the height grows. None means unconstrained, giving the natural size. This is the measurement wired into taffy’s measure closure for paragraphs.
measure_wrapped_resolved
Measures text under an already-resolved style, wrapping at max_width. The resolved counterpart of measure_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 a FontSystem is created — measurement here, rendering in frus-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_lines visual lines, and how many lines it actually took — None when 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
attrs with letter spacing: letter_spacing logical 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.