mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-04 13:02:50 -05:00
Merge main into feat/scripts-export-autocad
This commit is contained in:
commit
d09d00fa25
278 files changed
+9496
-2128
No files matched your search
@@ -374,52 +374,6 @@ fn auto_height_in_columns_matches_the_full_search_when_lines_start_small() {
|
||||
}
|
||||
}
|
||||
|
||||
/// Time typing at the start of a story of 5,000, 20,000 and 50,000 characters in Auto Size area
|
||||
/// type in 2 and 3 columns: 20 letters typed one at a time with the Type tool, with Auto Size as it
|
||||
/// runs and with `FULL_SEARCH` on (the columns laid out at every step of the bisection).
|
||||
/// Run with `cargo test --release -p vectorcraft-engine --lib auto_height_in_columns_typing_timing -- --ignored --nocapture`.
|
||||
#[test]
|
||||
#[ignore = "manual timing probe; wall-clock performance depends on machine load"]
|
||||
fn auto_height_in_columns_typing_timing() {
|
||||
use crate::cmd::typecmd::{COLUMN_LAYOUTS, FULL_SEARCH};
|
||||
const WORDS: &str = "The quick brown fox jumps over the lazy dog and keeps running far beyond the first frame of this story. ";
|
||||
let v = ViewInfo::default();
|
||||
for n in [5_000, 20_000, 50_000] {
|
||||
let story = format!("{}\n", WORDS.repeat(6).trim_end()).repeat(n / 600 + 1)[..n].to_string();
|
||||
for cols in [2, 3] {
|
||||
let mut row = format!("{n} characters in {cols} columns:");
|
||||
for full in [false, true] {
|
||||
FULL_SEARCH.with(|c| c.set(full));
|
||||
let mut s = Session::new();
|
||||
s.execute("file.new", &json!({"width": 4400, "height": 1200})).unwrap();
|
||||
let area = json!({"width": 500, "height": 100, "fit": "autoHeight"});
|
||||
let id = s.execute("text.create", &json!({"x": 20, "y": 20, "size": 9, "text": story, "area": area})).unwrap()["id"].clone();
|
||||
s.execute("select.set", &json!({"ids": [id]})).unwrap();
|
||||
s.execute("text.areaOptions", &json!({"columns": cols, "gutter": 12})).unwrap();
|
||||
s.select_tool("type", v).unwrap();
|
||||
for kind in [PointerKind::Down, PointerKind::Up] {
|
||||
s.pointer(&PointerEvent::new(kind, 21.0, 24.0), v).unwrap();
|
||||
}
|
||||
let layouts = COLUMN_LAYOUTS.with(std::cell::Cell::get);
|
||||
let mut ms: Vec<f64> = "abcdefghijklmnopqrst"
|
||||
.chars()
|
||||
.map(|ch| {
|
||||
let start = std::time::Instant::now();
|
||||
s.tool_text(&ch.to_string(), v).unwrap();
|
||||
start.elapsed().as_secs_f64() * 1000.0
|
||||
})
|
||||
.collect();
|
||||
let per_key = (COLUMN_LAYOUTS.with(std::cell::Cell::get) - layouts) as f64 / ms.len() as f64;
|
||||
ms.sort_by(f64::total_cmp);
|
||||
let how = if full { "every step laid out" } else { "Auto Size" };
|
||||
row += &format!(" {how} {:.1} ms a keystroke ({per_key:.1} column layouts);", ms[ms.len() / 2]);
|
||||
}
|
||||
FULL_SEARCH.with(|c| c.set(false));
|
||||
println!("{row}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shrink_text_round_trips_through_the_native_format() {
|
||||
let mut s = session();
|
||||
|
||||
@@ -553,7 +553,7 @@ fn reset_bounding_box_squares_the_objects_inside_a_group() {
|
||||
// The group and both members, in one step.
|
||||
assert_eq!(s.execute("object.resetBoundingBox", &json!({})).unwrap()["changed"], 3);
|
||||
assert_eq!(undo_len(&s), n + 1);
|
||||
assert!(object_angles(&s).iter().all(|a| *a == 0.0), "{:?}", object_angles(&s));
|
||||
assert_eq!(object_angles(&s), [0.0; 3], "the group and both members");
|
||||
s.execute("object.ungroup", &json!({})).unwrap();
|
||||
assert_eq!(selection_box(&s).angle, 0.0);
|
||||
assert_eq!(s.execute("object.resetBoundingBox", &json!({})).unwrap()["changed"], 0);
|
||||
@@ -709,9 +709,11 @@ fn reset_bounding_box_squares_every_box_rotate_bounding_box_turned() {
|
||||
let art = (anchors(&s, a), anchors(&s, c));
|
||||
// The group, the masked object, its mask's art and the other rectangle.
|
||||
assert_eq!(s.execute("object.rotateBoundingBox", &json!({"angle": 25})).unwrap()["changed"], 4);
|
||||
assert!(object_angles(&s).iter().all(|x| near(*x, 25.0)), "{:?}", object_angles(&s));
|
||||
let turned = object_angles(&s);
|
||||
assert_eq!(turned.len(), 4, "{turned:?}");
|
||||
assert!(turned.iter().all(|x| near(*x, 25.0)), "{turned:?}");
|
||||
assert_eq!(s.execute("object.resetBoundingBox", &json!({})).unwrap()["changed"], 4);
|
||||
assert!(object_angles(&s).iter().all(|x| *x == 0.0), "{:?}", object_angles(&s));
|
||||
assert_eq!(object_angles(&s), [0.0; 4]);
|
||||
assert_eq!((anchors(&s, a), anchors(&s, c)), art);
|
||||
}
|
||||
|
||||
|
||||
@@ -1247,10 +1247,13 @@ fn pasted_brushed_art_brings_the_patterns_its_brush_art_uses() {
|
||||
run(&mut s, "brush.apply", json!({"name": "Dotted Band", "ids": [line]}));
|
||||
run(&mut s, "select.set", json!({"ids": [line]}));
|
||||
run(&mut s, "edit.copy", json!({}));
|
||||
let (brush, dots) = (vectorcraft_brush::find(doc(&s), "Dotted Band"), doc(&s).pattern("Dots").cloned());
|
||||
run(&mut s, "file.new", json!({"width": 200, "height": 200}));
|
||||
assert_eq!((vectorcraft_brush::find(doc(&s), "Dotted Band"), doc(&s).pattern("Dots")), (None, None), "a new document has neither");
|
||||
run(&mut s, "edit.paste", json!({}));
|
||||
assert!(vectorcraft_brush::find(doc(&s), "Dotted Band").is_some());
|
||||
assert!(doc(&s).pattern("Dots").is_some(), "the brush's art is filled with it");
|
||||
assert_eq!(vectorcraft_brush::find(doc(&s), "Dotted Band"), brush);
|
||||
assert_eq!(doc(&s).pattern("Dots").cloned(), dots, "the brush's art is filled with it");
|
||||
assert!(dots.is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -2533,6 +2533,9 @@ fn shape_builder_erase_click_or_drag_from_inside_a_narrow_overlap_deletes_it() {
|
||||
assert_eq!(r["edges"].as_u64(), Some(0), "{points}: {r}");
|
||||
let d = &s.doc().unwrap().doc;
|
||||
let left: Vec<f64> = d.children(d.default_layer()).unwrap().iter().filter_map(|c| c.geometric_bounds()).map(|b| b.width()).collect();
|
||||
let erased = r["regions"].as_u64().unwrap();
|
||||
assert!((1..=3).contains(&erased), "{points}: {r}");
|
||||
assert_eq!(left.len() as u64, 3 - erased, "{points}: the regions not erased stay: {left:?}");
|
||||
assert!(left.iter().all(|w| *w > 2.0), "{points}: no strip is left: {left:?}");
|
||||
}
|
||||
}
|
||||
@@ -4583,6 +4586,7 @@ fn live_paint_group_default_clears_the_faces_and_gives_the_edges_a_thin_black_st
|
||||
s.execute("paint.setStroke", &json!({"color": "#0000ff"})).unwrap();
|
||||
s.execute("paint.default", &json!({})).unwrap();
|
||||
let (faces, edges) = part_looks(&s, g);
|
||||
assert_eq!((faces.len(), edges.len() >= 4), (3, true), "{}", edges.len());
|
||||
assert!(faces.iter().all(|f| f.fill_paint().is_none() && f.stroke_paint().is_none()));
|
||||
assert!(edges.iter().all(|e| e.stroke_paint() == Paint::solid(Color::BLACK) && e.stroke_width() == 0.5 && e.fill_paint().is_none()));
|
||||
assert_eq!(sources_looks(&s, g), sources0);
|
||||
@@ -4627,6 +4631,7 @@ fn live_paint_group_invert_recolors_the_faces_fill() {
|
||||
let (_, edges0) = part_looks(&s, g);
|
||||
s.execute("paint.invert", &json!({"stroke": false})).unwrap();
|
||||
let (faces, edges) = part_looks(&s, g);
|
||||
assert_eq!((faces.len(), edges.len() >= 4), (3, true), "{}", edges.len());
|
||||
assert!(faces.iter().all(|f| f.fill_paint() == Paint::solid(Color::rgb(0.0, 1.0, 1.0))));
|
||||
assert_eq!(edges, edges0);
|
||||
assert_eq!(sources_looks(&s, g), sources0);
|
||||
@@ -4634,12 +4639,14 @@ fn live_paint_group_invert_recolors_the_faces_fill() {
|
||||
s.execute("paint.invert", &json!({"stroke": true, "target": "contents"})).unwrap();
|
||||
let (faces1, edges1) = part_looks(&s, g);
|
||||
assert_eq!(faces1, faces);
|
||||
assert_eq!(edges1.len(), edges.len());
|
||||
assert!(edges1.iter().all(|e| e.stroke_paint() == Paint::solid(Color::WHITE)));
|
||||
assert_eq!(sources_looks(&s, g), sources0);
|
||||
// A gradient edit of the fill goes to the faces only.
|
||||
s.execute("paint.setFill", &json!({"gradient": {}})).unwrap();
|
||||
s.execute("paint.editGradient", &json!({"stroke": false, "angle": 45})).unwrap();
|
||||
let (faces2, edges2) = part_looks(&s, g);
|
||||
assert_eq!(faces2.len(), 3);
|
||||
assert!(faces2.iter().all(|f| matches!(f.fill_paint(), Paint::Gradient(_))));
|
||||
assert_eq!(edges2, edges1, "edges take no fill gradient");
|
||||
assert_eq!(sources_looks(&s, g), sources0);
|
||||
@@ -4674,7 +4681,9 @@ fn live_paint_group_gradient_vector_and_freeform_edits_change_its_faces() {
|
||||
assert_eq!(sources_looks(&s, g), sources0);
|
||||
s.execute("paint.setFill", &json!({"gradient": {"kind": "freeform"}})).unwrap();
|
||||
s.execute("paint.freeform.addPoint", &json!({"stroke": false, "at": [25, 50], "color": "#00ff00"})).unwrap();
|
||||
assert!(part_looks(&s, g).0.iter().all(|f| matches!(f.fill_paint(), Paint::Gradient(gr) if gr.freeform.is_some())));
|
||||
let faces_now = part_looks(&s, g).0;
|
||||
assert_eq!(faces_now.len(), face_ids.len());
|
||||
assert!(faces_now.iter().all(|f| matches!(f.fill_paint(), Paint::Gradient(gr) if gr.freeform.is_some())));
|
||||
assert_eq!(part_looks(&s, g).1, edges0);
|
||||
assert_eq!(sources_looks(&s, g), sources0);
|
||||
}
|
||||
@@ -4944,16 +4953,19 @@ fn live_paint_group_contents_edits_follow_the_group_rule() {
|
||||
let sources0 = sources_looks(&s, g);
|
||||
s.execute("appearance.addFill", &json!({"target": "contents"})).unwrap();
|
||||
let (faces1, edges1) = part_looks(&s, g);
|
||||
assert_eq!((faces0.len(), faces1.len(), edges0.len() >= 4), (3, 3, true), "{}", edges0.len());
|
||||
assert!(faces1.iter().zip(&faces0).all(|(f, f0)| f.items.len() == f0.items.len() + 1), "every face takes a new fill");
|
||||
assert_eq!(edges1, edges0, "edges take no new fill");
|
||||
s.execute("appearance.addStroke", &json!({"target": "contents"})).unwrap();
|
||||
let (faces2, edges2) = part_looks(&s, g);
|
||||
assert_eq!(faces2, faces1, "faces take no new stroke");
|
||||
assert_eq!(edges2.len(), edges1.len());
|
||||
assert!(edges2.iter().zip(&edges1).all(|(e, e0)| e.items.len() == e0.items.len() + 1), "every edge takes a new stroke");
|
||||
// A stroke row edit of the contents reaches the edges, not the faces.
|
||||
s.execute("stroke.set", &json!({"target": "contents", "item": 0, "weight": 7})).unwrap();
|
||||
let (faces3, edges3) = part_looks(&s, g);
|
||||
assert_eq!(faces3, faces2, "faces keep their rows");
|
||||
assert_eq!(edges3.len(), edges2.len());
|
||||
assert!(edges3.iter().all(|e| e.stroke_at(Some(0)).map(|st| st.width) == Some(7.0)), "every edge's stroke row takes the weight");
|
||||
s.execute("appearance.clear", &json!({"target": "contents"})).unwrap();
|
||||
assert_eq!(sources_looks(&s, g), sources0, "the hidden source paths keep their appearance");
|
||||
@@ -5203,6 +5215,7 @@ fn live_paint_group_contents_take_a_graphic_style_by_kind() {
|
||||
s.execute("graphicStyle.apply", &json!({"name": "Both", "target": "contents", "add": add})).unwrap();
|
||||
assert!(parts_hold_their_kind(&s, g), "add {add}: faces hold fills and edges strokes");
|
||||
let (faces, edges) = part_looks(&s, g);
|
||||
assert_eq!((faces.len(), edges.len() >= 4), (3, true), "add {add}: {}", edges.len());
|
||||
assert!(faces.iter().all(|a| a.items.iter().any(|it| *it.paint() == red)), "add {add}: each face takes the style's fill");
|
||||
assert!(edges.iter().all(|a| a.items.iter().any(|it| *it.paint() == blue)), "add {add}: each edge takes the style's stroke");
|
||||
let n = node(&s, g);
|
||||
@@ -6199,6 +6212,7 @@ fn live_paint_bucket_edge_double_click_after_filling_a_face_paints_the_joined_ed
|
||||
let black = Paint::solid(Color::rgb(0.0, 0.0, 0.0));
|
||||
let green = Paint::solid(Color::from_hex("#00ff00").unwrap());
|
||||
let all = edges_in(&s, g, Rect::new(-1.0, -1.0, 101.0, 51.0));
|
||||
assert!(all.len() >= 3, "the outline and the shared edge: {all:?}");
|
||||
paint_parts(&mut s, &all, &black, &[(a, black.clone()), (b, black.clone())]);
|
||||
let v = ViewInfo::default();
|
||||
s.select_tool("livePaintBucket", v).unwrap();
|
||||
@@ -9217,16 +9231,23 @@ fn image_trace_refuses_an_unknown_setting() {
|
||||
}
|
||||
}
|
||||
|
||||
/// Every preset's settings, as imageTrace.presets lists them, trace when passed back whole.
|
||||
/// A preset's settings, as imageTrace.presets lists them, trace when passed back whole, and the
|
||||
/// trace keeps them: a preset with an enhanced version, both ways, and a preset without one.
|
||||
#[test]
|
||||
fn image_trace_takes_every_preset_back_as_params() {
|
||||
fn image_trace_takes_a_preset_back_as_params() {
|
||||
let list = session().execute("imageTrace.presets", &json!({})).unwrap();
|
||||
for preset in list["presets"].as_array().unwrap() {
|
||||
for params in [&preset["params"], &preset["enhanced"]].into_iter().filter(|p| !p.is_null()) {
|
||||
let mut s = session();
|
||||
image_doc(&mut s);
|
||||
let r = s.execute("imageTrace.make", &json!({"preset": preset["name"], "params": params}));
|
||||
assert!(r.is_ok(), "{}: {r:?}", preset["name"]);
|
||||
let preset = |name: &str| list["presets"].as_array().unwrap().iter().find(|p| p["name"] == name).unwrap().clone();
|
||||
let (six, flat) = (preset("6 Colors"), preset("Flat Logo"));
|
||||
for (name, params) in [("6 Colors", &six["params"]), ("6 Colors", &six["enhanced"]), ("Flat Logo", &flat["params"])] {
|
||||
let mut s = session();
|
||||
image_doc(&mut s);
|
||||
let r = s.execute("imageTrace.make", &json!({"preset": name, "params": params})).unwrap();
|
||||
let stored = node(&s, NodeId(r["id"].as_u64().unwrap())).extras().trace.clone().unwrap();
|
||||
assert_eq!(stored["preset"], name);
|
||||
let given = params.as_object().unwrap();
|
||||
assert!(given.len() > 1, "{name}: {params}");
|
||||
for (key, value) in given {
|
||||
assert_eq!(&stored["params"][key], value, "{name}: `{key}` is kept");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,5 +87,10 @@ fn nothing_is_cancelled_outside_a_scope() {
|
||||
token.cancel();
|
||||
// The token only counts for work run under it, on its thread.
|
||||
let mut s = session(1);
|
||||
assert!(s.execute("document.exportPdf", &json!({})).is_ok());
|
||||
let r = cancel::scope(&token, None, || s.execute("document.exportPdf", &json!({})));
|
||||
assert!(matches!(r, Err(EngineError::Cancelled)), "under the token: {r:?}");
|
||||
let r = s.execute("document.exportPdf", &json!({})).unwrap();
|
||||
let bytes = vectorcraft_format::base64_decode(r["dataBase64"].as_str().unwrap()).unwrap();
|
||||
assert!(bytes.starts_with(b"%PDF-"), "outside it the whole file is written");
|
||||
assert!(bytes.ends_with(b"%%EOF"), "to its end");
|
||||
}
|
||||
@@ -155,5 +155,7 @@ fn type_as_a_clipping_path_paints_its_characters() {
|
||||
let p = paint(&s);
|
||||
assert!(p.stroke.is_none());
|
||||
let NodeKind::Text(fill) = &p.fill.expect("the characters' fill paints").kind else { panic!("type") };
|
||||
assert!(fill.runs.iter().all(|r| r.style.fill.color().is_some() && r.style.stroke.is_none()));
|
||||
assert_eq!(fill.plain_text(), "Clip");
|
||||
let blue = vectorcraft_color::Color::from_hex("#0000ff");
|
||||
assert!(!fill.runs.is_empty() && fill.runs.iter().all(|r| r.style.fill.color() == blue && r.style.stroke.is_none()), "{:?}", fill.runs);
|
||||
}
|
||||
@@ -1160,9 +1160,10 @@ fn a_blend_mode_over_art_of_several_colors_has_no_one_answer() {
|
||||
assert!((ratio(&r) - 21.0).abs() < 1e-3, "white minus white is black: {r}");
|
||||
}
|
||||
|
||||
/// A Difference square over a white square in a 50 % group that isolates its blending, over the
|
||||
/// edge between black and white art: the square blends only with the white inside the group, so
|
||||
/// A Difference square over a 50 % white square in a 50 % group that isolates its blending, over
|
||||
/// the edge between black and white art: the square blends only with the white inside the group, so
|
||||
/// the art of two colors outside it, which the group draws over in Normal mode, leaves one answer.
|
||||
/// Without isolation the blend also reaches that art, and there is no one answer.
|
||||
#[test]
|
||||
fn a_blend_mode_inside_an_isolating_group_answers_over_art_of_several_colors() {
|
||||
let mut s = session();
|
||||
@@ -1177,14 +1178,33 @@ fn a_blend_mode_inside_an_isolating_group_answers_over_art_of_several_colors() {
|
||||
let back = id(s.execute("shape.rectangle", &json!({"x": 60, "y": 60, "width": 80, "height": 80})).unwrap());
|
||||
s.execute("paint.setFill", &json!({"color": "#ffffff"})).unwrap();
|
||||
s.execute("paint.setStroke", &json!({"none": true})).unwrap();
|
||||
// Translucent, so that a blend that is not isolated also reaches the art behind the group.
|
||||
s.execute("transparency.set", &json!({"opacity": 50})).unwrap();
|
||||
let square = id(s.execute("shape.rectangle", &json!({"x": 70, "y": 70, "width": 60, "height": 60})).unwrap());
|
||||
s.execute("paint.setStroke", &json!({"none": true})).unwrap();
|
||||
s.execute("paint.setFill", &json!({"color": "#ffffff"})).unwrap();
|
||||
s.execute("transparency.set", &json!({"blend": "difference"})).unwrap();
|
||||
s.execute("object.group", &json!({"ids": [back, square]})).unwrap();
|
||||
let group = id(s.execute("object.group", &json!({"ids": [back, square]})).unwrap());
|
||||
s.execute("transparency.set", &json!({"opacity": 50, "isolate": true})).unwrap();
|
||||
s.execute("select.set", &json!({"ids": [square]})).unwrap();
|
||||
s.execute("color.contrast", &json!({})).unwrap();
|
||||
let r = s.execute("color.contrast", &json!({})).unwrap();
|
||||
let isolated = ratio(&r);
|
||||
assert!(isolated > 1.0, "{r}");
|
||||
assert!(r["against"].as_str().is_some_and(|h| vectorcraft_color::Color::from_hex(h).is_some()), "{r}");
|
||||
// Without isolation the square also blends with the black and white art, so there is no one answer.
|
||||
let set_isolate = |s: &mut Session, on: bool| {
|
||||
s.execute("select.set", &json!({"ids": [group]})).unwrap();
|
||||
s.execute("transparency.set", &json!({"isolate": on})).unwrap();
|
||||
s.execute("select.set", &json!({"ids": [square]})).unwrap();
|
||||
};
|
||||
set_isolate(&mut s, false);
|
||||
let e = s.execute("color.contrast", &json!({})).unwrap_err().to_string();
|
||||
assert!(e.contains("is not one color where it is read"), "{e}");
|
||||
set_isolate(&mut s, true);
|
||||
// The Difference mode is applied: in Normal mode the same square gives another answer.
|
||||
s.execute("transparency.set", &json!({"blend": "normal"})).unwrap();
|
||||
let normal = ratio(&s.execute("color.contrast", &json!({})).unwrap());
|
||||
assert!((isolated - normal).abs() > 0.1, "difference {isolated} against normal {normal}");
|
||||
}
|
||||
|
||||
/// With a fill of None, what a pick would be measured against is still read: the Color Wheel's
|
||||
|
||||
@@ -739,7 +739,9 @@ fn separations_preview_compares_the_visible_plates_as_a_set() {
|
||||
assert_eq!(sep(&mut s, json!({"plates": ["Cyan", "Magenta", "Yellow", "Black"]})), all, "every plate in plate order");
|
||||
sep(&mut s, json!({"plates": ["Cyan", "Cyan"]}));
|
||||
let r = s.execute("view.separationsPreview", &json!({"toggle": "Cyan"})).unwrap();
|
||||
assert!(r["plates"].as_array().unwrap().iter().all(|p| p["visible"] == false), "{r}");
|
||||
let plates = r["plates"].as_array().unwrap();
|
||||
assert_eq!(plates.len(), 4, "{r}");
|
||||
assert!(plates.iter().all(|p| p["visible"] == false), "{r}");
|
||||
}
|
||||
|
||||
/// Each plate's visibility in a `view.separationsPreview` or `color.plates` reply, in plate order.
|
||||
|
||||
@@ -345,7 +345,9 @@ fn constrain_angle_turns_the_new_objects_bounding_box() {
|
||||
let id =
|
||||
NodeId(s.execute("shape.polarGrid", &json!({"x": 0, "y": 0, "width": 40, "height": 20, "rotation": -30})).unwrap()["id"].as_u64().unwrap());
|
||||
let n = s.doc().unwrap().doc.node(id).unwrap().clone();
|
||||
assert!(n.children().unwrap().iter().all(|c| close(c.bbox_angle, 30.0)));
|
||||
let lines = n.children().unwrap();
|
||||
assert!(lines.len() > 1, "{}", lines.len());
|
||||
assert!(lines.iter().all(|c| close(c.bbox_angle, 30.0)));
|
||||
s.execute("text.create", &json!({"x": 10, "y": 20, "text": "Hi", "rotation": -30})).unwrap();
|
||||
assert!(close(selection_rotation(&s), 30.0));
|
||||
s.execute("text.create", &json!({"x": 10, "y": 20, "text": "Hi"})).unwrap();
|
||||
|
||||
@@ -1350,7 +1350,9 @@ fn a_stroke_on_a_picked_type_object_without_a_weight_draws() {
|
||||
s.execute("paint.setStroke", &json!({"color": "#ff0000"})).unwrap();
|
||||
let part = s.doc().unwrap().selected_symbol_part().unwrap();
|
||||
let NodeKind::Text(tx) = &part.kind else { panic!("type: {part:?}") };
|
||||
assert!(tx.runs.iter().all(|r| r.style.stroke_width == 1.0 && !r.style.stroke.is_none()), "{:?}", tx.runs);
|
||||
assert_eq!(tx.plain_text(), "Hi");
|
||||
let red = Paint::solid(vectorcraft_color::Color::from_hex("#ff0000").unwrap());
|
||||
assert!(!tx.runs.is_empty() && tx.runs.iter().all(|r| r.style.stroke_width == 1.0 && r.style.stroke == red), "{:?}", tx.runs);
|
||||
}
|
||||
|
||||
/// The colors the Fill and Stroke proxies show, as `paint.proxies` replies them.
|
||||
|
||||
@@ -417,6 +417,7 @@ fn a_search_skips_font_files_too_large_to_add() {
|
||||
/// A suitcase font: a file without an extension or with `.suit`, empty but for the fonts in its
|
||||
/// resource fork, which only macOS keeps. A search finds it, and Add Fonts copies it with its fork.
|
||||
#[cfg(target_os = "macos")]
|
||||
// test-lint: allow never-run macOS only; CI runs tests on Linux and FreeBSD
|
||||
#[test]
|
||||
fn suitcase_fonts_are_found_and_copied_with_their_fork() {
|
||||
use vectorcraft_testkit::fonts::{renamed, suitcase_fork};
|
||||
|
||||
@@ -115,7 +115,9 @@ fn cmyk_stops_recolor_the_points_with_inks() {
|
||||
let id = shape(&mut s, "shape.rectangle", 100.0, 100.0, 100.0, 100.0);
|
||||
run(&mut s, "paint.setFill", json!({"gradient": {"kind": "linear", "stops": cyan_to_black}}));
|
||||
run(&mut s, "paint.editGradient", json!({"kind": "freeform"}));
|
||||
assert!(points(&s, id).points.iter().all(|p| cyan_and_black(p.color)), "{:?}", points(&s, id).points);
|
||||
let placed = points(&s, id).points;
|
||||
assert!(!placed.is_empty());
|
||||
assert!(placed.iter().all(|p| cyan_and_black(p.color)), "{placed:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -181,6 +183,7 @@ fn reapplied_gradients_place_their_points_afresh() {
|
||||
let other = shape(&mut s, "shape.rectangle", 400.0, 300.0, 100.0, 100.0);
|
||||
run(&mut s, "paint.lastGradient", json!({}));
|
||||
let (a, (b, _)) = (points(&s, id), node(&s, other).proxy_freeform(false, None).unwrap());
|
||||
assert!(!a.points.is_empty() && b.points.len() == a.points.len(), "{:?}", b.points);
|
||||
assert!(b.points.iter().all(|p| p.at.x >= 400.0 && p.at.y >= 300.0), "{:?}", b.points);
|
||||
assert_eq!(a.points.iter().map(|p| p.color.to_hex()).collect::<Vec<_>>(), b.points.iter().map(|p| p.color.to_hex()).collect::<Vec<_>>());
|
||||
}
|
||||
|
||||
@@ -38,8 +38,11 @@ fn new_gradient_defaults_follow_the_cmyk_document_mode() {
|
||||
let id = rect(&mut s, 10.0, 10.0, 100.0, 100.0);
|
||||
s.execute("paint.editGradient", &json!({"kind":kind})).unwrap();
|
||||
let g = fill_gradient(&s, id);
|
||||
assert!(g.gradient.stops.len() >= 2, "{kind}: {:?}", g.gradient.stops);
|
||||
assert!(g.gradient.stops.iter().all(|stop| matches!(stop.color, Color::Cmyk { .. })), "{kind}: {:?}", g.gradient.stops);
|
||||
assert_eq!(g.freeform.is_some(), kind == "freeform", "{kind}");
|
||||
if let Some(freeform) = g.freeform {
|
||||
assert!(!freeform.points.is_empty());
|
||||
assert!(freeform.points.iter().all(|point| matches!(point.color, Color::Cmyk { .. })), "freeform points must use the same color model");
|
||||
}
|
||||
}
|
||||
@@ -52,6 +55,7 @@ fn editing_an_explicit_rgb_gradient_in_cmyk_keeps_its_color_model() {
|
||||
let id = rect(&mut s, 10.0, 10.0, 100.0, 100.0);
|
||||
s.execute("paint.editGradient", &json!({"kind":"linear","keepModel":true})).unwrap();
|
||||
let before = fill_gradient(&s, id).gradient.stops;
|
||||
assert_eq!(before.len(), 2, "{before:?}");
|
||||
assert!(before.iter().all(|stop| matches!(stop.color, Color::Rgb { .. })));
|
||||
s.execute("paint.editGradient", &json!({"angle":45})).unwrap();
|
||||
assert_eq!(fill_gradient(&s, id).gradient.stops, before);
|
||||
@@ -67,6 +71,7 @@ fn drawing_a_new_gradient_vector_uses_cmyk_default_stops() {
|
||||
let appearance = &node(&s, id).appearance;
|
||||
let paint = if stroke { appearance.stroke_paint() } else { appearance.fill_paint() };
|
||||
let Paint::Gradient(g) = paint else { panic!("not a gradient") };
|
||||
assert_eq!(g.gradient.stops.len(), 2, "stroke={stroke}: {:?}", g.gradient.stops);
|
||||
assert!(g.gradient.stops.iter().all(|stop| matches!(stop.color, Color::Cmyk { .. })), "stroke={stroke}: {:?}", g.gradient.stops);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,10 +25,15 @@ fn ids_stand_in_for_the_selection() {
|
||||
("object.makePixelPerfect", json!({})),
|
||||
] {
|
||||
let (mut s, id) = doc_with_rect();
|
||||
assert!(s.execute(cmd, ¶ms).is_err(), "{cmd}: nothing selected and no ids");
|
||||
let (before, undo) = (s.doc().unwrap().doc.clone(), s.doc().unwrap().history.undo.len());
|
||||
let mut p = params;
|
||||
p["ids"] = json!([id]);
|
||||
let r = s.execute(cmd, &p);
|
||||
assert!(r.is_ok(), "{cmd}: {r:?}");
|
||||
let st = s.doc().unwrap();
|
||||
assert_ne!(st.doc, before, "{cmd}: the object given is changed");
|
||||
assert_eq!(st.history.undo.len(), undo + 1, "{cmd}: one undo step");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -174,10 +174,10 @@ fn guides_align_to_a_key_object_among_others_and_parallel_ones_to_a_key_guide()
|
||||
s.execute("select.key", &json!({"id": b.0})).unwrap();
|
||||
s.execute("object.align", &json!({"horizontal": "left"})).unwrap();
|
||||
assert_eq!(bounds(&s, a).x0, 300.0);
|
||||
assert!(positions(&s).iter().all(|p| *p == 300.0));
|
||||
assert_eq!(positions(&s), [300.0, 300.0], "both guides");
|
||||
// Aligning to the selection leaves guides alone.
|
||||
s.execute("object.align", &json!({"horizontal": "right", "to": "selection"})).unwrap();
|
||||
assert!(positions(&s).iter().all(|p| *p == 300.0));
|
||||
assert_eq!(positions(&s), [300.0, 300.0]);
|
||||
// A key guide stays put, and the other vertical guide lines up on it.
|
||||
s.execute("guide.move", &json!({"index": 1, "pos": 700})).unwrap();
|
||||
s.execute("select.key", &json!({"guide": 1})).unwrap();
|
||||
|
||||
@@ -189,6 +189,7 @@ fn a_path_on_a_mapped_drive_is_on_the_share_behind_it() {
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
// test-lint: allow never-run Windows only; CI runs tests on Linux and FreeBSD
|
||||
#[test]
|
||||
fn links_on_a_mapped_drives_share_are_followed() {
|
||||
use crate::cmd::fileio::{document_path_with, share_of};
|
||||
@@ -208,6 +209,7 @@ fn links_on_a_mapped_drives_share_are_followed() {
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
// test-lint: allow never-run Windows only; CI runs tests on Linux and FreeBSD
|
||||
#[test]
|
||||
fn links_on_a_drive_mapped_to_another_share_are_not_followed() {
|
||||
use crate::cmd::fileio::{document_path_on, drive_share_of, share_of};
|
||||
@@ -228,6 +230,7 @@ fn links_on_a_drive_mapped_to_another_share_are_not_followed() {
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
// test-lint: allow never-run Windows only; CI runs tests on Linux and FreeBSD
|
||||
#[test]
|
||||
fn links_on_the_documents_share_or_this_computer_are_followed() {
|
||||
use crate::cmd::fileio::{document_path_on, drive_share_of, share_of};
|
||||
|
||||
@@ -4113,7 +4113,8 @@ fn smart_punctuation_with_nothing_to_change_records_no_undo_step() {
|
||||
let before = history(&s);
|
||||
let r = s.execute("type.smartPunctuation", &json!({})).unwrap();
|
||||
assert_eq!(r["changed"], 0, "{id:?}");
|
||||
assert!(r["replaced"].as_object().unwrap().values().all(|n| n == 0), "{id:?}: {r}");
|
||||
let none = json!({"fiLigatures": 0, "flLigatures": 0, "quotes": 0, "spaces": 0, "dashes": 0, "ellipses": 0, "fractions": 0});
|
||||
assert_eq!(r["replaced"], none, "{id:?}: {r}");
|
||||
assert_eq!(history(&s), before, "{id:?}");
|
||||
}
|
||||
assert_eq!(plain(&s, t), "“Hi” it’s 1–2 and 3—4…");
|
||||
|
||||
@@ -269,7 +269,8 @@ fn overprint_black_covers_type_gradients_spots_and_groups() {
|
||||
|
||||
s.execute("edit.colors.overprintBlack", &json!({})).unwrap();
|
||||
let NodeKind::Text(tx) = &node(&s, t).kind else { panic!() };
|
||||
assert!(tx.runs.iter().all(|r| r.style.overprint_fill), "type characters, inside the selected group");
|
||||
assert_eq!(tx.plain_text(), "Hi");
|
||||
assert!(!tx.runs.is_empty() && tx.runs.iter().all(|r| r.style.overprint_fill), "type characters, inside the selected group");
|
||||
let fill = |s: &Session, id| node(s, id).appearance.fill().unwrap().overprint;
|
||||
assert!(!fill(&s, g), "a gradient with a rich-black stop");
|
||||
assert!(!fill(&s, spot), "spot blacks need includeSpotBlacks");
|
||||
|
||||
@@ -78,7 +78,9 @@ fn two_links_and_a_font_are_collected_and_relinked() {
|
||||
s.doc().unwrap().doc.visit_images(|_, im| paths.push(im.link.clone().unwrap()));
|
||||
paths
|
||||
};
|
||||
assert!(link(&s).iter().all(|l| l.path.contains("art")));
|
||||
let links = link(&s);
|
||||
assert_eq!(links.len(), 2, "{links:?}");
|
||||
assert!(links.iter().all(|l| l.path.contains("art")), "{links:?}");
|
||||
// The packaged one opens with the copies, even with the originals gone.
|
||||
std::fs::remove_dir_all(dir.0.join("art")).unwrap();
|
||||
let r = open(&mut s, &root.join("poster.vectorcraft").to_string_lossy());
|
||||
|
||||
@@ -1794,12 +1794,16 @@ fn commands_reject_bad_input() {
|
||||
("object.path.offsetPath", json!({"offset": "abc"})),
|
||||
("object.path.offsetPath", json!({"offset": 1e300})),
|
||||
("object.path.simplify", json!({"tolerance": -5})),
|
||||
("object.path.simplify", json!({"level": 101})),
|
||||
("object.path.splitIntoGrid", json!({"rows": 1e9, "columns": -1})),
|
||||
("text.setStyle", json!({"size": -3})),
|
||||
("type.createOutlines", json!({})),
|
||||
("object.pathfinder.divide", json!({"junk": [1, 2]})),
|
||||
] {
|
||||
let _ = s.execute(c, &p);
|
||||
let (before, undo) = (s.doc().unwrap().doc.clone(), s.doc().unwrap().history.undo.len());
|
||||
let r = s.execute(c, &p);
|
||||
assert!(r.is_err(), "{c} {p}: {r:?}");
|
||||
assert_eq!((&s.doc().unwrap().doc, s.doc().unwrap().history.undo.len()), (&before, undo), "{c} {p}: nothing changes");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1087,13 +1087,17 @@ fn delete_and_rename_reach_a_graphs_stored_paints() {
|
||||
let mut s = session();
|
||||
make_dots(&mut s);
|
||||
let g = graph_painted_with(&mut s, "Dots");
|
||||
assert_eq!(stored_graph_paints(&s, g).len(), 4, "the series fill and stroke and the value labels' fill and stroke");
|
||||
s.execute("pattern.options", &json!({"name": "Dots", "newName": "Spots"})).unwrap();
|
||||
assert!(stored_graph_paints(&s, g).iter().all(|p| is_pattern(p, "Spots")), "the rename reaches the graph");
|
||||
let renamed = stored_graph_paints(&s, g);
|
||||
assert!(renamed.len() == 4 && renamed.iter().all(|p| is_pattern(p, "Spots")), "the rename reaches the graph: {renamed:?}");
|
||||
s.execute("edit.undo", &json!({})).unwrap();
|
||||
assert!(stored_graph_paints(&s, g).iter().all(|p| is_pattern(p, "Dots")));
|
||||
let back = stored_graph_paints(&s, g);
|
||||
assert!(back.len() == 4 && back.iter().all(|p| is_pattern(p, "Dots")), "{back:?}");
|
||||
let v = s.execute("pattern.delete", &json!({"name": "Dots"})).unwrap();
|
||||
assert_eq!(v["unpainted"], 4, "the series fill and stroke and the value labels' fill and stroke");
|
||||
assert!(stored_graph_paints(&s, g).iter().all(Paint::is_none));
|
||||
let cleared = stored_graph_paints(&s, g);
|
||||
assert!(cleared.len() == 4 && cleared.iter().all(Paint::is_none), "{cleared:?}");
|
||||
s.execute("graph.setData", &json!({"id": g.0, "rows": [[2], [4]]})).unwrap();
|
||||
assert_eq!(pattern_uses(doc(&s), "Dots"), 0, "the redrawn graph holds no paint of the deleted pattern");
|
||||
}
|
||||
|
||||
@@ -496,12 +496,14 @@ fn snap_to_grid_lands_drawn_and_moved_art_on_gridlines() {
|
||||
let n = s.doc().unwrap().doc.node(id).unwrap().path_data().unwrap().clone();
|
||||
n.anchors().map(|(_, _, an)| g.to_plane(Plane::Left, an.p).unwrap()).collect()
|
||||
};
|
||||
assert!(corners(&s).iter().all(|q| on_line(q.x) && on_line(q.y)), "{:?}", corners(&s));
|
||||
let drawn = corners(&s);
|
||||
assert!(drawn.len() == 4 && drawn.iter().all(|q| on_line(q.x) && on_line(q.y)), "{drawn:?}");
|
||||
// Moved a cell and a bit: it lands a whole cell over.
|
||||
let from = g.to_page(Plane::Left, Point::new(3.0 * g.cell, 2.0 * g.cell)).unwrap();
|
||||
let to = g.to_page(Plane::Left, Point::new(4.0 * g.cell + 2.0, 2.0 * g.cell)).unwrap();
|
||||
run(&mut s, "perspective.move", json!({"ids": [id.0], "from": [from.x, from.y], "to": [to.x, to.y]}));
|
||||
assert!(corners(&s).iter().all(|q| on_line(q.x) && on_line(q.y)), "{:?}", corners(&s));
|
||||
let moved = corners(&s);
|
||||
assert!(moved.len() == 4 && moved.iter().all(|q| on_line(q.x) && on_line(q.y)), "{moved:?}");
|
||||
// Without snapping it moves exactly.
|
||||
let before = corners(&s);
|
||||
run(&mut s, "perspective.move", json!({"ids": [id.0], "from": [from.x, from.y], "to": [to.x, to.y], "snap": false}));
|
||||
|
||||
@@ -205,6 +205,7 @@ fn stroke_edits_keep_it_aligned() {
|
||||
assert!(whole(&points(&s, id)), "{:?}", points(&s, id));
|
||||
s.execute("stroke.set", &json!({"weight": 3})).unwrap();
|
||||
let pts = points(&s, id);
|
||||
assert_eq!(pts.len(), 4, "{pts:?}");
|
||||
assert!(pts.iter().all(|(x, y)| (x - x.floor() - 0.5).abs() < 1e-9 && (y - y.floor() - 0.5).abs() < 1e-9), "{pts:?}");
|
||||
// Inside alignment puts the stroke within the path, so the anchors go back to whole points.
|
||||
s.execute("stroke.set", &json!({"align": "inside"})).unwrap();
|
||||
@@ -763,8 +764,10 @@ fn objects_on_path_members_stay_on_the_grid() {
|
||||
// Editing the path places the member again, and it goes back on the grid.
|
||||
let anchors = json!([{"x": 0.6, "y": 120.7}, {"x": 300.6, "y": 120.7}]);
|
||||
s.execute("path.setAnchors", &json!({"id": spine, "subpaths": [{"anchors": anchors, "closed": false}]})).unwrap();
|
||||
assert!(whole(&points(&s, a)), "path edited: {:?}", points(&s, a));
|
||||
assert!(points(&s, a).iter().all(|(_, y)| *y > 105.0), "followed the path: {:?}", points(&s, a));
|
||||
let placed = points(&s, a);
|
||||
assert_eq!(placed.len(), 4, "{placed:?}");
|
||||
assert!(whole(&placed), "path edited: {placed:?}");
|
||||
assert!(placed.iter().all(|(_, y)| *y > 105.0), "followed the path: {placed:?}");
|
||||
}
|
||||
|
||||
fn align_new(s: &Session) -> bool {
|
||||
@@ -1465,6 +1468,7 @@ fn an_instance_snapped_to_the_grid_moves_its_linked_mask() {
|
||||
assert!(whole(&[(e, f)]) && (e, f) != (e0, f0), "{e} {f}");
|
||||
let moved: Vec<_> = mask_before.iter().map(|(x, y)| (x + e - e0, y + f - f0)).collect();
|
||||
let after = mask_points(&s, linked);
|
||||
assert!(!moved.is_empty() && after.len() == moved.len(), "{after:?} != {moved:?}");
|
||||
assert!(moved.iter().zip(&after).all(|(a, b)| close(*a, *b)), "{after:?} != {moved:?}");
|
||||
assert!(whole(&placed_points(&s, unlinked)));
|
||||
assert_eq!(mask_points(&s, unlinked), unlinked_before);
|
||||
|
||||
@@ -1916,19 +1916,6 @@ fn refresh_takes_objects_in_definition_art() {
|
||||
assert_eq!(listed(&mut s), [kept.0]);
|
||||
}
|
||||
|
||||
/// `CRAFT_PLUGIN_PAINTS_WASM=<folder>` saves a test live effect to try in the app
|
||||
/// (`stroke-width-test-effect.wasm`): it draws a triangle over the area 100,80–300,230 while its
|
||||
/// object's stroke is 5 pt wide, and hands the geometry back otherwise.
|
||||
#[test]
|
||||
fn stroke_width_test_effect() {
|
||||
let Some(dir) = std::env::var_os("CRAFT_PLUGIN_PAINTS_WASM") else { return };
|
||||
let triangle = PathData::single(SubPath::polyline(&[Point::new(100.0, 230.0), Point::new(300.0, 230.0), Point::new(200.0, 80.0)], true));
|
||||
let manifest = r#"{"id":"org.example.strokewidth","name":"Stroke Width (test plug-in)","version":"1","kind":"effect",
|
||||
"description":"Draws a triangle while the object's stroke is 5 pt wide.","params":{}}"#;
|
||||
let src = tpl::when_given(manifest, tpl::Given::Input, r#""width":5.0"#, &json!({"objects": [{"path": triangle}]}).to_string());
|
||||
std::fs::write(std::path::Path::new(&dir).join("stroke-width-test-effect.wasm"), wat::parse_str(src).unwrap()).unwrap();
|
||||
}
|
||||
|
||||
/// A filter is given its objects' effect records and their strokes' join, cap and miter limit, and
|
||||
/// may return them. The records are admitted as effect.apply would admit them; one that isn't
|
||||
/// refuses the whole output, and nothing changes.
|
||||
@@ -1978,26 +1965,6 @@ fn filters_set_effects_and_stroke_styles() {
|
||||
}
|
||||
}
|
||||
|
||||
/// `CRAFT_PLUGIN_FRAME_WASM=<folder>` saves a test filter to try in the app
|
||||
/// (`rough-frame-test-filter.wasm`): it adds a frame around 60,40–340,260 with a 6 pt stroke with
|
||||
/// round joins and caps, roughened by the Roughen effect.
|
||||
#[test]
|
||||
fn rough_frame_test_filter() {
|
||||
let Some(dir) = std::env::var_os("CRAFT_PLUGIN_FRAME_WASM") else { return };
|
||||
let frame = PathData::single(SubPath::polyline(
|
||||
&[Point::new(60.0, 40.0), Point::new(340.0, 40.0), Point::new(340.0, 260.0), Point::new(60.0, 260.0)],
|
||||
true,
|
||||
));
|
||||
let ink = json!({"type": "solid", "color": {"model": "rgb", "r": 0.15, "g": 0.2, "b": 0.45}});
|
||||
let out = json!({"objects": [{"name": "Frame", "path": frame, "fills": [],
|
||||
"strokes": [{"paint": ink, "width": 6, "join": "round", "cap": "round"}],
|
||||
"effects": [{"id": "distort.roughen", "params": {"size": 2, "detail": 8, "points": "smooth"}}]}]});
|
||||
let manifest = r#"{"id":"org.example.frame","name":"Rough Frame (test plug-in)","version":"1","kind":"filter",
|
||||
"description":"Adds a frame whose stroke is roughened by the Roughen effect.","params":{}}"#;
|
||||
let src = tpl::returning(manifest, &out.to_string());
|
||||
std::fs::write(std::path::Path::new(&dir).join("rough-frame-test-filter.wasm"), wat::parse_str(src).unwrap()).unwrap();
|
||||
}
|
||||
|
||||
/// A filter keeps data with the document: it writes it with `documentData` in the same undo step as
|
||||
/// its objects (`null` removes it) and reads what it last wrote in `_context.documentData`, which
|
||||
/// no other filter is given. It is the document's foreign data, so the native file keeps it with
|
||||
@@ -2177,11 +2144,13 @@ fn plugins_folder_set_again_after_clearing_installs_its_plugins() {
|
||||
let mut s = session();
|
||||
let folder = json!({"key": "pluginsFolder", "value": dir.0.display().to_string()});
|
||||
run(&mut s, "prefs.set", folder.clone());
|
||||
assert!(vectorcraft_plugins::registry::get(id).is_some(), "installed from the folder");
|
||||
assert_eq!(run(&mut s, "plugin.list", json!({}))["folder"]["loaded"], json!([id]), "installed from the folder");
|
||||
run(&mut s, "plugin.remove", json!({"id": id}));
|
||||
assert!(vectorcraft_plugins::registry::get(id).is_none());
|
||||
run(&mut s, "prefs.set", json!({"key": "pluginsFolder", "value": ""}));
|
||||
assert_eq!(run(&mut s, "plugin.list", json!({}))["folder"]["loaded"], json!(null), "a cleared folder loads nothing");
|
||||
run(&mut s, "prefs.set", folder);
|
||||
assert!(vectorcraft_plugins::registry::get(id).is_some(), "installed again when the folder is set again");
|
||||
assert_eq!(run(&mut s, "plugin.list", json!({}))["folder"]["loaded"], json!([id]), "installed again when the folder is set again");
|
||||
run(&mut s, "plugin.remove", json!({"id": id}));
|
||||
}
|
||||
|
||||
@@ -4110,6 +4079,7 @@ fn a_removal_deletes_only_folders_it_marked() {
|
||||
/// Windows keeps a file another program holds open without delete sharing, so the last grant can't
|
||||
/// be removed by deleting `grants.json`.
|
||||
#[cfg(windows)]
|
||||
// test-lint: allow never-run Windows only; CI runs tests on Linux and FreeBSD
|
||||
#[test]
|
||||
fn a_grants_file_that_cannot_be_deleted_keeps_the_stored_module() {
|
||||
use std::os::windows::fs::OpenOptionsExt;
|
||||
|
||||
@@ -99,6 +99,7 @@ fn a_white_background_makes_effect_images_opaque() {
|
||||
assert_eq!(clear.get_pixel(0, 0)[3], 0, "transparent by default");
|
||||
s.execute(C, &json!({"background": "white"})).unwrap();
|
||||
let white = effect_image(&s.doc().unwrap().doc);
|
||||
assert_eq!(white.dimensions(), clear.dimensions(), "the same image, on white");
|
||||
assert!(white.pixels().all(|p| p[3] == 255), "every pixel is opaque");
|
||||
assert_eq!(white.get_pixel(0, 0).0, [255, 255, 255, 255]);
|
||||
// With a clipping mask, the white stays under the art only.
|
||||
|
||||
@@ -250,7 +250,8 @@ fn used_colors_give_no_swatch_for_a_stop_that_mixes_its_ink_with_process_inks()
|
||||
assert_eq!(entry("cmyk 0 50 30 0")["swatch"], "Ink", "{r}");
|
||||
// recolor.colors keeps the swatch it lists.
|
||||
let listed = run(&mut s, "recolor.colors", json!({}));
|
||||
assert!(listed["colors"].as_array().unwrap().iter().all(|c| c["swatch"] == "Ink"), "{listed}");
|
||||
let colors = listed["colors"].as_array().unwrap();
|
||||
assert!(!colors.is_empty() && colors.iter().all(|c| c["swatch"] == "Ink"), "{listed}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -446,7 +447,9 @@ fn limit_to_library_snaps_new_colours() {
|
||||
let c = color_value(k).unwrap();
|
||||
c.to_rgb().iter().all(|v| ((v * 5.0).round() - v * 5.0).abs() < 1e-3)
|
||||
};
|
||||
assert!(r["map"].as_array().unwrap().iter().all(|row| web(&row["to"])), "{r}");
|
||||
let map = r["map"].as_array().unwrap();
|
||||
assert_eq!(map.len(), 2, "a row for each color: {r}");
|
||||
assert!(map.iter().all(|row| web(&row["to"])), "{r}");
|
||||
run(&mut s, "recolor.apply", json!({"map": {"#f01020": "#f01020"}, "limitTo": "Web Safe 216"}));
|
||||
let hexes: Vec<Value> = run(&mut s, "recolor.colors", json!({}))["colors"].as_array().unwrap().iter().map(|c| c["hex"].clone()).collect();
|
||||
assert!(hexes.contains(&json!("#ff0033")) && !hexes.contains(&json!("#f01020")), "{hexes:?}");
|
||||
@@ -1333,10 +1336,11 @@ fn document_model_converts_the_colours_of_a_group_too() {
|
||||
g.swatches.iter().filter_map(|w| w.paint.color()).collect()
|
||||
};
|
||||
// Group-only edit from the rows, and with explicit group colours.
|
||||
let cmyk = |cs: &[Color]| cs.len() == 1 && cs.iter().all(|c| c.model() == vectorcraft_color::cms::Model::Cmyk);
|
||||
run(&mut s, "recolor.apply", json!({"map": {"cmyk 0 0 0 50": "#ff0000"}, "group": "Theme", "model": "document"}));
|
||||
assert!(group(&s).iter().all(|c| c.model() == vectorcraft_color::cms::Model::Cmyk), "{:?}", group(&s));
|
||||
assert!(cmyk(&group(&s)), "{:?}", group(&s));
|
||||
run(&mut s, "recolor.apply", json!({"map": [], "group": "Theme", "groupColors": ["#00ff00"], "model": "document"}));
|
||||
assert!(group(&s).iter().all(|c| c.model() == vectorcraft_color::cms::Model::Cmyk), "{:?}", group(&s));
|
||||
assert!(cmyk(&group(&s)), "{:?}", group(&s));
|
||||
}
|
||||
|
||||
fn stroke(s: &Session, id: NodeId) -> Color {
|
||||
@@ -1620,7 +1624,7 @@ fn theme_picker_leaves_out_clear_pixels_and_unreadable_images() {
|
||||
let cut = super::menucmds::place_undecodable_png(&mut s);
|
||||
let cb = s.doc().unwrap().doc.node(cut).unwrap().visual_bounds().unwrap();
|
||||
let r = run(&mut s, "recolor.pickTheme", json!({"picks": [{"rect": [cb.x0, cb.y0, cb.x1, cb.y1]}]}));
|
||||
assert!(r["colors"].as_array().unwrap().iter().all(|k| k == "rgb 255 0 0"), "the undecodable image adds nothing: {r}");
|
||||
assert_eq!(r["colors"], json!(["rgb 255 0 0"]), "the undecodable image adds nothing to the red under it: {r}");
|
||||
}
|
||||
|
||||
/// A large image is read through about 65,536 pixels: its palette still holds both halves.
|
||||
|
||||
@@ -155,6 +155,37 @@ fn page_item_size_setters_on_a_rotated_object_give_the_page_aligned_size() {
|
||||
assert_eq!(format!("{:?}", s.active().unwrap().doc.node(b)), other, "the other object stays as it was");
|
||||
}
|
||||
|
||||
/// Type in a document in the back that the switch to that document measures again (here: not
|
||||
/// measured yet) is sized and moved by the bounds measured after the switch.
|
||||
#[test]
|
||||
fn page_item_size_and_position_setters_measure_type_in_a_back_document_after_the_switch() {
|
||||
let mut s = Session::new();
|
||||
s.execute("file.new", &json!({"width": 400, "height": 300})).unwrap();
|
||||
let id = NodeId(s.execute("text.create", &json!({"x": 10, "y": 100, "text": "Wide type here", "size": 40})).unwrap()["id"].as_u64().unwrap());
|
||||
let uid = s.active().unwrap().uid;
|
||||
s.execute("file.new", &json!({"width": 200, "height": 100})).unwrap();
|
||||
let front = s.active().unwrap().uid;
|
||||
let unmeasure = |s: &mut Session| {
|
||||
let st = s.document_mut(uid).unwrap();
|
||||
if let Some(NodeKind::Text(t)) = std::sync::Arc::make_mut(&mut st.doc).node_mut(id).map(|n| &mut n.kind) {
|
||||
t.cached_bounds = None;
|
||||
t.cached_baselines.clear();
|
||||
}
|
||||
};
|
||||
let mut got = Vec::new();
|
||||
for (set, want) in
|
||||
[("t.width = 150; vc.log(t.width);", 150.0), ("t.height = 90; vc.log(t.height);", 90.0), ("t.top = 200; vc.log(t.top);", 200.0)]
|
||||
{
|
||||
unmeasure(&mut s);
|
||||
let out = log(&mut s, &format!("var t = app.documents[1].pageItems[0]; {set}"));
|
||||
got.push((set, out[0].as_f64().unwrap(), want));
|
||||
}
|
||||
for (set, got, want) in got {
|
||||
assert!((got - want).abs() < 1e-6, "{set} read {got}");
|
||||
}
|
||||
assert_eq!(s.active().unwrap().uid, front, "the front document stays in front");
|
||||
}
|
||||
|
||||
/// `controlBounds` holds a curve's handles, which reach past the curve; for a rectangle it is the
|
||||
/// visible bounds.
|
||||
#[test]
|
||||
|
||||
@@ -1020,6 +1020,7 @@ fn script_file_alias_is_not_left_behind_a_folder_replaced_by_a_link() {
|
||||
/// Where a hidden file is not one whose name starts with a dot, setting `hidden` and `createAlias`
|
||||
/// set `error` and change nothing.
|
||||
#[cfg(not(unix))]
|
||||
// test-lint: allow never-run Windows only (not Unix); CI runs tests on Linux and FreeBSD
|
||||
#[test]
|
||||
fn script_file_hidden_and_aliases_are_refused_off_unix() {
|
||||
let base = folder("hiddenoff");
|
||||
@@ -1637,6 +1638,7 @@ fn script_file_rename_does_not_take_the_settings_folders_name() {
|
||||
/// Where case does not matter, a folder named in another case is still the folder that holds the
|
||||
/// settings folder, or the settings folder itself: it is not renamed or removed.
|
||||
#[cfg(any(windows, target_os = "macos"))]
|
||||
// test-lint: allow never-run needs a case-insensitive file system (Windows, macOS); CI runs tests on Linux and FreeBSD
|
||||
#[test]
|
||||
fn script_file_rename_does_not_move_the_settings_folder_named_in_another_case() {
|
||||
let base = folder("moveupcase");
|
||||
@@ -1660,6 +1662,7 @@ fn script_file_rename_does_not_move_the_settings_folder_named_in_another_case()
|
||||
/// Where case does not matter, a folder renamed under its name in another case still moves the open
|
||||
/// objects of the files in it: changes are written under the new name, not lost at the old one.
|
||||
#[cfg(any(windows, target_os = "macos"))]
|
||||
// test-lint: allow never-run needs a case-insensitive file system (Windows, macOS); CI runs tests on Linux and FreeBSD
|
||||
#[test]
|
||||
fn script_file_rename_of_a_folder_named_in_another_case_moves_its_open_files() {
|
||||
let base = folder("renamecase");
|
||||
|
||||
@@ -2,9 +2,11 @@
|
||||
//! specifiers and paths, the run's limits, and errors at the file they are in.
|
||||
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::time::Duration;
|
||||
|
||||
use serde_json::{Value, json};
|
||||
|
||||
use crate::script::folder::Clock;
|
||||
use crate::*;
|
||||
|
||||
/// A fresh folder for test `name`, with a `main` folder inside it for the script.
|
||||
@@ -217,8 +219,11 @@ fn script_module_is_listed_and_taken_by_path() {
|
||||
write(&root.join("tool.mjs"), "export var a = 1;");
|
||||
let mut s = Session::new();
|
||||
s.attach_scripts_dir(root.clone());
|
||||
// The listing's time limit is checked against a clock that does not move.
|
||||
s.set_script_listing_clock(Clock::Fixed(Duration::ZERO));
|
||||
let listed = s.execute("script.listInstalled", &json!({})).unwrap();
|
||||
assert_eq!(listed["scripts"], json!([{"path": root.join("tool.mjs").to_string_lossy(), "label": "tool", "folders": []}]));
|
||||
assert_eq!(listed["truncated"], false);
|
||||
// A script given as text is not a module, whatever its name.
|
||||
let mut s = Session::new();
|
||||
let r = s.execute("script.run", &json!({"source": "export var a = 1;", "name": "t.mjs"}));
|
||||
|
||||
@@ -10,13 +10,77 @@ use crate::*;
|
||||
|
||||
const DENIED: &str = "Script file access denied";
|
||||
|
||||
/// A test's folder, removed when the test ends, a failed assertion included. A read-only file in
|
||||
/// it, which Windows does not delete, is made writable first when the first removal fails.
|
||||
struct Workspace(PathBuf);
|
||||
|
||||
impl std::ops::Deref for Workspace {
|
||||
type Target = Path;
|
||||
|
||||
fn deref(&self) -> &Path {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl AsRef<Path> for Workspace {
|
||||
fn as_ref(&self) -> &Path {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for Workspace {
|
||||
fn drop(&mut self) {
|
||||
if std::fs::remove_dir_all(&self.0).is_err() {
|
||||
make_writable(&self.0);
|
||||
let _ = std::fs::remove_dir_all(&self.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Clears the read-only flag of every file and folder in `path`, `path` included. Links are not
|
||||
/// followed.
|
||||
fn make_writable(path: &Path) {
|
||||
let Ok(meta) = std::fs::symlink_metadata(path) else { return };
|
||||
if meta.file_type().is_symlink() {
|
||||
return;
|
||||
}
|
||||
let mut perms = meta.permissions();
|
||||
if perms.readonly() {
|
||||
#[allow(clippy::permissions_set_readonly_false)]
|
||||
perms.set_readonly(false);
|
||||
let _ = std::fs::set_permissions(path, perms);
|
||||
}
|
||||
if meta.is_dir() {
|
||||
for entry in std::fs::read_dir(path).into_iter().flatten().flatten() {
|
||||
make_writable(&entry.path());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A fresh folder for test `name`, by its real path, with `main` for the script.
|
||||
fn folder(name: &str) -> PathBuf {
|
||||
fn folder(name: &str) -> Workspace {
|
||||
let base = std::env::temp_dir().join(format!("vc-script-save-{name}-{}", std::process::id()));
|
||||
let _ = std::fs::remove_dir_all(&base);
|
||||
std::fs::create_dir_all(base.join("main")).unwrap();
|
||||
std::fs::create_dir_all(base.join("outside")).unwrap();
|
||||
std::fs::canonicalize(&base).unwrap()
|
||||
Workspace(std::fs::canonicalize(&base).unwrap())
|
||||
}
|
||||
|
||||
/// A test that fails leaves no folder behind, also when it made a file in it read-only.
|
||||
#[test]
|
||||
fn a_failed_test_leaves_no_folder() {
|
||||
let base = folder("failed");
|
||||
let path = base.to_path_buf();
|
||||
let failed = std::panic::catch_unwind(std::panic::AssertUnwindSafe(move || {
|
||||
let locked = base.join("main/locked.txt");
|
||||
std::fs::write(&locked, b"x").unwrap();
|
||||
let mut perms = std::fs::metadata(&locked).unwrap().permissions();
|
||||
perms.set_readonly(true);
|
||||
std::fs::set_permissions(&locked, perms).unwrap();
|
||||
panic!("a failed assertion");
|
||||
}));
|
||||
assert!(failed.is_err());
|
||||
assert!(!path.exists(), "{} is left", path.display());
|
||||
}
|
||||
|
||||
/// A session whose scripts keep their data folders in `base/settings/Script Data`.
|
||||
|
||||
@@ -260,7 +260,10 @@ fn a_leading_equal_to_the_auto_leading_turns_auto_leading_off() {
|
||||
assert_eq!(out, vec![json!([false, 14.4])]);
|
||||
assert_eq!(undo_steps(&s), before + 1);
|
||||
match &s.active().unwrap().doc.node(id).unwrap().kind {
|
||||
NodeKind::Text(t) => assert!(t.runs.iter().all(|r| r.style.leading.is_some_and(|l| (l - 14.4).abs() < 1e-9)), "{:?}", t.runs),
|
||||
NodeKind::Text(t) => {
|
||||
assert_eq!(t.plain_text(), "abc");
|
||||
assert!(!t.runs.is_empty() && t.runs.iter().all(|r| r.style.leading.is_some_and(|l| (l - 14.4).abs() < 1e-9)), "{:?}", t.runs);
|
||||
}
|
||||
_ => panic!("not text"),
|
||||
}
|
||||
// A fixed leading set to its own value is still no change.
|
||||
@@ -371,7 +374,10 @@ fn turning_auto_leading_off_keeps_each_characters_leading() {
|
||||
assert!(e.contains("autoLeading cannot be turned off"), "{e}");
|
||||
assert_eq!(undo_steps(&s), before);
|
||||
match &s.active().unwrap().doc.node(id).unwrap().kind {
|
||||
NodeKind::Text(t) => assert!(t.runs.iter().all(|r| r.style.leading.is_none())),
|
||||
NodeKind::Text(t) => {
|
||||
assert_eq!(t.plain_text(), "ab\ncd");
|
||||
assert!(!t.runs.is_empty() && t.runs.iter().all(|r| r.style.leading.is_none()), "{:?}", t.runs);
|
||||
}
|
||||
_ => panic!("not text"),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -730,8 +730,7 @@ fn a_temporary_file_starts_private() {
|
||||
|
||||
/// A replaced sidecar that had no access ACL takes none from its folder's default ACL, whose named
|
||||
/// users the sidecar's group bits would let in. The default ACL is set through its extended
|
||||
/// attribute, so the test runs where the `acl` tools are not installed. (Skipped on a file system
|
||||
/// without ACLs.)
|
||||
/// attribute, so the test runs where the `acl` tools are not installed.
|
||||
#[cfg(target_os = "linux")]
|
||||
#[test]
|
||||
fn a_replaced_sidecar_takes_no_inherited_acl() {
|
||||
@@ -752,14 +751,8 @@ fn a_replaced_sidecar_takes_no_inherited_acl() {
|
||||
acl.extend(perm.to_le_bytes());
|
||||
acl.extend(id.to_le_bytes());
|
||||
}
|
||||
match rustix::fs::setxattr(parent, "system.posix_acl_default", &acl, rustix::fs::XattrFlags::empty()) {
|
||||
Ok(()) => {}
|
||||
Err(e) if e == rustix::io::Errno::NOTSUP => {
|
||||
let _ = std::fs::remove_dir_all(base);
|
||||
return;
|
||||
}
|
||||
Err(e) => panic!("setting the default ACL: {e}"),
|
||||
}
|
||||
rustix::fs::setxattr(parent, "system.posix_acl_default", &acl, rustix::fs::XattrFlags::empty())
|
||||
.unwrap_or_else(|e| panic!("setting the default ACL (the temporary folder's file system needs ACLs): {e}"));
|
||||
let mut buf = vec![0u8; 4096];
|
||||
let probe = parent.join("probe");
|
||||
std::fs::write(&probe, b"").unwrap();
|
||||
|
||||
@@ -79,6 +79,7 @@ fn file_names(dir: &std::path::Path) -> Vec<String> {
|
||||
|
||||
/// Windows does not allow replacing a read-only file or writing into it, so the write fails.
|
||||
#[cfg(windows)]
|
||||
// test-lint: allow never-run Windows only; CI runs tests on Linux and FreeBSD
|
||||
#[test]
|
||||
fn a_rename_that_only_changes_case_and_cannot_be_written_keeps_the_old_file() {
|
||||
let root = fresh_dir("rename-case-fails");
|
||||
|
||||
@@ -34,12 +34,10 @@ fn arrow_align_is_set_per_stroke_and_validated() {
|
||||
#[test]
|
||||
fn profiles_come_from_the_preset_catalogue() {
|
||||
let (mut s, id) = session_with_line();
|
||||
for p in WidthProfile::PRESETS {
|
||||
s.execute("stroke.set", &json!({"profile": p.id})).unwrap();
|
||||
let st = stroke(&s, id);
|
||||
assert_eq!(WidthProfile::id_of(st.profile.as_ref()), p.id);
|
||||
}
|
||||
assert!(stroke(&s, id).profile.is_some());
|
||||
s.execute("stroke.set", &json!({"profile": "lens"})).unwrap();
|
||||
assert_eq!(stroke(&s, id).profile.map(|p| p.points), Some(vec![(0.0, 0.0, 0.0), (0.5, 1.0, 1.0), (1.0, 0.0, 0.0)]));
|
||||
s.execute("stroke.set", &json!({"profile": "pinch"})).unwrap();
|
||||
assert_eq!(stroke(&s, id).profile.map(|p| p.points), Some(vec![(0.0, 1.0, 1.0), (0.5, 0.25, 0.25), (1.0, 1.0, 1.0)]));
|
||||
s.execute("stroke.set", &json!({"profile": "uniform"})).unwrap();
|
||||
assert!(stroke(&s, id).profile.is_none(), "uniform is the plain stroke");
|
||||
assert!(s.execute("stroke.set", &json!({"profile": "zigzag"})).is_err());
|
||||
@@ -53,9 +51,12 @@ fn profiles_come_from_the_preset_catalogue() {
|
||||
for a in vectorcraft_doc::Arrowhead::ALL {
|
||||
let name = serde_json::to_value(&a).unwrap();
|
||||
assert!(spec.params.contains(name.as_str().unwrap()), "{name}");
|
||||
s.execute("stroke.set", &json!({"endArrow": name})).unwrap();
|
||||
assert_eq!(stroke(&s, id).end_arrow, Some(a));
|
||||
}
|
||||
s.execute("stroke.set", &json!({"endArrow": "TriangleOpen", "startArrow": "Diamond"})).unwrap();
|
||||
let st = stroke(&s, id);
|
||||
assert_eq!((st.start_arrow, st.end_arrow), (Some(Arrowhead::Diamond), Some(Arrowhead::TriangleOpen)));
|
||||
assert!(s.execute("stroke.set", &json!({"endArrow": "Arrow999"})).is_err());
|
||||
assert_eq!(stroke(&s, id).end_arrow, Some(Arrowhead::TriangleOpen), "a refused name changes nothing");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -125,9 +125,12 @@ fn override_character_color_clears_the_run_fill() {
|
||||
assert_eq!(run(&mut s, "graphicStyle.setOptions", json!({}))["overrideCharColor"], true);
|
||||
let a = text(&mut s, 100.0);
|
||||
run(&mut s, "paint.setFill", json!({"color": "#ff0000", "ids": [a.0]}));
|
||||
assert!(runs(&s, a).iter().all(|(f, _)| *f != Paint::None));
|
||||
let red = Paint::solid(Color::from_hex("#ff0000").unwrap());
|
||||
let painted = runs(&s, a);
|
||||
assert!(!painted.is_empty() && painted.iter().all(|(f, _)| *f == red), "{painted:?}");
|
||||
run(&mut s, "graphicStyle.apply", json!({"name": "Blue", "ids": [a.0]}));
|
||||
assert!(runs(&s, a).iter().all(|(f, st)| *f == Paint::None && *st == Paint::None));
|
||||
let styled = runs(&s, a);
|
||||
assert!(styled.len() == painted.len() && styled.iter().all(|(f, st)| *f == Paint::None && *st == Paint::None), "{styled:?}");
|
||||
assert_eq!(s.doc().unwrap().doc.node(a).unwrap().appearance.fill_paint(), Paint::solid(Color::from_hex("#0000ff").unwrap()));
|
||||
// Off: they keep it (the style's paint draws over them).
|
||||
assert_eq!(run(&mut s, "graphicStyle.setOptions", json!({"overrideCharColor": false}))["overrideCharColor"], false);
|
||||
|
||||
@@ -722,7 +722,8 @@ fn a_cmyk_document_starts_with_cmyk_swatches_and_stores_new_colours_as_cmyk() {
|
||||
json!({"ids": [a.0], "gradient": {"stops": [{"offset": 0, "color": "#ffffff"}, {"offset": 1, "color": "#0000ff"}]}}),
|
||||
);
|
||||
let Paint::Gradient(g) = fill(&s, a) else { panic!("a gradient") };
|
||||
assert!(g.gradient.stops.iter().all(|st| matches!(st.color, Color::Cmyk { .. })));
|
||||
assert_eq!(g.gradient.stops.len(), 2, "{:?}", g.gradient.stops);
|
||||
assert!(g.gradient.stops.iter().all(|st| matches!(st.color, Color::Cmyk { .. })), "{:?}", g.gradient.stops);
|
||||
// A swatch made from a hex colour is CMYK as well; the document round-trips natively.
|
||||
let name = run(&mut s, "swatch.new", json!({"color": "#00ff00"}))["name"].as_str().unwrap().to_string();
|
||||
assert_eq!(doc(&s).swatch(&name).and_then(|w| w.paint.color()), Some(managed(Color::rgb(0.0, 1.0, 0.0))));
|
||||
|
||||
@@ -265,6 +265,7 @@ fn nature_icons_library_places_and_survives_save() {
|
||||
for (i, name) in names.iter().enumerate() {
|
||||
let symbol = &library["symbols"][i];
|
||||
let size = symbol["size"].as_array().unwrap();
|
||||
assert_eq!(size.len(), 2, "{name}: width and height");
|
||||
assert!(size.iter().all(|n| n.as_f64().is_some_and(|n| n.is_finite() && n > 0.0)), "{name}");
|
||||
let added = run(
|
||||
&mut s,
|
||||
|
||||
@@ -161,7 +161,11 @@ fn auto_height_x_composer() {
|
||||
}
|
||||
s.execute("text.setFormat", &json!({"ids": [id.0], "composer": "singleLine"})).unwrap();
|
||||
s.execute("text.setStyle", &json!({"id": id.0, "justify": "justifyAll"})).unwrap();
|
||||
assert!(text(&s, id).paragraph_styles().iter().all(|p| p.composer == Composer::SingleLine && p.justify == Justify::JustifyAll));
|
||||
let t = text(&s, id);
|
||||
assert_eq!(t.paragraph_count(), 2);
|
||||
for k in 0..2 {
|
||||
assert_eq!((t.para_at(k).composer, t.para_at(k).justify), (Composer::SingleLine, Justify::JustifyAll), "paragraph {k}");
|
||||
}
|
||||
assert_tight(&s, id, "justified");
|
||||
}
|
||||
|
||||
|
||||
@@ -323,7 +323,8 @@ fn optical_set_format_clears_existing_pair_override() {
|
||||
let result = s.execute("text.setFormat", &json!({"ids": [id.0], "kerning": "optical"})).unwrap();
|
||||
assert_eq!(result["kerning"], "optical");
|
||||
let t = obj(&s, id);
|
||||
assert!(t.runs.iter().all(|r| r.style.optical_kerning));
|
||||
assert_eq!(t.plain_text(), "III");
|
||||
assert!(!t.runs.is_empty() && t.runs.iter().all(|r| r.style.optical_kerning), "{:?}", t.runs);
|
||||
assert!(t.runs.iter().all(|r| r.style.kerning.is_none()), "choosing Optical clears the manual value");
|
||||
}
|
||||
|
||||
@@ -488,8 +489,10 @@ fn char_style_range_past_u32_styles_nothing() {
|
||||
let mut s = session();
|
||||
let id = text(&mut s, "Hello world");
|
||||
s.execute("charStyle.new", &json!({"name": "Big", "attrs": {"size": 40.0}})).unwrap();
|
||||
let before = obj(&s, id);
|
||||
assert!(!before.runs.is_empty() && before.runs.iter().all(|r| r.style.size == 20.0 && r.style.style_name.is_none()), "{:?}", before.runs);
|
||||
s.execute("charStyle.apply", &json!({"name": "Big", "id": id.0, "start": 1u64 << 32, "end": (1u64 << 32) + 5})).unwrap();
|
||||
assert!(obj(&s, id).runs.iter().all(|r| r.style.size == 20.0 && r.style.style_name.is_none()), "{:?}", obj(&s, id).runs);
|
||||
assert_eq!(obj(&s, id), before, "no character is styled");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -2008,7 +2011,8 @@ fn the_eyedropper_styles_the_whole_story_that_select_all_selected() {
|
||||
let r = s.execute("appearance.copyFrom", &json!({"source": source})).unwrap();
|
||||
assert_eq!(r, json!({"ids": [a.0, b.0]}));
|
||||
for id in [a, b] {
|
||||
assert!(obj(&s, id).runs.iter().all(|r| (r.style.size - 30.0).abs() < 1e-9), "every character of frame {} takes the size", id.0);
|
||||
let runs = obj(&s, id).runs;
|
||||
assert!(!runs.is_empty() && runs.iter().all(|r| (r.style.size - 30.0).abs() < 1e-9), "every character of frame {} takes the size", id.0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2223,7 +2227,8 @@ fn a_type_step_keeps_a_story_that_left_the_edited_frame_selected() {
|
||||
let c = selected_story_moved_into_a_new_frame(&mut s, a, b);
|
||||
// Alt+Right steps the tracking of the selected text, not the kerning at a caret.
|
||||
key(&mut s, ToolKey::Right, Mods { alt: true, ..Mods::default() });
|
||||
assert!(obj(&s, c).runs.iter().all(|r| r.style.tracking > 0.0), "every character of the story takes the step");
|
||||
let runs = obj(&s, c).runs;
|
||||
assert!(!runs.is_empty() && runs.iter().all(|r| r.style.tracking > 0.0), "every character of the story takes the step: {runs:?}");
|
||||
// A key that does nothing leaves it selected as well.
|
||||
key(&mut s, ToolKey::BracketLeft, Mods::default());
|
||||
assert!(third_frame_highlighted(&mut s));
|
||||
@@ -2567,6 +2572,7 @@ fn convert_to_text_in_one_frame_leaves_the_other_frames() {
|
||||
let (ta, tb) = (obj(&s, a), obj(&s, b));
|
||||
assert_eq!(ta.plain_text(), in_a, "the first frame's text is as it was");
|
||||
assert!(ta.para_at(0).list.is_some(), "the first frame stays a list");
|
||||
assert!(tb.paragraph_count() > 1, "{:?}", tb.plain_text());
|
||||
assert!((0..tb.paragraph_count()).all(|k| tb.para_at(k).list.is_none()), "the edited frame leaves its list");
|
||||
assert!(tb.plain_text().contains("\u{2022}\t"), "the edited frame holds its bullets as characters");
|
||||
}
|
||||
@@ -3765,7 +3771,7 @@ fn the_glyph_query_shapes_an_overflowing_character_in_its_paragraph_direction()
|
||||
|
||||
let boxed = create(&mut s, text, rtl, char_ltr, 30.0);
|
||||
let lay = vectorcraft_text::layout(db, &obj(&s, boxed));
|
||||
assert!(lay.glyphs.iter().all(|g| g.byte < 2), "{text:?}: the second paragraph overflows");
|
||||
assert!(!lay.glyphs.is_empty() && lay.glyphs.iter().all(|g| g.byte < 2), "{text:?}: only the first paragraph is laid out");
|
||||
let r = s.execute("text.glyphAlternates", &json!({"id": boxed.0, "start": at})).unwrap();
|
||||
assert_eq!(r["chosen"], json!(face.glyph_for(drawn)), "{text:?}: the glyph drawn when it fits");
|
||||
}
|
||||
|
||||
@@ -123,7 +123,8 @@ fn transform_again_after_a_handle_drag_resizes_the_type_area_again() {
|
||||
assert!(near(r.origin(), Point::ZERO) && (r.width() - 640.0 / 3.0).abs() < 1e-6 && (r.height() - 250.0).abs() < 1e-6, "{r:?}");
|
||||
let t = text(&s, id);
|
||||
assert_eq!(t.xf, Affine::translate((40.0, 40.0)), "the type isn't scaled");
|
||||
assert!(t.runs.iter().all(|r| r.style.size == 12.0));
|
||||
assert_eq!(t.plain_text(), STORY);
|
||||
assert!(!t.runs.is_empty() && t.runs.iter().all(|r| r.style.size == 12.0), "{:?}", t.runs);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -1367,6 +1367,7 @@ fn distort_refuses_corners_type_and_symbol_instances_cannot_follow() {
|
||||
let want = [(0.4, 0.0), (0.6, 0.0), (1.0, 1.0), (0.0, 1.0)].map(|(u, v)| Point::new(b.x0 + u * b.width(), b.y0 + v * b.height()));
|
||||
s.execute("object.distort", &json!({ "corners": want.map(|p| [p.x, p.y]) })).unwrap();
|
||||
let got = drawn_corners(&s, id);
|
||||
assert_eq!(got.len(), 4, "{got:?}");
|
||||
assert!(got.iter().zip(want).all(|(g, w)| g.distance(w) < 1e-3), "{got:?} against {want:?}");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user