text

package
v0.9.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 16, 2026 License: MIT Imports: 24 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package text lays out text and rasterizes glyphs with the system's own text stack: DirectWrite on Windows, Core Text on macOS and Pango with cairo on Linux. They find the fonts, fall back to other fonts for what one lacks, shape and break lines; the package assembles their lines into layouts, with carets, selection and truncation of its own, and keeps the glyphs in the atlases scenes draw from. All methods of System are safe from any goroutine; the ui package uses them from the main thread.

Index

Constants

View Source
const Shades = 4

Shades is the number of shades of text.

Variables

This section is empty.

Functions

func EncodeSpans

func EncodeSpans(spans []Span) string

EncodeSpans writes spans for Params.Spans, which, as a string, keeps Params a value layouts are cached by.

func IsCombiningMark added in v0.9.1

func IsCombiningMark(r rune) bool

IsCombiningMark reports whether Backspace after r takes r alone, as systems do for combining marks, not the whole grapheme. Variation selectors are left out, so emoji sequences go whole and a selector never goes unseen. Sara am, a letter the segmenter joins to its consonant, goes alone too.

func IsWordRune added in v0.6.4

func IsWordRune(r rune) bool

IsWordRune reports whether r is part of a word: a letter, a digit or an underscore.

func RegisterAppFont added in v0.9.1

func RegisterAppFont(data []byte, family string) error

RegisterAppFont registers a font in Shared, as its RegisterFont does, and in every System New makes: before it lays out text, or at its next layout when it was made before. A Tester's window, which shapes in a System of its own, then draws the app's fonts as its windows do.

func StandsAlone added in v0.6.4

func StandsAlone(r rune) bool

StandsAlone reports whether r is a word on its own: a Han ideograph (with the iteration mark 々), a Hiragana or a Katakana (with the prolonged sound mark ー).

func WordBoundary added in v0.6.4

func WordBoundary(a, b rune) bool

WordBoundary reports whether a and b, next to each other, are in different words or runs of other runes: one is part of a word and the other is not, or either is a word on its own (StandsAlone). Script changes between Latin and Han or kana and kanji are boundaries so.

Types

type Affinity added in v0.2.17

type Affinity uint8

Affinity chooses the preceding or following logical text at a boundary. The two edges can occupy different positions in bidi text or at a wrap.

const (
	Downstream Affinity = iota
	Upstream
)

type Align

type Align uint8

Align is the horizontal alignment of the lines of a layout.

const (
	// Start aligns lines to the left, or to the right in right-to-left
	// paragraphs.
	Start Align = iota
	Center
	End
	// Left and Right align lines so whatever their direction, as the
	// start and the end of an interface laid out right to left do.
	Left
	Right
)

type Boundaries

type Boundaries struct {
	// contains filtered or unexported fields
}

Boundaries finds grapheme and word boundaries in text.

func (*Boundaries) GraphemeOffsets added in v0.2.17

func (b *Boundaries) GraphemeOffsets() []int

GraphemeOffsets returns a copy of the grapheme starts and text's end for a retained shaped-text layout.

func (*Boundaries) NextGrapheme

func (b *Boundaries) NextGrapheme(i int) int

NextGrapheme returns the end of the grapheme starting at or containing i.

func (*Boundaries) NextWord

func (b *Boundaries) NextWord(i int) int

NextWord returns the end of the word after i, skipping what is between. Each ideograph and kana is a word (see WordBoundary).

func (*Boundaries) PrevGrapheme

func (b *Boundaries) PrevGrapheme(i int) int

PrevGrapheme returns the start of the grapheme before i.

func (*Boundaries) PrevWord

func (b *Boundaries) PrevWord(i int) int

PrevWord returns the start of the word before i.

func (*Boundaries) Reset

func (b *Boundaries) Reset(runes []rune)

Reset prepares b for runes.

func (*Boundaries) WordAt

func (b *Boundaries) WordAt(i int) (start, end int)

