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§
- Line
Metrics - Lines of a shaped text at one wrapping width (
ShapedText::lines_at). - Shaped
Text - A request’s text shaped once, for layout: its lines at any wrapping
width, broken as
TextRasterizer::rasterizebreaks them, without shaping again (TextRasterizer::shape). - Text
Background - A box behind each non-empty line: the line’s ink width and one font size
tall, grown by
paddingpixels on every side. Boxes that meet merge. - Text
Font - One caller-owned font registered in fallback order.
- Text
Measure - 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 textureTextRasterizer::rasterizedraws for the request holds that corner at (TextTexture::layout_x,TextTexture::layout_y). - Text
Outline - A band of
widthpixels around every glyph, behind it, in a straight (not premultiplied), sRGB-encoded RGBA color. - Text
Raster Request - One text layout request.
- Text
Raster Result - Rasterized pixels and their text-specific layout descriptor.
- Text
Rasterizer - Deterministic text host with version-key result caching.
Enums§
- Text
Raster Error - Typed text-host failure.
Constants§
- DEFAULT_
TEXT_ CACHE_ BYTES - The pixel bytes a
TextRasterizerkeeps cached by default: room for a few full-frame 4K titles, or hundreds of caption-sized ones.
Functions§
- check_
font - Checks that
byteshold an OpenType face atface_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.Nonefor bytes that do not parse or name no family.