findfont

package module
v0.0.0-...-9f18048 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 2, 2020 License: MIT Imports: 5 Imported by: 6

README

GoDoc 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.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Find

func Find(fileName string) (filePath string, err error)

Find tries to locate the specified font file in the current directory as well as in platform specific user and system font directories; if there is no exact match, Find tries substring matching.

func List

func List() (filePaths []string)

List returns a list of all font files found on the system.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL