Documentation
¶
Overview ¶
Package textshape provides the pure-Go shaping foundation for MeUI.
It turns a UTF-8 string into visual runs with bidi levels, script segmentation, glyph IDs, advances and clusters. It deliberately has no renderer or widget dependency: the toolkit can use it for measurement and selection today, and renderer backends can grow a glyph-ID draw path later.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LineBreakOffsets ¶ added in v0.5.41
LineBreakOffsets returns byte offsets where UAX #14 permits a line break, excluding the end of the string. It covers scripts without spaces as well as punctuation rules that a naive "break every rune" wrapper violates.
Types ¶
type Glyph ¶
type Glyph struct {
GlyphID uint16 `json:"glyph_id"`
Cluster int `json:"cluster"`
Runes int `json:"runes"`
Advance float32 `json:"advance"`
XOffset float32 `json:"x_offset"`
YOffset float32 `json:"y_offset"`
XBearing float32 `json:"x_bearing"`
YBearing float32 `json:"y_bearing"`
Width float32 `json:"width"`
Height float32 `json:"height"`
}
Glyph is one shaped glyph. Cluster is a rune index into the original string (global across runs), not a byte offset.
type Run ¶
type Run struct {
Text string `json:"text"`
Start int `json:"start"` // rune index into the input
End int `json:"end"` // exclusive rune index
Direction Direction `json:"direction"`
Level uint8 `json:"level"`
Script string `json:"script"`
Advance float32 `json:"advance"`
Glyphs []Glyph `json:"glyphs"`
}
Run is a visually contiguous run with one direction and one script.
func VisualRuns ¶ added in v0.5.18
VisualRuns reorders logical runs into left-to-right visual slots using the UAX #9 L2 reversal pass. Levels come from the bidi run output. A renderer then lays each run out in its slot; RTL glyphs inside a run are already in visual order.
type Shaper ¶
type Shaper struct {
// contains filtered or unexported fields
}
Shaper owns a parsed font and reusable shaping/bidi state. It is safe for reuse, but callers should not use one Shaper concurrently.
func New ¶
New parses a TTF and returns a Shaper. OTF/CFF support follows the typesetting parser; MeUI's core font loader still accepts TTF only.
func (*Shaper) Shape ¶
Shape shapes text at size pixels. base is the paragraph direction; bidi overrides it when the text contains strong directional characters.
Runs are returned in logical order (bidi levels are preserved on each run). A renderer laying out a line reorders runs by level for visual placement. Glyph clusters remain indices into the original text, so selection and cursor mapping do not need a second rune-to-glyph table.