Read binary TeX inputs and render default ICC colors

This commit is contained in:
gloamxun committed 2026-11-29 02:55:37 +08:00
1 parent e9893a5c1b
commit 52db77885d
10 files changed
+379 -19

No files matched your search

@@ -13,6 +13,13 @@ impl SourceProvider for Host {
data: file.data,
})
}
fn optional_tex_input(
&mut self,
name: &str,
from: &str,
) -> Result<Option<texrra_tex_core::resources::LoadedResource>, String> {
self.0.read_tex_input_optional(name, Path::new(from))
}
fn file_size(&mut self, name: &str, from: &str) -> Result<Option<u64>, String> {
Ok(self
.0
@@ -90,3 +97,58 @@ fn file_size_expands_names_and_distinguishes_empty_from_missing() {
);
fs::remove_dir_all(dir).unwrap();
}
#[test]
fn file_dump_expands_binary_ranges_with_real_file_versions() {
let root = std::env::temp_dir().join(format!("texrra-filedump-{}", std::process::id()));
fs::create_dir_all(&root).unwrap();
fs::write(root.join("sample data.bin"), [0, 255, 10, 13, 0x81, 0x42]).unwrap();
let body = r"\catcode123=1 \catcode125=2
\def\name{sample data.bin}
\message{AUDIT:[\dumpbytes offset 1 length 4 {\name}][\dumpbytes offset 5 length 20 {\name}]%
[\dumpbytes offset 6 length 1 {\name}][\dumpbytes length 1 {missing.bin}]%
[\dumpbytes {skip-missing.bin}][\dumpbytes offset 2 length 0 {skip-zero.bin}]}
\end
";
let entry = root.join("probe.tex");
for (profile, command) in [
(InputProfile::TeX8Bit, "pdffiledump"),
(InputProfile::XeTeX, "filedump"),
] {
let mut host = Host(FileWorld::new(WorldConfig::new(root.clone())).unwrap());
let source = body.replace(r"\dumpbytes", &format!("\\{command}"));
let e = Executor::new(
State::initex().with_etex().with_input_profile(profile),
Limits::default(),
)
.run(
SourceFile {
name: entry.display().to_string(),
data: source.into_bytes(),
},
&mut host,
)
.unwrap();
assert!(e.events.iter().any(|event| matches!(
event, Event::Message { text, .. } if text == "AUDIT:[FF0A0D81][42][][][][]"
)));
let trace = host.0.trace();
assert_eq!(trace.reads.len(), 3);
let version = &trace.reads[0];
assert_eq!(version.bytes, 6);
assert!(version.path.ends_with("sample data.bin"));
assert!(trace.reads.iter().all(|read| read == version));
assert!(
trace
.lookups
.iter()
.any(|entry| { entry.name == "missing.bin" && entry.resolved.is_none() })
);
assert!(
!trace
.lookups
.iter()
.any(|entry| entry.name.starts_with("skip-"))
);
}
}