Git Product home page Git Product logo

sysfont's Introduction

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.

sysfont's People

Contributors

adrg avatar dependabot[bot] avatar darkliquid avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.