Merge remote-tracking branch 'origin/main' into fix/import-document-title

This commit is contained in:
Taha-Mahmoodi
2026-11-04 10:54:57 +04:30
18 changed files with 516 additions and 52 deletions
+32 -3
View File
@@ -89,29 +89,58 @@ fn text_tweaker(s: &mut Session, p: &Value) -> Result<Value> {
let mut rng = Rng::new(whole_or(p, "seed", 0, C)?);
let skip = switch_or(p, "skipSpaces", true, C)?;
let setup = s.doc()?.doc.setup.clone();
// A range given as anything but whole bytes is refused, not read as all of the text.
for k in ["start", "end"] {
if p.get(k).is_some_and(|v| !v.is_null() && v.as_u64().is_none()) {
return Err(bad(C, format!("`{k}` must be a whole number of bytes")));
}
}
// At a caret, all of the object's text.
let ranges = type_ranges(s, p, C, |text, _| Some((0, text.len())))?;
// Each object's changed characters: (byte, its change), worked out before the edit.
let mut plans: Vec<(NodeId, Vec<(usize, CharChange)>)> = vec![];
let mut count = 0;
let (mut seen, mut count) = (0, 0);
for (id, a, b, _) in ranges {
let t = text_ref(s, id)?;
let text = t.plain_text();
let chars: Vec<usize> =
text.char_indices().filter(|&(i, c)| (a..b).contains(&i) && !(skip && (c.is_whitespace() || c.is_control()))).map(|(i, _)| i).collect();
count += chars.len();
if count > MAX_CHARS {
seen += chars.len();
if seen > MAX_CHARS {
return Err(bad(C, format!("too many characters: at most {MAX_CHARS}")));
}
// Each run's end byte, to find the style a character has now.
let ends: Vec<usize> = t
.runs
.iter()
.scan(0, |off, r| {
*off += r.text.len();
Some(*off)
})
.collect();
let n = chars.len();
let mut changes = Vec::with_capacity(n);
let mut run = 0;
for (i, at) in chars.into_iter().enumerate() {
let random = if shape == "random" { unit(&mut rng) } else { 0.0 };
let value = from + (to - from) * amount(shape, i, n, random);
let mut change = CharChange::parse(&json!({ key: value }), C, &setup)?;
change.localize(&t, C)?;
while ends.get(run).is_some_and(|&e| e <= at) {
run += 1;
}
// A character that already has the value is left out, so a run that changes nothing
// makes no step.
if let Some(r) = t.runs.get(run) {
let mut style = r.style.clone();
change.apply(&mut style);
if style == r.style {
continue;
}
}
changes.push((at, change));
}
count += changes.len();
if !changes.is_empty() {
plans.push((id, changes));
}
@@ -62,7 +62,8 @@ fn a_straight_ramp_sizes_each_letter_and_skips_spaces() {
select(&mut s, &[id]);
let n = steps(&s);
let out = s.execute(C, &json!({"attribute": "size", "from": 10, "to": 40})).unwrap();
assert_eq!(out, json!({"count": 4, "ids": [id.0]}));
// `b` is 20 pt already: three characters change.
assert_eq!(out, json!({"count": 3, "ids": [id.0]}));
assert_eq!(steps(&s), n + 1, "one undo step");
let sizes: Vec<(char, f64)> = styles(&s, id).into_iter().map(|(c, st)| (c, st.size)).collect();
assert_eq!(sizes, [('a', 10.0), ('b', 20.0), (' ', 20.0), ('c', 30.0), ('d', 40.0)], "the space keeps its size");
@@ -108,7 +109,8 @@ fn each_object_gets_its_own_ramp() {
let (a, b) = (text(&mut s, "abc"), text(&mut s, "de"));
select(&mut s, &[a, b]);
let out = s.execute(C, &json!({"attribute": "rotation", "from": 0, "to": 30})).unwrap();
assert_eq!(out["count"], json!(5));
// Each first character is upright already.
assert_eq!(out["count"], json!(3));
let turns = |id| styles(&s, id).iter().map(|(_, st)| st.rotation).collect::<Vec<_>>();
assert_eq!((turns(a), turns(b)), (vec![0.0, 15.0, 30.0], vec![0.0, 30.0]));
}
@@ -161,6 +163,19 @@ fn empty_text_and_only_spaces_change_nothing() {
assert_eq!(steps(&s), n, "no step");
}
#[test]
fn characters_that_already_have_the_value_are_left_out() {
let mut s = session();
let id = text(&mut s, "abc");
select(&mut s, &[id]);
let p = json!({"attribute": "rotation", "from": 0, "to": 30});
// The first character already has 0°.
assert_eq!(s.execute(C, &p).unwrap(), json!({"count": 2, "ids": [id.0]}));
let (before, n) = (s.doc().unwrap().doc.clone(), steps(&s));
assert_eq!(s.execute(C, &p).unwrap(), json!({"count": 0, "ids": []}), "again: nothing to change");
assert_eq!((s.doc().unwrap().doc.clone(), steps(&s)), (before, n), "no step");
}
#[test]
fn bad_params_are_refused_without_a_change() {
let mut s = session();
@@ -179,6 +194,9 @@ fn bad_params_are_refused_without_a_change() {
json!({"seed": -1}),
json!({"skipSpaces": "yes"}),
json!({"ids": [999_999]}),
json!({"id": id.0, "start": -1}),
json!({"id": id.0, "start": 1, "end": 1.5}),
json!({"end": "2"}),
] {
assert!(s.execute(C, &p).is_err(), "{p}");
assert_eq!(s.doc().unwrap().doc, before, "{p}");
+1 -1
View File
@@ -201,7 +201,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Break Link to Symbol",
[],
None,
"{ids?|id?} expand selected instances into plain art (with their appearance changes to a dynamic symbol), placed through the symbol's 9-slice guides when it has them → {ids}",
"{ids?|id?} expand selected instances into plain art (with their appearance changes to a dynamic symbol), placed through the symbol's 9-slice guides when it has them, with the instance's opacity mask → {ids}",
has_selection,
symbol_break_link
),
+13 -3
View File
@@ -341,7 +341,8 @@ pub(super) fn symbol_place(s: &mut Session, p: &Value) -> Result<Value> {
/// The plain art of instance `inst` in document space (fresh ids), with the instance's own
/// appearance changes to a dynamic symbol's art when `own`, placed through its symbol's 9-slice
/// guides when it has them.
/// guides when it has them. The instance's opacity mask goes on the art, or on a group around it
/// when the art has a mask of its own.
fn expanded_instance(d: &mut Document, inst: &Node, own: bool) -> Option<Node> {
let NodeKind::SymbolInstance { symbol, xf } = &inst.kind else { return None };
let sym = d.symbols.iter().find(|s| &s.name == symbol)?;
@@ -361,13 +362,21 @@ fn expanded_instance(d: &mut Document, inst: &Node, own: bool) -> Option<Node> {
art.opacity *= inst.opacity;
art.blend = inst.blend;
}
if let Some(mask) = &inst.extras().mask {
if art.extras().mask.is_some() {
let id = d.alloc_id();
art = Node::group(id, vec![Arc::new(art)]);
}
art.extras_mut().mask = Some(mask.clone());
}
Some(art)
}
/// The most objects [`expanded_instance`] makes of instance `inst` in `d` (`own` as there): its
/// symbol's object count with the art of its opacity masks, or
/// [`vectorcraft_doc::NineSliceMap::most_placed`] when it is placed through 9-slice guides, plus
/// the group that opacity or a blending mode adds. 0 for any other object.
/// the group that opacity, a blending mode or the instance's opacity mask adds, plus the art of
/// the instance's opacity mask. 0 for any other object.
fn expanded_bound(d: &Document, inst: &Node, own: bool) -> u64 {
let NodeKind::SymbolInstance { symbol, xf } = &inst.kind else { return 0 };
let Some(sym) = d.symbols.iter().find(|s| &s.name == symbol) else { return 0 };
@@ -378,7 +387,8 @@ fn expanded_bound(d: &Document, inst: &Node, own: bool) -> u64 {
None if dynamic => vectorcraft_doc::symbol_overrides::dynamic_art(&sym.art, inst).count_with_masks() as u64,
None => sym.art.count_with_masks() as u64,
};
most.saturating_add(1)
let mask = inst.extras().mask.as_ref().map_or(0, |m| m.art.count_with_masks() as u64);
most.saturating_add(1).saturating_add(mask)
}
/// Replace instances `ids` with their art ([`expanded_instance`], `own` as there). Returns the
+12 -5
View File
@@ -328,8 +328,9 @@ fn same_text(s: &mut Session, cmd: &str, eq: fn(&CharStyle, &CharStyle) -> bool)
/// Call `f` with each type object among the selected objects and inside them, in selection order,
/// keeping only those [`walk_selectable`] visits: none that is hidden, locked, on a hidden, locked
/// or template layer, or outside the isolated group. A type object inside two selected objects is
/// given twice. The walk stops when `f` returns false.
/// or template layer, or outside the isolated group. A selected layer or sublayer gives the type
/// on it that passes the same test. A type object inside two selected objects is given twice. The
/// walk stops when `f` returns false.
fn each_selected_text(s: &Session, mut f: impl FnMut(NodeId) -> bool) {
fn inside(n: &Node, f: &mut impl FnMut(NodeId) -> bool) -> bool {
if !n.visible || n.locked {
@@ -340,12 +341,18 @@ fn each_selected_text(s: &Session, mut f: impl FnMut(NodeId) -> bool) {
}
n.children().into_iter().flatten().all(|c| inside(c, f))
}
fn from(n: &Node, selectable: &impl Fn(NodeId) -> bool, f: &mut impl FnMut(NodeId) -> bool) -> bool {
if n.is_layer() {
return n.children().into_iter().flatten().all(|c| from(c, selectable, f));
}
!selectable(n.id) || inside(n, f)
}
let Some(st) = s.active() else { return };
let locks = st.doc.locked_artboards();
let selectable = |id| is_selectable(&st.doc, st.isolation, &locks, id);
for id in &st.selection.objects {
if is_selectable(&st.doc, st.isolation, &locks, *id)
&& let Some(n) = st.doc.node(*id)
&& !inside(n, &mut f)
if let Some(n) = st.doc.node(*id)
&& !from(n, &selectable, &mut f)
{
return;
}
+13 -4
View File
@@ -107,7 +107,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Fill Color",
["Select", "Same"],
None,
"{} the objects filled with the first selected object's fill colour (any tint of its global or spot swatch, the same tint with prefs selectSameTintPercent); a member path of a compound path selected first compares as its compound path, except in isolation mode inside that compound path; from a Live Paint face, the faces of its Live Paint group only, and from any other object, no Live Paint face",
"{} the objects filled with the first selected object's fill colour (any tint of its global or spot swatch, the same tint with prefs selectSameTintPercent); a member path of a compound path selected first compares as its compound path, except in isolation mode inside that compound path; from a Live Paint face, the faces of its Live Paint group only, and from any other object, no Live Paint face; every select.same command that compares with the first selected object passes over a selected object that is hidden or locked, on a template layer or outside the isolated group",
has_selection,
|s, _| {
let tint = s.prefs.select_same_tint_percent;
@@ -686,12 +686,21 @@ fn paint_reported(d: &Document, n: &Node) -> bool {
}
/// The object Select > Same compares the others with, and whether isolation mode is inside a
/// compound path. The object is the first selected one, or its compound path when it is a member
/// of one; in isolation mode inside a compound path it is the member path itself.
/// compound path. The object is the first selected one that [`is_selectable`] accepts (none that is
/// hidden, locked, on a hidden, locked or template layer, or outside the isolated group), or its
/// compound path when it is a member of one; in isolation mode inside a compound path it is the
/// member path itself.
fn same_reference<'a>(st: &'a DocState, cmd: &str) -> Result<(&'a Node, bool)> {
let compound = |n: &Node| matches!(n.kind, NodeKind::Compound { .. });
let members = st.isolation.and_then(|i| st.doc.ancestry(i)).is_some_and(|a| a.iter().any(|i| st.doc.node(*i).is_some_and(compound)));
let first = st.selection.objects.first().and_then(|id| st.doc.node(*id)).ok_or_else(|| bad(cmd, "nothing selected"))?;
let locks = st.doc.locked_artboards();
let first = st
.selection
.objects
.iter()
.find(|id| is_selectable(&st.doc, st.isolation, &locks, **id))
.and_then(|id| st.doc.node(*id))
.ok_or_else(|| bad(cmd, "nothing selected"))?;
let refn = match st.doc.parent_of(first.id).and_then(|p| st.doc.node(p)) {
Some(p) if !members && compound(p) => p,
_ => first,
+8 -1
View File
@@ -351,6 +351,8 @@ pub(crate) struct CharChange {
stroke: Option<Paint>,
/// Weight (`strokeWidth`), cap, join, miter limit and dashes of the character stroke.
stroke_opts: StrokeChange,
/// Document points per text-space point for a stroke edit.
stroke_scale: Option<f64>,
underline: Option<bool>,
strikethrough: Option<bool>,
all_caps: Option<bool>,
@@ -641,6 +643,7 @@ impl CharChange {
fill: paint_param(p, "fill", cmd)?,
stroke: paint_param(p, "stroke", cmd)?,
stroke_opts,
stroke_scale: None,
underline: flag("underline"),
strikethrough: flag("strikethrough"),
all_caps: flag("allCaps"),
@@ -723,6 +726,7 @@ impl CharChange {
self.tcy_up_down = self.tcy_up_down.map(|v| local_type_value(t, v, (-1296.0, 1296.0), false, cmd)).transpose()?;
self.tcy_left_right = self.tcy_left_right.map(|v| local_type_value(t, v, (-1296.0, 1296.0), false, cmd)).transpose()?;
self.h_scale = self.h_scale.map(|v| local_type_value(t, v, (1.0, 10000.0), true, cmd)).transpose()?;
self.stroke_scale = Some(vectorcraft_doc::Scaling::factor(t.xf).filter(|k| k.is_finite() && *k > 1e-12).unwrap_or(1.0));
Ok(())
}
@@ -809,10 +813,13 @@ impl CharChange {
st.fill = v.clone();
}
if let Some(v) = &self.stroke {
if !v.is_none() {
super::gradient::run_stroke_weight(st);
}
st.stroke = v.clone();
}
if !self.stroke_opts.is_empty() {
self.stroke_opts.apply_char(st);
self.stroke_opts.apply_char_scaled(st, self.stroke_scale.unwrap_or(1.0));
}
if let Some(v) = self.underline {
st.underline = v;
+53
View File
@@ -1242,6 +1242,59 @@ fn break_link_then_update_redefines_all_instances() {
assert!((bounds(&s, other).center().x - 300.0).abs() < 1e-6);
}
/// A linked opacity mask of a 10 × 10 square at (100, 50).
fn square_mask(s: &mut Session) -> Box<vectorcraft_doc::OpacityMask> {
let doc = std::sync::Arc::make_mut(&mut s.doc_mut().unwrap().doc);
let art = Node::path(doc.alloc_id(), vectorcraft_geom::shapes::rectangle(Rect::new(100.0, 50.0, 110.0, 60.0)), Default::default());
Box::new(vectorcraft_doc::OpacityMask::new(art, true))
}
/// Break Link to Symbol keeps the instance's opacity mask on the art.
#[test]
fn break_link_keeps_the_instances_opacity_mask() {
let mut s = session();
let (inst, _, _) = make_symbol(&mut s);
let m = square_mask(&mut s);
std::sync::Arc::make_mut(&mut s.doc_mut().unwrap().doc).node_mut(inst).unwrap().extras_mut().mask = Some(m.clone());
let r = s.execute("symbol.breakLink", &json!({"ids": [inst.0]})).unwrap();
let art = node(&s, NodeId(r["ids"][0].as_u64().unwrap()));
assert!(matches!(art.kind, NodeKind::Path { .. }), "{}", art.kind_label());
assert_eq!(art.extras().mask, Some(m), "the art keeps the mask");
}
/// When the symbol's art has an opacity mask of its own, Break Link puts the instance's mask on a
/// group around the art, and the art keeps its own.
#[test]
fn break_link_puts_the_instances_mask_on_a_group_around_masked_art() {
let mut s = session();
let (inst, name, _) = make_symbol(&mut s);
let (own, m) = (square_mask(&mut s), square_mask(&mut s));
let doc = std::sync::Arc::make_mut(&mut s.doc_mut().unwrap().doc);
let sym = doc.symbols.iter_mut().find(|s| s.name == name).unwrap();
std::sync::Arc::make_mut(&mut sym.art).extras_mut().mask = Some(own);
doc.node_mut(inst).unwrap().extras_mut().mask = Some(m.clone());
let r = s.execute("symbol.breakLink", &json!({"ids": [inst.0]})).unwrap();
let art = node(&s, NodeId(r["ids"][0].as_u64().unwrap()));
let NodeKind::Group { children, .. } = &art.kind else { panic!("a group around the art: {}", art.kind_label()) };
assert_eq!(art.extras().mask, Some(m), "the group holds the instance's mask");
assert!(children.len() == 1 && children[0].extras().mask.is_some(), "the art keeps its own mask");
}
/// The art of the instance's opacity mask counts against Break Link's object limit: an instance
/// whose mask holds more than a million objects stays an instance.
#[test]
fn break_link_counts_the_instances_mask_art() {
let mut s = session();
let (inst, _, _) = make_symbol(&mut s);
let doc = std::sync::Arc::make_mut(&mut s.doc_mut().unwrap().doc);
let square =
std::sync::Arc::new(Node::path(doc.alloc_id(), vectorcraft_geom::shapes::rectangle(Rect::new(100.0, 50.0, 110.0, 60.0)), Default::default()));
let art = Node::group(doc.alloc_id(), vec![square; 1_000_000]);
doc.node_mut(inst).unwrap().extras_mut().mask = Some(Box::new(vectorcraft_doc::OpacityMask::new(art, true)));
assert!(s.execute("symbol.breakLink", &json!({"ids": [inst.0]})).is_err(), "too many objects");
assert!(matches!(node(&s, inst).kind, NodeKind::SymbolInstance { .. }), "it stays an instance");
}
#[test]
fn delete_duplicate_and_replace_symbols() {
let mut s = session();
+15
View File
@@ -91,6 +91,21 @@ fn range_stroke_options_split_runs() {
assert!(s.execute("text.setRangeStyle", &json!({"id": id.0, "strokeOptions": 3})).is_err());
}
#[test]
fn range_stroke_gains_a_default_weight_and_scales_explicit_weight() {
let mut s = session();
let id = NodeId(run(&mut s, "text.create", json!({"x": 10, "y": 50, "text": "ABCD"}))["id"].as_u64().unwrap());
let weights = |s: &Session| text(s, id).runs.iter().map(|r| r.style.stroke_width).collect::<Vec<_>>();
run(&mut s, "text.setRangeStyle", json!({"id": id.0, "start": 0, "end": 2, "stroke": "#ff0000"}));
assert_eq!(weights(&s), [1.0, 0.0], "a newly painted range has a visible default stroke");
run(&mut s, "object.scale", json!({"ids": [id.0], "sx": 200, "sy": 200}));
run(&mut s, "text.setRangeStyle", json!({"id": id.0, "start": 0, "end": 2, "strokeWidth": 2.0}));
assert_eq!(weights(&s), [1.0, 0.0], "two document points become one text-space point at 200% scale");
run(&mut s, "text.setRangeStyle", json!({"id": id.0, "start": 2, "end": 4, "stroke": "#0000ff", "strokeWidth": 4.0}));
assert_eq!(weights(&s), [1.0, 2.0], "a different range receives its scaled weight");
}
#[test]
fn eyedropper_and_outlines_carry_the_character_stroke() {
let mut s = session();
+82
View File
@@ -1995,6 +1995,36 @@ fn select_same_font_skips_type_that_cannot_be_selected() {
assert_eq!(selected(&s), vec![g]);
}
/// A selected layer gives the type on it that can be selected as the reference of the font Same
/// commands: a hidden or locked layer gives none.
#[test]
fn select_same_font_takes_its_reference_from_the_type_on_a_selected_layer() {
let mut s = session();
let typed =
|s: &mut Session, y: f64, font: &str| id_of(&s.execute("text.create", &json!({"x": 0, "y": y, "text": "type", "font": font})).unwrap());
let arial = typed(&mut s, 20.0, "Arial");
let courier = typed(&mut s, 60.0, "Courier");
let l2 = id_of(&s.execute("layer.new", &json!({"top": true})).unwrap());
let on_layer = typed(&mut s, 100.0, "Courier");
sel(&mut s, &[l2]);
assert_eq!(s.execute("select.same.fontFamily", &json!({})).unwrap()["count"], 2);
let mut got = selected(&s);
got.sort();
let mut want = vec![courier, on_layer];
want.sort();
assert_eq!(got, want);
assert!(!selected(&s).contains(&arial));
for (off, on) in [
(json!({"id": l2.0, "visible": false}), json!({"id": l2.0, "visible": true})),
(json!({"id": l2.0, "locked": true}), json!({"id": l2.0, "locked": false})),
] {
s.execute("layer.setProps", &off).unwrap();
sel(&mut s, &[l2]);
assert!(s.execute("select.same.fontFamily", &json!({})).is_err(), "{off}");
s.execute("layer.setProps", &on).unwrap();
}
}
/// Select › Same › Text Fill & Stroke Color selects the type with characters whose fill and stroke
/// both match the first character of the selected type: the same fill with another stroke, or the
/// same stroke with another fill, is left out, and in type with several runs one run has to match
@@ -2185,6 +2215,58 @@ fn select_same_matches_compound_paths_on_their_own_paint() {
assert_eq!(same(&mut s, outer, "select.same.shapeType"), vec![outer, inner]);
}
/// Select > Same compares the other objects with the first selected object that can be selected:
/// one that is hidden or locked, on a template layer, or outside the isolated group is passed
/// over. A selection that holds no such object has nothing to compare with.
#[test]
fn select_same_skips_a_reference_that_cannot_be_selected() {
let mut s = session();
let [red, blue, other_blue, other_red, grouped_red] = [0.0, 20.0, 40.0, 60.0, 80.0].map(|x| rect(&mut s, x, 0.0, 10.0, 10.0));
for id in [red, other_red, grouped_red] {
fill(&mut s, id, "#ff0000");
}
for id in [blue, other_blue] {
fill(&mut s, id, "#0000ff");
}
let same = |s: &mut Session, from: &[NodeId], cmd: &str| {
sel(s, from);
assert_eq!(selected(s), from, "select.set keeps {from:?}");
s.execute(cmd, &json!({})).unwrap();
let mut v = selected(s);
v.sort();
v
};
// A hidden or locked red path selected first is not the reference.
for (on, off) in [
(json!({"id": red.0, "visible": false}), json!({"id": red.0, "visible": true})),
(json!({"id": red.0, "locked": true}), json!({"id": red.0, "locked": false})),
] {
s.execute("layer.setProps", &on).unwrap();
for cmd in ["select.same.fillColor", "select.same.fillAndStroke"] {
assert_eq!(same(&mut s, &[red, blue], cmd), vec![blue, other_blue], "{cmd} {on}");
}
s.execute("layer.setProps", &off).unwrap();
}
// A red path on a template layer is not the reference.
let l2 = id_of(&s.execute("layer.new", &json!({"top": true})).unwrap());
let on_template = rect(&mut s, 100.0, 0.0, 10.0, 10.0);
fill(&mut s, on_template, "#ff0000");
s.execute("layer.setProps", &json!({"id": l2.0, "template": true})).unwrap();
assert_eq!(same(&mut s, &[on_template, blue], "select.same.fillColor"), vec![blue, other_blue]);
// A red path outside the isolated group is not the reference.
sel(&mut s, &[blue, grouped_red]);
let g = id_of(&s.execute("object.group", &json!({})).unwrap());
s.execute("object.isolate", &json!({"id": g.0})).unwrap();
assert_eq!(same(&mut s, &[other_red, blue], "select.same.fillColor"), vec![blue]);
s.execute("object.exitIsolation", &json!({})).unwrap();
// With no object that can be selected, there is nothing to compare with, and the selection stays.
s.execute("layer.setProps", &json!({"id": red.0, "visible": false})).unwrap();
sel(&mut s, &[red, on_template]);
let r = s.execute("select.same.fillColor", &json!({}));
assert!(matches!(&r, Err(EngineError::BadParams { msg, .. }) if *msg == "nothing selected"), "{r:?}");
assert_eq!(selected(&s), vec![red, on_template]);
}
/// Select > Same > Fill Color and Fill & Stroke from a Live Paint face select the faces of that
/// Live Paint group with the same fill, and nothing outside it. From an object outside every Live
/// Paint group, they select no face.
+26
View File
@@ -286,6 +286,32 @@ fn select_same_style_and_attribute_from_a_compound_path_member() {
assert!(s.execute("select.same.graphicStyle", &json!({})).is_err());
}
/// Select > Same > Graphic Style and Appearance Attribute pass over a hidden object selected first
/// and compare the other objects with the next one.
#[test]
fn select_same_style_and_attribute_skip_a_hidden_reference() {
let mut s = session();
let a = rect(&mut s, 10.0);
set_fill(&mut s, a, "#ff0000");
run(&mut s, "effect.apply", json!({"effect": "distort.roughen"}));
run(&mut s, "graphicStyle.new", json!({"name": "Rough"}));
run(&mut s, "graphicStyle.apply", json!({"name": "Rough"}));
let b = rect(&mut s, 100.0);
run(&mut s, "graphicStyle.apply", json!({"name": "Rough"}));
let hidden = rect(&mut s, 200.0);
set_fill(&mut s, hidden, "#0000ff");
run(&mut s, "graphicStyle.new", json!({"name": "Blue"}));
run(&mut s, "graphicStyle.apply", json!({"name": "Blue"}));
rect(&mut s, 300.0);
run(&mut s, "graphicStyle.apply", json!({"name": "Blue"}));
run(&mut s, "layer.setProps", json!({"id": hidden.0, "visible": false}));
for cmd in ["select.same.graphicStyle", "select.same.appearanceAttribute"] {
run(&mut s, "select.set", json!({"ids": [hidden.0, a.0]}));
run(&mut s, cmd, json!({}));
assert_eq!(s.doc().unwrap().selection.objects, vec![a, b], "{cmd}");
}
}
#[test]
fn document_info_lists_style_names() {
let mut s = session();