Documentation
¶
Overview ¶
Package sysfont resolves system fonts through fontscan's CSS font selection rules, replacing per-app guesswork. Family matching here understands generic families, so "sans-serif" can never resolve to a serif face.
The system store is scanned once per process and its coverage map is reused for every resolution after that; Fallback builds on it to shape mixed-script text (CJK, emoji, Cyrillic in a latin face) by picking a covering face per rune instead of drawing .notdef boxes.
Index ¶
- func Best(family string, size float64) (*render.Typeface, error)
- func FaceFile(path string) (*render.Typeface, error)
- func Fallback(base *render.Typeface, onResolved func()) *render.Chain
- func FallbackFamilies() []string
- func Families() ([]string, error)
- func FamilyDisplay(family string) string
- func FamilyKey(name string) string
- func Monospace() (*render.Typeface, error)
- func PeekFaceFile(path string) (*render.Typeface, bool)
- func Sans() (*render.Typeface, error)
- func Serif() (*render.Typeface, error)
- func UI() (*render.Typeface, error)
- func UIMono() (*render.Typeface, error)
- func Variant(base *render.Typeface, bold, italic bool) (*render.Typeface, error)
- func Warm()
- func Weighted(family string, size float64, weight int, italic bool) (*render.Typeface, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Best ¶
Best resolves the family a widget asks for: any installed family name (symbol and emoji faces included, even though they lack latin coverage), or a CSS generic - sans-serif, serif, monospace. Size is the pixel size the face will shape at; resolution itself is size-independent, because outlines scale at shape time and the rasterizer scales to the canvas's device scale (see render.Canvas). A non-positive size is a caller bug and errors.
func FaceFile ¶
FaceFile loads a font file's first face once per path — the @font-face loader's entry point for app fonts declared in stylesheets. A file that fails to load is tried again by the next call. The path is the stylesheet's own src, app input like every stylesheet path. It maps and parses the file, so a first load belongs off the UI loop.
func Fallback ¶
Fallback returns a chain that shapes with base and, for runes it lacks, a face from the system store: the first of base's family and the standard fallback families (fallbackFamilies) that covers the rune, else the store's own pick for its script. The matcher picks from the store's coverage index, so only a face some rune needs is ever loaded: text in one script never pulls in a CJK collection or an emoji font. Pass the chain anywhere a render.Font is expected; a base with full coverage never consults the store. Runes nothing covers render .notdef, as before.
The store answers on the chain's own goroutine, so a paint never reads a font file; until then the rune shapes with base. onResolved, nil for none, runs on that goroutine when an answer changes the shaping.
func FallbackFamilies ¶
func FallbackFamilies() []string
FallbackFamilies returns the standard Linux fallback family names Fallback chains prefer, reporting only the ones installed, in preference order. Diagnostics (the doctor block) use it to show what mixed-script text falls back to; it loads no face.
func Families ¶
Families enumerates the system store's installed font families, sorted and deduped: the normalized names the matcher - and Best - accept, the set a font chooser offers. The store's own scan shares the disk index this reads.
func FamilyDisplay ¶
FamilyDisplay returns family's display-cased name, read from one of its faces (cached with the face itself); family unchanged when no face loads. Chooser rows and previews call this lazily, so a long family list never parses more than the faces actually shown.
func FamilyKey ¶
FamilyKey is the key Families lists a family under: name normalized the way the matcher normalizes it (lowercased, spaces and separators dropped), so "JetBrains Mono" finds "jetbrainsmono".
func PeekFaceFile ¶ added in v0.2.5
PeekFaceFile returns the typeface FaceFile loaded for path, reading nothing.
func Sans ¶
Sans returns the system's default sans-serif face, resolved with the same rules a browser applies to font-family: sans-serif.
func UI ¶
UI returns the face lys-ui's default look is drawn in: Geist, embedded in the binary, so every desktop renders the same UI face.
func Variant ¶
Variant resolves a bold, italic, or bold-italic face of the same family base was resolved from, with the CSS matcher's fallback: a family without the requested face returns its closest face, usually the regular one. RichLabel wiring compares identity with base and downgrades to plain rendering when they match.
func Warm ¶ added in v0.2.5
func Warm()
Warm scans the system font store and parses the embedded faces, so the UI loop's first look at a font finds them ready. It belongs off the loop; a scan cannot be interrupted, and the goroutine running it ends with the scan. An error sticks for whoever asks next, who reports it.
Types ¶
This section is empty.