WordAt returns the word, or the run of other runes, around i, within its line: an ideograph or a kana is a word alone.

type CaretPosition added in v0.2.17

type CaretPosition struct {
	Index    int
	Affinity Affinity
}

type Decoration added in v0.2.4

type Decoration uint8

Decoration is a line drawn along text.

const (
	Underline Decoration = iota
	Strikethrough
	// SolidUnderline is an Underline drawn through descenders, as links
	// mark hover, instead of skipping the ink of glyphs as Core Text does.
	SolidUnderline
)

type Font

type Font struct {
	// Size is the em size in DIPs.
	Size float32
	// Ascent, Descent and LineGap are the font's vertical metrics in
	// DIPs.
	Ascent, Descent, LineGap float32
	// contains filtered or unexported fields
}

Font is a font of the system, or of the app, at a size. Layouts and glyphs refer to fonts by pointer: an engine returns the same Font for the same font and size. A Font draws for as long as anything refers to it, after the System let go of it too (nativeFonts).

type FontFamily added in v0.5.0

type FontFamily struct {
	Name string
	// Monospaced is whether its regular font gives every character the
	// same advance.
	Monospaced bool
	// Registered is whether the app registered it (RegisterFont).
	Registered bool
}

A FontFamily is a font family text can use.

type Glyph

type Glyph struct {
	Font *Font
	ID   uint32
	// Size is the font size in DIPs.
	Size float32
	// X is the glyph's drawing origin, including shaping offsets, Y its
	// baseline. Advance moves the pen independently of those offsets.
	X, Y    float32
	Advance float32
	// Cluster is the first rune of the glyph's cluster, Runes how many
	// runes the cluster holds; glyphs of the ellipsis have Runes 0.
	Cluster, Runes int
	// RTL marks a glyph of a right-to-left run, whose cluster's first
	// rune is on its right.
	RTL bool
	// Object marks the box of an inline object (Span.ObjectWidth), which
	// draws no glyph: what shows there is the caller's.
	Object bool
}

Glyph is a positioned glyph.

type GlyphImage

type GlyphImage struct {
	// OK is false for glyphs without pixels, such as spaces.
	OK bool
	// Colored glyphs are in the color atlas, the others in the mask atlas
	// but Subpixel ones, in the color atlas too, which hold the coverage of
	// each pixel's red, green and blue subpixels.
	Colored, Subpixel bool
	// Thin glyphs are of a font too thin for antialiasing, which renderers
	// give more contrast (scene.Glyph.Thin).
	Thin bool
	// X, Y, W and H are the bitmap's rectangle in its atlas.
	X, Y, W, H uint16
	// Left and Top place the bitmap relative to the glyph's origin on the
	// baseline, in pixels: Top is usually negative.
	Left, Top float32
}

GlyphImage is a rasterized glyph in an atlas.

type Layout

type Layout struct {
	Params Params
	Runes  []rune
	Lines  []Line
	// Width is the width of the longest line, the first line's indent
	// included, Height the sum of the line heights.
	Width, Height float32

	// Truncated reports that MaxLines cut the text.
	Truncated bool
	// contains filtered or unexported fields
}

Layout is shaped and wrapped text. Positions are in DIPs relative to the top-left corner of the text.

func (*Layout) AppendSelection added in v0.5.0

func (l *Layout) AppendSelection(dst []Rect, start, end int, on bool) []Rect

AppendSelection appends the rectangles of SelectionVisual to dst, for callers that keep them frame after frame.

func (*Layout) Caret

func (l *Layout) Caret(index int) (x, y, h float32)

Caret returns the position of the caret before rune index: its x, the top of its line and the line's height.

func (*Layout) CaretAt added in v0.2.17

func (l *Layout) CaretAt(p CaretPosition) (x, y, h float32)

CaretAt preserves affinity at bidi boundaries and soft line breaks.

func (*Layout) IndexAt

func (l *Layout) IndexAt(x, y float32) int

