text

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2022 License: MIT, Unlicense Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Alignment

type Alignment uint8
const (
	Start Alignment = iota
	End
	Middle
)

func (Alignment) String

func (a Alignment) String() string

type Cache

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

Cache implements cached layout and shaping of text from a set of registered fonts.

If a font matches no registered shape, Cache falls back to the first registered face.

The LayoutString and ShapeString results are cached and re-used if possible.

func NewCache

func NewCache(collection []FontFace) *Cache

func (*Cache) Layout

func (c *Cache) Layout(font Font, size fixed.Int26_6, maxWidth int, lc system.Locale, txt io.RuneReader) ([]Line, error)

Layout implements the Shaper interface.

func (*Cache) LayoutString

func (c *Cache) LayoutString(font Font, size fixed.Int26_6, maxWidth int, lc system.Locale, str string) []Line

LayoutString is a caching implementation of the Shaper interface.

func (*Cache) Shape

func (c *Cache) Shape(font Font, size fixed.Int26_6, layout Layout) clip.PathSpec

Shape is a caching implementation of the Shaper interface. Shape assumes that the layout argument is unchanged from a call to Layout or LayoutString.

type Face

type Face interface {
	Layout(ppem fixed.Int26_6, maxWidth int, lc system.Locale, txt io.RuneReader) ([]Line, error)
	Shape(ppem fixed.Int26_6, str Layout) clip.PathSpec
}

Face implements text layout and shaping for a particular font. All methods must be safe for concurrent use.

type Font

type Font struct {
	Typeface Typeface
	Variant  Variant
	Style    Style
	// Weight is the text weight. If zero, Normal is used instead.
	Weight Weight
}

Font specify a particular typeface variant, style and weight.

type FontFace

type FontFace struct {
	Font Font
	Face Face
}

A FontFace is a Font and a matching Face.

type Glyph

type Glyph struct {
	// ID is this glyph's identifier within the font it was shaped with.
	ID GlyphID
	// ClusterIndex is the identifier for the text shaping cluster that
	// this glyph is part of.
	ClusterIndex int
	// GlyphCount is the number of glyphs in the same cluster as this glyph.
	GlyphCount int
	// RuneCount is the quantity of runes in the source text that this glyph
	// corresponds to.
	RuneCount int
	// XAdvance and YAdvance describe the distance the dot moves when
	// laying out the glyph on the X or Y axis.
	XAdvance, YAdvance fixed.Int26_6
	// XOffset and YOffset describe offsets from the dot that should be
	// applied when rendering the glyph.
	XOffset, YOffset fixed.Int26_6
}

Glyph contains the metadata needed to render a glyph.

type GlyphCluster

type GlyphCluster struct {
	// Advance is the cumulative advance of all glyphs in the cluster.
	Advance fixed.Int26_6
	// Runes indicates the position and quantity of the runes represented by
	// this cluster within the text.
	Runes Range
	// Glyphs indicates the position and quantity of the glyphs within this
	// cluster in a Layout's Glyphs slice.
	Glyphs Range
}

GlyphCluster provides metadata about a sequence of indivisible shaped glyphs.

func (GlyphCluster) RuneWidth

func (c GlyphCluster) RuneWidth() fixed.Int26_6

RuneWidth returns the effective width of one rune for this cluster. If the cluster contains multiple runes, the width of the glyphs of the cluster is divided evenly among the runes.

type GlyphID

type GlyphID = font.GID

GlyphID uniquely identifies a glyph within a specific font.

type Layout

type Layout struct {
	// Glyphs are the actual font characters for the text. They are ordered
	// from left to right regardless of the text direction of the underlying
	// text.
	Glyphs []Glyph
	// Clusters are metadata about the shaped glyphs. They are mostly useful for
	// interactive text widgets like editors. The order of clusters is logical,
	// so the first cluster will describe the beginning of the text and may
	// refer to the final glyphs in the Glyphs field if the text is RTL.
	Clusters []GlyphCluster
	// Runes describes the position of the text data this layout represents
	// within the overall body of text being shaped.
	Runes Range
	// Direction is the layout direction of the text.
	Direction system.TextDirection
}

func (Layout) Slice

func (l Layout) Slice(start, end int) Layout

Slice returns a layout starting at the glyph cluster index start and running through the glyph cluster index end. The Offsets field of the returned layout is adjusted to reflect the new rune range covered by the layout. The returned layout will have no Clusters.

type Line

type Line struct {
	Layout Layout
	// Width is the width of the line.
	Width fixed.Int26_6
	// Ascent is the height above the baseline.
	Ascent fixed.Int26_6
	// Descent is the height below the baseline, including
	// the line gap.
	Descent fixed.Int26_6
	// Bounds is the visible bounds of the line.
	Bounds fixed.Rectangle26_6
}

A Line contains the measurements of a line of text.

type Range

type Range struct {
	// Count describes the number of items represented by the Range.
	Count int
	// Offset describes the start position of the represented
	// items within a larger list.
	Offset int
}

Range describes the position and quantity of a range of text elements within a larger slice. The unit is usually runes of unicode data or glyphs of shaped font data.

type Shaper

type Shaper interface {
	// Layout a text according to a set of options.
	Layout(font Font, size fixed.Int26_6, maxWidth int, lc system.Locale, txt io.RuneReader) ([]Line, error)
	// LayoutString is Layout for strings.
	LayoutString(font Font, size fixed.Int26_6, maxWidth int, lc system.Locale, str string) []Line
	// Shape a line of text and return a clipping operation for its outline.
	Shape(font Font, size fixed.Int26_6, layout Layout) clip.PathSpec
}

Shaper implements layout and shaping of text.

type Style

type Style int

Style is the font style.

const (
	Regular Style = iota
	Italic
)

func (Style) String

func (s Style) String() string

type Typeface

type Typeface string

Typeface identifies a particular typeface design. The empty string denotes the default typeface.

type Variant

type Variant string

Variant denotes a typeface variant such as "Mono" or "Smallcaps".

type Weight

type Weight int

Weight is a font weight, in CSS units subtracted 400 so the zero value is normal text weight.

const (
	Thin       Weight = 100 - 400
	Hairline   Weight = Thin
	ExtraLight Weight = 200 - 400
	UltraLight Weight = ExtraLight
	Light      Weight = 300 - 400
	Normal     Weight = 400 - 400
	Medium     Weight = 500 - 400
	SemiBold   Weight = 600 - 400
	DemiBold   Weight = SemiBold
	Bold       Weight = 700 - 400
	ExtraBold  Weight = 800 - 400
	UltraBold  Weight = ExtraBold
	Black      Weight = 900 - 400
	Heavy      Weight = Black
	ExtraBlack Weight = 950 - 400
	UltraBlack Weight = ExtraBlack
)

func (Weight) String

func (w Weight) String() string

Jump to

Keyboard shortcuts

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