Skip to content

Commit

Permalink
Fix text placement with right alignment
Browse files Browse the repository at this point in the history
  • Loading branch information
tdewolff committed Nov 2, 2023
1 parent 523d6c6 commit 204a490
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion text.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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++
Expand Down

0 comments on commit 204a490

Please sign in to comment.