IndexAt returns the rune index of the caret position closest to (x, y), between graphemes: never inside a cluster of runes.

func (*Layout) LineAt

func (l *Layout) LineAt(index int) int

LineAt returns the index of the line holding rune index, the start of the next line at a soft line break.

func (*Layout) MoveCaret added in v0.2.17

func (l *Layout) MoveCaret(p CaretPosition, direction int) CaretPosition

MoveCaret advances one visual grapheme, preserving the edge arrived at.

func (*Layout) PositionAt added in v0.2.17

func (l *Layout) PositionAt(x, y float32) CaretPosition

PositionAt hit-tests whole graphemes, retaining the visual edge chosen.

func (*Layout) Selection

func (l *Layout) Selection(start, end int) []Rect

Selection returns the rectangles covering the runes from start to end.

func (*Layout) SelectionOn added in v0.2.8

func (l *Layout) SelectionOn(start, end int, on bool) []Rect

SelectionOn is Selection for a layout of a paragraph of a longer text, whose selection goes on past the newline after the paragraph when on is set: the newline shows, as between the lines of a layout.

func (*Layout) SelectionRanges added in v0.2.17

func (l *Layout) SelectionRanges(a, b CaretPosition) []Range

SelectionRanges returns logical ranges covered by a visual gesture. A gesture through mixed-direction text can cover discontiguous ranges.

func (*Layout) SelectionVisual added in v0.2.17

func (l *Layout) SelectionVisual(start, end int, on bool) []Rect

SelectionVisual returns separate rectangles for selected visual runs. At bidi boundaries a logical range may cover disjoint areas on a line; taking the minimum and maximum caret would highlight intervening unselected text. on includes the paragraph's following newline, as SelectionOn does.

type Line

type Line struct {
	// X, Y, Width and Height are the line's box; X includes the alignment.
	X, Y, Width, Height float32
	// Baseline is the y of the baseline; Ascent and Descent the extent of
	// the fonts above and below it.
	Baseline, Ascent, Descent float32
	// Start and End are the line's runes; a newline ending it is not
	// included.
	Start, End int
	// RTL reports a right-to-left paragraph.
	RTL bool
	// Glyphs are in visual order, from the left, on every engine: X
	// ascends but for shaping offsets, and Cluster descends through a
	// right-to-left run (Glyph.RTL). The glyphs of a cluster are next to
	// each other.
	Glyphs []Glyph
	// contains filtered or unexported fields
}

Line is a line of a Layout.

type LineStyle added in v0.8.0

type LineStyle struct {
	// Thick, if positive, is the line's thickness in DIPs, around its
	// middle, rounded to whole pixels (at least one) and on whole pixels,
	// so that it is as sharp as browsers draw text-decoration-thickness.
	Thick float32
	// Offset, if HasOffset, puts the top of an underline Offset DIPs below
	// the baseline, or above it if negative, rounded to whole pixels, as
	// CSS's text-underline-offset does: an underline skipping ink skips
	// the glyphs where it is then. Strikethroughs stay where they are.
	Offset    float32
	HasOffset bool
}

LineStyle is how a decoration's line is drawn where the font leaves it otherwise.

type Params

