Merge main into feat/scripts-export-autocad

This commit is contained in:
dotCooCoo committed 2026-12-02 02:20:49 -08:00
commit d09d00fa25
278 files changed
+9496 -2128

No files matched your search

+24 -1
View File
@@ -929,7 +929,20 @@ fn mutate_text(src: &str, cut: usize, edits: &[(usize, char)]) -> String {
fn svg_type_shifted_two_billion_points_exports_to_pdf() {
let svg = r#"<svg xmlns="http://www.w3.org/2000/svg"><text baseline-shift="-2147483649">f</text></svg>"#;
let d = vectorcraft_svg::import(svg).unwrap();
assert!(vectorcraft_engine::export_pdf(&d, &vectorcraft_pdf::PdfOptions::default()).is_ok());
// The type opens with its shift, so the export below meets a glyph that far out.
let mut shifts = Vec::new();
d.walk(|n| {
if let vectorcraft_doc::NodeKind::Text(t) = &n.kind {
shifts.extend(t.runs.iter().map(|r| r.style.baseline_shift));
}
});
assert!(shifts.iter().any(|&s| s.abs() > 2e9), "baseline shifts read: {shifts:?}");
let pdf = vectorcraft_engine::export_pdf(&d, &vectorcraft_pdf::PdfOptions::default()).unwrap();
// The PDF leaves the type out: reading it back finds no type.
let back = vectorcraft_pdf::import(&pdf).unwrap();
let mut text = 0;
back.walk(|n| text += usize::from(matches!(n.kind, vectorcraft_doc::NodeKind::Text(_))));
assert_eq!(text, 0, "type left out of the page");
}
proptest! {
@@ -8630,6 +8643,16 @@ fn a_long_thin_shape_with_a_shadow_renders_and_exports() {
let stream = canvas_stream(vec![with_effects(rectangle(10, (0.0, 0.0), (3_276_800.0, 50.0)), vec![shadow()])]);
let bytes = affinity_sample_file(&stream, None);
let doc = vectorcraft_engine::cmd::fileio::load("long.af", &bytes).unwrap().doc;
// The shape opens whole, with its shadow, so the exports below draw the shadow that far out.
let mut shadowed = Vec::new();
doc.walk(|n| {
if n.appearance.effects.iter().any(|e| e.id == "stylize.dropShadow") {
shadowed.push(n.id);
}
});
assert_eq!(shadowed.len(), 1, "one shape with a drop shadow");
let width = doc.bounds_of(&shadowed, false).map(|r| r.width());
assert!(width.is_some_and(|w| w > 3_000_000.0), "the shape is {width:?} pt wide");
survive("long shape", || Some(doc)).unwrap();
}
+3 -2
View File
@@ -2,7 +2,7 @@
//! recursively) opens as editable art, and each artboard is compared with the thumbnail Affinity
//! stored in the file. Reports the mean difference per artboard (0–255, both on white); with
//! `AFFINITY_SAMPLES_OUT` set, writes each board's thumbnail crop and render side by side there.
//! Skipped when `AFFINITY_SAMPLES` is unset (as in CI).
//! Ignored by default; run it with `--ignored` and `AFFINITY_SAMPLES` set.
use std::path::{Path, PathBuf};
@@ -28,8 +28,9 @@ fn on_white(p: &[u8]) -> [f64; 3] {
}
#[test]
#[ignore = "local samples: set AFFINITY_SAMPLES to a folder of Affinity documents"]
fn local_affinity_documents_render_like_their_thumbnails() {
let Some(root) = std::env::var_os("AFFINITY_SAMPLES").map(PathBuf::from) else { return };
let root = PathBuf::from(std::env::var_os("AFFINITY_SAMPLES").expect("AFFINITY_SAMPLES names the folder of documents to check"));
let out = std::env::var_os("AFFINITY_SAMPLES_OUT").map(PathBuf::from);
let mut paths = Vec::new();
files(&root, &mut paths);
+1
View File
@@ -476,6 +476,7 @@ fn turned_horizontal_dimensions_stay_horizontal() {
let mut ys = [d.a.y.round(), d.b.y.round()];
ys.sort_by(f64::total_cmp);
assert_eq!(ys, [180.0, 280.0]);
assert_eq!(path_ends(&s, id)[2].len(), 2, "{:?}", path_ends(&s, id));
assert!(path_ends(&s, id)[2].iter().all(|(_, y)| (y - 130.0).abs() < 1e-6), "{:?}", path_ends(&s, id));
let line = run(&mut s, "shape.line", json!({"x1":100,"y1":400,"x2":200,"y2":400}))["id"].as_u64().unwrap();
let anchor = |anchor: u64| json!({"node":line,"subpath":0,"anchor":anchor});
+10 -2
View File
@@ -76,10 +76,18 @@ fn a_file_the_import_left_things_out_of_is_not_written_over_unasked() {
fn a_file_the_import_read_whole_is_written_over_as_before() {
let d = dir("b");
let src = d.join("plain.eps");
std::fs::write(&src, "%!PS-Adobe-3.0 EPSF-3.0\n%%BoundingBox: 0 0 100 100\n%%EndComments\n0 0 1 0 setcmykcolor 10 10 moveto 14 10 lineto 14 14 lineto closepath fill\nshowpage\n%%EOF\n").unwrap();
let original = "%!PS-Adobe-3.0 EPSF-3.0\n%%BoundingBox: 0 0 100 100\n%%EndComments\n0 0 1 0 setcmykcolor 10 10 moveto 14 10 lineto 14 14 lineto closepath fill\nshowpage\n%%EOF\n";
std::fs::write(&src, original).unwrap();
let mut s = Session::new();
s.execute("document.open", &json!({ "path": src.to_string_lossy() })).unwrap();
let opened = s.execute("document.open", &json!({ "path": src.to_string_lossy() })).unwrap();
assert_eq!(opened["warnings"], json!([]), "{opened}");
s.execute("document.export", &json!({ "path": src.to_string_lossy(), "format": "eps" })).unwrap();
let written = std::fs::read(&src).unwrap();
assert_ne!(written, original.as_bytes(), "the export wrote over the file");
let mut again = Session::new();
again.execute("document.open", &json!({ "path": src.to_string_lossy() })).unwrap();
let doc = &again.doc().unwrap().doc;
assert!(doc.layers.iter().any(|l| l.children().is_some_and(|c| !c.is_empty())), "the square is in the file written");
std::fs::remove_dir_all(d).ok();
}
+3 -1
View File
@@ -209,7 +209,9 @@ fn preflight_resource_font_finding_locates_its_instance() {
s.execute("symbol.new", &json!({ "name": "Label" })).unwrap();
let r = check(&mut s);
let f = r["findings"].as_array().unwrap().iter().find(|f| f["code"] == "missingFont").unwrap();
assert!(f["ids"].as_array().unwrap().iter().all(|id| s.doc().unwrap().doc.node(NodeId(id.as_u64().unwrap())).is_some()), "{r}");
let ids = f["ids"].as_array().unwrap();
assert!(!ids.is_empty(), "the finding names where the font is used: {r}");
assert!(ids.iter().all(|id| s.doc().unwrap().doc.node(NodeId(id.as_u64().unwrap())).is_some()), "{r}");
}
struct Folder(std::path::PathBuf);