test(pdf): no-overlap census of the frozen PDF runs
This commit is contained in:
1 parent
1efb057ca2
commit
8ff2c2ce15
4 files changed
+174
-7
No files matched your search
@@ -6,6 +6,8 @@
|
||||
clippy::expect_used
|
||||
)]
|
||||
|
||||
#[cfg(feature = "pdf-write")]
|
||||
pub mod page_boxes;
|
||||
pub mod r4;
|
||||
pub mod sheet_readers;
|
||||
pub mod svg_tree;
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
//! Boxes of a draw-log page for the no-overlap census of the PDF (owner 2026-11-22, R2). Text:
|
||||
//! from its baseline, 0.25 em down and 0.8 em up, its measured width; images and rectangles as
|
||||
//! drawn; lines widened by half their thickness. The footer region is what the footer calls
|
||||
//! cover; the content keeps `CLEARANCE` above it.
|
||||
|
||||
use faunosteo_core::pdf::write::draw_log::{DrawOp, PAGE_HEIGHT, PAGE_WIDTH, PageLog};
|
||||
use faunosteo_core::pdf::write::text::measure;
|
||||
|
||||
pub const CLEARANCE: f64 = 1.0;
|
||||
/// View images sit under the title block (its baseline is at 719.89); header images above.
|
||||
pub const BODY_TOP: f64 = 700.0;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
pub struct PageBox {
|
||||
pub index: usize,
|
||||
pub image: bool,
|
||||
pub x0: f64,
|
||||
pub y0: f64,
|
||||
pub x1: f64,
|
||||
pub y1: f64,
|
||||
}
|
||||
|
||||
impl PageBox {
|
||||
fn meets(&self, other: &PageBox) -> bool {
|
||||
self.x0 < other.x1 && other.x0 < self.x1 && self.y0 < other.y1 && other.y0 < self.y1
|
||||
}
|
||||
}
|
||||
|
||||
pub fn box_of(index: usize, op: &DrawOp) -> PageBox {
|
||||
let (image, x0, y0, x1, y1) = match op {
|
||||
DrawOp::Text(t) => {
|
||||
let width = measure(t.font, &t.text, t.size);
|
||||
(
|
||||
false,
|
||||
t.x,
|
||||
t.y - 0.25 * t.size,
|
||||
t.x + width,
|
||||
t.y + 0.8 * t.size,
|
||||
)
|
||||
}
|
||||
DrawOp::Image(i) => (true, i.x, i.y, i.x + i.width, i.y + i.height),
|
||||
DrawOp::Rectangle(r) => (false, r.x, r.y, r.x + r.width, r.y + r.height),
|
||||
DrawOp::Line(l) => {
|
||||
let half = l.thickness / 2.0;
|
||||
let (xa, xb) = (l.start.x.min(l.end.x), l.start.x.max(l.end.x));
|
||||
let (ya, yb) = (l.start.y.min(l.end.y), l.start.y.max(l.end.y));
|
||||
(false, xa - half, ya - half, xb + half, yb + half)
|
||||
}
|
||||
};
|
||||
PageBox {
|
||||
index,
|
||||
image,
|
||||
x0,
|
||||
y0,
|
||||
x1,
|
||||
y1,
|
||||
}
|
||||
}
|
||||
|
||||
/// What breaks R2 on `page`: a content call outside the page or within `CLEARANCE` of the
|
||||
/// footer region, a view image touching any other content call.
|
||||
pub fn census(page: &PageLog) -> Vec<String> {
|
||||
let content: Vec<PageBox> = page.ops[..page.footer_start]
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(i, op)| box_of(i, op))
|
||||
.collect();
|
||||
let footer_top = page.ops[page.footer_start..]
|
||||
.iter()
|
||||
.map(|op| box_of(0, op).y1)
|
||||
.fold(f64::NEG_INFINITY, f64::max);
|
||||
let mut faults = Vec::new();
|
||||
for b in &content {
|
||||
if b.x0 < 0.0 || b.x1 > PAGE_WIDTH || b.y0 < 0.0 || b.y1 > PAGE_HEIGHT {
|
||||
faults.push(format!("call {} leaves the page", b.index));
|
||||
}
|
||||
if b.y0 < footer_top + CLEARANCE {
|
||||
faults.push(format!("call {} reaches the footer ({:.2})", b.index, b.y0));
|
||||
}
|
||||
}
|
||||
for view in content.iter().filter(|b| b.image && b.y1 <= BODY_TOP) {
|
||||
for other in content
|
||||
.iter()
|
||||
.filter(|o| o.index != view.index && o.meets(view))
|
||||
{
|
||||
faults.push(format!("image {} touches call {}", view.index, other.index));
|
||||
}
|
||||
}
|
||||
faults
|
||||
}
|
||||
|
||||
/// The lowest text baseline under `BODY_TOP` of the content calls of `page`, if any.
|
||||
pub fn lowest_body_baseline(page: &PageLog) -> Option<f64> {
|
||||
page.ops[..page.footer_start]
|
||||
.iter()
|
||||
.filter_map(|op| match op {
|
||||
DrawOp::Text(t) if t.y < BODY_TOP => Some(t.y),
|
||||
_ => None,
|
||||
})
|
||||
.reduce(f64::min)
|
||||
}
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
mod common;
|
||||
|
||||
use common::page_boxes::{census, lowest_body_baseline};
|
||||
use common::r4::{PngKeeper, repo_root, sha256_hex};
|
||||
use faunosteo_core::domain::archive::Locale;
|
||||
use faunosteo_core::domain::js::parse_json;
|
||||
@@ -241,6 +242,35 @@ fn o1_draw_logs_match_the_typescript_at_full_precision() {
|
||||
println!("O1: 12 runs, {ops} ops equal");
|
||||
}
|
||||
|
||||
/// R2 (owner 2026-11-22): on the frozen runs no content call reaches the footer or leaves the
|
||||
/// page, and no view image touches another call. Prints the lowest body baseline per run
|
||||
/// (Task 26's text floor is 76).
|
||||
#[test]
|
||||
fn r2_the_frozen_runs_keep_clear_of_the_footer_and_of_each_other() {
|
||||
let mut faults = Vec::new();
|
||||
for report in REPORTS {
|
||||
for locale in LOCALES {
|
||||
for mode in MODES {
|
||||
let name = format!("{report}.{locale}.{mode}");
|
||||
let input = export_input(report, locale, mode);
|
||||
let rasters = stub_rasters(&input, mode);
|
||||
let checked = check_input(input).unwrap();
|
||||
let drawn = layout(&checked, &rasters, &mut PngKeeper::default()).unwrap();
|
||||
let mut lowest = f64::INFINITY;
|
||||
for (p, page) in drawn.log.pages.iter().enumerate() {
|
||||
for fault in census(page) {
|
||||
faults.push(format!("{name} page {p}: {fault}"));
|
||||
}
|
||||
lowest = lowest.min(lowest_body_baseline(page).unwrap_or(f64::INFINITY));
|
||||
}
|
||||
println!("R2 {name}: lowest body baseline {lowest:.2}");
|
||||
assert!(lowest >= 76.0, "{name}: baseline {lowest} under the floor");
|
||||
}
|
||||
}
|
||||
}
|
||||
assert!(faults.is_empty(), "{}", faults.join("\n"));
|
||||
}
|
||||
|
||||
/// Two decimals as the Step 6 recorder rounded (`Math.round(n * 100) / 100`).
|
||||
fn round2(n: f64) -> f64 {
|
||||
(n * 100.0).round() / 100.0
|
||||
|
||||
@@ -13,7 +13,8 @@ mod common;
|
||||
use std::collections::BTreeMap;
|
||||
use std::process::Command;
|
||||
|
||||
use common::r4::{repo_root, sha256_hex};
|
||||
use common::page_boxes::{census, lowest_body_baseline};
|
||||
use common::r4::{PngKeeper, repo_root, sha256_hex};
|
||||
use faunosteo_core::domain::archive::Locale;
|
||||
use faunosteo_core::domain::js::parse_json;
|
||||
use faunosteo_core::domain::sheet::{BundledSheetData, LoadedSheet};
|
||||
@@ -21,7 +22,8 @@ use faunosteo_core::json::to_js_compact;
|
||||
use faunosteo_core::pdf::import::import_pdf;
|
||||
use faunosteo_core::pdf::read::probe::{ProbeLimits, read_attached_document};
|
||||
use faunosteo_core::pdf::write::export::{export_from_envelope, export_pdf};
|
||||
use faunosteo_core::pdf::write::input::{ExportInput, Rasters};
|
||||
use faunosteo_core::pdf::write::input::{ExportInput, Rasters, check_input};
|
||||
use faunosteo_core::pdf::write::layout::layout;
|
||||
use lopdf::{Dictionary, Document, Object, ObjectId};
|
||||
use serde_json::{Value, json};
|
||||
|
||||
@@ -119,8 +121,8 @@ fn stub_run(report: &str, locale: &str, mode: &str) -> Run {
|
||||
}
|
||||
}
|
||||
|
||||
/// The real-raster run: v2full's first observation, the PNGs the browser made (manifest).
|
||||
fn real_run() -> Run {
|
||||
/// The real-raster run's inputs: v2full's first observation, the PNGs the browser made (manifest).
|
||||
fn real_inputs() -> (Vec<u8>, ExportInput, Rasters) {
|
||||
let r3 = fixture("pdf/r3/real/v2full-obs1.fr.logos.pdf");
|
||||
let input = input_from(&envelope_of(&r3));
|
||||
let manifest: Value = serde_json::from_slice(&fixture("pdf/r3/real/manifest.json")).unwrap();
|
||||
@@ -140,6 +142,11 @@ fn real_run() -> Run {
|
||||
rasters.views.insert(key, png);
|
||||
}
|
||||
}
|
||||
(r3, input, rasters)
|
||||
}
|
||||
|
||||
fn real_run() -> Run {
|
||||
let (r3, input, rasters) = real_inputs();
|
||||
let result = export_pdf(input, &rasters).unwrap();
|
||||
assert!(result.warnings.is_empty());
|
||||
Run {
|
||||
@@ -150,15 +157,20 @@ fn real_run() -> Run {
|
||||
}
|
||||
}
|
||||
|
||||
/// The store-path run: the report as the editor's store ordered it (D-R11: the attachment's
|
||||
/// report is in contract order in R4, values identical).
|
||||
fn store_path_run() -> Run {
|
||||
/// The store-path run's inputs: the report as the editor's store ordered it (D-R11: the
|
||||
/// attachment's report is in contract order in R4, values identical).
|
||||
fn store_path_inputs() -> (Vec<u8>, ExportInput, Rasters) {
|
||||
let r3 = fixture("pdf/r3/store-path.fr.nologos.pdf");
|
||||
let envelope = envelope_of(&r3);
|
||||
let mut input = input_from(&envelope);
|
||||
let report: Value = serde_json::from_slice(&fixture("pdf/r3/store-path.report.json")).unwrap();
|
||||
input.report = serde_json::from_value(report).unwrap();
|
||||
let rasters = stub_rasters(&input, &base64(ONE_PX_PNG));
|
||||
(r3, input, rasters)
|
||||
}
|
||||
|
||||
fn store_path_run() -> Run {
|
||||
let (r3, input, rasters) = store_path_inputs();
|
||||
let result = export_pdf(input, &rasters).unwrap();
|
||||
Run {
|
||||
name: "store-path.fr.nologos".to_owned(),
|
||||
@@ -831,3 +843,25 @@ fn l_report_with_real_rasters_costs_what_it_costs() {
|
||||
);
|
||||
assert!(result.warnings.is_empty());
|
||||
}
|
||||
|
||||
/// R2 (owner 2026-11-22): the two runs the R4 digests pin keep clear of the footer and of each
|
||||
/// other. Prints the lowest body baseline per run (Task 26's text floor is 76).
|
||||
#[test]
|
||||
fn r2_the_pinned_runs_keep_clear_of_the_footer_and_of_each_other() {
|
||||
let runs = [
|
||||
("real.v2full-obs1.fr.logos", real_inputs()),
|
||||
("store-path.fr.nologos", store_path_inputs()),
|
||||
];
|
||||
for (name, (_, input, rasters)) in runs {
|
||||
let checked = check_input(input).unwrap();
|
||||
let drawn = layout(&checked, &rasters, &mut PngKeeper::default()).unwrap();
|
||||
let mut lowest = f64::INFINITY;
|
||||
for (p, page) in drawn.log.pages.iter().enumerate() {
|
||||
let faults = census(page);
|
||||
assert!(faults.is_empty(), "{name} page {p}: {faults:?}");
|
||||
lowest = lowest.min(lowest_body_baseline(page).unwrap_or(f64::INFINITY));
|
||||
}
|
||||
println!("R2 {name}: lowest body baseline {lowest:.2}");
|
||||
assert!(lowest >= 76.0, "{name}: baseline {lowest} under the floor");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user