Skip to main content

Crate alpha2_text

Crate alpha2_text 

Source
Expand description

Text shaping and rasterization for alpha2 hosts.

Produces the engine’s TextTexture in pure Rust from caller-supplied fonts. Paragraphs are split by direction (UAX #9), script and font, shaped with rustybuzz, broken per UAX #14 and rasterized with ab_glyph_rasterizer (color glyphs in color). The same request and fonts give the same pixels natively and in wasm, so browser preview and native export match.

Structs§

ClampedLines
The lines a clamp keeps (ShapedText::lines_within).
ClusterInfo
One cluster of a TextLayout.
ClusterState
Animation state of one cluster.
ColorMix
A color change base * keep + add in premultiplied linear light. Mixing toward a target by w is keep = 1 - w, add = w * target; mixes compose.
LineInfo
One line of a TextLayout.
LineMetrics
Lines of a shaped text at one wrapping width (ShapedText::lines_at).
RevealEdge
A straight edge that shows a cluster’s unit (its group’s box, outset by the text’s strokes) up to it, as a linear wipe. In the unit’s own frame, before its transform, the edge’s centre lies at a - w / 2 + progress (b - a + w) along direction, [a, b] the box’s extent along it and w the feather, at least a pixel; a point at s keeps clamp((e - s) / w + 0.5, 0, 1) of itself. Progress 0 hides the unit and 1 shows it whole, exactly.
ShapedText
Text shaped once (TextRasterizer::shape) so lines can be broken at any width without reshaping.
TextBackground
A box behind each non-empty line: its advance by its em box, grown by padding, with a radius and a border. Overlapping boxes show their union with one outline.
TextBoxBorder
A text box’s border.
TextBoxDash
SVG stroke-dasharray and stroke-dashoffset in pixels, from the end of the top-left corner clockwise.
TextClamp
Lines past the clamp point (line_limit) are discarded, as CSS line-clamp discards them. A cut text’s last line ends with the ellipsis, one more cluster (ClusterInfo::ellipsis).
TextFont
One caller-owned font registered in fallback order.
TextGradient
A gradient over a text’s layout box. Points are fractions of the box ((0, 0) top-left) and a radius is a fraction of its shorter side.
TextGradientStop
One color of a TextGradient.
TextHighlightRequest
A box over the run being said that slides from run to run, drawn over the background boxes and run backgrounds and under the glyphs.
TextLayout
Cluster and line positions, matching TextRasterizer::rasterize.
TextMeasure
Text geometry from TextRasterizer::measure. Rectangles are [left, top, right, bottom] in pixels from the layout box’s top-left, which sits at (TextTexture::layout_x, TextTexture::layout_y) in the rasterized texture.
TextRasterRequest
One text layout request.
TextRasterResult
Rasterized pixels and their text-specific layout descriptor.
TextRasterizer
Deterministic text host with version-key result caching.
TextSpan
A byte range of a request’s text with its own face, size, spacing, paint and decorations.
TextStroke
An outline band drawn behind the glyphs and earlier strokes.

Enums§

BoxExtent
Which part of each line a text’s background box spans.
ClusterGrouping
The units whose clusters scale and turn about one pivot, as After Effects’ Anchor Point Grouping.
FontStyle
Which faces of a family a span prefers, as CSS font-style.
TextFill
What paints a text’s glyphs.
TextGradientKind
Where a gradient’s offsets lie.
TextRasterError
Typed text-host failure.
TextSpread
What a linear or radial gradient shows past its first and last stops.

Constants§

DEFAULT_TEXT_CACHE_BYTES
Default result cache budget in bytes: a few full-frame 4K titles.
MAX_CLUSTER_SCALE
Largest scale of a ClusterState on either axis.
MAX_ELLIPSIS_BYTES
Most bytes in a TextClamp::ellipsis.
MAX_HIGHLIGHT_STEPS
Most steps a TextHighlightRequest takes.
MAX_REVEAL_EDGES
Most reveal edges a ClusterState takes.
MAX_TEXT_BOX
The widest wrapping width and the largest raster side in pixels.
MAX_TEXT_SPANS
Most spans one request holds.

Functions§

check_font
Checks that bytes hold an OpenType face at face_index, as TextRasterizer::add_font would, so a host can reject a file at import.
face_count
Number of faces in a font collection (.ttc, .otc), else 1.
fold_family
Normalizes a family name for comparison: NFC, then Unicode lowercase.
font_family
The face’s typographic family (name ID 16), else family (name ID 1), preferring US English. None for unparsable bytes or no family name.
font_family_names
Every distinct name ID 16 and 1 family name in every language, in table order. A project may name a family by any of them. Empty for unparsable bytes.
half_leading
CSS half-leading above the em box, or zero when lines are closer than an em.
line_limit
The most lines a clamp keeps of text font_size pixels tall with lines line_height font sizes apart: at most max_lines, and as many as fit in max_height pixels (non-positive for no height), but at least one. None when neither limits.
wrap_width
The width lines of a text max_width wide (non-positive for any width) break at when animation can widen its advances by advance_headroom (TextRasterRequest::advance_headroom).