Skip to content

Commit

Permalink
Fix panic in TextMBB for empty message
Browse files Browse the repository at this point in the history
Signed-off-by: Glenn Lewis <6598971+gmlewis@users.noreply.github.com>
  • Loading branch information
gmlewis committed Jan 21, 2023
1 parent 35a5497 commit 81c8165
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
14 changes: 14 additions & 0 deletions fonts/freeserif/font_test.go
Original file line number Diff line number Diff line change
@@ -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")
}
}
4 changes: 4 additions & 0 deletions fonts/text.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 81c8165

Please sign in to comment.