type Params struct {
	Text  string
	Style Style
	// Width wraps lines to this many DIPs; 0 or less only breaks lines at
	// newlines.
	Width float32
	// MaxLines truncates the text to that many lines, ending it with
	// Ellipsis ("…" when empty); 0 is unlimited.
	MaxLines int
	Ellipsis string
	// TruncateMiddle puts the Ellipsis of a text that MaxLines cuts in
	// the middle of its last line rather than at its end: the line keeps
	// as many of the graphemes it starts with and of those ending its
	// paragraph as fit Width beside the ellipsis, about as wide on each
	// side, as a path keeps its first folders and its file's name. Where
	// the paragraph fits, and only the text after it is cut, or without a
	// width, the ellipsis ends the line all the same. TruncateStart, with
	// it, cuts the start instead. It takes effect once
	// System.UseTruncateMiddle or UseTruncateStart was called.
	TruncateMiddle bool
	// TruncateStart puts the Ellipsis of a text that MaxLines cuts at the
	// start of its last line rather than at its end: the line keeps as
	// many of the graphemes ending its paragraph as fit Width beside the
	// ellipsis, as a path keeps its file's name and the folders nearest
	// it. Where the paragraph fits, and only the text after it is cut, or
	// without a width, the ellipsis ends the line all the same. With
	// TruncateMiddle too, the start is cut. It takes effect once
	// System.UseTruncateStart or UseTruncateMiddle was called.
	TruncateStart bool
	// NoWrap breaks lines only at newlines, aligning them within Width
	// all the same.
	NoWrap bool
	Align  Align
	// RTL makes paragraphs without a strongly directional character, as
	// numbers or an empty line, right to left, as in an interface laid out
	// right to left; the others read in the direction of their first
	// strongly directional character, as Unicode's bidirectional
	// algorithm finds it by default (rules P2 and P3), whichever this is.
	RTL bool
	// KeepSpaces keeps the advance of whitespace at the end of wrapped
	// lines, as text editors do.
	KeepSpaces bool
	// NoBreakWords only breaks lines between words, letting a long word
	// overflow the width instead of breaking it.
	NoBreakWords bool
	// Indent moves the first line of the text this many DIPs from the
	// start of its paragraph's direction, the left or the right, and
	// wraps it that much narrower, as CSS's text-indent; 0 or less is
	// none. The lines after a newline are not indented.
	Indent float32
	// Justify stretches every line that Width wraps to Width, the
	// whitespace ending it left out, by widening the spaces between its
	// words and the room after Han characters and kana, as browsers
	// justify text, once System.UseJustify was called. Align places the
	// last line of each paragraph, and a line with nothing to widen.
	Justify bool
	// Balance wraps each paragraph that Width wraps in lines of about the
	// same length, as CSS's text-wrap: balance does: in as many lines as
	// it takes, wrapped at the narrowest width that keeps them as many,
	// rather than full lines and a short last one. The lines are aligned
	// within Width all the same. A paragraph that MaxLines cuts wraps as
	// it would without it.
	Balance bool
	// Pretty keeps the last line of each paragraph that Width wraps from
	// holding a single word, as CSS's text-wrap: pretty does at least: the
	// line before gives it a word, wrapped as wide as that leaves them,
	// the lines before as they are. A paragraph that Balance balances or
	// MaxLines cuts wraps as it would without it. It takes effect once
	// System.UsePretty was called.
	Pretty bool
	// Spans styles runs of the text apart from Style, as EncodeSpans
	// writes them.
	Spans string
}

Params describe a text to lay out.

type Range added in v0.2.17

type Range struct{ Start, End int }

type Rect

type Rect struct{ X, Y, W, H float32 }

Rect is a rectangle in DIPs relative to the layout.

type Shade added in v0.2.4

type Shade uint8

A Shade is how light the color of text is, from 0 (dark) to Shades-1 (light). Core Text's font smoothing, which AppKit draws text with, emboldens glyphs more the lighter their color is, in four steps of its relative luminance: the glyphs of its fonts are rasterized for each.

const Flat Shade = Shades + 1

Flat is a shade beyond the others, for text drawn without font smoothing, whatever its color: thinner, as browsers draw text styled -webkit-font-smoothing: antialiased on macOS. Engines that do not smooth fonts draw it as other text.

const Thick Shade = Shades

Thick is a shade beyond the others, for text drawn thicker: with Core Text's font smoothing at its strongest, whatever the text's color and the user's setting, as Ghostty's font-thicken draws it. Engines that do not thicken glyphs draw them as for other text.

func ShadeOf added in v0.2.4

func ShadeOf(r, g, b uint8) Shade

ShadeOf returns the shade of text of an sRGB color: its relative luminance rounded to a quarter, as Core Text rounds it, and at most 3/4.

type Span

