From 646568c788fc91b10f433eb2acd7135b756be9f8 Mon Sep 17 00:00:00 2001 From: flopp Date: Sat, 5 Mar 2016 20:46:55 +0100 Subject: [PATCH] LoadFontface returns an error --- README.md | 2 +- context.go | 11 +++++------ examples/meme.go | 4 +++- examples/scatter.go | 8 ++++++-- examples/text.go | 4 +++- examples/wrap.go | 8 ++++++-- 6 files changed, 24 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index aabdd0b..50fc33c 100644 --- a/README.md +++ b/README.md @@ -91,7 +91,7 @@ DrawStringWrapped(s string, x, y, ax, ay, width, lineSpacing float64, align Alig MeasureString(s string) (w, h float64) WordWrap(s string, w float64) []string SetFontFace(fontFace font.Face) -LoadFontFace(path string, points float64) +LoadFontFace(path string, points float64) error ``` ## Color Functions diff --git a/context.go b/context.go index 0d9df50..ad73ee5 100644 --- a/context.go +++ b/context.go @@ -555,14 +555,13 @@ func (dc *Context) SetFontFace(fontFace font.Face) { dc.fontFace = fontFace } -func (dc *Context) LoadFontFace(path string, points float64) { - if face, err := loadFontFace(path, points); err == nil { +func (dc *Context) LoadFontFace(path string, points float64) error { + face, err := loadFontFace(path, points) + if err == nil { dc.fontFace = face dc.fontHeight = points * 72 / 96 - } else { - dc.fontFace = basicfont.Face7x13 - dc.fontHeight = 13 - } + } + return err } func (dc *Context) drawString(im *image.RGBA, s string, x, y float64) { diff --git a/examples/meme.go b/examples/meme.go index b6db789..cd21592 100644 --- a/examples/meme.go +++ b/examples/meme.go @@ -7,7 +7,9 @@ func main() { dc := gg.NewContext(S, S) dc.SetRGB(1, 1, 1) dc.Clear() - dc.LoadFontFace("/Library/Fonts/Impact.ttf", 96) + if err := dc.LoadFontFace("/Library/Fonts/Impact.ttf", 96); err != nil { + panic(err) + } dc.SetRGB(0, 0, 0) s := "ONE DOES NOT SIMPLY" n := 6 // "stroke" size diff --git a/examples/scatter.go b/examples/scatter.go index 09157a6..3dca3c0 100644 --- a/examples/scatter.go +++ b/examples/scatter.go @@ -54,9 +54,13 @@ func main() { // draw text dc.Identity() dc.SetRGB(0, 0, 0) - dc.LoadFontFace("/Library/Fonts/Arial Bold.ttf", 24) + if err := dc.LoadFontFace("/Library/Fonts/Arial Bold.ttf", 24); err != nil { + panic(err) + } dc.DrawStringAnchored("Chart Title", S/2, P/2, 0.5, 0.5) - dc.LoadFontFace("/Library/Fonts/Arial.ttf", 18) + if err := dc.LoadFontFace("/Library/Fonts/Arial.ttf", 18); err != nil { + panic(err) + } dc.DrawStringAnchored("X Axis Title", S/2, S-P/2, 0.5, 0.5) dc.SavePNG("out.png") } diff --git a/examples/text.go b/examples/text.go index 273cddd..2b16aee 100644 --- a/examples/text.go +++ b/examples/text.go @@ -8,7 +8,9 @@ func main() { dc.SetRGB(1, 1, 1) dc.Clear() dc.SetRGB(0, 0, 0) - dc.LoadFontFace("/Library/Fonts/Arial.ttf", 96) + if err := dc.LoadFontFace("/Library/Fonts/Arial.ttf", 96); err != nil { + panic(err) + } dc.DrawStringAnchored("Hello, world!", S/2, S/2, 0.5, 0.5) dc.SavePNG("out.png") } diff --git a/examples/wrap.go b/examples/wrap.go index cf3e6b3..f654e3b 100644 --- a/examples/wrap.go +++ b/examples/wrap.go @@ -18,7 +18,9 @@ func main() { dc.SetLineWidth(3) dc.Stroke() dc.SetRGB(0, 0, 0) - dc.LoadFontFace("/Library/Fonts/Arial Bold.ttf", 18) + if err := dc.LoadFontFace("/Library/Fonts/Arial Bold.ttf", 18); err != nil { + panic(err) + } dc.DrawStringWrapped("UPPER LEFT", P, P, 0, 0, 0, 1.5, gg.AlignLeft) dc.DrawStringWrapped("UPPER RIGHT", W-P, P, 1, 0, 0, 1.5, gg.AlignRight) dc.DrawStringWrapped("BOTTOM LEFT", P, H-P, 0, 1, 0, 1.5, gg.AlignLeft) @@ -27,7 +29,9 @@ func main() { dc.DrawStringWrapped("LOWER MIDDLE", W/2, H-P, 0.5, 1, 0, 1.5, gg.AlignCenter) dc.DrawStringWrapped("LEFT MIDDLE", P, H/2, 0, 0.5, 0, 1.5, gg.AlignLeft) dc.DrawStringWrapped("RIGHT MIDDLE", W-P, H/2, 1, 0.5, 0, 1.5, gg.AlignRight) - dc.LoadFontFace("/Library/Fonts/Arial.ttf", 12) + if err := dc.LoadFontFace("/Library/Fonts/Arial.ttf", 12); err != nil { + panic(err) + } dc.DrawStringWrapped(TEXT, W/2-P, H/2-P, 1, 1, W/3, 1.75, gg.AlignLeft) dc.DrawStringWrapped(TEXT, W/2+P, H/2-P, 0, 1, W/3, 2, gg.AlignLeft) dc.DrawStringWrapped(TEXT, W/2-P, H/2+P, 1, 0, W/3, 2.25, gg.AlignLeft)