All Projects → flopp → go-findfont

flopp / go-findfont

Licence: MIT License
A platform-agnostic go (golang) library to easily locate truetype font files in your system's user and system font directories

Programming Languages

go
31211 projects - #10 most used programming language

PkgGoDev Go Report Card License MIT

go-findfont

A platform-agnostic go (golang) library to easily locate truetype font files in your system's user and system font directories.

What?

go-findfont is a golang library that allows you to locate font file on your system. The library is currently aware of the default font directories on Linux/Unix, Windows, and MacOS.

How?

Installation

Installing go-findfont is as easy as

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

Library Usage

import (
  "fmt"
  "io/ioutil"
  
  "github.com/flopp/go-findfont"
  "github.com/golang/freetype/truetype"
)

func main() {
  fontPath, err := findfont.Find("arial.ttf")
  if err != nil {
    panic(err)
  }
  fmt.Printf("Found 'arial.ttf' in '%s'\n", fontPath)

  // load the font with the freetype library
  fontData, err := ioutil.ReadFile(fontPath)
  if err != nil {
    panic(err)
  }
  font, err := truetype.Parse(fontData)
  if err != nil {
    panic(err)
  }

  // use the font...
}

License

Copyright 2016 Florian Pigorsch. All rights reserved.

Use of this source code is governed by a MIT-style license that can be found in the LICENSE file.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].