type Span struct {
	End           int
	Family        string
	Size          float32
	Weight        int
	Italic        bool
	LetterSpacing float32
	// SpacingSet makes LetterSpacing the span's when zero too, rather
	// than the text's, as CSS's letter-spacing: 0 on an inline box.
	SpacingSet bool
	Features   string
	// Lang is the language of the runes, as Style.Lang; "" keeps the
	// text's.
	Lang string
	// ObjectWidth and ObjectHeight, when ObjectWidth is set, make each
	// rune of the span, an object replacement character (U+FFFC), an
	// inline object: a box that wide, standing that high on the baseline,
	// which lines break around and which draws no glyph, as an image in a
	// rich text's line (Glyph.Object). ObjectDescent extends the box that
	// far below the baseline, as math's subscripts and fractions go.
	ObjectWidth, ObjectHeight, ObjectDescent float32
	// BaselineShift raises the span's glyphs and objects that many DIPs
	// above the baseline, or lowers them when negative, as superscripts
	// and subscripts are; the line makes room for them.
	BaselineShift float32
	// PaddingX widens the span that many DIPs at both ends of each line's
	// piece of it, as the horizontal padding of CSS's inline boxes with
	// box-decoration-break: clone: the glyphs move in, and the line, which
	// breaks to fit it, is that much wider.
	PaddingX float32
	// PaddingStart widens the span that many DIPs more at the start of
	// each line's piece of it, past PaddingX, as CSS's
	// padding-inline-start: the left of a left-to-right piece, the right
	// of a right-to-left one. Room for an icon drawn before the span, a
	// link's site's.
	PaddingStart float32
}

Span styles the runes of a text before End, after those of the spans before it. What it sets replaces the Style of the layout; Italic only turns italics on.

func DecodeSpans added in v0.5.0

func DecodeSpans(s string) []Span

DecodeSpans reads what EncodeSpans wrote.

type Stroke added in v0.2.4

type Stroke struct{ X0, X1, Top, Bottom float32 }

A Stroke is a stretch of a decoration's line, in device pixels: from X0 to X1 and from Top to Bottom, which renderers antialias where they fall within pixels.

type Style

type Style struct {
	// Family is a comma-separated list of font families, where "system-ui"
	// and "monospace" are the system's own; "" is the system UI font.
	Family string
	// Size in DIPs; 0 is 14.
	Size float32
	// Weight from 100 (thin) to 900 (black); 0 is 400.
	Weight int
	Italic bool
	// LineHeight is the height of a line as a multiple of Size; 0 takes
	// the font's own line spacing.
	LineHeight float32
	// LetterSpacing adds DIPs after every character; negative tightens.
	LetterSpacing float32
	// Features are OpenType features, comma separated: a tag turns one
	// on, and tag=value sets it, as "tnum, liga=0, salt=2".
	Features string
	// Lang is the language of the text, a BCP 47 tag as "ja" or
	// "zh-Hant": the system's text stack picks the glyphs of that
	// language, as the Han characters Chinese and Japanese write apart,
	// and falls back to fonts for it. Korean text breaks its lines
	// between words (keepWordsWhole). "" is the language of the System
	// (SetLanguage).
	Lang string
	// TabSize puts tab stops every TabSize spaces of the style's font,
	// letter spacing included, from the start of each line, as CSS's
	// tab-size, once System.UseTabSize was called; 0 leaves them where
	// the system's text stack puts them.
	TabSize float32
	// contains filtered or unexported fields
}

Style selects the font of a text.

func (Style) FontSize

func (s Style) FontSize() float32

FontSize returns the size in DIPs.

type System

type System struct {

	// MaskAtlas holds coverage masks, ColorAtlas color glyphs.
	MaskAtlas, ColorAtlas *scene.Atlas
	// contains filtered or unexported fields
}

System lays out text and rasterizes glyphs with the system's own text engine. Use Shared.

func New added in v0.9.1

func New() *System

