loadFontFace errors

This commit is contained in:
Michael Fogleman 2016-02-22 22:36:34 -05:00
parent c839b5829a
commit 2a0857f791
2 changed files with 12 additions and 6 deletions

View File

@ -406,8 +406,13 @@ func (dc *Context) SetFontFace(fontFace font.Face) {
} }
func (dc *Context) LoadFontFace(path string, points float64) { func (dc *Context) LoadFontFace(path string, points float64) {
dc.fontFace = loadFontFace(path, points) if face, err := loadFontFace(path, points); err == nil {
dc.fontFace = face
dc.fontHeight = points * 72 / 96 dc.fontHeight = points * 72 / 96
} else {
dc.fontFace = basicfont.Face7x13
dc.fontHeight = 13
}
} }
func (dc *Context) DrawString(s string, x, y float64) { func (dc *Context) DrawString(s string, x, y float64) {

View File

@ -90,19 +90,20 @@ func unfix(x fixed.Int26_6) float64 {
return 0 return 0
} }
func loadFontFace(path string, points float64) font.Face { func loadFontFace(path string, points float64) (font.Face, error) {
fontBytes, err := ioutil.ReadFile(path) fontBytes, err := ioutil.ReadFile(path)
if err != nil { if err != nil {
panic(err) return nil, err
} }
f, err := truetype.Parse(fontBytes) f, err := truetype.Parse(fontBytes)
if err != nil { if err != nil {
panic(err) return nil, err
} }
return truetype.NewFace(f, &truetype.Options{ face := truetype.NewFace(f, &truetype.Options{
Size: points, Size: points,
// Hinting: font.HintingFull, // Hinting: font.HintingFull,
}) })
return face, nil
} }
func flattenPath(p raster.Path) [][]Point { func flattenPath(p raster.Path) [][]Point {