Skip to content

DesignCraft: An open-source page and layout design editor written by scratch in pure Rust

Integration: shatai glyphs in right-to-left lines always take a tagged run

aionggd5fe4ec201e5
diff --git a/crates/pdf/src/rtl_tests.rs b/crates/pdf/src/rtl_tests.rs
index 724eb1308..37c9865af 100644
--- a/crates/pdf/src/rtl_tests.rs
+++ b/crates/pdf/src/rtl_tests.rs
@@ -227,10 +227,10 @@ fn right_to_left_lines_carry_actual_text_only_on_their_clusters() {
}
}
-/// A slanted (shatai) glyph in a right-to-left line is drawn inside the line's span, not in a span
-/// of its own (marked content can't nest).
+/// A slanted (shatai) glyph in a right-to-left line is drawn through its own tagged run; tagged
+/// exports must not nest marked content (krilla panics on it).
#[test]
-fn shatai_glyphs_in_right_to_left_lines_stay_in_the_line_span() {
+fn shatai_glyphs_in_right_to_left_lines_export_in_reading_order() {
hebrew_font();
let text = "דוד & שרה";
let mut d = doc(text, HEBREW, Rect::new(36.0, 36.0, 576.0, 300.0), rtl());
@@ -238,7 +238,8 @@ fn shatai_glyphs_in_right_to_left_lines_stay_in_the_line_span() {
d.story_mut(sid).unwrap().format_chars(0.."דוד".len(), |f| f.over.shatai_magnification = Some(30.0));
for tagged in [false, true] {
let bytes = export_pdf(&d, &Cache::new(), &PdfOptions { tagged, ..PdfOptions::default() }).unwrap();
- assert_eq!(line_actual_texts(&bytes), [text], "tagged: {tagged}");
+ assert_eq!(opened_inside_actual_text(&bytes), 0, "tagged: {tagged}");
+ assert!(actual_texts(&bytes).iter().all(|t| !t.contains(' ')), "tagged: {tagged}");
assert_eq!(extract_text(&bytes)[0], text, "tagged: {tagged}");
}
}
diff --git a/crates/pdf/src/text.rs b/crates/pdf/src/text.rs
index 54ae5138a..fb0f17ea2 100644
--- a/crates/pdf/src/text.rs
+++ b/crates/pdf/src/text.rs
@@ -242,11 +242,7 @@ impl Exporter<'_> {
if turn.is_some() || shatai.is_some() {
let m = turn.unwrap_or(Affine::IDENTITY) * shatai.unwrap_or(Affine::IDENTITY);
s.push_transform(&crate::export::tf(m));
- if line_span {
- self.run(s, cs, &gs[i..i + 1], l.baseline, story);
- } else {
- self.tagged_run(s, cs, &gs[i..i + 1], l.baseline, story);
- }
+ self.tagged_run(s, cs, &gs[i..i + 1], l.baseline, story);
s.pop();
i += 1;
continue;