fonts

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: AGPL-3.0 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 fonts lists the font families installed on the machine, for the interface's and the terminal's font settings. It asks MyGo's text engine first (ui.FontFamilies: Core Text, DirectWrite, fontconfig through Pango), which knows what text can actually draw with; where that lists nothing, it reads the system itself, without cgo: fontconfig's fc-list on Linux when present, else the font files in the platform's font directories (macOS's, %WINDIR%\Fonts and the per-user fonts on Windows, fontconfig's on Linux), whose names and pitch it parses from their OpenType tables.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dirs

func Dirs(goos string, getenv func(string) string, home string) []string

Dirs are where a platform keeps its fonts, the user's own included.

func Has

func Has(fs []Family, name string) bool

Has reports whether name is one of fs, without regard to case.

Types

type Family

type Family struct {
	Name string
	// Mono is whether it is monospaced, as a terminal wants.
	Mono bool
}

Family is an installed font family.

func ForTerminal

func ForTerminal(fs []Family, monoOnly bool) []Family

ForTerminal orders families for a terminal's font setting: the monospaced ones first, then, unless monoOnly, the others.

func List

func List() []Family

List lists the installed families, each once, sorted without regard to case.

func Normalize

func Normalize(fs []Family) []Family

Normalize drops empty and hidden names (".SF NS", as macOS keeps for itself) and lists each family once, monospaced if any of its fonts is, sorted without regard to case.

func ParseFCList

func ParseFCList(out string) []Family

ParseFCList parses `fc-list --format '%{family}\t%{spacing}\n'`: per font, its family names (a comma-separated list, the first the canonical one; commas within names are escaped as "\,") and its spacing, 100 for monospaced and 90 for dual-width (as CJK monospace fonts are), empty for proportional.

func ParseFont

func ParseFont(data []byte) ([]Family, error)

ParseFont reads the family of each font in a TrueType or OpenType font, or collection: its typographic family name (name ID 16) or else its family name (1), English first; monospaced when its post table says isFixedPitch or its OS/2 PANOSE proportion is monospaced.

func Scan

func Scan() []Family

Scan reads the system's families without the text engine.

func ScanDirs

func ScanDirs(dirs []string) []Family

ScanDirs reads the families of the font files under dirs.

Jump to

Keyboard shortcuts

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