Honor XeTeX page setup during native shipout

This commit is contained in:
gloamxun committed 2026-11-27 14:38:19 +08:00
1 parent 9da2ee41cd
commit d944552188
7 files changed
+281 -42

No files matched your search

+83
View File
@@ -136,3 +136,86 @@ fn illegal_or_incompatible_magnification_and_huge_pages_protect_existing_pdf() {
}
fs::remove_dir_all(p).unwrap();
}
#[test]
fn xdv_page_setup_edit_updates_the_local_sheet_and_inherited_origin() {
use std::sync::Arc;
use texrra_engine::native::{
CompileRequest, Entry, NativeCompiler, ProjectDefinition, ProjectSnapshot,
};
use texrra_tex_core::{
execution::{InputProfile, JobTime},
resources::WorldConfig,
};
let root = directory().canonicalize().unwrap();
let entry = root.join("probe.tex");
let sheet = root.join("sheet.tex");
let prefix = r"\catcode123=1 \catcode125=2
\pdfpagewidth=11182899sp \pdfpageheight=16445440sp
\shipout\hbox{\special{pdf:pagesize width 170bp height 250bp xoffset 24bp}\vrule width10pt height4pt}
";
let padding = format!("{}\n", "\\relax ".repeat(32)).repeat(48);
let tail = r"\input sheet.tex
\shipout\hbox{\sheet\vrule width10pt height4pt}
\shipout\hbox{\vrule width10pt height4pt}
\shipout\hbox{\special{pdf:pagesize default}\vrule width10pt height4pt}
\end
";
let from_sheet = |width, x| -> Arc<[u8]> {
format!("\\def\\sheet{{\\special{{pdf:pagesize width {width}bp xoffset {x}bp}}}}\n")
.into_bytes()
.into()
};
let world = WorldConfig::new(&root);
let snapshot = ProjectSnapshot::new(ProjectDefinition {
configuration: world.clone(),
revision: 1,
roots: [root.clone()].into(),
files: [
(
entry.clone(),
format!("{prefix}{padding}{tail}").into_bytes().into(),
),
(sheet.clone(), from_sheet(190, 36)),
]
.into(),
directories: Default::default(),
aliases: Default::default(),
generated_roots: [root.clone()].into(),
generated: Default::default(),
})
.unwrap();
let time = JobTime::new(2026, 11, 27, 0).unwrap();
let mut request = CompileRequest::new(world, entry, "result.pdf", time);
request.entry = Entry::Initex;
request.input_profile = InputProfile::XeTeX;
request.etex = true;
let compiler = NativeCompiler::default().with_entry_checkpoints(prefix.len() + 60);
let first = compiler
.compile(request.clone().with_project(snapshot.clone()))
.unwrap();
let updated = snapshot
.with_file_edits(2, [(sheet, from_sheet(205, 46))].into())
.unwrap();
let revised = request.with_project(updated);
let next = compiler.compile(revised.clone()).unwrap();
assert!(next.entry_checkpoint_work.reused_steps > 0);
let widths: Vec<_> = next.pages.iter().map(|page| page.width).collect();
assert_eq!(
widths,
[170, 205, 170, 170].map(|bp| (f64::from(bp) * 65_781.76).round() as i64)
);
let delta = next.preview_since(Some(first.revision())).unwrap();
let changed: Vec<_> = delta.pages.iter().map(|page| page.index).collect();
assert_eq!(changed, [1, 2]);
let full = NativeCompiler::default().compile(revised).unwrap();
assert_eq!(next.pdf, full.pdf);
assert_eq!(next.source_map.pages, full.source_map.pages);
assert_eq!(
next.preview_since(None).unwrap().pages,
full.preview_since(None).unwrap().pages
);
fs::remove_dir_all(root).unwrap();
}