diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-05-27 15:54:54 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-05-27 15:54:54 +0200 |
| commit | d4e59d4be1f4c0c673c5e22828348fc99a75facd (patch) | |
| tree | ebd783bb3fe199eafda23855fd3ed8e9148bbb7b | |
| parent | 73086b5a7c1b0f9f638165803c237901499adb64 (diff) | |
Make justified break work for last line
| -rw-r--r-- | src/library/text/par.rs | 15 | ||||
| -rw-r--r-- | tests/ref/text/justify.png | bin | 29352 -> 30128 bytes | |||
| -rw-r--r-- | tests/typ/text/justify.typ | 5 |
3 files changed, 12 insertions, 8 deletions
diff --git a/src/library/text/par.rs b/src/library/text/par.rs index 709dc756..a6f7c273 100644 --- a/src/library/text/par.rs +++ b/src/library/text/par.rs @@ -770,7 +770,7 @@ fn linebreak_optimized<'a>( ratio = ratio.min(10.0); // Determine the cost of the line. - let mut cost = if ratio < if p.justify { MIN_RATIO } else { 0.0 } { + let mut cost = if ratio < if attempt.justify { MIN_RATIO } else { 0.0 } { // The line is overfull. This is the case if // - justification is on, but we'd need to shrink to much // - justification is off and the line just doesn't fit @@ -938,29 +938,30 @@ fn line<'a>( mandatory: bool, hyphen: bool, ) -> Line<'a> { + let end = range.end; + let mut justify = p.justify && end < p.bidi.text.len() && !mandatory; + if range.is_empty() { return Line { bidi: &p.bidi, - end: range.end, + end, trimmed: range, first: None, inner: &[], last: None, width: Length::zero(), - justify: !mandatory, + justify, dash: false, }; } // Slice out the relevant items. - let end = range.end; let (expanded, mut inner) = p.slice(range.clone()); let mut width = Length::zero(); // Reshape the last item if it's split in half or hyphenated. let mut last = None; let mut dash = false; - let mut justify = !mandatory; if let Some((Item::Text(shaped), before)) = inner.split_last() { // Compute the range we want to shape, trimming whitespace at the // end of the line. @@ -1129,9 +1130,7 @@ fn commit( // Determine how much to justify each space. let fr = line.fr(); let mut justification = Length::zero(); - if remaining < Length::zero() - || (p.justify && line.justify && line.end < line.bidi.text.len() && fr.is_zero()) - { + if remaining < Length::zero() || (line.justify && fr.is_zero()) { let justifiables = line.justifiables(); if justifiables > 0 { justification = remaining / justifiables as f64; diff --git a/tests/ref/text/justify.png b/tests/ref/text/justify.png Binary files differindex 396adc77..e8b50723 100644 --- a/tests/ref/text/justify.png +++ b/tests/ref/text/justify.png diff --git a/tests/typ/text/justify.typ b/tests/typ/text/justify.typ index 0cdef000..aa0878d3 100644 --- a/tests/typ/text/justify.typ +++ b/tests/typ/text/justify.typ @@ -20,6 +20,11 @@ A B C \ D --- +// Test forced justification with justified break. +A B C \+ +D E F \+ + +--- // Test that justificating chinese text is at least a bit sensible. #set page(width: 200pt) #set par(justify: true) |
