Skip to content
Draft
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: 4 additions & 1 deletion shaping/wrapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -1218,7 +1218,10 @@ func (l *LineWrapper) processBreakOption(option breakOption, config lineConfig)
// Fill candidate line with runs until the run containing the break option.
l.fillUntil(l.glyphRuns, option)

currRunIndex, run, _ := l.glyphRuns.Peek()
currRunIndex, run, isValid := l.glyphRuns.Peek()
if !isValid {
return breakInvalid, Output{}
}
l.mapper.mapRun(currRunIndex, run)
if !option.isValid(l.mapper.mapping, run) {
// Reject invalid line break candidate and acquire a new one.
Expand Down
13 changes: 13 additions & 0 deletions shaping/wrapping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3623,3 +3623,16 @@ func TestWrapping_oneLine_overflow_bug(t *testing.T) {
_, done := l.WrapNextLine(maxWidth)
tu.Assert(t, done)
}

func TestWrapForcedBreak(t *testing.T) {
f := loadOpentypeFont(t, "../font/testdata/Roboto-Regular.ttf")

s := []rune("line1\nline2")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's certainly better not to crash in this case, but isn't this API misuse? The whole shaping infrastructure expects you to perform segmentation before you shape. Segmentation should convert this input string into two runs.

Or is the problem that we previously would fail to convert this into two runs, and would shape/wrap it as a single run regardless?

I don't think I understand the full context of the problem. 😅 Sorry! I've reread the PR description a few times, but I think I'm still missing something.

@benoitkugler benoitkugler Jul 15, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I think I've mixed up line break and paragraph break. That's probably why the context is not very clear here.
We will probably need to tweak our bidi implementation, but I need to double check that.
Sorry for the noise...

// bidi segmentation will split the input at the first line
input := Input{Text: s, RunEnd: 5, Direction: di.DirectionLTR, Size: fixed.I(10), Face: f}
run := (&HarfbuzzShaper{}).Shape(input)

var l LineWrapper
l.Prepare(WrapConfig{BreakPolicy: Never}, []rune(s), NewSliceIterator([]Output{run}))
_, _ = l.WrapNextLine(math.MaxInt) // assert there is no crash
}
Loading