sysfont

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT, MIT Imports: 13 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 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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Best

func Best(family string, size float64) (*render.Typeface, error)

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

func FaceFile(path string) (*render.Typeface, error)

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

func Fallback(base *render.Typeface, onResolved func()) *render.Chain

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

func Families() ([]string, error)

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

func FamilyDisplay(family string) string

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

func FamilyKey(name string) string

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 Monospace

func Monospace() (*render.Typeface, error)

Monospace returns the system's default monospace face.

func PeekFaceFile

func PeekFaceFile(path string) (*render.Typeface, bool)

PeekFaceFile returns the typeface FaceFile loaded for path, reading nothing.

func Sans

func Sans() (*render.Typeface, error)

Sans returns the system's default sans-serif face, resolved with the same rules a browser applies to font-family: sans-serif.

func Serif

func Serif() (*render.Typeface, error)

Serif returns the system's default serif face.

func UI

func UI() (*render.Typeface, error)

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 UIMono

func UIMono() (*render.Typeface, error)

UIMono returns the default look's monospace face: Geist Mono, embedded beside UI.

func Variant

func Variant(base *render.Typeface, bold, italic bool) (*render.Typeface, error)

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

func Warm(ctx context.Context)

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, and returns soon after ctx is done, leaving the store to whoever asks next. An error sticks for whoever asks next, who reports it.

func Weighted

func Weighted(family string, size float64, weight int, italic bool) (*render.Typeface, error)

Weighted resolves family at a CSS numeric weight (100-900) and style, with the same closest-face fallback as Variant: a family without that weight returns its nearest face. Size follows Best.

Types

This section is empty.

Jump to

Keyboard shortcuts

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