Skip to content

Commit ee6638f

Browse files
committed
Use layout width (without trailing white space)
1 parent 25ce7e3 commit ee6638f

4 files changed

+16
-16
lines changed

parley/src/layout/alignment.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,19 @@ pub(crate) fn align<B: Brush>(
1515
) {
1616
// Whether the text base direction is right-to-left.
1717
let is_rtl = layout.base_level & 1 == 1;
18-
let alignment_width = alignment_width.unwrap_or(layout.full_width);
18+
let alignment_width = alignment_width.unwrap_or(layout.width);
1919

2020
// Apply alignment to line items
2121
for line in &mut layout.lines {
2222
// TODO: remove this field
2323
line.alignment = alignment;
2424

25+
if is_rtl {
26+
// In RTL text, trailing whitespace is on the left. As we hang that whitespace, offset
27+
// the line to the left.
28+
line.metrics.offset = -line.metrics.trailing_whitespace;
29+
}
30+
2531
// Compute free space.
2632
let free_space = alignment_width - line.metrics.advance + line.metrics.trailing_whitespace;
2733

@@ -38,10 +44,10 @@ pub(crate) fn align<B: Brush>(
3844
// Do nothing
3945
}
4046
(Alignment::Right, _) | (Alignment::Start, true) | (Alignment::End, false) => {
41-
line.metrics.offset = free_space;
47+
line.metrics.offset += free_space;
4248
}
4349
(Alignment::Middle, _) => {
44-
line.metrics.offset = free_space * 0.5;
50+
line.metrics.offset += free_space * 0.5;
4551
}
4652
(Alignment::Justified, _) => {
4753
// Justified alignment doesn't have any effect if free_space is negative or zero
@@ -54,7 +60,7 @@ pub(crate) fn align<B: Brush>(
5460
// case, start-align, i.e., left-align for LTR text and right-align for RTL text.
5561
if line.break_reason == BreakReason::None || line.num_spaces == 0 {
5662
if is_rtl {
57-
line.metrics.offset = free_space;
63+
line.metrics.offset += free_space;
5864
}
5965
continue;
6066
}
@@ -92,12 +98,6 @@ pub(crate) fn align<B: Brush>(
9298
});
9399
}
94100
}
95-
96-
if is_rtl {
97-
// In RTL text, trailing whitespace is on the left. As we hang that whitespace, offset
98-
// the line to the left.
99-
line.metrics.offset -= line.metrics.trailing_whitespace;
100-
}
101101
}
102102
}
103103

Loading
Loading
Loading

0 commit comments

Comments
 (0)