Documentation
¶
Overview ¶
Package text lays out paragraphs on go-text: the font collection, shaping, line breaking, bidi and glyph outlines.
Flutter: libtxt and Skia's paragraph module (engine/src/flutter/third_party/txt).
Index ¶
- Constants
- func IsEmoji(r rune) bool
- type Collection
- func (c *Collection) AddBundled(family string, data []byte) error
- func (c *Collection) Face(ctx context.Context, f FontFile, variations ...Variation) (*font.Face, error)
- func (c *Collection) Fallback(ctx context.Context, family string, weight int, italic bool, lang string, ...) (FontFile, bool, error)
- func (c *Collection) Match(ctx context.Context, family string, weight int, italic bool, lang string) ([]FontFile, error)
- type CollectionOpts
- type Fallbacker
- type FontFile
- type Matcher
- type Variation
Constants ¶
const BundledPrefix = "bundled:"
BundledPrefix starts the Path of a FontFile that is a bundled font (AddBundled) rather than a file on disk.
Flutter: no counterpart
Variables ¶
This section is empty.
Functions ¶
func IsEmoji ¶
IsEmoji reports whether the rune is one that a text normally shows as a color emoji: the pictographs of the emoji blocks and the symbols and dingbats that have an emoji presentation. A font that has such a rune in color is preferred over one that has it as a black and white symbol.
Flutter: no counterpart
Types ¶
type Collection ¶
type Collection struct {
// contains filtered or unexported fields
}
Collection finds and loads fonts: the bundled ones, and the system fonts in the order the Matcher (or the font scan) gives. It caches the loaded faces. It is safe for concurrent use, but a font.Face it returns is not: each variation set has its own Face, which one goroutine at a time may use.
Flutter: engine/src/flutter/third_party/txt/src/txt/font_collection.cc FontCollection
func NewCollection ¶
func NewCollection(opts ...CollectionOpts) *Collection
NewCollection makes an empty font collection. More than one options value panics with MultipleOptions.
Flutter: engine/src/flutter/third_party/txt/src/txt/font_collection.cc FontCollection::FontCollection
func (*Collection) AddBundled ¶
func (c *Collection) AddBundled(family string, data []byte) error
AddBundled registers a font that is part of the program under a family name, such as Roboto or MaterialIcons. A request for that family finds it before any system font. data is the content of a TrueType or OpenType file (a collection is read at index 0). It fails with FontBundledInvalid when the data is not a font.
Flutter: engine/src/flutter/third_party/txt/src/txt/font_collection.cc FontCollection::RegisterFont
func (*Collection) Face ¶
func (c *Collection) Face(ctx context.Context, f FontFile, variations ...Variation) (*font.Face, error)
Face returns the face of the font with the variable axes set. The same file, index and variations give the same Face. It fails with FontLoadFailed when the file cannot be read or is not a font, or has no face at the index, and with FontLoadCanceled when ctx is done. A variation whose tag is not four letters fails with FontVariationInvalid.
Flutter: engine/src/flutter/third_party/txt/src/txt/font_collection.cc FontCollection::CreateMinikinFontCollection
func (*Collection) Fallback ¶
func (c *Collection) Fallback(ctx context.Context, family string, weight int, italic bool, lang string, r rune) (FontFile, bool, error)
Fallback returns a system font that has a glyph for r, when the fonts of Match do not; it is false when there is none (or the Matcher cannot look for a character). It fails like Match.
Flutter: engine/src/flutter/third_party/txt/src/txt/font_collection.cc FontCollection::GetFallbackFontForRune
func (*Collection) Match ¶
func (c *Collection) Match(ctx context.Context, family string, weight int, italic bool, lang string) ([]FontFile, error)
Match returns the fonts for the family, best first: the bundled font of that family if there is one, then the system fonts in the order of the Matcher or of the font scan (only TrueType and OpenType files, which go-text reads). weight is an OpenType weight (400 regular, 700 bold), lang a BCP 47 tag or "". It fails with FontMatchCanceled when ctx is done, with FontScanFailed when the fonts cannot be scanned; the Matcher's own error is returned unchanged.
Flutter: engine/src/flutter/third_party/txt/src/txt/font_collection.cc FontCollection::GetMinikinFontCollectionForFamilies
type CollectionOpts ¶
type CollectionOpts struct {
// Matcher decides the fallback order. When nil, the Collection scans the system
// font directories with go-text's fontscan, and keeps its index in CacheDir.
Matcher Matcher
// CacheDir is where the fontscan index is kept. It defaults to
// $XDG_CACHE_HOME/glutter/fonts (~/.cache/glutter/fonts).
CacheDir string
// Logger receives the non-fatal problems fontscan finds (fonts it cannot read).
// It defaults to a logger that discards them.
Logger interface {
Printf(format string, args ...any)
}
}
CollectionOpts are the optional parameters of NewCollection.
Flutter: no counterpart
type Fallbacker ¶
type Fallbacker interface {
// Fallback returns a font with a glyph for r, or false when there is none.
Fallback(ctx context.Context, family string, weight int, italic bool, lang string, r rune) (FontFile, bool, error)
}
Fallbacker is a Matcher that can also find a font for one character that the fonts of Match do not have. A Collection uses it when the Matcher implements it.
Flutter: no counterpart
type FontFile ¶
type FontFile struct {
// Path is the font file, or BundledPrefix followed by the family of a bundled
// font.
Path string
// Index is the face in a font collection (the low 16 bits). The high 16 bits
// that fontconfig sets for a named instance of a variable font are ignored:
// the caller sets the variable axes (the weight, for one) with Variation.
Index int
// Family is the family name of the font, or "" when unknown.
Family string
}
FontFile is one font of a fallback list: a file on disk (or a bundled font) and the face in it. Its fields are those of the fontconfig package's File.
Flutter: no counterpart
type Matcher ¶
type Matcher interface {
// Match returns the fallback order for the family (which can be a generic name
// such as "sans-serif"), the OpenType weight (400 regular), the slant and the
// BCP 47 language tag ("" for the default).
Match(ctx context.Context, family string, weight int, italic bool, lang string) ([]FontFile, error)
}
Matcher says which font files fit a family and style, best first. The fontconfig package implements it on Linux; without it the Collection scans the font directories itself.
Flutter: no counterpart