gg/util.go

47 lines
830 B
Go
Raw Normal View History

2016-02-18 22:02:57 +01:00
package dd
import (
"image"
"image/png"
2016-02-19 04:53:47 +01:00
"io/ioutil"
2016-02-18 22:02:57 +01:00
"os"
2016-02-19 04:53:47 +01:00
"github.com/golang/freetype/truetype"
"golang.org/x/image/font"
2016-02-18 22:02:57 +01:00
"golang.org/x/image/math/fixed"
)
func writeToPNG(path string, im image.Image) error {
file, err := os.Create(path)
if err != nil {
return err
}
defer file.Close()
return png.Encode(file, im)
}
func fp(x, y float64) fixed.Point26_6 {
return fixed.Point26_6{fixed.Int26_6(x * 64), fixed.Int26_6(y * 64)}
}
func fi(x float64) fixed.Int26_6 {
return fixed.Int26_6(x * 64)
}
2016-02-19 04:53:47 +01:00
func loadFontFace(path string, size float64) font.Face {
fontBytes, err := ioutil.ReadFile(path)
if err != nil {
panic(err)
}
f, err := truetype.Parse(fontBytes)
if err != nil {
panic(err)
}
return truetype.NewFace(f, &truetype.Options{
Size: size,
DPI: 96,
Hinting: font.HintingFull,
})
}