查找系统字体
一 安装包
go get -u github.com/flopp/go-findfont
二 代码段
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...
}