mirror of
https://github.com/typst/typst
synced 2025-06-28 00:03:17 +08:00
Make justified break work for last line
This commit is contained in:
parent
73086b5a7c
commit
d4e59d4be1
@ -770,7 +770,7 @@ fn linebreak_optimized<'a>(
|
|||||||
ratio = ratio.min(10.0);
|
ratio = ratio.min(10.0);
|
||||||
|
|
||||||
// Determine the cost of the line.
|
// 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
|
// The line is overfull. This is the case if
|
||||||
// - justification is on, but we'd need to shrink to much
|
// - justification is on, but we'd need to shrink to much
|
||||||
// - justification is off and the line just doesn't fit
|
// - justification is off and the line just doesn't fit
|
||||||
@ -938,29 +938,30 @@ fn line<'a>(
|
|||||||
mandatory: bool,
|
mandatory: bool,
|
||||||
hyphen: bool,
|
hyphen: bool,
|
||||||
) -> Line<'a> {
|
) -> Line<'a> {
|
||||||
|
let end = range.end;
|
||||||
|
let mut justify = p.justify && end < p.bidi.text.len() && !mandatory;
|
||||||
|
|
||||||
if range.is_empty() {
|
if range.is_empty() {
|
||||||
return Line {
|
return Line {
|
||||||
bidi: &p.bidi,
|
bidi: &p.bidi,
|
||||||
end: range.end,
|
end,
|
||||||
trimmed: range,
|
trimmed: range,
|
||||||
first: None,
|
first: None,
|
||||||
inner: &[],
|
inner: &[],
|
||||||
last: None,
|
last: None,
|
||||||
width: Length::zero(),
|
width: Length::zero(),
|
||||||
justify: !mandatory,
|
justify,
|
||||||
dash: false,
|
dash: false,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Slice out the relevant items.
|
// Slice out the relevant items.
|
||||||
let end = range.end;
|
|
||||||
let (expanded, mut inner) = p.slice(range.clone());
|
let (expanded, mut inner) = p.slice(range.clone());
|
||||||
let mut width = Length::zero();
|
let mut width = Length::zero();
|
||||||
|
|
||||||
// Reshape the last item if it's split in half or hyphenated.
|
// Reshape the last item if it's split in half or hyphenated.
|
||||||
let mut last = None;
|
let mut last = None;
|
||||||
let mut dash = false;
|
let mut dash = false;
|
||||||
let mut justify = !mandatory;
|
|
||||||
if let Some((Item::Text(shaped), before)) = inner.split_last() {
|
if let Some((Item::Text(shaped), before)) = inner.split_last() {
|
||||||
// Compute the range we want to shape, trimming whitespace at the
|
// Compute the range we want to shape, trimming whitespace at the
|
||||||
// end of the line.
|
// end of the line.
|
||||||
@ -1129,9 +1130,7 @@ fn commit(
|
|||||||
// Determine how much to justify each space.
|
// Determine how much to justify each space.
|
||||||
let fr = line.fr();
|
let fr = line.fr();
|
||||||
let mut justification = Length::zero();
|
let mut justification = Length::zero();
|
||||||
if remaining < Length::zero()
|
if remaining < Length::zero() || (line.justify && fr.is_zero()) {
|
||||||
|| (p.justify && line.justify && line.end < line.bidi.text.len() && fr.is_zero())
|
|
||||||
{
|
|
||||||
let justifiables = line.justifiables();
|
let justifiables = line.justifiables();
|
||||||
if justifiables > 0 {
|
if justifiables > 0 {
|
||||||
justification = remaining / justifiables as f64;
|
justification = remaining / justifiables as f64;
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 29 KiB After Width: | Height: | Size: 29 KiB |
@ -19,6 +19,11 @@ First line indents and hyphenation play nicely with justified text.
|
|||||||
A B C \
|
A B C \
|
||||||
D
|
D
|
||||||
|
|
||||||
|
---
|
||||||
|
// Test forced justification with justified break.
|
||||||
|
A B C \+
|
||||||
|
D E F \+
|
||||||
|
|
||||||
---
|
---
|
||||||
// Test that justificating chinese text is at least a bit sensible.
|
// Test that justificating chinese text is at least a bit sensible.
|
||||||
#set page(width: 200pt)
|
#set page(width: 200pt)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user