font/opentype: treat invalid characters less specially

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2019-11-20 20:15:31 +01:00
parent c072a7eb87
commit f3f079df32
+2 -6
View File
@@ -79,18 +79,14 @@ func layoutText(buf *sfnt.Buffer, ppem fixed.Int26_6, str string, f *opentype, o
} }
for prev.idx < len(str) { for prev.idx < len(str) {
c, s := utf8.DecodeRuneInString(str[prev.idx:]) c, s := utf8.DecodeRuneInString(str[prev.idx:])
a, ok := f.GlyphAdvance(buf, ppem, c) a, valid := f.GlyphAdvance(buf, ppem, c)
if !ok {
prev.idx += s
continue
}
next := state{ next := state{
r: c, r: c,
advs: prev.advs, advs: prev.advs,
idx: prev.idx + s, idx: prev.idx + s,
x: prev.x + prev.adv, x: prev.x + prev.adv,
adv: a, adv: a,
valid: true, valid: valid,
} }
if c == '\n' { if c == '\n' {
// The newline is zero width; use the previous // The newline is zero width; use the previous