Skip to content
This repository has been archived by the owner on Feb 16, 2024. It is now read-only.

Go bindings for the FreeType library. Only the high-level API is bound.

License

Notifications You must be signed in to change notification settings

Shuttlerock/go-freetype

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-freetype

Go Report Card License MIT Go Doc

Go bindings for the FreeType library. Only the high-level API is bound.

Install

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

And then import the package in your code:

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

Example

An example described below is one of the use cases.

package main

import (
	"fmt"
	"image/png"
	"io/ioutil"
	"os"

	"github.com/danielgatis/go-findfont/findfont"
	"github.com/danielgatis/go-freetype/freetype"
)

func checkErr(err error) {
	if err != nil {
		fmt.Printf("Failed: %v\n", err)
		os.Exit(1)
	}
}

func main() {
	fonts, err := findfont.Find("Arial", findfont.FontRegular)
	checkErr(err)

	data, err := ioutil.ReadFile(fonts[0][2])
	checkErr(err)

	lib, err := freetype.NewLibrary()
	checkErr(err)

	face, err := freetype.NewFace(lib, data, 0)
	checkErr(err)

	err = face.Pt(32, 72)
	checkErr(err)

	img, m, err := face.Glyph('A')
	checkErr(err)

	f, err := os.Create("image.png")
	checkErr(err)

	err = png.Encode(f, img)
	checkErr(err)

	fmt.Printf("Image: %v\n", f.Name())
	fmt.Printf("Metrics: %v\n", m)

	err = face.Done()
	checkErr(err)

	err = lib.Done()
	checkErr(err)
}
❯ go run main.go
Image: image.png
Metrics: &{23 23 -1 23 21 -11 3 30}

image.png

image.png

License

Copyright (c) 2020-present Daniel Gatis

Licensed under MIT License

About

Go bindings for the FreeType library. Only the high-level API is bound.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%