Skip to content

Commit

Permalink
Line breaking: fix tests by choosing longer (but still beyond the str…
Browse files Browse the repository at this point in the history
…etchable tolerance) lines over shorter; note that this reverts a revert commit to fix #265, this fixes all cases
  • Loading branch information
tdewolff committed Nov 8, 2024
1 parent e334b24 commit f1581cb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
6 changes: 6 additions & 0 deletions text/linebreak.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,12 @@ func (lb *linebreaker) computeAdjustmentRatio(b int, active *Breakpoint) float64
}
ratio := 0.0
if L < lb.width {
if lb.Y-active.Y == 0.0 {
// unstretchable line, act as if we have a very small stretchable space.
// this helps to distinguish between between smaller and longer lines if both would
// need to stretched beyond the tolerance
return Infinity * (1.0 + (lb.width-L)/lb.width)
}
ratio = (lb.width - L) / (lb.Y - active.Y)
} else if lb.width < L {
ratio = (lb.width - L) / (lb.Z - active.Z)
Expand Down
3 changes: 3 additions & 0 deletions text/linebreak_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ func TestLinebreak(t *testing.T) {
{[]Item{Box(50.0), P, Box(40.0), P, Box(50.0), P, Box(40.0), P, Box(50.0)}, "7>3>0", []float64{0.0, 0.0, 0.0}},
{[]Item{Box(30.0), P, Box(30.0), P, Box(30.0), P, Box(60.0), G, P, g, Box(60.0)}, "8>5>0", []float64{0.0, 0.0, 0.0}},

// CJK
{[]Item{Box(21.0), P, Box(21.0), P, Box(21.0), P, Box(21.0), P, Box(21.0), P, Box(21.0), P, Box(21.0), P, Box(21.0), P, Box(21.0)}, "15>7>0", []float64{0.0, 0.0, 0.0}},

// line too long
{[]Item{Box(120.0), P, Box(100.0)}, "1>0", []float64{0.0, 0.0}},
}
Expand Down

0 comments on commit f1581cb

Please sign in to comment.