Documentation
¶
Overview ¶
Package winfonts finds the system fonts of Windows: it answers a request for a family, a weight, a slant and a language with the fonts in the order Windows would try them, and a request for a character with the first font of the fallback chain that has it (SPEC §25.8).
The package is plain Go: it does not call Windows and has no build tags, so it is tested on every OS with lists of families and files written for the tests. The reading of the system (the font directories and the registry keys that list the installed fonts) is in package internal/platform/windows (fonts_windows.go), which gives the list of files to Scan; Scan reads the family, the weight and the slant of each face from the font file with go-text, as fontscan does. The matcher implements text.Matcher, text.Aliaser, text.Lister and text.Fallbacker.
Flutter: no counterpart (Skia: src/ports/SkFontMgr_win_dw.cpp chooses the fonts through DirectWrite; Glutter does not use DirectWrite)
Index ¶
- Constants
- func SupportedFile(path string) bool
- type Cache
- type Face
- type Matcher
- func (m *Matcher) Aliases(ctx context.Context, name string) ([]string, error)
- func (m *Matcher) Covers(_ context.Context, f text.FontFile, r rune) (has, known bool)
- func (m *Matcher) Fallback(ctx context.Context, name string, weight int, italic bool, lang string, r rune) (text.FontFile, bool, error)
- func (m *Matcher) Families(ctx context.Context) ([]string, error)
- func (m *Matcher) Match(ctx context.Context, name string, weight int, italic bool, lang string) ([]text.FontFile, error)
- type Options
- type Stamp
Constants ¶
const ( // // Flutter: no counterpart TagUnavailable = "WindowsFontsUnavailable" )
The tags of the errors that this file makes (rm4n0s/errors, R5).
Variables ¶
This section is empty.
Functions ¶
func SupportedFile ¶
SupportedFile says whether go-text can read the file, judging by its extension: TrueType and OpenType fonts and their collections. Windows also lists bitmap fonts (.fon) and Type 1 fonts.
Flutter: no counterpart
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache keeps the faces that Scan read, so that the next start of the app does not open every font file of the machine (hundreds on Windows). It is kept in a file in the cache directory of the user (Load and Save); a damaged file is an empty cache. It is not safe for concurrent use; Scan locks it.
Flutter: no counterpart
func LoadCache ¶
LoadCache reads the cache from a file. A file that is missing, damaged or of another version gives an empty cache, with no error: the next Scan reads the fonts and Save writes the file again.
Flutter: no counterpart
func (*Cache) Dirty ¶
Dirty says whether Scan learned a file since the cache was loaded or saved.
Flutter: no counterpart
type Face ¶
type Face struct {
// Family is the name of the family.
Family string
// Path is the font file; Index the face in it (0 for a file with one font).
Path string
Index int
// Weight is the OpenType weight (400 regular, 700 bold) and Italic whether the face is slanted
// (italic or oblique).
Weight int
Italic bool
}
Face is one face of a font file that is installed: the family it belongs to, as its name table says (the preferred family, so that "Segoe UI Semibold" is a weight of "Segoe UI"), its weight and slant, and where it is. A font collection (.ttc) has a face for each font in it.
Flutter: no counterpart
func Describe ¶
Describe reads the faces of a font file: the family, the weight and the slant of each font in it. The file is not kept open. It fails with WindowsFontUnreadable when the file cannot be opened or is not a font.
Flutter: no counterpart
func Scan ¶
func Scan(ctx context.Context, files []string, cache *Cache, onError func(path string, err error)) []Face
Scan reads the faces of the files, several at a time. A file that cannot be read is left out and reported to onError (when it is not nil); the faces keep the order of the files. A cache that has the file with the same stamp (see Stamp) saves reading it, and learns the files it did not have.
Flutter: no counterpart
type Matcher ¶
type Matcher struct {
// contains filtered or unexported fields
}
Matcher chooses the system fonts of Windows from the list of installed faces (SPEC §25.8). Build it with New. It is safe for concurrent use.
Flutter: no counterpart
func New ¶
New builds the matcher from the installed faces. It fails with WindowsFontsUnavailable when there are no faces.
Flutter: no counterpart
func (*Matcher) Aliases ¶
Aliases returns the installed families that the name stands for, most preferred first: Arial for Helvetica. A name that is not an alias, or an alias with no installed target, has none. It fails with WindowsFontsCanceled when ctx is done.
Flutter: no counterpart
func (*Matcher) Covers ¶
Covers implements text.Coverer with the reading of the font's cmap that Fallback uses (Options.HasGlyph), so that the text layout does not parse a font that cannot show a character. It knows only the installed faces, and is unknown for a font it cannot read.
Flutter: no counterpart
func (*Matcher) Fallback ¶
func (m *Matcher) Fallback(ctx context.Context, name string, weight int, italic bool, lang string, r rune) (text.FontFile, bool, error)
Fallback returns the first font that has a glyph for r: the font of the family (when it is installed), then, for an emoji, Segoe UI Emoji, then the families of the fallback chain in the order for the language. For each family only the face nearest to the weight and slant is asked. It is false when no font has the character. It fails with WindowsFontsCanceled when ctx is done.
Flutter: no counterpart
func (*Matcher) Families ¶
Families returns the names of the installed families, sorted without regard to case. It fails with WindowsFontsCanceled when ctx is done.
Flutter: no counterpart
func (*Matcher) Match ¶
func (m *Matcher) Match(ctx context.Context, name string, weight int, italic bool, lang string) ([]text.FontFile, error)
Match returns the fonts for the family, the OpenType weight (400 regular), the slant and the BCP 47 language, best first: the family itself (its face nearest to the weight and slant), then, for a generic family (sans-serif, serif, monospace, cursive, fantasy, system-ui, math and emoji), the families of the fallback chain, each with its nearest face, in the order for the language. A family that is not generic gives its own face only, or that of the family an alias stands for (Helvetica is Arial); one that is not installed gives none and no error, so the caller can go on to the next family. It fails with WindowsFontsCanceled when ctx is done.
Flutter: no counterpart
type Options ¶
type Options struct {
// Faces are the installed faces (Scan reads them from the files). New fails when there are none.
Faces []Face
// Locale is the BCP 47 tag of the language used when a request names none (the user's first
// language); "" keeps the order of the chain.
Locale string
// HasGlyph says whether the face at index of a font file has a glyph for r. It is how Fallback
// finds a font for a character. It defaults to the cmap of the font, read with go-text and kept
// per file and index.
HasGlyph func(path string, index int, r rune) bool
}
Options are the parameters of New.
Flutter: no counterpart