Skip to content
pixi-silk
GitHub repository
Entry point

pixi-silk/i18n/shaper

The shaper path for text slots: kb_text_shape in WebAssembly (62 kB brotli) shapes player names with the font the bundle was baked from, drawn as a distance-field run sprite. TrueType fonts only.

import { KbShaper, ShapedTextProvider, createKbShaper, createShapedText } from 'pixi-silk/i18n/shaper';

Classes#

ClassDescription
KbShaperA RuntimeShaper for one TrueType font, backed by kb_text_shape compiled to WebAssembly (62 kB with brotli). It shapes Arabic, Hebrew, Latin and the other scripts kb_text_shape knows, with the bidi algorithm for mixed runs. Each shaper owns one WebAssembly instance and its memory.
ShapedTextProviderThe text slot provider createShapedText returns.

Interfaces#

InterfaceDescription
FontTablesThe tables of a TrueType font a run sprite needs.
KbShaperOptionsOptions of createKbShaper.
OutlinePointA point of a flattened outline, in font units, y up.
ShapedTextOptionsOptions of createShapedText.

Type Aliases#

Type AliasDescription
ContourOne closed contour as a polyline: quadratic curves are flattened.
KbWasmSourceWhere the kb_text_shape WebAssembly module comes from: its bytes, a compiled module or a URL.

Functions#

FunctionDescription
createKbShaperLoads kb_text_shape and a TrueType font into a KbShaper.
createShapedTextThe shaper path for text slots (brief sec. 6.5, shaper mode). kb_text_shape shapes the value with the font the bundle was baked from, the outlines are filled in JavaScript and a distance transform turns them into a run sprite. Slots then match the baked text in font, shaping and metrics on every platform, with no canvas. Pass the result as dynamicText to Silk.create.
fillContoursFills polygons into a coverage bitmap with exact area anti-aliasing: each edge adds its signed area to an accumulation buffer, and a running sum gives the coverage. Overlapping contours of the same direction (variable fonts) clamp to full coverage. Coordinates are in pixels, y down.
readFontpixi-silk/i18n/shaper: draws text slots (player names) with the font a bundle was baked from. kb_text_shape in WebAssembly shapes the value. The TrueType outlines are filled in JavaScript, and a distance transform turns them into a run sprite. Pass await createShapedText({ font }) as dynamicText to Silk.create. The kb.wasm file is fetched next to this module.