Skip to content

Find system fonts through the fontconfig library (a.k.a `fc-match`).

License

Notifications You must be signed in to change notification settings

danielgatis/go-findfont

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-findfont

Go Report Card License MIT Go Doc

A pure Go library to find fonts on the system. Works on macOS, Linux, and Windows without any external dependencies.

Install

go get -u github.com/danielgatis/go-findfont

And then import the package in your code:

import "github.com/danielgatis/go-findfont/findfont"

Usage

Find a font by name

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

List all fonts

fonts := findfont.List()
for _, f := range fonts {
	fmt.Println(f)
}

Find with custom suffixes

path, err := findfont.FindWithSuffixes("MyFont", []string{".ttf", ".otf"})

CLI

You can also use it as a command-line tool:

# Find a font
go-findfont Arial

# List all fonts
go-findfont --list

Supported Platforms

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

License

Copyright (c) 2020-present Daniel Gatis

Licensed under MIT License

About

Find system fonts through the fontconfig library (a.k.a `fc-match`).

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages