From e39b84180f98c54e6f94f62860f98cca36a21b28 Mon Sep 17 00:00:00 2001 From: Ben Perry Date: Wed, 11 Sep 2024 01:32:04 -0500 Subject: [PATCH] Expand bounds for space characters if font does not properly compute bounds --- ext/text/text.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/ext/text/text.go b/ext/text/text.go index c82a65b..626fed4 100644 --- a/ext/text/text.go +++ b/ext/text/text.go @@ -381,8 +381,20 @@ func (txt *Text) drawBuf() { continue } + var dot pixel.Vec var rect, frame, bounds pixel.Rect - rect, frame, bounds, txt.Dot = txt.Atlas().DrawRune(txt.prevR, r, txt.Dot) + rect, frame, bounds, dot = txt.Atlas().DrawRune(txt.prevR, r, txt.Dot) + if r == ' ' { + // Space character has empty bounds for some fonts + if bounds.W() == 0 { + bounds.Max = bounds.Max.Add(dot.Sub(txt.Dot)) + } + if bounds.H() == 0 { + bounds.Min = txt.Dot + bounds.Max.Y += txt.atlas.lineHeight + } + } + txt.Dot = dot txt.prevR = r