Skip to content

Commit 4fe1195

Browse files
hojjatabdollahijackpot51
authored andcommitted
fix: Do not drop RTL-only text in a LTR buffer if width is None
Handles a specific case that wasn't happening before since we could only have RTL-only text on an LTR line if the text was wrapping otherwise the line would automatically be RTL
1 parent 4a64858 commit 4fe1195

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

src/shape.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1969,9 +1969,15 @@ impl ShapeLine {
19691969
} else {
19701970
(WordGlyphPos::ZERO, WordGlyphPos::new(span.words.len(), 0))
19711971
}
1972-
} else if span_index == start.span {
1972+
} else if span_index == start.span && (start.word, start.glyph) != (0, 0) {
1973+
// Continuation of an incongruent (reversed) span after a wrap:
1974+
// this visual line holds the logically-leading words [0, start).
19731975
(WordGlyphPos::ZERO, start.word_glyph_pos())
19741976
} else {
1977+
// No continuation offset, so the whole incongruent span belongs to
1978+
// this line. Without this, a fully-RTL span under a forced-LTR base
1979+
// direction (start == 0) would collapse to an empty range and drop
1980+
// all of its glyphs.
19751981
(WordGlyphPos::ZERO, WordGlyphPos::new(span.words.len(), 0))
19761982
};
19771983

tests/direction.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,22 @@ fn forced_ltr_overrides_rtl_content() {
5454
assert!(!first_run_rtl(&buffer),);
5555
}
5656

57+
#[test]
58+
fn forced_ltr_keeps_rtl_glyphs() {
59+
// a line whose content is entirely RTL must still produce glyphs
60+
// when the base direction is forced to LTR (incongruent span on the no-wrap path)
61+
let mut font_system = font_system();
62+
let buffer = make_buffer(&mut font_system, "سلام", Direction::LeftToRight);
63+
let run = buffer
64+
.layout_runs()
65+
.next()
66+
.expect("expected at least one layout run");
67+
assert!(
68+
!run.glyphs.is_empty(),
69+
"forced-LTR RTL line produced no glyphs"
70+
);
71+
}
72+
5773
#[test]
5874
fn force_ltr_overrides_first_strong_rtl() {
5975
let mut font_system = font_system();

0 commit comments

Comments
 (0)