Documentation
¶
Overview ¶
Package text shapes strings into grapheme clusters with terminal-cell widths and line-break opportunities for inline layout. Shaper caches shaping results.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BreakClass ¶
type BreakClass int
BreakClass describes the line-break opportunity BEFORE a grapheme cluster. Values mirror the simplified UAX.
const ( // BreakNone means there is no line-break opportunity before this cluster. BreakNone BreakClass = iota // BreakSoft is a discretionary break: at word boundaries (between a // whitespace cluster and the following non-whitespace cluster) and at // U+00AD (SOFT HYPHEN). When a soft-hyphen break is taken, a "-" is // rendered at the end of the line. BreakSoft // BreakMandatory is an unconditional break: LF, CR, CRLF, FF, U+0085 // (NEL), U+2028 (LINE SEPARATOR), U+2029 (PARAGRAPH SEPARATOR). BreakMandatory // BreakAnywhere marks every cluster boundary as a break opportunity. // Assigned to CJK Unified Ideographs, Hangul, Hiragana, Katakana, and // emoji clusters. BreakAnywhere )
type Cluster ¶
type Cluster struct {
Bytes []byte // UTF-8 grapheme bytes (no copy; refs source)
CellWidth int // 0, 1, or 2 per East Asian Width + emoji presentation
BreakClass BreakClass // line-break opportunity before this cluster
}
Cluster is a shaped extended grapheme cluster the atomic unit of text rendering and line-breaking in kite.
Bytes references the source string's backing memory without copying. Callers must not modify the slice and must ensure the source string outlives the returned clusters.
func Shape ¶
Shape segments text into extended grapheme clusters, assigns East-Asian-Width cell widths, and classifies line-break opportunities.
The Bytes field of each returned Cluster aliases text's backing memory without copying. text must outlive the returned slice.
Returns nil for an empty string.
type Shaper ¶
type Shaper struct {
// contains filtered or unexported fields
}
Shaper shapes text into grapheme clusters and caches results by (text, fontSubsetID) under a configurable byte-budget LRU policy. fontSubsetID is always 0 in kitex v2 (single font subset).
Shaper is not safe for concurrent use.
func NewShaper ¶
NewShaper creates a Shaper with the given byte budget. Pass 0 to use the default 256 KiB budget.
func (*Shaper) MeasureRun ¶
MeasureRun returns the total display cell width of text, reusing the shaping cache.