Text layout: right-to-left runs and leading spaces like the reference

MTEXT paragraphs keep left-to-right order and their attachment's
alignment even when they start with Hebrew or Arabic: a run of
right-to-left words (with the spaces between and after them) reads
backwards in place, and inside a word each right-to-left letter run is
reversed on its own while digits, punctuation and Latin keep their
order. Shaped text gets a left-to-right paragraph direction, so TEXT
follows the bidirectional rules with a left-to-right base, and a TEXT
line that starts with Hebrew or Arabic is no longer right-aligned. A
paragraph's leading spaces keep their width and trailing spaces are left
out of the width used for centring and right alignment.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
ramox81andClaude Opus 5.5 committed 2026-10-06 14:10:45 +03:00
1 parent 3830a69ca7
commit acafb3be29
3 files changed
+122 -81

No files matched your search

+5 -30
View File
@@ -281,38 +281,13 @@ pub fn text_run_placement_at_scale(
// box one way while the strokes run the other (the bounds advance is
// always positive — it uses |width_factor|). Left keeps its 0 reference.
let sign = width_factor.signum();
let is_rtl = {
let mut strong_rtl = false;
for ch in value_for_bounds.chars() {
match unicode_bidi::bidi_class(ch) {
unicode_bidi::BidiClass::R | unicode_bidi::BidiClass::AL => {
strong_rtl = true;
break;
}
unicode_bidi::BidiClass::L => {
break;
}
_ => {}
}
}
strong_rtl
};
// Left / right alignment do not depend on the text's script: the
// reference lays a line that starts with Hebrew or Arabic out from its
// left end like any other.
let ax = match t.horizontal_alignment {
HA::Left => {
if is_rtl {
b.advance * sign
} else {
0.0
}
}
HA::Left => 0.0,
HA::Center | HA::Middle => b.advance * 0.5 * sign,
HA::Right => {
if is_rtl {
0.0
} else {
b.advance * sign
}
}
HA::Right => b.advance * sign,
HA::Aligned | HA::Fit => 0.0,
};
// Vertical anchor uses the inked extent (cap / baseline geometry).