Advance native LaTeX execution and preview
This commit is contained in:
1 parent
91f9d76b16
commit
2741546ca8
414 files changed
+99872
-933
No files matched your search
@@ -0,0 +1,138 @@
|
||||
//! Actual native PDF device state, without changing original TeX geometry.
|
||||
#[path = "support/native_fonts.rs"]
|
||||
mod native_fonts;
|
||||
use std::{
|
||||
fs,
|
||||
path::PathBuf,
|
||||
process::Command,
|
||||
sync::atomic::{AtomicU64, Ordering},
|
||||
};
|
||||
fn directory() -> PathBuf {
|
||||
static N: AtomicU64 = AtomicU64::new(0);
|
||||
let p = std::env::temp_dir().join(format!(
|
||||
"texrra-native-device-{}-{}",
|
||||
std::process::id(),
|
||||
N.fetch_add(1, Ordering::Relaxed)
|
||||
));
|
||||
fs::create_dir_all(&p).unwrap();
|
||||
p
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn real_device_fixture_keeps_each_physical_page_and_actual_late_aux_writes() {
|
||||
let p = directory();
|
||||
let root = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
||||
let source = root.join("examples/native-bootstrap/device.tex");
|
||||
let before = fs::read(&source).unwrap();
|
||||
let r = native_fonts::command()
|
||||
.args([
|
||||
"native",
|
||||
"--job",
|
||||
"--initex",
|
||||
"--etex",
|
||||
"--resource-manifest",
|
||||
"resources.json",
|
||||
])
|
||||
.arg(&source)
|
||||
.arg("native.pdf")
|
||||
.current_dir(&p)
|
||||
.output()
|
||||
.unwrap();
|
||||
assert!(r.status.success(), "{}", String::from_utf8_lossy(&r.stderr));
|
||||
let r = Command::new("pdfinfo")
|
||||
.args(["-f", "1", "-l", "3", "native.pdf"])
|
||||
.current_dir(&p)
|
||||
.output()
|
||||
.unwrap();
|
||||
assert!(r.status.success());
|
||||
let text = String::from_utf8(r.stdout).unwrap();
|
||||
let sizes: Vec<Vec<f64>> = text
|
||||
.lines()
|
||||
.filter(|s| s.starts_with("Page"))
|
||||
.filter_map(|s| {
|
||||
s.split_once("size:").map(|(_, s)| {
|
||||
s.split_whitespace()
|
||||
.take(3)
|
||||
.filter_map(|s| s.parse().ok())
|
||||
.collect()
|
||||
})
|
||||
})
|
||||
.collect();
|
||||
assert_eq!(sizes.len(), 3, "{text}");
|
||||
assert_eq!(sizes[0], [320.0, 240.0]);
|
||||
assert_eq!(sizes[1], [280.0, 210.0]);
|
||||
assert!((sizes[2][0] - 255.104).abs() < 0.002, "{text}");
|
||||
assert_eq!(
|
||||
fs::read(p.join("device.aux")).unwrap(),
|
||||
b"SHIP=1;MAG=1200\nSHIP=2;MAG=1200\nSHIP=3;MAG=1200\n"
|
||||
);
|
||||
let trace: serde_json::Value =
|
||||
serde_json::from_slice(&fs::read(p.join("resources.json")).unwrap()).unwrap();
|
||||
for suffix in [
|
||||
"device.tex",
|
||||
"math-fonts.tex",
|
||||
"cmr10.tfm",
|
||||
"cmmi7.tfm",
|
||||
"cmr10.pfb",
|
||||
"cmmi7.pfb",
|
||||
] {
|
||||
assert!(
|
||||
trace["reads"]
|
||||
.as_array()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.any(|v| v["path"].as_str().unwrap().ends_with(suffix)),
|
||||
"missing {suffix}"
|
||||
);
|
||||
}
|
||||
assert_eq!(fs::read(source).unwrap(), before);
|
||||
fs::remove_dir_all(p).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn illegal_or_incompatible_magnification_and_huge_pages_protect_existing_pdf() {
|
||||
let p = directory();
|
||||
for (body, expected) in [
|
||||
(r"\mag=0\shipout\hbox{}\end", "magnification"),
|
||||
(r"\mag=-1\dimen0=1truept\end", "magnification"),
|
||||
(r"\mag=32769\shipout\hbox{}\end", "magnification"),
|
||||
(
|
||||
r"\mag=1200\dimen0=1truept\mag=1000\shipout\hbox{}\end",
|
||||
"magnification",
|
||||
),
|
||||
(
|
||||
r"\shipout\hbox{}\mag=1200\shipout\hbox{}\end",
|
||||
"magnification",
|
||||
),
|
||||
(
|
||||
r"\hoffset=16383pt\shipout\hbox{\vrule width100pt}\end",
|
||||
"huge native page",
|
||||
),
|
||||
(r"\pdfgamma=1000\end", "undefined native control sequence"),
|
||||
] {
|
||||
let source = format!("\\catcode123=1\\catcode125=2\n{body}\n");
|
||||
fs::write(p.join("probe.tex"), &source).unwrap();
|
||||
fs::write(p.join("native.pdf"), b"KEEP").unwrap();
|
||||
let r = native_fonts::command()
|
||||
.args([
|
||||
"native",
|
||||
"--job",
|
||||
"--initex",
|
||||
"--etex",
|
||||
"probe.tex",
|
||||
"native.pdf",
|
||||
])
|
||||
.current_dir(&p)
|
||||
.output()
|
||||
.unwrap();
|
||||
assert_eq!(r.status.code(), Some(1), "{body}");
|
||||
assert!(
|
||||
String::from_utf8_lossy(&r.stderr).contains(expected),
|
||||
"{body}: {}",
|
||||
String::from_utf8_lossy(&r.stderr)
|
||||
);
|
||||
assert_eq!(fs::read(p.join("native.pdf")).unwrap(), b"KEEP");
|
||||
assert_eq!(fs::read_to_string(p.join("probe.tex")).unwrap(), source);
|
||||
}
|
||||
fs::remove_dir_all(p).unwrap();
|
||||
}
|
||||
Reference in new issue
Block a user