diff --git a/text/shaper.go b/text/shaper.go index 96f0a36f..531e49a1 100644 --- a/text/shaper.go +++ b/text/shaper.go @@ -121,7 +121,7 @@ type Glyph struct { // belongs to. If Flags does not contain FlagClusterBreak, this value will // always be zero. The final glyph in the cluster contains the runes count // for the entire cluster. - Runes int + Runes uint16 // Flags encode special properties of this glyph. Flags Flags } @@ -469,7 +469,7 @@ func (l *Shaper) NextGlyph() (_ Glyph, ok bool) { Ascent: line.ascent, Descent: line.descent, Advance: g.xAdvance, - Runes: g.runeCount, + Runes: uint16(g.runeCount), Offset: fixed.Point26_6{ X: g.xOffset, Y: g.yOffset, @@ -505,7 +505,7 @@ func (l *Shaper) NextGlyph() (_ Glyph, ok bool) { if endOfCluster { glyph.Flags |= FlagClusterBreak if run.truncator { - glyph.Runes += l.txt.unreadRuneCount + glyph.Runes += uint16(l.txt.unreadRuneCount) } } else { glyph.Runes = 0 diff --git a/text/shaper_test.go b/text/shaper_test.go index 9a85efe7..47a12d96 100644 --- a/text/shaper_test.go +++ b/text/shaper_test.go @@ -51,9 +51,9 @@ func TestWrappingTruncation(t *testing.T) { for g, ok := cache.NextGlyph(); ok; g, ok = cache.NextGlyph() { glyphs = append(glyphs, g) if g.Flags&FlagTruncator != 0 && g.Flags&FlagClusterBreak != 0 { - truncatedRunes += g.Runes + truncatedRunes += int(g.Runes) } else { - untruncatedRunes += g.Runes + untruncatedRunes += int(g.Runes) } if g.Flags&FlagLineBreak != 0 { lineCount++ @@ -117,9 +117,9 @@ func TestWrappingForcedTruncation(t *testing.T) { for g, ok := cache.NextGlyph(); ok; g, ok = cache.NextGlyph() { glyphs = append(glyphs, g) if g.Flags&FlagTruncator != 0 && g.Flags&FlagClusterBreak != 0 { - truncatedRunes += g.Runes + truncatedRunes += int(g.Runes) } else { - untruncatedRunes += g.Runes + untruncatedRunes += int(g.Runes) } if g.Flags&FlagLineBreak != 0 { lineCount++ @@ -191,9 +191,9 @@ func TestShapingNewlineHandling(t *testing.T) { for g, ok := cache.NextGlyph(); ok; g, ok = cache.NextGlyph() { glyphs = append(glyphs, g) if g.Flags&FlagTruncator == 0 { - runes += g.Runes + runes += int(g.Runes) } else { - truncated += g.Runes + truncated += int(g.Runes) } } if expected := len([]rune(tc.textInput)) - tc.expectedTruncated; expected != runes { @@ -571,7 +571,7 @@ func TestShapeStringRuneAccounting(t *testing.T) { } totalRunes := 0 for _, g := range glyphs { - totalRunes += g.Runes + totalRunes += int(g.Runes) } if inputRunes := len([]rune(tc.input)); totalRunes != inputRunes { t.Errorf("input contained %d runes, but glyphs contained %d", inputRunes, totalRunes) diff --git a/widget/label.go b/widget/label.go index 2275e3eb..a8842be2 100644 --- a/widget/label.go +++ b/widget/label.go @@ -138,7 +138,7 @@ func (it *textIterator) processGlyph(g text.Glyph, ok bool) (_ text.Glyph, visib if it.maxLines > 0 { if g.Flags&text.FlagTruncator != 0 && g.Flags&text.FlagClusterBreak != 0 { // A glyph carrying both of these flags provides the count of truncated runes. - it.truncated = g.Runes + it.truncated = int(g.Runes) } if g.Flags&text.FlagLineBreak != 0 { it.linesSeen++