From 5f231da8df9d89341d5b7beea065e6ab34bfd5cc Mon Sep 17 00:00:00 2001 From: Taco de Wolff Date: Sun, 24 Nov 2024 19:45:01 -0300 Subject: [PATCH] Fix line breaking with explicit line breaks, fixes #325 --- text/linebreak.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/text/linebreak.go b/text/linebreak.go index 34ff5a44..7c208bf8 100644 --- a/text/linebreak.go +++ b/text/linebreak.go @@ -665,7 +665,13 @@ func GlyphsToItems(glyphs []Glyph, indent float64, align Align) []Item { } else if IsNewline(glyph.Text) { // only add one penalty for \r\n if glyph.Text != '\n' || i == 0 || glyphs[i-1].Text != '\r' { - items = append(items, Penalty(0.0, -Infinity, false)) + if align == Centered { + items = append(items, Glue(0.0, stretchWidth, 0.0)) + items = append(items, Penalty(0.0, -Infinity, false)) + } else { + items = append(items, Glue(0.0, math.Inf(1.0), 0.0)) + items = append(items, Penalty(0.0, -Infinity, true)) + } } items[len(items)-1].Size++ } else if glyph.Text == '\u00AD' || glyph.Text == '\u200B' {