Handle unclaimed XeTeX specials at shipout

This commit is contained in:
gloamxun committed 2026-11-28 06:04:09 +08:00
1 parent e2af618e65
commit 885911485e
10 files changed
+273 -21

No files matched your search

+86
View File
@@ -707,6 +707,92 @@ fn font_mapping_changes_recover_and_update_the_page_that_used_the_resource() {
fs::remove_dir_all(p).unwrap();
}
#[test]
fn xetex_unclaimed_special_warns_at_shipout_and_retains_the_whatsit() {
use texrra_tex_core::execution::{Event, InputProfile};
let root = directory("xetex-unclaimed-special");
let mut job = request(&root);
job.world = WorldConfig::new(&root);
job.input_profile = InputProfile::XeTeX;
let entry = root.join("main.tex");
fs::write(
root.join("face.ttf"),
include_bytes!("../assets/fonts-subset/LiberationSerif-Regular.ttf"),
)
.unwrap();
fs::write(
&entry,
br#"\catcode123=1 \catcode125=2 \catcode37=12
\setbox0=\hbox{\special{unshipped marker}}
\font\face="[face.ttf]" at 9pt
\shipout\hbox{\face A\special{ vendor: marker}A\special{src:1 source.tex}A
\special{% comment-only}A\special{}A}
\end"#,
)
.unwrap();
let compiler = NativeCompiler::default();
let result = compiler.compile(job.clone()).unwrap();
let shipout = result
.execution
.execution
.events
.iter()
.find_map(|event| {
if let Event::Shipout(page) = event {
Some(page)
} else {
None
}
})
.unwrap();
let specials: Vec<_> = shipout
.specials
.iter()
.map(|special| special.bytes.as_ref())
.collect();
assert_eq!(
specials,
[
b" vendor: marker".as_slice(),
b"src:1 source.tex",
b"% comment-only",
b"",
]
);
let log = fs::read_to_string(root.join("job.log")).unwrap();
assert_eq!(
log.matches("Unparsed material at end of special ignored.")
.count(),
1
);
assert!(log.contains("Current input buffer is -->vendor: marker<--"));
let pdf = result.pdf.as_deref().unwrap();
let pdf = lopdf::Document::load_mem(pdf).unwrap();
let content = pdf.get_page_content(pdf.get_pages()[&1]).unwrap();
let content = String::from_utf8(content).unwrap();
assert_eq!(content.matches("BT /U").count(), 5);
assert!(!content.contains("vendor:"));
fs::write(
&entry,
br"\catcode123=1 \catcode125=2 \shipout\hbox{\special{tpic:pn 5}}\end",
)
.unwrap();
let error = compiler
.compile_detailed(job)
.err()
.unwrap()
.error
.to_string();
assert!(
error.contains("unsupported native XeTeX device special: tpic:pn"),
"{error}"
);
assert!(Arc::ptr_eq(&result, &compiler.latest().unwrap()));
fs::remove_dir_all(root).unwrap();
}
#[test]
fn xetex_vertical_font_uses_tex_box_metrics_and_pdf_writing_mode() {
use texrra_tex_core::execution::{Event, InputProfile};