From b0e80ce961f0c634f3e68460e5b1f3948cd76bc7 Mon Sep 17 00:00:00 2001 From: "sashakoshka@tebibyte.media" Date: Tue, 3 Sep 2024 17:04:57 -0400 Subject: [PATCH] DoWord adds a RuneLayout for invalid characters Defaults to an emspace for the width. Progress on #2 --- layout.go | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/layout.go b/layout.go index 6df7c82..d299c38 100644 --- a/layout.go +++ b/layout.go @@ -58,13 +58,16 @@ func DoWord (text []rune, face font.Face) (word WordLayout, remaining []rune) { // consume and process the rune remaining = remaining[1:] - _, advance, ok := face.GlyphBounds(char) - if !ok { continue } - word.Runes = append (word.Runes, RuneLayout { + advance, ok := face.GlyphAdvance(char) + if !ok { + advance = tofuAdvance(face) + } + runeLayout := RuneLayout { X: x, Width: advance, Rune: char, - }) + } + word.Runes = append(word.Runes, runeLayout) // advance if gettingSpace { @@ -209,3 +212,11 @@ func (line *LineLayout) justify () { x += spacePerWord + word.Width } } + +func tofuAdvance (face font.Face) fixed.Int26_6 { + if advance, ok := face.GlyphAdvance('M'); ok { + return advance + } else { + return 16 + } +}