New returns a text system apart from the shared one, as a Tester's window uses: its shaping and its glyph atlases are its own, so windows that draw at the same time, as Testers do in parallel tests, neither race over nor invalidate each other's atlases. An app's windows share Shared.

func Shared

func Shared() *System

Shared returns the process-wide text system.

func (*System) Baseline added in v0.2.4

func (s *System) Baseline(y float32) float32

Baseline returns where the system's text stack draws a baseline that is y device pixels from the top: on a whole pixel.

func (*System) BeginFrame

func (s *System) BeginFrame()

BeginFrame starts painting a frame: the masks drawn for the previous frame alone are forgotten.

func (*System) Decorate added in v0.2.4

func (s *System) Decorate(l *Layout, li, i, j int, x, y, scale float32, d Decoration, ls LineStyle) []Stroke

Decorate returns the strokes the system's text stack draws for decoration d of glyphs [i, j) of line li of l, runes of one style, with the layout's origin at (x, y) DIPs, at scale pixels per DIP: placed as AppKit, Direct2D or GTK place underlines and strikethroughs, with their thickness, but for what ls sets.

func (*System) EndFrame

func (s *System) EndFrame()

EndFrame forgets layouts no frame used for a while. The ui package calls it after each frame.

func (*System) FontFamilies added in v0.5.0

func (s *System) FontFamilies() []FontFamily

FontFamilies lists the families text can use: the app's registered ones first, under the names it gave them, or their own when it gave none, then the system's, each once and sorted without regard to case. The system's are listed once, outside the lock, and kept until RegisterFont.

func (*System) Full

func (s *System) Full() bool

Full reports whether an atlas filled up during the frame being painted and left out glyphs or masks it draws. MakeRoom then makes room for them.

func (*System) Generation added in v0.2.9

func (s *System) Generation() uint64

Generation returns a number that changes whenever the system forgets its layouts, as it lets go of its fonts (EndFrame) or takes other ones: the layouts it returned before are then to be made anew. Until then they still draw, with the fonts they were made with.

func (*System) Glyph

func (s *System) Glyph(f *Font, id uint32, scale, x float32, shade Shade, opaque bool) GlyphImage

Glyph rasterizes glyph id of a font at scale pixels per DIP whose pen is x device pixels from the left, for text of a shade, placed as the system's text stack places glyphs: at one of the positions within a pixel it draws them at. Left is relative to the pixel x is in. Glyphs on opaque backgrounds may be subpixel ones, when the system's settings (TextParams) ask for subpixel antialiasing.

func (*System) GlyphBitmap added in v0.9.1

func (s *System) GlyphBitmap(f *Font, id uint32, scale, dx, stroke float32) (left, top, w, h int, pix []byte)

GlyphBitmap rasterizes a glyph of f for drawing on the CPU, as the text of SVG documents is drawn, and keeps it nowhere: at scale pixels per DIP, its origin dx pixels right of the left edge of a pixel (0 ≤ dx < 1), unshaded, or with stroke > 0 the stroke of its outline stroke pixels wide (StrokeGlyph). It returns w×h bytes of coverage, color glyphs' alpha, placed left and top pixels from the glyph's origin.

func (*System) GlyphRun added in v0.2.4

func (s *System) GlyphRun(f *Font, ids []uint32, xs []float32, scale float32, shade Shade, opaque bool) GlyphImage

GlyphRun returns glyphs ids of a font, their pens at xs device pixels from the left, joined as the system's text stack draws a run whose antialiased edges share pixels (JoinsGlyphs): their coverage added and clamped. The glyphs are for text of a shade, on an opaque background or not, as for Glyph. Left is relative to the pixel the first pen is in.

func (*System) JoinsGlyphs added in v0.2.4

func (s *System) JoinsGlyphs() bool

JoinsGlyphs reports whether glyphs of a run whose edges share pixels look as the system's text stack draws them only joined (GlyphRun), with their coverage added before blending (cairo, GTK), rather than blended each in turn as renderers do (Core Graphics, Direct2D).

