From 204a4903fdc11bb9e3aba69e141422b58c6b2b94 Mon Sep 17 00:00:00 2001 From: Taco de Wolff Date: Wed, 1 Nov 2023 22:32:12 -0300 Subject: [PATCH] Fix text placement with right alignment --- text.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/text.go b/text.go index 4fe37720..7bbd70c3 100644 --- a/text.go +++ b/text.go @@ -707,6 +707,12 @@ func (rt *RichText) ToText(width, height float64, halign, valign TextAlign, inde // [ai,bi) is the range of items // [ag,bg) is the range of glyphs eolSkip := 0 // number of glyphs after the last box + + // skip glues/penalties with no glyphs + for ai < breaks[j].Position && items[ai].Type != canvasText.BoxType { + ag += items[ai].Size + ai++ + } bi, bg := breaks[j].Position, ag // apply stretching or shrinking of glue (whitespace) @@ -769,7 +775,7 @@ func (rt *RichText) ToText(width, height float64, halign, valign TextAlign, inde bi++ // absorb whitespace after breakpoint - for bi < len(items) && (items[bi].Type == canvasText.GlueType || items[bi].Type == canvasText.PenaltyType) { + for bi < len(items) && items[bi].Type == canvasText.GlueType { eolSkip += items[bi].Size bg += items[bi].Size bi++