Skip to main content

Crate alpha2_text

Crate alpha2_text 

Source
Expand description

Text shaping and rasterization for alpha2 hosts.

The engine takes text as a host texture (TextTexture); this crate is one host for it, in pure Rust, from font bytes the caller supplies. Each paragraph is split by direction (UAX #9), script, and font, rustybuzz shapes each run, lines break where UAX #14 allows, and each glyph’s outline is drawn by ab_glyph_rasterizer when it is placed, or its color form (a COLR painting or a CBDT or sbix bitmap) by color. It builds the same way natively and for wasm, and the same request with the same fonts gives the same pixels on every target, so a browser preview and a native export of one project draw identical text. alpha2/text exposes it to JavaScript as WasmTextRasterizer.

Structs§

TextBackground
A box behind each non-empty line: the line’s ink width and one font size tall, grown by padding pixels on every side. Boxes that meet merge.
TextFont
One caller-owned font registered in fallback order.
TextMeasure
Where a request’s text lies, without drawing it (TextRasterizer::measure): rectangles as [left, top, right, bottom] in pixels from the layout box’s top-left corner, y down. The texture TextRasterizer::rasterize draws for the request holds that corner at (TextTexture::layout_x, TextTexture::layout_y).
TextOutline
A band of width pixels around every glyph, behind it, in a straight (not premultiplied), sRGB-encoded RGBA color.
TextRasterRequest
One text layout request.
TextRasterResult
Rasterized pixels and their text-specific layout descriptor.
TextRasterizer
Deterministic text host with version-key result caching.

Enums§

TextRasterError
Typed text-host failure.

Constants§

DEFAULT_TEXT_CACHE_BYTES
The pixel bytes a TextRasterizer keeps cached by default: room for a few full-frame 4K titles, or hundreds of caption-sized ones.

Functions§

check_font
Checks that bytes hold an OpenType face at face_index, as adding the font to a rasterizer checks it, without keeping anything: a host can refuse a file at import that the rasterizer would refuse later.
font_family
The family a font’s name table gives the face at face_index: its typographic family (name ID 16), else its family (name ID 1), in US English where the table has it, else in the first entry that decodes. None for bytes that do not parse or name no family.