func (*System) Language added in v0.5.0

func (s *System) Language() string

Language returns the language SetLanguage set.

func (*System) Layout

func (s *System) Layout(p Params) *Layout

Layout shapes and wraps p.Text. The result is shared and must not be modified.

func (*System) LayoutFrom added in v0.8.0

func (s *System) LayoutFrom(l *Layout, p Params) *Layout

LayoutFrom lays out p as Layout does, from l, if not nil, a layout of the same text at another width, as a box growing or shrinking lays its text out at each width: where l wraps none of its lines and fits p's width, p lays out alike, its lines aligned anew, rather than shaped again; at the left of their box, it shares them. So does the text's layout without a width, once made.

func (*System) LayoutsMade added in v0.2.8

func (s *System) LayoutsMade() uint64

LayoutsMade returns how many layouts the system has made, those Layout found in its cache left out.

func (*System) MakeRoom

func (s *System) MakeRoom()

MakeRoom makes room in the atlases that filled up: it keeps what the frame being painted drew, growing the atlas when that and what the frame still needs take much of it, or when room made for the frame before did not suffice, and forgets everything else. Everything kept moves, so the frame must be painted again.

func (*System) Mask

func (s *System) Mask(key uint64, draw func() (w, h int, pix []byte)) GlyphImage

Mask returns a coverage mask cached under key in the mask atlas, drawing it when it is not: draw returns its size and one byte per pixel. Icons and other vector shapes use it. If the dimensions cannot fit the current atlas, draw may return nil pixels: the miss records that size for MakeRoom without rasterizing it.

A mask a frame draws for the first time may be one frame of an animation, never drawn again: it lasts for that frame only, in the atlas's transient room. Later frames try to cache it in lasting room, requesting MakeRoom when that is full. A recovery paint can fall back to transient room if lasting room is still full.

func (*System) MaskFull added in v0.9.1

func (s *System) MaskFull() bool

MaskFull reports whether the coverage atlas left out a glyph or mask, as distinct from the color atlas. A painter can then release large path masks in favor of tiles before making room for the final retry.

func (*System) Metrics

func (s *System) Metrics(style Style) (ascent, descent, lineHeight float32)

Metrics returns the ascent, descent and default line height of a style.

func (*System) Origin added in v0.8.0

func (s *System) Origin(f *Font, scale, x float32, opaque bool) float32

Origin returns where Glyph puts the origin of a glyph of f whose pen is x device pixels from the left: at the position within a pixel the system's text stack draws it at.

func (*System) Preload

func (s *System) Preload()

Preload starts the text engine and finds the system UI font, which the first layout otherwise waits for.

func (*System) RegisterFont

func (s *System) RegisterFont(data []byte, family string) error

RegisterFont adds a TrueType or OpenType font (or collection) to the fonts text can use, under family, or the font's own family name when family is empty.

func (*System) ReleaseShaping added in v0.8.0

func (s *System) ReleaseShaping()

ReleaseShaping lets go of what the engine keeps of text shaped lately, for when a window goes idle: the next frames shape it again.

func (*System) SetFontRendering added in v0.2.4

func (s *System) SetFontRendering(antialias, hinting, subpixels string)

SetFontRendering sets how text is rasterized where the system's text stack does not know the desktop's settings, as Pango on Linux: antialiasing ("none", "gray" or "subpixel"), hinting ("none", "slight", "medium" or "full") and the order of the screen's subpixels ("rgb", "bgr", "vrgb" or "vbgr"), "" for the default. Other engines ignore it.

func (*System) SetLanguage added in v0.5.0

func (s *System) SetLanguage(tag string)

SetLanguage sets the language of the texts whose Style names none, a BCP 47 tag, or "" for none: the system's text stack then picks glyphs and fallback fonts as it does by default, by the user's settings. The ui package sets the language the app shows. The layouts made before are made anew (Generation).

func (*System) SetUIFamily

func (s *System) SetUIFamily(family string)

