Use Base-14 fonts when possible and center natural-width tables

This commit is contained in:
gloamxun committed 2026-10-19 17:40:04 +08:00
1 parent 1da9e0dde9
commit ca5cb0b8af
8 files changed
+295 -35

No files matched your search

+1 -1
View File
@@ -258,7 +258,7 @@ fn serves_project_api_preview_and_pdf() {
assert!((value["pageWidthMm"].as_f64().unwrap() - 210.0).abs() < 0.1);
let pdf = server.request("POST", "/api/projects/hello/pdf", &[], "application/pdf");
assert_eq!(pdf.status, 200);
assert_eq!(pdf.status, 200, "{}", String::from_utf8_lossy(&pdf.body));
assert!(pdf.body.starts_with(b"%PDF-"), "missing PDF header");
}
+63
View File
@@ -987,6 +987,69 @@ After.
);
}
#[test]
fn ascii_documents_use_base14_fonts_without_embedding() {
let source = r"\documentclass{article}
\begin{document}
Plain text that only needs the standard Times encoding.
\end{document}";
let pdf = CompilerSession::default()
.compile(source, "base14.tex")
.expect("base14 PDF");
let text = String::from_utf8_lossy(&pdf);
assert!(
text.contains("Times-Roman"),
"expected a Base-14 Times face"
);
assert!(
!text.contains("FontFile2"),
"ASCII text should not embed a TrueType program"
);
}
#[test]
fn arxiv_table_rules_follow_a_narrow_centered_table() {
let path = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("fixtures")
.join("arxiv-template")
.join("template.tex");
let source = std::fs::read_to_string(&path).expect("read arXiv fixture");
let file_name = path.to_string_lossy().to_string();
let value = fresh_preview(&source, &file_name);
assert_eq!(value["status"], "ok", "{}", value["message"]);
let svg = page_svg(&value, 2);
let mut table_rules = Vec::new();
for fragment in svg.split("<line ").skip(1) {
let tag = fragment.split('>').next().unwrap_or(fragment);
let x1 = tag
.split("x1=\"")
.nth(1)
.and_then(|rest| rest.split('"').next())
.and_then(|value| value.parse::<f64>().ok());
let x2 = tag
.split("x2=\"")
.nth(1)
.and_then(|rest| rest.split('"').next())
.and_then(|value| value.parse::<f64>().ok());
if let (Some(x1), Some(x2)) = (x1, x2) {
let width = x2 - x1;
if x1 > 20.0 && width > 40.0 && width < 140.0 {
table_rules.push((x1, width));
}
}
}
assert!(
table_rules.len() >= 4,
"expected the table's top/mid/bottom rules, got {table_rules:?}"
);
assert!(
table_rules
.iter()
.all(|(x, width)| *x > 20.0 && *width < 140.0),
"table rules should be centered and narrower than the text block: {table_rules:?}"
);
}
#[test]
fn abstract_environment_gets_an_unumbered_heading() {
let source = r"\documentclass{article}