Execute and render TeX--XeT direction spans in native layouts

This commit is contained in:
gloamxun committed 2026-11-21 16:46:17 +08:00
1 parent a93d1bb902
commit 22e3ba993d
17 files changed
+460 -54

No files matched your search

@@ -206,3 +206,71 @@ fn xetex_format_preserves_internal_version_and_profile_identity() {
))
);
}
#[test]
fn xetex_formats_and_paints_nested_direction_spans() {
use texrra_tex_core::render::DisplayItem;
let profile_probe = r"\catcode123=1 \catcode125=2
\message{\meaning\TeXXeTstate/\meaning\beginR/\meaning\endR}\end";
let pdftex = run(
State::initex().with_input_profile(InputProfile::TeX8Bit).with_etex(),
profile_probe,
);
assert_eq!(messages(&pdftex), [r"\TeXXeTstate/\beginR/\endR"]);
let plain = run(State::initex().with_input_profile(InputProfile::XeTeX), profile_probe);
assert_eq!(messages(&plain), ["undefined/undefined/undefined"]);
let seed = r"\catcode123=1 \catcode125=2
\TeXXeTstate=1 \let\rtl\beginR
\setbox0=\hbox{\vrule width2pt height2pt
\rtl\message{\the\lastnodetype}\vrule width3pt height2pt
\beginL\vrule width4pt height2pt\vrule width5pt height2pt\endL
\vrule width6pt height2pt\endR
\vrule width7pt height2pt}\dump";
let state = State::initex().with_input_profile(InputProfile::XeTeX).with_etex();
let dump = run(state, seed);
assert_eq!(messages(&dump), ["10"]);
let image = FormatImage::from_dump(dump, Vec::new(), Vec::new()).unwrap();
let bytes = image.encode().unwrap();
let result = FormatImage::decode(&bytes)
.unwrap()
.new_job(
Profile::EtexBootstrap,
InputProfile::XeTeX,
JobTime::new(2025, 10, 9, 0).unwrap(),
Limits::default(),
|_| Ok(seed.as_bytes().to_vec()),
)
.unwrap()
.with_native_pages()
.run(
source(r"{\TeXXeTstate=0 \message{\the\TeXXeTstate}}
\message{\the\TeXXeTstate} \shipout\box0 \end"),
&mut TestDevice,
)
.unwrap();
assert_eq!(messages(&result), ["0", "1"]);
let page = result.events.iter().find_map(|event| match event {
Event::Shipout(page) => Some(page.display_list().unwrap()),
_ => None,
}).unwrap();
let rules: Vec<_> = page.items.iter().filter_map(|item| match item {
DisplayItem::Rule { x, width, .. } => Some((*x, *width)),
_ => None,
}).collect();
let origin = rules[0].0;
let offsets: Vec<_> = rules.iter().map(|(x, w)| (x - origin, *w)).collect();
assert_eq!(
offsets,
[(0, 2), (2, 6), (8, 4), (12, 5), (17, 3), (20, 7)].map(|(x, w)| (x * 65536, w * 65536))
);
let error = Executor::new(
State::initex().with_input_profile(InputProfile::XeTeX).with_etex(),
Limits::default(),
)
.run(source(r"\noindent\beginR"), &mut NoFiles)
.unwrap_err();
assert!(error.message.contains(r"Improper \beginR"));
}