DoWord adds a RuneLayout for invalid characters

Defaults to an emspace for the width. Progress on #2
This commit is contained in:
Sasha Koshka 2024-09-03 17:04:57 -04:00
parent a1bd411e43
commit b0e80ce961

View File

@ -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
}
}