From 55628fdc476f1e27c322c835634fd44ad6f3cad7 Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Mon, 31 May 2021 13:29:30 +0200 Subject: [PATCH] Don't guess max point size --- fonts.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/fonts.go b/fonts.go index fc41ead..6836b66 100644 --- a/fonts.go +++ b/fonts.go @@ -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