Export native TeX shipouts as binary DVI
This commit is contained in:
1 parent
34325317d2
commit
d9edc6c6e7
10 files changed
+459
-14
No files matched your search
+97
-1
@@ -1,4 +1,4 @@
|
||||
//! Actual native PDF device state, without changing original TeX geometry.
|
||||
//! Actual native device state, without changing original TeX geometry.
|
||||
#[path = "support/native_fonts.rs"]
|
||||
mod native_fonts;
|
||||
use std::{
|
||||
@@ -89,6 +89,102 @@ fn real_device_fixture_keeps_each_physical_page_and_actual_late_aux_writes() {
|
||||
fs::remove_dir_all(p).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dvi_job_emits_original_glyphs_rules_and_opaque_specials() {
|
||||
let p = directory();
|
||||
let oracle =
|
||||
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("scripts/native-math-dvi-oracle.py");
|
||||
let special = "payload:".repeat(36);
|
||||
let source = format!(
|
||||
r"\catcode123=1 \catcode125=2
|
||||
\pdfoutput=0 \hoffset=5pt \voffset=-3pt
|
||||
\font\roman=cmr10 \roman
|
||||
\count0=7 \count1=-42
|
||||
\shipout\vbox{{\hbox{{left\special{{{special}}}\kern2pt right}}\hrule height1pt}}
|
||||
\count0=8 \count1=20
|
||||
\shipout\hbox{{\vrule height4pt width10pt right}}
|
||||
\end
|
||||
"
|
||||
);
|
||||
fs::write(p.join("probe.tex"), source).unwrap();
|
||||
let reference = Command::new("pdftex")
|
||||
.args([
|
||||
"-ini",
|
||||
"-etex",
|
||||
"-halt-on-error",
|
||||
"-interaction=nonstopmode",
|
||||
"probe.tex",
|
||||
])
|
||||
.current_dir(&p)
|
||||
.output()
|
||||
.unwrap();
|
||||
assert!(
|
||||
reference.status.success(),
|
||||
"{}",
|
||||
String::from_utf8_lossy(&reference.stdout)
|
||||
);
|
||||
let native = native_fonts::command()
|
||||
.args([
|
||||
"native",
|
||||
"--job",
|
||||
"--initex",
|
||||
"--etex",
|
||||
"--input-profile",
|
||||
"tex8bit",
|
||||
"probe.tex",
|
||||
"native.dvi",
|
||||
])
|
||||
.current_dir(&p)
|
||||
.output()
|
||||
.unwrap();
|
||||
assert!(
|
||||
native.status.success(),
|
||||
"{}",
|
||||
String::from_utf8_lossy(&native.stderr)
|
||||
);
|
||||
let decode = |name| {
|
||||
let result = Command::new("python3")
|
||||
.arg(&oracle)
|
||||
.arg(p.join(name))
|
||||
.output()
|
||||
.unwrap();
|
||||
assert!(
|
||||
result.status.success(),
|
||||
"{}",
|
||||
String::from_utf8_lossy(&result.stderr)
|
||||
);
|
||||
serde_json::from_slice::<serde_json::Value>(&result.stdout).unwrap()
|
||||
};
|
||||
assert_eq!(decode("native.dvi"), decode("probe.dvi"));
|
||||
let bytes = fs::read(p.join("native.dvi")).unwrap();
|
||||
assert!(
|
||||
bytes
|
||||
.windows(special.len())
|
||||
.any(|payload| payload == special.as_bytes())
|
||||
);
|
||||
let read = |index| i32::from_be_bytes(bytes[index..index + 4].try_into().unwrap());
|
||||
let end = bytes.iter().rposition(|&byte| byte != 223).unwrap();
|
||||
assert_eq!(bytes[end], 2);
|
||||
let post = read(end - 4) as usize;
|
||||
assert_eq!(bytes[post], 248);
|
||||
let second = read(post + 1) as usize;
|
||||
let first = read(second + 41) as usize;
|
||||
assert_eq!(
|
||||
(
|
||||
bytes[first],
|
||||
read(first + 1),
|
||||
read(first + 5),
|
||||
read(first + 41)
|
||||
),
|
||||
(139, 7, -42, -1)
|
||||
);
|
||||
assert_eq!(
|
||||
(bytes[second], read(second + 1), read(second + 5)),
|
||||
(139, 8, 20)
|
||||
);
|
||||
fs::remove_dir_all(p).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn illegal_or_incompatible_magnification_and_huge_pages_protect_existing_pdf() {
|
||||
let p = directory();
|
||||
|
||||
Reference in new issue
Block a user