Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions shaping/wrapping.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package shaping

import (
"math"
"sort"

"github.com/go-text/typesetting/di"
Expand Down Expand Up @@ -784,6 +785,10 @@ func (l *LineWrapper) Prepare(config WrapConfig, paragraph []rune, runs RunItera
//
// See also [WrapParagraphF] which supports a decimal [maxWidth].
func (l *LineWrapper) WrapParagraph(config WrapConfig, maxWidth int, paragraph []rune, runs RunIterator) (_ []Line, truncated int) {
maxFixed := math.MaxInt32 >> 6
if maxWidth > maxFixed {
maxWidth = maxFixed
}
return l.WrapParagraphF(config, fixed.I(maxWidth), paragraph, runs)
}

Expand Down
33 changes: 33 additions & 0 deletions shaping/wrapping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package shaping
import (
"bytes"
"fmt"
"math"
"os"
"reflect"
"sort"
Expand Down Expand Up @@ -3587,3 +3588,35 @@ func TestMaxWidthRouding(t *testing.T) {
line, _ = wr.WrapNextLineF(run.Advance)
tu.Assert(t, line.NextLine == 13)
}

func TestWrapping_oneLine_overflow_bug(t *testing.T) {

maxWidth := math.MaxInt

textInput := []rune("Lorem ipsum") // a simple input that fits on one line
face := benchEnFace
var shaper HarfbuzzShaper
out := []Output{shaper.Shape(Input{
Text: textInput,
RunStart: 0,
RunEnd: len(textInput),
Direction: di.DirectionLTR,
Face: face,
Size: fixed.I(16),
Script: language.Latin,
Language: language.NewLanguage("EN"),
})}
iter := NewSliceIterator(out)
var l LineWrapper

outs, _ := l.WrapParagraph(WrapConfig{BreakPolicy: Never}, maxWidth, textInput, iter)
if len(outs) != 1 {
t.Errorf("expected one line, got %d", len(outs))
}

// the run in iter should have been consumed
outs, _ = l.WrapParagraph(WrapConfig{BreakPolicy: Never}, maxWidth, textInput, iter)
if len(outs) != 0 {
t.Errorf("expected no line, got %d", len(outs))
}
}