https://github.com/danielgatis/go-freetype
Go bindings for the FreeType library. Only the high-level API is bound.
https://github.com/danielgatis/go-freetype
font fonts freetype freetype-bindings freetype2 go golang
Last synced: about 2 months ago
JSON representation
Go bindings for the FreeType library. Only the high-level API is bound.
- Host: GitHub
- URL: https://github.com/danielgatis/go-freetype
- Owner: danielgatis
- License: mit
- Created: 2020-05-30T00:13:07.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-09-26T04:33:33.000Z (over 4 years ago)
- Last Synced: 2025-02-08T20:47:32.723Z (3 months ago)
- Topics: font, fonts, freetype, freetype-bindings, freetype2, go, golang
- Language: Go
- Size: 8.79 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-freetype
[](https://goreportcard.com/report/github.com/danielgatis/go-freetype)
[](https://raw.githubusercontent.com/danielgatis/go-freetype/master/LICENSE)
[](https://godoc.org/github.com/danielgatis/go-freetype)Go bindings for the FreeType library. Only the high-level API is bound.
## Install
```bash
go get -u github.com/danielgatis/go-freetype
```And then import the package in your code:
```go
import "github.com/danielgatis/go-freetype/freetype"
```### Example
An example described below is one of the use cases.
```go
package mainimport (
"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

## License
Copyright (c) 2020-present [Daniel Gatis](https://github.com/danielgatis)
Licensed under [MIT License](./LICENSE)