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,136 @@
|
||||
#[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-pk-{}-{}",
|
||||
std::process::id(),
|
||||
N.fetch_add(1, Ordering::Relaxed)
|
||||
));
|
||||
fs::create_dir_all(&p).unwrap();
|
||||
p
|
||||
}
|
||||
fn command() -> Command {
|
||||
let root = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
||||
let mut c = native_fonts::command();
|
||||
let pk = root.join("crates/texrra-tex-core/tests/fixtures/pk");
|
||||
c.env("TEXFONTMAPS", &pk).env("PKFONTS", &pk);
|
||||
c
|
||||
}
|
||||
#[test]
|
||||
fn actual_pk_fonts_pages_and_late_auxiliary_writes_reach_the_native_cli() {
|
||||
let p = directory();
|
||||
let source =
|
||||
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("examples/native-bootstrap/pk-device.tex");
|
||||
let before = fs::read(&source).unwrap();
|
||||
let r = 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 fonts = Command::new("pdffonts")
|
||||
.arg(p.join("native.pdf"))
|
||||
.output()
|
||||
.unwrap();
|
||||
assert!(fonts.status.success());
|
||||
let fonts = String::from_utf8_lossy(&fonts.stdout);
|
||||
assert_eq!(fonts.matches("Type 3").count(), 3, "{fonts}");
|
||||
let info = Command::new("pdfinfo")
|
||||
.arg(p.join("native.pdf"))
|
||||
.output()
|
||||
.unwrap();
|
||||
assert!(info.status.success());
|
||||
assert!(
|
||||
String::from_utf8_lossy(&info.stdout)
|
||||
.lines()
|
||||
.any(|l| l.starts_with("Pages:") && l.ends_with('2'))
|
||||
);
|
||||
assert_eq!(
|
||||
fs::read(p.join("bitmap.aux")).unwrap(),
|
||||
b"PAGE=1;DPI=300\nPAGE=2;DPI=1200\n"
|
||||
);
|
||||
let trace: serde_json::Value =
|
||||
serde_json::from_slice(&fs::read(p.join("resources.json")).unwrap()).unwrap();
|
||||
let reads = trace["reads"].as_array().unwrap();
|
||||
for name in ["cmr10", "cmmi10", "cmex10"] {
|
||||
assert!(reads.iter().any(|v| {
|
||||
v["path"]
|
||||
.as_str()
|
||||
.unwrap()
|
||||
.ends_with(&format!("{name}.600pk"))
|
||||
}));
|
||||
assert!(reads.iter().any(|v| {
|
||||
v["path"]
|
||||
.as_str()
|
||||
.unwrap()
|
||||
.ends_with(&format!("{name}.tfm"))
|
||||
}));
|
||||
}
|
||||
assert!(
|
||||
!reads
|
||||
.iter()
|
||||
.any(|v| v["path"].as_str().unwrap().ends_with(".pfb"))
|
||||
);
|
||||
assert_eq!(fs::read(&source).unwrap(), before);
|
||||
fs::remove_dir_all(p).unwrap();
|
||||
}
|
||||
#[test]
|
||||
fn absent_pk_density_fails_without_substitution_and_keeps_existing_output_and_trace() {
|
||||
let p = directory();
|
||||
let source =
|
||||
br"\catcode123=1\catcode125=2\pdfpkresolution=700\font\F=cmr10\F\shipout\hbox{A}\end";
|
||||
fs::write(p.join("source.tex"), source).unwrap();
|
||||
fs::write(p.join("native.pdf"), b"KEEP").unwrap();
|
||||
let r = command()
|
||||
.args([
|
||||
"native",
|
||||
"--job",
|
||||
"--initex",
|
||||
"--etex",
|
||||
"--resource-manifest",
|
||||
"resources.json",
|
||||
"source.tex",
|
||||
"native.pdf",
|
||||
])
|
||||
.current_dir(&p)
|
||||
.output()
|
||||
.unwrap();
|
||||
assert!(!r.status.success());
|
||||
let error = String::from_utf8_lossy(&r.stderr);
|
||||
assert!(error.contains("cmr10 at 700 dpi not found"), "{error}");
|
||||
assert_eq!(fs::read(p.join("native.pdf")).unwrap(), b"KEEP");
|
||||
assert_eq!(fs::read(p.join("source.tex")).unwrap(), source);
|
||||
let trace: serde_json::Value =
|
||||
serde_json::from_slice(&fs::read(p.join("resources.json")).unwrap()).unwrap();
|
||||
assert!(
|
||||
trace["lookups"]
|
||||
.as_array()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.any(|v| v["kind"] == "Pk" && v["resolved"].is_null())
|
||||
);
|
||||
assert!(
|
||||
!trace["reads"]
|
||||
.as_array()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.any(|v| v["path"].as_str().unwrap().ends_with(".pfb"))
|
||||
);
|
||||
fs::remove_dir_all(p).unwrap();
|
||||
}
|
||||
Reference in new issue
Block a user