mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-03 04:25:52 -05:00
The Affinity raster tests compared decoded pixels with CRCs captured from the reader's own output, so a decoding error present when the CRC was taken would pass. They now read the image's tiles straight from the archive (256-byte by 256-row planes, states 2 and 4), interleave them, scale 16-bit samples with rounding, and compare the whole buffer. The Affinity 3 signatures drop the CRC of the model's Debug output and keep the feature counts. The DXF golden test no longer rewrites its expected files when WRITE_DXF_GOLDENS is set. Each golden file is first checked against the drawing it should hold (rectangle corners, circle center, radius and bulges, ACI and true colors, lineweights), and a mismatch saves the output to the temp directory for review.
62 lines
3.2 KiB
Rust
62 lines
3.2 KiB
Rust
//! Structural regression signatures, measured from the pinned files through our own reader.
|
|
//! They count retained features; they are not independent visual or compatibility oracles.
|
|
//! Pixels are checked against the stored tiles in `raster.rs`. Input authenticity is checked
|
|
//! with SHA256 by the corpus gate.
|
|
use std::collections::{BTreeMap, BTreeSet};
|
|
use vectorcraft_affinity::model::{Document, Kind, Node};
|
|
use vectorcraft_affinity::paint::Paint;
|
|
|
|
pub fn signature(doc: &Document) -> String {
|
|
fn visit(nodes: &[Node], counts: &mut BTreeMap<&'static str, usize>, fonts: &mut BTreeSet<String>, boards: &mut Vec<String>, depth: usize) {
|
|
for n in nodes {
|
|
*counts.entry("nodes").or_default() += 1;
|
|
counts.entry("depth").and_modify(|v| *v = (*v).max(depth)).or_insert(depth);
|
|
let key = match &n.kind {
|
|
Kind::Layer => "layers",
|
|
Kind::Group => "groups",
|
|
Kind::Artboard { rect, .. } => {
|
|
boards.push(format!("{}:{:.4},{:.4},{:.4},{:.4}", n.name, rect.x0, rect.y0, rect.x1, rect.y1));
|
|
"artboards"
|
|
}
|
|
Kind::Shape { path, fills, strokes, .. } => {
|
|
*counts.entry("subpaths").or_default() += path.subpaths.len();
|
|
*counts.entry("segments").or_default() += path.subpaths.iter().map(|p| p.segments.len()).sum::<usize>();
|
|
*counts.entry("fills").or_default() += fills.len();
|
|
*counts.entry("strokes").or_default() += strokes.len();
|
|
*counts.entry("gradients").or_default() += fills.iter().filter(|p| matches!(p, Paint::Gradient(_))).count();
|
|
"shapes"
|
|
}
|
|
Kind::Text(t) => {
|
|
*counts.entry("text_runs").or_default() += t.runs.len();
|
|
*counts.entry("text_chars").or_default() += t.runs.iter().map(|r| r.text.chars().count()).sum::<usize>();
|
|
for r in &t.runs {
|
|
fonts.insert(format!("{}:{}:{}:{}", r.family, r.postscript, r.weight, r.italic));
|
|
}
|
|
"texts"
|
|
}
|
|
Kind::Table(t) => {
|
|
*counts.entry("table_cells").or_default() += t.cells.len();
|
|
"tables"
|
|
}
|
|
Kind::Image(_) => "images",
|
|
Kind::MasterInstance { .. } => "master_instances",
|
|
Kind::Unsupported => "unsupported",
|
|
};
|
|
*counts.entry(key).or_default() += 1;
|
|
for (key, yes) in
|
|
[("hidden", !n.visible), ("vector_masks", n.mask.is_some()), ("pixel_masks", n.pixel_mask.is_some()), ("opacity", n.opacity < 1.0)]
|
|
{
|
|
if yes {
|
|
*counts.entry(key).or_default() += 1;
|
|
}
|
|
}
|
|
visit(&n.children, counts, fonts, boards, depth + 1);
|
|
}
|
|
}
|
|
let (mut counts, mut fonts, mut boards) = (BTreeMap::new(), BTreeSet::new(), Vec::new());
|
|
for spread in &doc.spreads {
|
|
visit(&spread.nodes, &mut counts, &mut fonts, &mut boards, 1);
|
|
}
|
|
format!("dpi={};spreads={};counts={counts:?};boards={boards:?};fonts={fonts:?};warnings={:?}", doc.dpi, doc.spreads.len(), doc.warnings)
|
|
}
|