SetUIFamily sets the family "system-ui" stands for where the system's text stack does not know the desktop's interface font, as Pango on Linux, which finds fontconfig's default sans-serif. Other engines ignore it.

func (*System) ShadowGlyph added in v0.8.0

func (s *System) ShadowGlyph(f *Font, id uint32, scale, x float32, shade Shade, opaque bool, sigma float32) GlyphImage

ShadowGlyph returns the coverage mask of the glyph Glyph returns for the same arguments blurred by a Gaussian of standard deviation sigma device pixels, placed as that glyph is, wider by the blur: a mask glyph, for color glyphs too, of their pixels' alpha, which a text's shadow (CSS's text-shadow) paints in its color.

func (*System) Shape added in v0.2.4

func (s *System) Shape(p Params) *Layout

Shape lays out p.Text as Layout does, but caches nothing, for text that its caller keeps or rarely draws twice. The result belongs to the caller.

func (*System) Shares added in v0.2.4

func (s *System) Shares(a GlyphImage, ax, ay float32, b GlyphImage, bx, by float32) bool

Shares reports whether glyphs a and b, their bitmaps' top-left corners at (ax, ay) and (bx, by) device pixels, both cover a pixel.

func (*System) StrokeGlyph added in v0.8.0

func (s *System) StrokeGlyph(f *Font, id uint32, scale, x float32, shade Shade, opaque bool, width float32) GlyphImage

StrokeGlyph returns the coverage mask of a stroke width device pixels wide along the outline of the glyph Glyph returns for the same arguments, centered on it and round at its corners, placed as that glyph is: a mask glyph, for color glyphs too, which strokes the edge of their pixels. Text stroked under its fill (CSS's paint-order: stroke fill) shows the half outside the glyph.

func (*System) TextParams added in v0.2.4

func (s *System) TextParams() scene.TextParams

TextParams returns how renderers correct the coverage of glyphs, as the system's settings say, for the frame being painted, and has glyphs on opaque backgrounds take subpixel antialiasing if they ask for it.

func (*System) TransientUses added in v0.7.0

func (s *System) TransientUses() uint64

TransientUses returns how many times Mask returned a mask drawn for the frame being painted alone, since the system started: a scene drawing one must not be drawn again after the next frame of any window begins (BeginFrame), which draws over it.

func (*System) TryMask added in v0.9.1

func (s *System) TryMask(key uint64, draw func() (w, h int, pix []byte)) GlyphImage

TryMask is Mask without asking for room: a mask that finds none is not left out of the frame, which then neither reports Full nor has MakeRoom make room for it, for a caller that draws it another way.

func (*System) Unkeep added in v0.8.0

func (s *System) Unkeep(keys []uint64)

Unkeep lets the masks cached under keys go as the atlas makes room for the frame being painted (MakeRoom), unless it draws them again first: masks it drew that the frame painted again draws otherwise, which the room made would keep but no paint draws.

func (*System) UseJustify added in v0.7.2

func (s *System) UseJustify()

UseJustify lets layouts justify their lines (Params.Justify), which package ui calls as the first TextShape asks for it.

func (*System) UsePretty added in v0.8.0

func (s *System) UsePretty()

UsePretty lets layouts keep the last line of a paragraph from holding a single word (Params.Pretty), which package ui calls as an element or a TextShape asks for it.

func (*System) UseTabSize added in v0.8.0

func (s *System) UseTabSize()

UseTabSize lets layouts set their tab stops (Style.TabSize), which package ui calls as an element sets a tab size.

func (*System) UseTruncateMiddle added in v0.9.0

func (s *System) UseTruncateMiddle()

UseTruncateMiddle lets layouts cut text in its middle (Params.TruncateMiddle), which package ui calls as an element asks for it.

func (*System) UseTruncateStart added in v0.9.1

func (s *System) UseTruncateStart()

UseTruncateStart lets layouts cut text at its start (Params.TruncateStart), which package ui calls as an element asks for it.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL