Oregami
Repositories/oxedyne/fe2o3

oxedyne/fe2o3/fe2o3_austenite/tests/pdf_math_faces_eval.rs

2.1 KiB, 1 run

created by r1870400018:66214, which is this file's identity for as long as the history lasts, whatever it is later renamed to

download · who wrote it · its history

1//! The maths faces of a PDF written through the evaluator are the faces Typst writes: an equation is set in
2//! New Computer Modern Math Book, and text that asks for the family in bold is set in its Bold face. The
3//! expectation is Typst's own PDF of the same source, its font names read by the same `pdffonts`.
4
5#![allow(dead_code)]
6
7#[path = "eval_oracle/mod.rs"]
8mod harness;
9
10use harness::oracle::Oracle;
11use harness::pdf::{
12 austenite_pdf,
13 tool,
14 typst_pdf,
15 work_dir,
16};
17
18use oxedyne_fe2o3_core::prelude::*;
19
20use std::collections::BTreeSet;
21use std::path::Path;
22
23// An equation, and the family asked for in bold.
24const SOURCE: &str = "#set page(width: 200pt, height: 80pt, margin: 10pt)\n\
25 An equation $x^2 + y$ and #text(font: \"New Computer Modern Math\", weight: \"bold\")[bold].\n";
26
27// The base names of the fonts `pdffonts` lists, without the subset tag and without `-Identity-H`.
28fn names(pdf: &Path) -> Outcome<BTreeSet<String>> {
29 let listing = res!(tool("pdffonts", &[], pdf, &[]));
30 let mut out = BTreeSet::new();
31 for line in listing.lines().skip(2) {
32 if let Some(name) = line.split_whitespace().next() {
33 let name = name.split_once('+').map(|(_, n)| n).unwrap_or(name);
34 out.insert(name.strip_suffix("-Identity-H").unwrap_or(name).to_string());
35 }
36 }
37 Ok(out)
38}
39
40#[test]
41fn an_equation_is_set_in_the_book_face_and_bold_text_in_the_bold_face_as_typst_sets_them() -> Outcome<()> {
42 if res!(Oracle::find()).is_none() {
43 return Ok(());
44 }
45 let dir = res!(work_dir("pdf-math-faces-eval"));
46 let src = dir.join("main.typ");
47 res!(std::fs::write(&src, SOURCE));
48 let theirs = dir.join("typst.pdf");
49 res!(typst_pdf(&src, &theirs));
50 let made = res!(austenite_pdf(&src));
51 let ours = dir.join("austenite.pdf");
52 res!(std::fs::write(&ours, &made.bytes));
53 let (want, got) = (res!(names(&theirs)), res!(names(&ours)));
54 // Fixed by construction, so a comparison of two sets that are both missing the faces cannot pass.
55 assert!(want.contains("NewCMMath-Book") && want.contains("NewCMMath-Bold"), "Typst's fonts: {:?}", want);
56 assert!(!want.contains("NewCMMath-Regular"), "Typst's fonts: {:?}", want);
57 assert_eq!(got, want, "the fonts differ from Typst's");
58 Ok(())
59}