Sysfont Save

Golang identification and matching of system fonts

Project README

sysfont

Build Status pkg.go.dev documentation MIT license Go report card GitHub issues Buy me a coffee

sysfont is a small package that makes it easy to identify installed fonts. It is useful for listing installed fonts or for matching fonts based on user queries. The matching process also suggests viable font alternatives.

The package uses a collection of standard fonts compiled from the os-font-list project along with string processing and similarity metrics for scoring font matches, in order to account for partial or inexact input queries.

Full documentation can be found at: https://pkg.go.dev/github.com/adrg/sysfont.

Installation

go get github.com/adrg/sysfont

Usage

List fonts

finder := sysfont.NewFinder(nil)

for _, font := range finder.List() {
    fmt.Println(font.Family, font.Name, font.Filename)
}

Match fonts

The matching process has three steps. Identification of the best matching installed font, based on the specified query, is attempted first. If no close match is found, alternative fonts are searched. If no alternative font is found, a suitable default font is returned.

finder := sysfont.NewFinder(nil)

terms := []string{
    "AmericanTypewriter",
    "AmericanTypewriter-Bold",
    "Andale",
    "Arial",
    "Arial Bold",
    "Arial-BoldItalicMT",
    "ArialMT",
    "Baskerville",
    "Candara",
    "Corbel",
    "Gill Sans",
    "Hoefler Text Bold",
    "Impact",
    "Palatino",
    "Symbol",
    "Tahoma",
    "Times",
    "Times Bold",
    "Times BoldItalic",
    "Times Italic Bold",
    "Times Roman",
    "Verdana",
    "Verdana-Italic",
    "Webdings",
    "ZapfDingbats",
}

for _, term := range terms {
    font := finder.Match(term)
    fmt.Printf("%-30s -> %-30s (%s)\n", term, font.Name, font.Filename)
}

Output: sysfont test output minimal

A more comprehensive test made on Ubuntu: sysfont test output full

References

For more information see:

Contributing

Contributions in the form of pull requests, issues or just general feedback, are always welcome.
See CONTRIBUTING.MD.

License

Copyright (c) 2019 Adrian-George Bostan.

This project is licensed under the MIT license. See LICENSE for more details.

Open Source Agenda is not affiliated with "Sysfont" Project. README Source: adrg/sysfont

Open Source Agenda Badge

Open Source Agenda Rating