diff --git a/fonts/freeserif/font_test.go b/fonts/freeserif/font_test.go new file mode 100644 index 00000000..9755142c --- /dev/null +++ b/fonts/freeserif/font_test.go @@ -0,0 +1,14 @@ +package freeserif + +import ( + "testing" + + "github.com/gmlewis/go-fonts/fonts" +) + +func TestTextMBB(t *testing.T) { + // See: https://github.com/gmlewis/go-gerber/issues/8 + if _, err := fonts.TextMBB(0, 0, 1, 1, "", "freeserif"); err == nil { + t.Error("TextMBB = nil, want err") + } +} diff --git a/fonts/text.go b/fonts/text.go index 21381c15..60a052d6 100644 --- a/fonts/text.go +++ b/fonts/text.go @@ -187,6 +187,10 @@ func TextMBB(xPos, yPos, xScale, yScale float64, message, fontName string) (*MBB } } + if result == nil { + return nil, errors.New("message must not be empty") + } + // log.Printf("TextMBB: xScale,yScale=(%v,%v)", xScale, yScale) fsf := 1.0 / font.UnitsPerEm xScale *= fsf