mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-16 07:17:00 +00:00
Merge main into fix/int-param-wrong-type
This commit is contained in:
@@ -2446,6 +2446,193 @@ fn live_paint_stroke_edge() {
|
||||
assert!(s.execute("livePaint.strokeEdge", &json!({"group": g.0, "point": [300, 300]})).is_err());
|
||||
}
|
||||
|
||||
/// The undo and redo depths, the unsaved state and the revision of the active document.
|
||||
fn history_state(s: &Session) -> (usize, usize, bool, u64) {
|
||||
let st = s.doc().unwrap();
|
||||
(st.history.undo.len(), st.history.redo.len(), st.is_dirty(), st.revision)
|
||||
}
|
||||
|
||||
/// Draw a rectangle and undo it, so a redo step is waiting, then mark the document saved with `g`
|
||||
/// alone selected.
|
||||
fn redo_waiting_and_saved(s: &mut Session, g: NodeId) {
|
||||
rect(s, 300.0, 300.0, 10.0, 10.0);
|
||||
s.execute("edit.undo", &json!({})).unwrap();
|
||||
s.execute("select.set", &json!({"ids": [g.0]})).unwrap();
|
||||
s.doc_mut().unwrap().mark_saved();
|
||||
}
|
||||
|
||||
/// The active document and its [`history_state`].
|
||||
type Snapshot = (vectorcraft_doc::Document, (usize, usize, bool, u64));
|
||||
|
||||
fn snapshot(s: &Session) -> Snapshot {
|
||||
((*s.doc().unwrap().doc).clone(), history_state(s))
|
||||
}
|
||||
|
||||
/// After a Live Paint edit that changed nothing: the document, the undo and redo steps, the saved
|
||||
/// state and the revision are as `before`, and Redo still brings back the rectangle
|
||||
/// [`redo_waiting_and_saved`] undid. Undoes the rectangle again, marks the document saved and
|
||||
/// takes a new `before`.
|
||||
fn assert_unchanged(s: &mut Session, before: &mut Snapshot, what: &str) {
|
||||
assert!(*s.doc().unwrap().doc == before.0, "{what}: the document is as it was");
|
||||
assert_eq!(history_state(s), before.1, "{what}: no undo step, the redo step kept, still saved");
|
||||
let children = layer_children(s);
|
||||
s.execute("edit.redo", &json!({})).unwrap();
|
||||
assert_eq!(layer_children(s), children + 1, "{what}: Redo brings back the rectangle");
|
||||
s.execute("edit.undo", &json!({})).unwrap();
|
||||
s.doc_mut().unwrap().mark_saved();
|
||||
*before = snapshot(s);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn live_paint_fill_same_paint_is_no_op() {
|
||||
let mut s = session();
|
||||
let g = live(&mut s);
|
||||
let drag = json!({"group": g.0, "point": [25, 50], "points": [[25, 50], [125, 50]], "color": "#00ff00"});
|
||||
s.execute("livePaint.fill", &drag).unwrap();
|
||||
redo_waiting_and_saved(&mut s, g);
|
||||
// A color used since stays the newest recent color and the last color.
|
||||
let blue = Color::rgb(0.0, 0.0, 1.0);
|
||||
s.remember_paint_now(&Paint::solid(blue));
|
||||
let recent = (s.recent_colors.clone(), s.last_solid);
|
||||
let mut before = snapshot(&s);
|
||||
let click = s.execute("livePaint.fill", &json!({"group": g.0, "point": [75, 50], "color": "#00ff00"})).unwrap();
|
||||
let face = vectorcraft_tools::builder::face_at(&node(&s, g), Point::new(75.0, 50.0)).unwrap().id;
|
||||
assert_eq!(click, json!({"group": g.0, "face": face.0}), "the usual reply");
|
||||
assert_unchanged(&mut s, &mut before, "a click on a face with the paint");
|
||||
s.execute("livePaint.fill", &drag).unwrap();
|
||||
assert_unchanged(&mut s, &mut before, "a drag over faces with the paint");
|
||||
// Without a group, the click finds the Live Paint group among the selected objects.
|
||||
s.execute("livePaint.fill", &json!({"point": [125, 50], "color": "#00ff00"})).unwrap();
|
||||
assert_unchanged(&mut s, &mut before, "a click in the selected group");
|
||||
assert_eq!((s.recent_colors.clone(), s.last_solid), recent, "the recent colors are as they were");
|
||||
// A drag that reaches one face without the paint is one undo step and remembers the color.
|
||||
let red = Paint::solid(Color::from_hex("#ff0000").unwrap());
|
||||
for x in [25, 75] {
|
||||
s.execute("livePaint.fill", &json!({"group": g.0, "point": [x, 50], "color": "#ff0000"})).unwrap();
|
||||
}
|
||||
s.remember_paint_now(&Paint::solid(blue));
|
||||
let depth = s.doc().unwrap().history.undo.len();
|
||||
s.execute("livePaint.fill", &json!({"group": g.0, "point": [25, 50], "points": [[25, 50], [125, 50]], "color": "#ff0000"})).unwrap();
|
||||
assert_eq!(s.doc().unwrap().history.undo.len(), depth + 1);
|
||||
assert_eq!(Paint::solid(s.last_solid), red);
|
||||
let gn = node(&s, g);
|
||||
for x in [25.0, 75.0, 125.0] {
|
||||
assert_eq!(vectorcraft_tools::builder::face_at(&gn, Point::new(x, 50.0)).unwrap().appearance.fill_paint(), red, "{x}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn live_paint_bucket_click_with_the_face_paint_is_no_op() {
|
||||
let mut s = session();
|
||||
let g = live(&mut s);
|
||||
let v = ViewInfo::default();
|
||||
s.select_tool("livePaintBucket", v).unwrap();
|
||||
s.paint.fill = Paint::solid(Color::rgb(0.0, 1.0, 1.0));
|
||||
let click = |s: &mut Session, x: f64| {
|
||||
s.pointer(&PointerEvent::new(PointerKind::Down, x, 50.0), v).unwrap();
|
||||
s.pointer(&PointerEvent::new(PointerKind::Up, x, 50.0), v).unwrap();
|
||||
};
|
||||
click(&mut s, 125.0);
|
||||
redo_waiting_and_saved(&mut s, g);
|
||||
let mut before = snapshot(&s);
|
||||
click(&mut s, 125.0);
|
||||
assert_unchanged(&mut s, &mut before, "a Bucket click on a face with the paint");
|
||||
// A drag over faces with the paint changes nothing either.
|
||||
click(&mut s, 25.0);
|
||||
click(&mut s, 75.0);
|
||||
redo_waiting_and_saved(&mut s, g);
|
||||
let mut before = snapshot(&s);
|
||||
s.pointer(&PointerEvent::new(PointerKind::Down, 25.0, 50.0), v).unwrap();
|
||||
s.pointer(&PointerEvent::new(PointerKind::Drag, 125.0, 50.0), v).unwrap();
|
||||
s.pointer(&PointerEvent::new(PointerKind::Up, 125.0, 50.0), v).unwrap();
|
||||
assert_unchanged(&mut s, &mut before, "a Bucket drag over faces with the paint");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn live_paint_stroke_edge_same_paint_and_width_is_no_op() {
|
||||
let mut s = session();
|
||||
let g = live(&mut s);
|
||||
let call = json!({"group": g.0, "point": [100, 50], "color": "#ff0000", "width": 3});
|
||||
let first = s.execute("livePaint.strokeEdge", &call).unwrap();
|
||||
redo_waiting_and_saved(&mut s, g);
|
||||
s.remember_paint_now(&Paint::solid(Color::rgb(0.0, 0.0, 1.0)));
|
||||
let last = s.last_solid;
|
||||
let mut before = snapshot(&s);
|
||||
assert_eq!(s.execute("livePaint.strokeEdge", &call).unwrap(), first, "the usual reply");
|
||||
assert_unchanged(&mut s, &mut before, "an edge with the paint and the width");
|
||||
assert_eq!(s.last_solid, last, "the last color is as it was");
|
||||
// Another width is an edit.
|
||||
s.execute("livePaint.strokeEdge", &json!({"group": g.0, "point": [100, 50], "color": "#ff0000", "width": 2})).unwrap();
|
||||
assert_eq!(history_state(&s).0, before.1.0 + 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn live_paint_gap_options_same_values_are_no_op() {
|
||||
let mut s = session();
|
||||
let g = live_square_with_a_gap(&mut s);
|
||||
let set = json!({"detect": true, "size": "small", "color": "#123456"});
|
||||
let first = s.execute("livePaint.gapOptions", &set).unwrap();
|
||||
redo_waiting_and_saved(&mut s, g);
|
||||
let mut before = snapshot(&s);
|
||||
assert_eq!(s.execute("livePaint.gapOptions", &set).unwrap(), first, "the usual reply");
|
||||
assert_unchanged(&mut s, &mut before, "the options the group has");
|
||||
s.execute("livePaint.gapOptions", &json!({})).unwrap();
|
||||
assert_unchanged(&mut s, &mut before, "no options given");
|
||||
// Close Gaps With Paths with a gap to close is an edit.
|
||||
let r = s.execute("livePaint.gapOptions", &json!({"closeGaps": true})).unwrap();
|
||||
assert_eq!(r["closed"], 1);
|
||||
assert_eq!(history_state(&s).0, before.1.0 + 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn live_paint_gap_options_close_without_gaps_is_no_op() {
|
||||
let mut s = session();
|
||||
let g = live(&mut s);
|
||||
redo_waiting_and_saved(&mut s, g);
|
||||
let mut before = snapshot(&s);
|
||||
let r = s.execute("livePaint.gapOptions", &json!({"id": g.0, "closeGaps": true})).unwrap();
|
||||
assert_eq!((ids(&r), &r["faces"], &r["closed"], gaps_of(&r).len()), (vec![g], &json!(3), &json!(0), 0));
|
||||
assert_unchanged(&mut s, &mut before, "no gap to close");
|
||||
// With other options, the faces keep their ids when no path is added.
|
||||
let faces = |s: &Session| vectorcraft_tools::builder::faces(&node(s, g)).iter().map(|f| f.id).collect::<Vec<_>>();
|
||||
let ids_before = faces(&s);
|
||||
s.execute("livePaint.gapOptions", &json!({"id": g.0, "closeGaps": true, "color": "#00ff00"})).unwrap();
|
||||
assert_eq!(history_state(&s).0, before.1.0 + 1);
|
||||
assert_eq!(faces(&s), ids_before);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn live_paint_make_existing_group_is_no_op() {
|
||||
let mut s = session();
|
||||
let g = live(&mut s);
|
||||
redo_waiting_and_saved(&mut s, g);
|
||||
let mut before = snapshot(&s);
|
||||
let r = s.execute("livePaint.make", &json!({})).unwrap();
|
||||
assert_eq!((NodeId(r["id"].as_u64().unwrap()), &r["faces"]), (g, &json!(3)));
|
||||
assert_eq!(r["edges"].as_u64().unwrap(), vectorcraft_tools::builder::edges(&node(&s, g)).len() as u64);
|
||||
assert_unchanged(&mut s, &mut before, "Make with the group alone");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn live_paint_merge_single_group_is_no_op() {
|
||||
let mut s = session();
|
||||
let g = live(&mut s);
|
||||
let other = rect(&mut s, 300.0, 0.0, 50.0, 50.0);
|
||||
redo_waiting_and_saved(&mut s, g);
|
||||
// Given by id, the group is selected without an undo step.
|
||||
s.execute("select.set", &json!({"ids": [other.0]})).unwrap();
|
||||
let before = snapshot(&s);
|
||||
let r = s.execute("livePaint.merge", &json!({"ids": [g.0]})).unwrap();
|
||||
assert_eq!((NodeId(r["id"].as_u64().unwrap()), &r["faces"]), (g, &json!(3)));
|
||||
assert_eq!(s.doc().unwrap().selection.objects, vec![g]);
|
||||
assert!(*s.doc().unwrap().doc == before.0);
|
||||
let (undo, redo, dirty, _) = history_state(&s);
|
||||
assert_eq!((undo, redo, dirty), (before.1.0, before.1.1, before.1.2));
|
||||
// A path to add is an edit.
|
||||
s.execute("livePaint.merge", &json!({"ids": [g.0, other.0]})).unwrap();
|
||||
assert_eq!(history_state(&s).0, before.1.0 + 1);
|
||||
}
|
||||
|
||||
/// Shape Builder refuses an on/off option that is not true or false and a tolerance or gap that is
|
||||
/// not a number, given as text or as another value of the wrong kind, naming the key; the document
|
||||
/// and the undo history stay as they were. True, false and null still work.
|
||||
|
||||
@@ -109,6 +109,48 @@ fn saturate_keeps_a_color_it_does_not_change() {
|
||||
assert_eq!(paint(&s, b), cmyk);
|
||||
}
|
||||
|
||||
/// An Edit Colors pass, a Blend or Recolor Artwork that changes nothing records no undo step, and the
|
||||
/// step that redo would bring back stays; one that changes a color still records one.
|
||||
#[test]
|
||||
fn edit_colors_that_change_nothing_record_no_undo_step() {
|
||||
let mut s = session();
|
||||
let gray = rect(&mut s, json!("#808080"));
|
||||
let a = rect(&mut s, json!("#ff0000"));
|
||||
let b = rect(&mut s, json!("#808080"));
|
||||
let c = rect(&mut s, json!("#0000ff"));
|
||||
s.execute("select.set", &json!({"ids": [a.0, b.0, c.0]})).unwrap();
|
||||
s.execute("edit.colors.blendFrontToBack", &json!({})).unwrap();
|
||||
// A step for redo to bring back.
|
||||
s.execute("edit.colors.invert", &json!({"ids": [a.0]})).unwrap();
|
||||
s.execute("edit.undo", &json!({})).unwrap();
|
||||
let history = |s: &Session| {
|
||||
let h = &s.doc().unwrap().history;
|
||||
(h.undo.len(), h.redo.len())
|
||||
};
|
||||
let before = history(&s);
|
||||
assert_eq!(before.1, 1, "one step to redo");
|
||||
let doc = s.doc().unwrap().doc.clone();
|
||||
let cases = [
|
||||
("edit.colors.invert", json!({"fill": false, "stroke": false})),
|
||||
("edit.colors.saturate", json!({"intensity": 0})),
|
||||
("edit.colors.toRGB", json!({})),
|
||||
("edit.colors.adjustBalance", json!({"mode": "rgb", "r": 0})),
|
||||
("edit.colors.blendFrontToBack", json!({})),
|
||||
("recolor.apply", json!({"map": {"#ff0000": "#ff0000"}})),
|
||||
// The complement of a gray is the same gray.
|
||||
("paint.complement", json!({"ids": [gray.0], "stroke": false})),
|
||||
("addon.color.filter", json!({"effect": "addon.color.invert", "fill": false, "stroke": false})),
|
||||
];
|
||||
for (id, p) in cases {
|
||||
let v = s.execute(id, &p).unwrap();
|
||||
assert_eq!(v["changed"], 0, "{id}");
|
||||
assert_eq!(history(&s), before, "{id}: no undo step, and redo is kept");
|
||||
assert_eq!(s.doc().unwrap().doc, doc, "{id}: the document is unchanged");
|
||||
}
|
||||
s.execute("edit.colors.invert", &json!({})).unwrap();
|
||||
assert_eq!(history(&s), (before.0 + 1, 0), "a pass that changes colors is one undo step");
|
||||
}
|
||||
|
||||
/// Adjust Color Balance refuses a channel that is not a number, which it would otherwise read as 0.
|
||||
#[test]
|
||||
fn adjust_balance_refuses_a_channel_that_is_not_a_number() {
|
||||
|
||||
@@ -712,6 +712,159 @@ fn type_in_symbol_art_reports_a_gradient_only_when_it_expands() {
|
||||
}
|
||||
}
|
||||
|
||||
/// Selected type "Hi" at 64 pt whose characters have no paint, with fills and strokes of its own:
|
||||
/// each of `items` is an `appearance.setItem` edit of a new object-level stroke when it has a
|
||||
/// `weight`, else of a new object-level fill; the first `below` of them paint below the characters.
|
||||
fn type_with_own_paint(s: &mut Session, items: &[Value], below: usize) -> NodeId {
|
||||
let t = run(s, "text.create", json!({"x": 25, "y": 110, "text": "Hi", "size": 64}))["id"].as_u64().unwrap();
|
||||
run(s, "select.set", json!({"ids": [t]}));
|
||||
run(s, "paint.setFill", json!({"none": true}));
|
||||
run(s, "paint.setStroke", json!({"none": true}));
|
||||
for (i, item) in items.iter().enumerate() {
|
||||
let add = if item.get("weight").is_some() { "appearance.addStroke" } else { "appearance.addFill" };
|
||||
run(s, add, json!({"target": "object"}));
|
||||
let mut p = item.clone();
|
||||
p["index"] = json!(i);
|
||||
run(s, "appearance.setItem", p);
|
||||
}
|
||||
run(s, "appearance.moveItem", json!({"from": "contents", "to": below}));
|
||||
NodeId(t)
|
||||
}
|
||||
|
||||
fn blue_stroke() -> Value {
|
||||
json!({"color": "#0000ff", "weight": 5})
|
||||
}
|
||||
|
||||
fn red_blue() -> Value {
|
||||
json!({"gradient": {"kind": "linear", "stops": [{"offset": 0, "color": "#ff0000"}, {"offset": 1, "color": "#0000ff"}]}})
|
||||
}
|
||||
|
||||
/// Create Outlines draws what the type drew: a gradient fill of the type object's own, below its
|
||||
/// characters, keeps one gradient across both glyphs over the layout's box, and its stroke stays
|
||||
/// over them.
|
||||
#[test]
|
||||
fn create_outlines_draws_the_type_objects_own_paint() {
|
||||
let mut s = session();
|
||||
type_with_own_paint(&mut s, &[red_blue(), blue_stroke()], 1);
|
||||
let before = render(&s);
|
||||
run(&mut s, "type.createOutlines", json!({}));
|
||||
let after = render(&s);
|
||||
let n = differing(&before, &after, 24);
|
||||
assert!(n < 40, "{n} pixels differ");
|
||||
assert!(differing(&before, &render(&session()), 24) > 1000, "the type paints something");
|
||||
}
|
||||
|
||||
/// `object.expand.info` reports the type object's own stroke, pattern fill and gradient fill, which
|
||||
/// Object turns into paths of its whole outline: a gradient only when that outline's box needs no
|
||||
/// more runs than are written.
|
||||
#[test]
|
||||
fn type_objects_own_stroke_pattern_and_gradient_are_reported() {
|
||||
let mut s = session();
|
||||
type_with_own_paint(&mut s, &[blue_stroke()], 0);
|
||||
let info = run(&mut s, "object.expand.info", json!({}));
|
||||
assert_eq!((info["object"].clone(), info["stroke"].clone(), info["fill"].clone()), (json!(true), json!(true), json!(false)), "{info}");
|
||||
|
||||
let mut s = session();
|
||||
pattern_rect(&mut s, Rect::new(150.0, 150.0, 190.0, 190.0), false);
|
||||
let t = type_with_own_paint(&mut s, &[json!({"swatch": "Dots"})], 0);
|
||||
run(&mut s, "select.set", json!({"ids": [t.0]}));
|
||||
let info = run(&mut s, "object.expand.info", json!({}));
|
||||
assert_eq!((info["fill"].clone(), info["gradient"].clone(), info["stroke"].clone()), (json!(true), json!(false), json!(false)), "{info}");
|
||||
|
||||
// 0.4 pt runs across about 80 pt: under the limit; 0.02 pt runs: far over it.
|
||||
for (len, expands) in [(40.0, true), (2.0, false)] {
|
||||
let mut s = session();
|
||||
let gradient = json!({"gradient": {"kind": "linear", "spread": "repeat", "repeats": 100, "start": [25, 100], "end": [25.0 + len, 100],
|
||||
"stops": [{"offset": 0, "color": "#ffff00"}, {"offset": 1, "color": "#004080"}]}});
|
||||
type_with_own_paint(&mut s, &[gradient], 0);
|
||||
let info = run(&mut s, "object.expand.info", json!({}));
|
||||
assert_eq!((info["gradient"].clone(), info["fill"].clone()), (json!(expands), json!(expands)), "{len}: {info}");
|
||||
run(&mut s, "object.expand", json!({}));
|
||||
let (gradients, texts) = gradients_and_type(&s);
|
||||
assert_eq!(texts, 0, "{len}: outlined");
|
||||
assert_eq!(gradients == 0, expands, "{len}: {gradients} gradient fills left");
|
||||
}
|
||||
}
|
||||
|
||||
/// Type with only spaces has no outline for its own stroke or pattern fill to go on, so
|
||||
/// `object.expand.info` reports neither.
|
||||
#[test]
|
||||
fn type_without_an_outline_reports_no_own_stroke_or_fill() {
|
||||
let mut s = session();
|
||||
pattern_rect(&mut s, Rect::new(150.0, 150.0, 190.0, 190.0), false);
|
||||
let t = run(&mut s, "text.create", json!({"x": 25, "y": 110, "text": " ", "size": 64}))["id"].as_u64().unwrap();
|
||||
run(&mut s, "select.set", json!({"ids": [t]}));
|
||||
run(&mut s, "paint.setFill", json!({"none": true}));
|
||||
run(&mut s, "paint.setStroke", json!({"none": true}));
|
||||
for (i, item) in [json!({"swatch": "Dots"}), blue_stroke()].into_iter().enumerate() {
|
||||
let add = if item.get("weight").is_some() { "appearance.addStroke" } else { "appearance.addFill" };
|
||||
run(&mut s, add, json!({"target": "object"}));
|
||||
let mut p = item;
|
||||
p["index"] = json!(i);
|
||||
run(&mut s, "appearance.setItem", p);
|
||||
}
|
||||
let info = run(&mut s, "object.expand.info", json!({}));
|
||||
assert_eq!(
|
||||
(info["object"].clone(), info["stroke"].clone(), info["fill"].clone(), info["gradient"].clone()),
|
||||
(json!(true), json!(false), json!(false), json!(false)),
|
||||
"{info}"
|
||||
);
|
||||
}
|
||||
|
||||
/// How many objects in the document have a visible stroke with paint and weight.
|
||||
fn painted_strokes(s: &Session) -> usize {
|
||||
let mut n = 0;
|
||||
s.doc().unwrap().doc.walk(|c| {
|
||||
n += usize::from(
|
||||
c.appearance.items.iter().any(|i| matches!(i, AppearanceItem::Stroke(st) if st.visible && !st.paint.is_none() && st.width > 0.0)),
|
||||
);
|
||||
});
|
||||
n
|
||||
}
|
||||
|
||||
/// A visible stroke under a topmost stroke with no paint still has something for Stroke to
|
||||
/// outline, on type's own appearance and on a path: `object.expand.info` reports it, and Expand
|
||||
/// outlines it.
|
||||
#[test]
|
||||
fn a_stroke_under_an_unpainted_stroke_is_reported_and_outlined() {
|
||||
let mut s = session();
|
||||
type_with_own_paint(&mut s, &[blue_stroke(), json!({"none": true, "weight": 1})], 0);
|
||||
let mut r = session();
|
||||
run(&mut r, "shape.rectangle", json!({"x": 40, "y": 40, "width": 100, "height": 80}));
|
||||
run(&mut r, "paint.setStroke", json!({"color": "#0000ff"}));
|
||||
run(&mut r, "stroke.set", json!({"weight": 4}));
|
||||
run(&mut r, "appearance.addStroke", json!({"target": "object"}));
|
||||
let top = node(&r, selected(&r).id).appearance.items.len() - 1;
|
||||
run(&mut r, "appearance.setItem", json!({"index": top, "none": true}));
|
||||
for (what, s) in [("type", &mut s), ("path", &mut r)] {
|
||||
let info = run(s, "object.expand.info", json!({}));
|
||||
assert_eq!(info["stroke"], json!(true), "{what}: {info}");
|
||||
run(s, "object.expand", json!({}));
|
||||
assert_eq!(painted_strokes(s), 0, "{what}: the stroke is outlined");
|
||||
}
|
||||
}
|
||||
|
||||
/// Expand keeps the type object's own stroke and gradient fill through Object: Stroke outlines the
|
||||
/// stroke and Fill expands the gradient, and with those options off they stay live on the path of
|
||||
/// the whole outline. The picture stays the same either way.
|
||||
#[test]
|
||||
fn expand_keeps_the_type_objects_own_paint() {
|
||||
for (opts, live) in [(json!({}), false), (json!({"fill": false, "stroke": false}), true)] {
|
||||
let mut s = session();
|
||||
type_with_own_paint(&mut s, &[red_blue(), blue_stroke()], 1);
|
||||
let before = render(&s);
|
||||
run(&mut s, "object.expand", opts.clone());
|
||||
let after = render(&s);
|
||||
assert!(mean_diff(&before, &after) < 2.0, "{opts}: {}", mean_diff(&before, &after));
|
||||
let (gradients, texts) = gradients_and_type(&s);
|
||||
assert_eq!(texts, 0, "{opts}: outlined");
|
||||
assert_eq!(gradients == 1, live, "{opts}: {gradients} gradient fills");
|
||||
let mut strokes = 0;
|
||||
s.doc().unwrap().doc.walk(|n| strokes += usize::from(!n.appearance.stroke_paint().is_none()));
|
||||
assert_eq!(strokes == 1, live, "{opts}: {strokes} strokes");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_mesh_option_makes_a_mesh_that_paints_the_gradient() {
|
||||
for gradient in [
|
||||
|
||||
@@ -1043,6 +1043,51 @@ fn create_outlines_matches_text_bounds() {
|
||||
assert!(s.doc().unwrap().doc.node(t).is_some());
|
||||
}
|
||||
|
||||
/// The type object's own fills and strokes (not its characters') become paths of its whole outline,
|
||||
/// with ids of their own: those below the Characters row under the glyph paths, the others over
|
||||
/// them, in their order. The group keeps no appearance of its own, and Undo brings the type back.
|
||||
#[test]
|
||||
fn create_outlines_keeps_the_objects_own_fills_and_strokes() {
|
||||
let mut s = session();
|
||||
let t = text(&mut s, "Hi", 64.0);
|
||||
s.execute("select.set", &json!({"ids": [t.0]})).unwrap();
|
||||
for (cmd, p) in [
|
||||
("appearance.addFill", json!({"target": "object"})),
|
||||
("appearance.setItem", json!({"index": 0, "color": "#ff0000"})),
|
||||
("appearance.addStroke", json!({"target": "object"})),
|
||||
("appearance.setItem", json!({"index": 1, "color": "#0000ff", "weight": 5})),
|
||||
("appearance.addFill", json!({"target": "object"})),
|
||||
("appearance.setItem", json!({"index": 2, "color": "#00ff00", "opacity": 50})),
|
||||
// The red fill paints below the characters; the stroke and the green fill over them.
|
||||
("appearance.moveItem", json!({"from": "contents", "to": 1})),
|
||||
] {
|
||||
s.execute(cmd, &p).unwrap_or_else(|e| panic!("{cmd} {p}: {e}"));
|
||||
}
|
||||
let own = node(&s, t).appearance.items.clone();
|
||||
assert_eq!(own.len(), 3);
|
||||
let r = ids(&s.execute("type.createOutlines", &json!({})).unwrap());
|
||||
let g = node(&s, r[0]);
|
||||
assert!(g.appearance.items.is_empty(), "the group paints nothing of its own");
|
||||
let ch = g.children().unwrap();
|
||||
assert_eq!(ch.len(), 4, "a path below, the two glyphs, a path above");
|
||||
let (first, last) = (&ch[0], &ch[3]);
|
||||
assert_eq!(first.appearance.items, own[..1], "the item below the characters");
|
||||
assert_eq!(last.appearance.items, own[1..], "the items over them, in their order");
|
||||
for c in [first, last] {
|
||||
assert!(matches!(c.kind, NodeKind::Path { .. }), "{:?}", c.kind);
|
||||
assert!(c.id != t && c.id != g.id, "a fresh id");
|
||||
}
|
||||
assert!(first.id != last.id);
|
||||
for c in &ch[1..3] {
|
||||
assert_eq!(c.appearance.fill_paint(), Paint::solid(Color::BLACK), "the characters keep their own paint");
|
||||
}
|
||||
// The whole-outline paths cover both glyphs.
|
||||
let glyphs = ch[1].geometric_bounds().unwrap().union(ch[2].geometric_bounds().unwrap());
|
||||
assert!(close(first.geometric_bounds().unwrap(), glyphs, 1e-6), "{:?} vs {glyphs:?}", first.geometric_bounds());
|
||||
s.execute("edit.undo", &json!({})).unwrap();
|
||||
assert_eq!(node(&s, t).appearance.items, own, "one undo step brings the type back");
|
||||
}
|
||||
|
||||
/// Colour bitmap glyphs (emoji) become embedded images where they sat; glyphs showing one image
|
||||
/// share its pixels.
|
||||
#[test]
|
||||
|
||||
@@ -12,7 +12,7 @@ fn is_bad_params(r: Result<Value>) -> bool {
|
||||
}
|
||||
|
||||
/// Folder preferences, which a preferences file leaves out.
|
||||
const FOLDERS: [&str; 4] = ["fontsFolder", "pluginsFolder", "recoveryFolder", "templatesFolder"];
|
||||
const FOLDERS: [&str; 6] = ["fontsFolder", "pluginsFolder", "scratchPrimary", "scratchSecondary", "recoveryFolder", "templatesFolder"];
|
||||
|
||||
/// A preferences file holding `prefs`, as `prefs.export` writes one.
|
||||
fn file(prefs: Value) -> String {
|
||||
@@ -46,7 +46,9 @@ fn in_file(s: &Session) -> Value {
|
||||
fn exported_preferences_import_unchanged() {
|
||||
let mut s = changed();
|
||||
s.prefs.fonts_folder = "/fonts/here".into();
|
||||
s.prefs.scratch_primary = "/scratch/here".into();
|
||||
let r = s.execute("prefs.export", &json!({})).unwrap();
|
||||
assert!(!r["data"].as_str().unwrap().contains("/scratch/here"), "a scratch disk folder is not written");
|
||||
let text = r["data"].as_str().unwrap().to_string();
|
||||
let written: Value = serde_json::from_str(&text).unwrap();
|
||||
assert_eq!((written["format"].as_str(), written["version"].as_u64()), (Some(PREFS_FORMAT), Some(1)));
|
||||
@@ -71,6 +73,7 @@ fn exported_preferences_import_unchanged() {
|
||||
assert_eq!(t.doc().unwrap().doc.units, Unit::Millimeters, "the document's units stay as they are");
|
||||
assert_eq!(t.doc().unwrap().history.undo.len(), undo, "no undo step");
|
||||
assert_eq!(t.prefs.fonts_folder, "", "folders are not carried over");
|
||||
assert_eq!(t.prefs.scratch_primary, "Startup", "nor is a scratch disk");
|
||||
|
||||
// Through a file, too.
|
||||
let path = std::env::temp_dir().join(format!("vc-prefs-{}.json", std::process::id())).to_string_lossy().to_string();
|
||||
@@ -96,6 +99,10 @@ fn a_hand_written_file_sets_what_it_names_and_leaves_the_rest() {
|
||||
assert_eq!(s.prefs.keyboard_increment, 3.0);
|
||||
assert_eq!(s.prefs.guide_color, "#abcdef");
|
||||
assert_eq!(s.prefs.history_states, 77, "a preference the file leaves out keeps its value");
|
||||
// A scratch disk choice names no folder, and is read.
|
||||
let choices = file(json!({"scratchPrimary": "None", "scratchSecondary": "Startup"}));
|
||||
assert_eq!(s.execute("prefs.import", &json!({"data": choices})).unwrap(), json!({"imported": 2}));
|
||||
assert_eq!((s.prefs.scratch_primary.as_str(), s.prefs.scratch_secondary.as_str()), ("None", "Startup"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -119,6 +126,8 @@ fn a_bad_preferences_file_is_refused_and_nothing_changes() {
|
||||
(json!({"data": file(json!({"uiAccent": "blue", "historyStates": 5000}))}), "`historyStates` must be a whole number between 5 and 1000"),
|
||||
(json!({"data": file(json!({"uiAccent": "blue", "eyedropper": 5}))}), "`eyedropper` must be an object"),
|
||||
(json!({"data": file(json!({"uiAccent": "blue", "fontsFolder": "/fonts"}))}), "`fontsFolder` names a folder"),
|
||||
(json!({"data": file(json!({"uiAccent": "blue", "scratchPrimary": "/scratch"}))}), "`scratchPrimary` names a folder"),
|
||||
(json!({"data": file(json!({"uiAccent": "blue", "scratchSecondary": " scratch "}))}), "`scratchSecondary` names a folder"),
|
||||
(json!({"data": too_large}), "larger than 1 MB"),
|
||||
(json!({"data": 5}), "`data` must be a string"),
|
||||
(json!({"path": "/a.json", "data": file(json!({"uiAccent": "blue"}))}), "give `path` or `data`"),
|
||||
|
||||
Reference in New Issue
Block a user