Skip to content

Commit 242a16e

Browse files
committed
Fix optimized linebreaks without justification (#5236)
1 parent 0774943 commit 242a16e

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

crates/typst/src/layout/inline/linebreak.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ fn raw_cost(
597597
let badness = if ratio < metrics.min_ratio(approx) {
598598
// Overfull line always has maximum cost.
599599
1_000_000.0
600-
} else if justify || ratio < 0.0 {
600+
} else if breakpoint != Breakpoint::Mandatory || justify || ratio < 0.0 {
601601
// If the line shall be justified or needs shrinking, it has normal
602602
// badness with cost 100|ratio|^3. We limit the ratio to 10 as to not
603603
// get to close to our maximum cost.
5.68 KB
Loading

tests/suite/layout/inline/linebreak.typ

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,19 @@ For info see #link("https://myhost.tld").
123123
// - shaping that results in multiple glyphs in the same cluster
124124
#set text(font: "Noto Sans Thai")
125125
#h(85pt) งบิก
126+
127+
--- issue-5235-linebreak-optimized-without-justify ---
128+
#set page(width: 207pt, margin: 15pt)
129+
#set text(11pt)
130+
131+
#set par(linebreaks: "simple")
132+
Some texts feature many longer
133+
words. Those are often exceedingly
134+
challenging to break in a visually
135+
pleasing way.
136+
137+
#set par(linebreaks: "optimized")
138+
Some texts feature many longer
139+
words. Those are often exceedingly
140+
challenging to break in a visually
141+
pleasing way.

0 commit comments

Comments
 (0)