Merge pull request #6 from flopp/LoadFontFace+error
LoadFontFace returns an error
This commit is contained in:
commit
928b874494
@ -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
|
||||
|
@ -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) {
|
||||
|
@ -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
|
||||
|
@ -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")
|
||||
}
|
||||
|
@ -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")
|
||||
}
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user