From 2a0857f791dbaa6bb730574166b17ece874bfbb7 Mon Sep 17 00:00:00 2001 From: Michael Fogleman Date: Mon, 22 Feb 2016 22:36:34 -0500 Subject: [PATCH] loadFontFace errors --- context.go | 9 +++++++-- util.go | 9 +++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/context.go b/context.go index 1763ba9..124363b 100644 --- a/context.go +++ b/context.go @@ -406,8 +406,13 @@ func (dc *Context) SetFontFace(fontFace font.Face) { } func (dc *Context) LoadFontFace(path string, points float64) { - dc.fontFace = loadFontFace(path, points) - dc.fontHeight = points * 72 / 96 + if face, err := loadFontFace(path, points); err == nil { + dc.fontFace = face + dc.fontHeight = points * 72 / 96 + } else { + dc.fontFace = basicfont.Face7x13 + dc.fontHeight = 13 + } } func (dc *Context) DrawString(s string, x, y float64) { diff --git a/util.go b/util.go index f2502b7..bd0acd9 100644 --- a/util.go +++ b/util.go @@ -90,19 +90,20 @@ func unfix(x fixed.Int26_6) float64 { return 0 } -func loadFontFace(path string, points float64) font.Face { +func loadFontFace(path string, points float64) (font.Face, error) { fontBytes, err := ioutil.ReadFile(path) if err != nil { - panic(err) + return nil, err } f, err := truetype.Parse(fontBytes) if err != nil { - panic(err) + return nil, err } - return truetype.NewFace(f, &truetype.Options{ + face := truetype.NewFace(f, &truetype.Options{ Size: points, // Hinting: font.HintingFull, }) + return face, nil } func flattenPath(p raster.Path) [][]Point {