Compare route-D raster geometry with pdfTeX
This commit is contained in:
1 parent
ea69301804
commit
c2dbf405ab
3 files changed
+146
-2
No files matched your search
@@ -465,6 +465,8 @@ variant for delimiters and large display operators, and builds taller glyphs
|
|||||||
from the font's MATH assembly parts. `\\left...\\right` target sizing follows
|
from the font's MATH assembly parts. `\\left...\\right` target sizing follows
|
||||||
the assignable TeX parameters `\\delimiterfactor` (default 901) and
|
the assignable TeX parameters `\\delimiterfactor` (default 901) and
|
||||||
`\\delimitershortfall` (default 5pt), including local and global assignments.
|
`\\delimitershortfall` (default 5pt), including local and global assignments.
|
||||||
|
Route-D integration can also be checked against a real TeX page: `cargo test -p texrra-tex-core --test route_d` includes `route_d_page_matches_pdftex_raster_geometry`, which renders the route-D PDF and a pdfTeX page at the same geometry, rasterizes both with `pdftoppm`, and compares ink line and edge positions. It is skipped when `pdflatex`/`pdftoppm` are unavailable.
|
||||||
|
|
||||||
These glyphs are rasterized at
|
These glyphs are rasterized at
|
||||||
600 dpi and shared by PDF and SVG. Ordinary math atom glyphs are rasterized from
|
600 dpi and shared by PDF and SVG. Ordinary math atom glyphs are rasterized from
|
||||||
the selected font face at the same resolution, so PDF and SVG paint the same
|
the selected font face at the same resolution, so PDF and SVG paint the same
|
||||||
|
|||||||
@@ -42,3 +42,145 @@ fn route_d_article_exports_pdf_and_reflows_only_the_edited_page() {
|
|||||||
);
|
);
|
||||||
assert_eq!(engine.pages().len(), 3);
|
assert_eq!(engine.pages().len(), 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Compare the rasterized route-D page against a real pdfTeX page at the same
|
||||||
|
/// page geometry. Glyph outlines differ (Liberation vs Computer Modern), so the
|
||||||
|
/// check is limited to page-level ink geometry: one text line, the same ink
|
||||||
|
/// columns start, and a matching vertical band. The test is skipped when the
|
||||||
|
/// host has no pdfTeX/poppler tooling.
|
||||||
|
#[test]
|
||||||
|
fn route_d_page_matches_pdftex_raster_geometry() {
|
||||||
|
use std::process::Command;
|
||||||
|
|
||||||
|
fn has(command: &str) -> bool {
|
||||||
|
Command::new(command)
|
||||||
|
.arg("--version")
|
||||||
|
.stdout(std::process::Stdio::null())
|
||||||
|
.stderr(std::process::Stdio::null())
|
||||||
|
.status()
|
||||||
|
.is_ok_and(|status| status.success())
|
||||||
|
}
|
||||||
|
if !has("pdflatex") || !has("pdftoppm") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn rasterize(pdf: &std::path::Path, output: &std::path::Path) {
|
||||||
|
let status = Command::new("pdftoppm")
|
||||||
|
.args(["-r", "72", "-gray", "-singlefile"])
|
||||||
|
.arg(pdf)
|
||||||
|
.arg(output.with_extension(""))
|
||||||
|
.status()
|
||||||
|
.expect("pdftoppm");
|
||||||
|
assert!(status.success(), "pdftoppm failed for {}", pdf.display());
|
||||||
|
}
|
||||||
|
|
||||||
|
fn ink_bbox(path: &std::path::Path) -> (usize, usize, usize, usize, usize, usize) {
|
||||||
|
let bytes = std::fs::read(path).expect("read PGM");
|
||||||
|
assert_eq!(&bytes[..2], b"P5", "expected binary PGM");
|
||||||
|
let mut fields = Vec::new();
|
||||||
|
let mut cursor = 2;
|
||||||
|
while fields.len() < 3 {
|
||||||
|
while cursor < bytes.len() && bytes[cursor].is_ascii_whitespace() {
|
||||||
|
cursor += 1;
|
||||||
|
}
|
||||||
|
let start = cursor;
|
||||||
|
while cursor < bytes.len() && bytes[cursor].is_ascii_digit() {
|
||||||
|
cursor += 1;
|
||||||
|
}
|
||||||
|
fields.push(
|
||||||
|
std::str::from_utf8(&bytes[start..cursor])
|
||||||
|
.expect("PGM number")
|
||||||
|
.parse::<usize>()
|
||||||
|
.expect("PGM number"),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
while cursor < bytes.len() && bytes[cursor].is_ascii_whitespace() {
|
||||||
|
cursor += 1;
|
||||||
|
}
|
||||||
|
let (width, height, _) = (fields[0], fields[1], fields[2]);
|
||||||
|
let pixels = &bytes[cursor..];
|
||||||
|
assert_eq!(pixels.len(), width * height, "PGM payload size");
|
||||||
|
let (mut x0, mut y0, mut x1, mut y1, mut rows) =
|
||||||
|
(usize::MAX, usize::MAX, 0usize, 0usize, 0usize);
|
||||||
|
for y in 0..height {
|
||||||
|
let mut row_has_ink = false;
|
||||||
|
for x in 0..width {
|
||||||
|
if pixels[y * width + x] < 160 {
|
||||||
|
row_has_ink = true;
|
||||||
|
x0 = x0.min(x);
|
||||||
|
y0 = y0.min(y);
|
||||||
|
x1 = x1.max(x);
|
||||||
|
y1 = y1.max(y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if row_has_ink {
|
||||||
|
rows += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
(x0, y0, x1, y1, rows, width)
|
||||||
|
}
|
||||||
|
|
||||||
|
let root = std::env::temp_dir().join(format!("texrra-raster-{}", std::process::id()));
|
||||||
|
let _ = std::fs::remove_dir_all(&root);
|
||||||
|
std::fs::create_dir_all(&root).expect("create raster dir");
|
||||||
|
|
||||||
|
let document = Document::new(700 * 65536, vec![Unit::paragraph(1, "Hello route-D")]);
|
||||||
|
let engine = Engine::layout(&document);
|
||||||
|
let pages: Vec<_> = engine
|
||||||
|
.pages()
|
||||||
|
.iter()
|
||||||
|
.map(|page| page.display_list())
|
||||||
|
.collect();
|
||||||
|
let route_pdf = display_lists_to_pdf(&pages, 792);
|
||||||
|
let route_pdf_path = root.join("route.pdf");
|
||||||
|
std::fs::write(&route_pdf_path, route_pdf).expect("write route PDF");
|
||||||
|
|
||||||
|
let classic = r"\documentclass[10pt]{article}
|
||||||
|
\pagestyle{empty}
|
||||||
|
\hoffset=-1in
|
||||||
|
\voffset=-1in
|
||||||
|
\oddsidemargin=0pt
|
||||||
|
\topmargin=0pt
|
||||||
|
\headheight=0pt
|
||||||
|
\headsep=0pt
|
||||||
|
\textwidth=480pt
|
||||||
|
\textheight=700pt
|
||||||
|
\topskip=10pt
|
||||||
|
\parindent=0pt
|
||||||
|
\begin{document}
|
||||||
|
Hello route-D
|
||||||
|
\end{document}
|
||||||
|
";
|
||||||
|
let classic_path = root.join("classic.tex");
|
||||||
|
std::fs::write(&classic_path, classic).expect("write classic TeX");
|
||||||
|
let status = Command::new("pdflatex")
|
||||||
|
.args(["-interaction=nonstopmode", "-halt-on-error"])
|
||||||
|
.arg(&classic_path)
|
||||||
|
.current_dir(&root)
|
||||||
|
.stdout(std::process::Stdio::null())
|
||||||
|
.stderr(std::process::Stdio::null())
|
||||||
|
.status()
|
||||||
|
.expect("pdflatex");
|
||||||
|
assert!(status.success(), "pdflatex failed");
|
||||||
|
|
||||||
|
let route_pgm = root.join("route.pgm");
|
||||||
|
let classic_pgm = root.join("classic.pgm");
|
||||||
|
rasterize(&route_pdf_path, &route_pgm);
|
||||||
|
rasterize(&root.join("classic.pdf"), &classic_pgm);
|
||||||
|
let route = ink_bbox(&route_pgm);
|
||||||
|
let classic = ink_bbox(&classic_pgm);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
route.4, classic.4,
|
||||||
|
"text line count: route={route:?} classic={classic:?}"
|
||||||
|
);
|
||||||
|
assert!(
|
||||||
|
route.2 <= classic.2 && route.2 + 10 >= classic.2,
|
||||||
|
"ink left edge: route={route:?} classic={classic:?}"
|
||||||
|
);
|
||||||
|
assert!(
|
||||||
|
route.3 <= classic.3 + 2 && route.3 + 2 >= classic.3,
|
||||||
|
"ink bottom edge: route={route:?} classic={classic:?}"
|
||||||
|
);
|
||||||
|
let _ = std::fs::remove_dir_all(&root);
|
||||||
|
}
|
||||||
+2
-2
@@ -267,7 +267,7 @@ M3 (partial): `Unit::halign` normalizes column widths, intercolumn gaps, row hei
|
|||||||
|
|
||||||
Math coverage includes fractions/roots, scripts, `\left...\right` with body-scaled delimiters, `\middle`, `\big`/`\Big`/`\bigg`/`\Bigg` and their `l`/`r` forms, control-sequence delimiters, accents (dot/check/breve/acute/grave/ring), `\text`/`\mathrm`, `\overbrace`/`\underbrace`, `\overset`/`\underset`, `\binom`, `\cancel`/`\bcancel`/`\xcancel`, `\bmod`/`\pmod`, fence symbols, `\operatorname*` and `\mathop` limits.
|
Math coverage includes fractions/roots, scripts, `\left...\right` with body-scaled delimiters, `\middle`, `\big`/`\Big`/`\bigg`/`\Bigg` and their `l`/`r` forms, control-sequence delimiters, accents (dot/check/breve/acute/grave/ring), `\text`/`\mathrm`, `\overbrace`/`\underbrace`, `\overset`/`\underset`, `\binom`, `\cancel`/`\bcancel`/`\xcancel`, `\bmod`/`\pmod`, fence symbols, `\operatorname*` and `\mathop` limits.
|
||||||
|
|
||||||
The crate currently has 142 unit tests plus one route-D integration test. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 238 tests (142 route-D unit, 1 route-D integration, 71 v1 integration, 18 server, 4 v1 unit, 1 doctest). v1 remains the live server path.
|
The crate currently has 142 unit tests plus two route-D integration tests. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 239 tests (142 route-D unit, 2 route-D integration, 71 v1 integration, 19 server, 4 v1 unit, 1 doctest). v1 remains the live server path.
|
||||||
|
|
||||||
### M0 incremental demo
|
### M0 incremental demo
|
||||||
|
|
||||||
@@ -309,6 +309,6 @@ deliberately open rather than approximated:
|
|||||||
through `Engine::edit` and reports the changed/recomputed pages, while
|
through `Engine::edit` and reports the changed/recomputed pages, while
|
||||||
structural edits fall back to a full layout. The v1 semantic pipeline remains
|
structural edits fall back to a full layout. The v1 semantic pipeline remains
|
||||||
the default fallback. LaTeX-to-route-D semantic mapping is still a subset, and
|
the default fallback. LaTeX-to-route-D semantic mapping is still a subset, and
|
||||||
there is no editor toggle UI or pixel comparison yet.
|
`route_d_page_matches_pdftex_raster_geometry` rasterizes the route-D PDF at 72 dpi and compares its ink line/left/bottom geometry against a pdfTeX page compiled with the same page geometry. The test skips on hosts without `pdflatex`/`pdftoppm`; exact glyph-outline pixel equality is still open because the two paths use different font outlines.
|
||||||
- `\middle` does not scale with its enclosing delimiter; math delimiters are
|
- `\middle` does not scale with its enclosing delimiter; math delimiters are
|
||||||
scaled glyphs rather than TeX delimiter variants.
|
scaled glyphs rather than TeX delimiter variants.
|
||||||
Reference in new issue
Block a user