Skip to content

Commit

Permalink
Don't guess max point size
Browse files Browse the repository at this point in the history
  • Loading branch information
muesli committed May 31, 2021
1 parent ffce5de commit 55628fd
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions fonts.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,11 @@ var (
ttfBoldFont *truetype.Font
)

// maxPointSize returns the maximum point size we can use to fit text inside width and height
// as well as the resulting text-width in pixels.
// maxPointSize returns the maximum point size we can use to fit text inside
// width and height, as well as the resulting text-width in pixels.
func maxPointSize(text string, c *freetype.Context, width, height int) (float64, int) {
// never let the font size exceed the requested height
fontsize := 72.0
for c.PointToFixed(fontsize).Round() > height {
fontsize -= 1
}
fontsize := float64(height<<6) / float64(dev.DPI) / (64.0 / 72.0)

// offset initial loop iteration
fontsize += 1
Expand Down

0 comments on commit 55628fd

Please sign in to comment.