Skip to content

Commit a2a8920

Browse files
committed
Use layout width (without trailing white space)
1 parent 1b0b887 commit a2a8920

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

@@ -34,10 +40,10 @@ pub(crate) fn align<B: Brush>(
3440
// Do nothing
3541
}
3642
(Alignment::Right, _) | (Alignment::Start, true) | (Alignment::End, false) => {
37-
line.metrics.offset = free_space;
43+
line.metrics.offset += free_space;
3844
}
3945
(Alignment::Middle, _) => {
40-
line.metrics.offset = free_space * 0.5;
46+
line.metrics.offset += free_space * 0.5;
4147
}
4248
(Alignment::Justified, _) => {
4349
// Justified alignment doesn't have any effect if free_space is negative or zero
@@ -50,7 +56,7 @@ pub(crate) fn align<B: Brush>(
5056
// case, start-align, i.e., left-align for LTR text and right-align for RTL text.
5157
if line.break_reason == BreakReason::None || line.num_spaces == 0 {
5258
if is_rtl {
53-
line.metrics.offset = free_space;
59+
line.metrics.offset += free_space;
5460
}
5561
continue;
5662
}
@@ -88,12 +94,6 @@ pub(crate) fn align<B: Brush>(
8894
});
8995
}
9096
}
91-
92-
if is_rtl {
93-
// In RTL text, trailing whitespace is on the left. As we hang that whitespace, offset
94-
// the line to the left.
95-
line.metrics.offset -= line.metrics.trailing_whitespace;
96-
}
9797
}
9898
}
9999

Loading
Loading
Loading

0 commit comments

Comments
 (0)