A pure Go library to find fonts on the system. Works on macOS, Linux, and Windows without any external dependencies.
go get -u github.com/danielgatis/go-findfontAnd then import the package in your code:
import "github.com/danielgatis/go-findfont/findfont"package main
import (
"fmt"
"os"
"github.com/danielgatis/go-findfont/findfont"
)
func main() {
path, err := findfont.Find("Arial")
if err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1)
}
fmt.Println(path)
}❯ go run main.go
/System/Library/Fonts/Supplemental/Arial.ttf
fonts := findfont.List()
for _, f := range fonts {
fmt.Println(f)
}path, err := findfont.FindWithSuffixes("MyFont", []string{".ttf", ".otf"})You can also use it as a command-line tool:
# Find a font
go-findfont Arial
# List all fonts
go-findfont --list| Platform | Font Directories |
|---|---|
| macOS | ~/Library/Fonts, /Library/Fonts, /System/Library/Fonts |
| Linux | ~/.fonts, ~/.local/share/fonts, /usr/share/fonts, /usr/local/share/fonts |
| Windows | %windir%\Fonts, %localappdata%\Microsoft\Windows\Fonts |
Copyright (c) 2020-present Daniel Gatis
Licensed under MIT License