mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-16 14:17:14 +00:00
Graphs: Invert, Complement and stroke weights of a design's art alone leave the new-art defaults
With only the art of a graph design in a series given or selected, paint.invert and paint.complement without an item recolored that art and remembered its new color, and stroke.set with a weight set the stroke weight for new art. Invert and Complement now leave the art out, as they do with an item, also when they are given the whole graph or a series group, and with only design art they change nothing. stroke.set with only design art leaves the weight for new art as it is. An item the art has no row of that kind for is still an error in the commands that leave the art out, as on any other object, and so is a bad aligned or target param. Without stroke, paint.editGradient and paint.setGradientGeom read the kind of an item named on design art alone from that art's row.
This commit is contained in:
@@ -451,6 +451,20 @@ pub(crate) fn drop_design_art(d: &Document, mut ids: Vec<NodeId>) -> Vec<NodeId>
|
||||
ids
|
||||
}
|
||||
|
||||
/// [`drop_design_art`] for an edit of the `item` rows of `ids` (`fill`: fill rows): an explicit `item` that a design's
|
||||
/// art has no row of that kind for is still an error of `cmd`, as on any other object.
|
||||
pub(crate) fn drop_design_art_rows(s: &Session, ids: Vec<NodeId>, item: ItemTarget, fill: bool, cmd: &str) -> Result<Vec<NodeId>> {
|
||||
let d = &s.doc()?.doc;
|
||||
for (id, it) in ids.iter().zip(item.per_target(s, &ids)) {
|
||||
if let (Some(it), Some(n)) = (it, d.node(*id))
|
||||
&& super::graph::is_design_art(d, *id)
|
||||
{
|
||||
it.resolve(&n.appearance, fill, cmd)?;
|
||||
}
|
||||
}
|
||||
Ok(drop_design_art(d, ids))
|
||||
}
|
||||
|
||||
/// The outermost art of graph designs drawn in graph series inside `roots`: the objects directly in a series group that
|
||||
/// [`super::graph::is_design_art`] accepts.
|
||||
pub(crate) fn design_art_in(d: &Document, roots: &[NodeId]) -> Vec<NodeId> {
|
||||
@@ -633,7 +647,10 @@ pub(crate) fn edits_stroke(s: &Session, p: &Value, item: ItemTarget, default: bo
|
||||
}
|
||||
let ItemTarget::Item { index, .. } = item else { return Ok(default) };
|
||||
let d = &s.doc()?.doc;
|
||||
let ids = drop_design_art(d, appearance_targets(s, p)?);
|
||||
let all = appearance_targets(s, p)?;
|
||||
// The art of a graph design is left out, unless it is all there is: the item is then a row of that art.
|
||||
let kept = drop_design_art(d, all.clone());
|
||||
let ids = if kept.is_empty() { all } else { kept };
|
||||
Ok(ids.get(item.anchor(s, &ids)).and_then(|id| d.node(*id)?.appearance.items.get(index)).map_or(default, |it| !it.is_fill()))
|
||||
}
|
||||
|
||||
|
||||
@@ -534,7 +534,7 @@ fn edit_gradient(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
// Objects were given or selected, even when all of them are graph design art left out below: the stroke mode is then
|
||||
// not one for new art.
|
||||
let selected = !ids.is_empty();
|
||||
let ids = super::appearance::drop_design_art(&s.doc()?.doc, ids);
|
||||
let ids = super::appearance::drop_design_art_rows(s, ids, item, !stroke, C)?;
|
||||
// How the gradient lies on a stroke (the panel's Stroke buttons).
|
||||
let mode = match str_param(p, "strokeMode") {
|
||||
None => None,
|
||||
@@ -768,7 +768,7 @@ fn set_gradient_geom(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
if targets.is_empty() {
|
||||
return Err(EngineError::Other("nothing selected".into()));
|
||||
}
|
||||
let targets = super::appearance::drop_design_art(&s.doc()?.doc, targets);
|
||||
let targets = super::appearance::drop_design_art_rows(s, targets, item, !stroke, C)?;
|
||||
let model = super::paint::new_color_model(s, &Value::Null);
|
||||
edit_items(s, &targets, item, C, "Gradient", !stroke, |n, index| {
|
||||
if index.is_none()
|
||||
|
||||
@@ -454,7 +454,7 @@ fn an_edit_of_a_graph_designs_art_is_lost_when_the_graph_is_drawn_again() {
|
||||
/// it, and edit the other objects they are given.
|
||||
#[test]
|
||||
fn paint_commands_leave_a_graph_designs_art_out() {
|
||||
let (mut s, _, copy, art, mark) = design_art();
|
||||
let (mut s, graph, copy, art, mark) = design_art();
|
||||
let fill = top_row(&s, art, true);
|
||||
let commands = [
|
||||
("stroke.set", json!({"weight": 5})),
|
||||
@@ -466,6 +466,7 @@ fn paint_commands_leave_a_graph_designs_art_out() {
|
||||
("paint.swap", json!({})),
|
||||
("paint.default", json!({})),
|
||||
("paint.invert", json!({"item": fill, "stroke": false})),
|
||||
("paint.invert", json!({})),
|
||||
];
|
||||
let (copy_was, art_was) = (look(&s, copy), look(&s, art));
|
||||
for (cmd, p) in &commands {
|
||||
@@ -489,6 +490,11 @@ fn paint_commands_leave_a_graph_designs_art_out() {
|
||||
s.execute("select.set", &json!({"ids": [art.0]})).unwrap();
|
||||
s.execute("stroke.set", &json!({"weight": 5})).unwrap();
|
||||
assert_eq!(look(&s, art), art_was);
|
||||
// Given the whole graph, Invert recolors the marks and leaves the art.
|
||||
let mark_was = look(&s, mark);
|
||||
s.execute("paint.invert", &json!({"ids": [graph.0]})).unwrap();
|
||||
assert_eq!(look(&s, art), art_was);
|
||||
assert_ne!(look(&s, mark), mark_was);
|
||||
// A freeform gradient point is refused on the art alone.
|
||||
refused_on_design_art(&mut s, "paint.freeform.addPoint", json!({"ids": [art.0], "at": [0, 0]}));
|
||||
}
|
||||
@@ -524,6 +530,10 @@ fn paint_edits_of_design_art_alone_leave_the_defaults() {
|
||||
("paint.default", json!({})),
|
||||
("paint.invert", json!({"item": fill, "stroke": false})),
|
||||
("paint.complement", json!({"item": fill, "stroke": false})),
|
||||
("paint.invert", json!({})),
|
||||
("paint.complement", json!({"stroke": true})),
|
||||
("stroke.set", json!({"weight": 7})),
|
||||
("stroke.weightUp", json!({})),
|
||||
];
|
||||
for (cmd, p) in &commands {
|
||||
let was = defaults(&s);
|
||||
@@ -538,6 +548,40 @@ fn paint_edits_of_design_art_alone_leave_the_defaults() {
|
||||
assert_eq!(defaults(&s), was, "{cmd}, selected");
|
||||
s.execute("select.set", &json!({"ids": []})).unwrap();
|
||||
}
|
||||
// A bad `item`, `aligned` or `target` is still an error with only design art given.
|
||||
for bad in [
|
||||
json!({"ids": [art.0], "item": "top"}),
|
||||
json!({"ids": [art.0], "item": fill, "aligned": "yes"}),
|
||||
json!({"ids": [art.0], "item": fill, "target": "nowhere"}),
|
||||
] {
|
||||
assert!(s.execute("paint.invert", &bad).is_err(), "{bad}");
|
||||
}
|
||||
// So is an `item` the art has no row for, in each command that leaves the art out.
|
||||
let steps = s.doc().unwrap().history.undo.len();
|
||||
for (cmd, p) in [
|
||||
("paint.invert", json!({})),
|
||||
("stroke.set", json!({"weight": 2})),
|
||||
("stroke.weightUp", json!({})),
|
||||
("stroke.setAdvanced", json!({"swapArrows": true})),
|
||||
("paint.editGradient", json!({"kind": "linear"})),
|
||||
("paint.setGradientGeom", json!({"start": [0, 0], "end": [50, 50]})),
|
||||
("object.setOverprint", json!({"fill": true})),
|
||||
] {
|
||||
let mut q = p.clone();
|
||||
q["ids"] = json!([art.0]);
|
||||
q["item"] = json!(99);
|
||||
assert!(s.execute(cmd, &q).is_err(), "{cmd}");
|
||||
}
|
||||
// The art's stroke row named without `stroke` is a stroke row: the gradient commands succeed and change nothing.
|
||||
let stroke_row = top_row(&s, art, false);
|
||||
for p in [json!({"kind": "linear"}), json!({"start": [0, 0], "end": [50, 50]})] {
|
||||
let cmd = if p.get("kind").is_some() { "paint.editGradient" } else { "paint.setGradientGeom" };
|
||||
let mut q = p.clone();
|
||||
q["ids"] = json!([art.0]);
|
||||
q["item"] = json!(stroke_row);
|
||||
s.execute(cmd, &q).unwrap();
|
||||
}
|
||||
assert_eq!(s.doc().unwrap().history.undo.len(), steps);
|
||||
// With nothing selected, the swap still swaps the defaults.
|
||||
let was = defaults(&s);
|
||||
s.execute("paint.swap", &json!({})).unwrap();
|
||||
|
||||
@@ -126,14 +126,21 @@ fn kinds(p: &Value, cmd: &str, keys: [&str; 2]) -> Result<Vec<(bool, bool)>> {
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Each kind's item target and objects: (fill?, item, ids).
|
||||
fn aims(s: &Session, p: &Value, cmd: &str, kinds: impl IntoIterator<Item = bool>) -> Result<Vec<(bool, ItemTarget, Vec<NodeId>)>> {
|
||||
/// Each kind's item target and objects: (fill?, item, ids). With `edit`, an explicit item that the graph design art left
|
||||
/// out has no row of that kind for is an error, as when the edit resolves it on the other objects.
|
||||
fn aims(s: &Session, p: &Value, cmd: &str, kinds: impl IntoIterator<Item = bool>, edit: bool) -> Result<Vec<(bool, ItemTarget, Vec<NodeId>)>> {
|
||||
let item = item_target(s, p, cmd)?;
|
||||
kinds
|
||||
.into_iter()
|
||||
.map(|fill| {
|
||||
let it = item.of_kind(s, fill);
|
||||
Ok((fill, it, super::appearance::drop_design_art(&s.doc()?.doc, it.targets(s, p)?)))
|
||||
let ids = it.targets(s, p)?;
|
||||
let ids = if edit {
|
||||
super::appearance::drop_design_art_rows(s, ids, it, fill, cmd)?
|
||||
} else {
|
||||
super::appearance::drop_design_art(&s.doc()?.doc, ids)
|
||||
};
|
||||
Ok((fill, it, ids))
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
@@ -159,7 +166,7 @@ pub(super) type OverprintJob = ((bool, ItemTarget, Vec<NodeId>), bool);
|
||||
/// `object.setOverprint` aims.
|
||||
pub(super) fn overprint_jobs(s: &Session, p: &Value, cmd: &str, keys: [&str; 2]) -> Result<Vec<OverprintJob>> {
|
||||
let kinds = kinds(p, cmd, keys)?;
|
||||
Ok(aims(s, p, cmd, kinds.iter().map(|k| k.0))?.into_iter().zip(kinds.iter().map(|k| k.1)).collect())
|
||||
Ok(aims(s, p, cmd, kinds.iter().map(|k| k.0), true)?.into_iter().zip(kinds.iter().map(|k| k.1)).collect())
|
||||
}
|
||||
|
||||
/// Apply `jobs` to `d`, adding the objects changed to `changed`.
|
||||
@@ -198,7 +205,7 @@ fn attributes(s: &Session, p: &Value) -> Result<AttributesInfo> {
|
||||
let d = &s.doc()?.doc;
|
||||
let mut info = AttributesInfo { ids: targets(s, p)?, recent_urls: s.recent_urls.clone(), ..Default::default() };
|
||||
super::attributes::fill_info(d, &mut info);
|
||||
for (fill, item, ids) in aims(s, p, C, [true, false])? {
|
||||
for (fill, item, ids) in aims(s, p, C, [true, false], false)? {
|
||||
let mut all =
|
||||
ids.iter().filter_map(|id| d.node(*id)).filter_map(|n| Some(flags(n, fill, item.resolve(&n.appearance, fill, C).ok()?))).flatten();
|
||||
let same = all.next().and_then(|first| all.all(|b| b == first).then_some(first));
|
||||
|
||||
@@ -1082,9 +1082,17 @@ fn proxy_recolor(s: &mut Session, p: &Value, cmd: &str, label: &str, f: &dyn Fn(
|
||||
return Ok(json!({ "changed": changed as usize }));
|
||||
}
|
||||
let item = item_target(s, p, cmd)?.of_kind(s, !stroke);
|
||||
// Read before the check below, so that a bad param (such as `target`, or an explicit `item` the art has no row
|
||||
// for) is still an error.
|
||||
let targets = super::appearance::drop_design_art_rows(s, item.targets(s, p)?, item, !stroke, cmd)?;
|
||||
let ids = super::appearance::drop_design_art(&s.doc()?.doc, ids);
|
||||
// Only design art was given or selected: nothing changes, the defaults and remembered colors included.
|
||||
if ids.is_empty() {
|
||||
return Ok(json!({ "changed": 0 }));
|
||||
}
|
||||
let (r, shown_item) = match item {
|
||||
ItemTarget::Item { index, .. } => {
|
||||
let ids = super::appearance::drop_design_art(&s.doc()?.doc, item.targets(s, p)?);
|
||||
let ids = targets;
|
||||
// Only design art was given or selected: nothing changes, the remembered colors included.
|
||||
if ids.is_empty() {
|
||||
return Ok(json!({ "changed": 0 }));
|
||||
@@ -1099,12 +1107,17 @@ fn proxy_recolor(s: &mut Session, p: &Value, cmd: &str, label: &str, f: &dyn Fn(
|
||||
(json!({ "changed": changed }), Some(index))
|
||||
}
|
||||
// The proxy recolors its paints, including a colorized image's fill, without changing image pixels or pattern tiles.
|
||||
// Design art inside a given graph or series group is left out too.
|
||||
ItemTarget::Top => {
|
||||
let q = json!({"fill": !stroke, "stroke": stroke, "includeImages": false, "includePatterns": false, "ids": ids.iter().map(|i| i.0).collect::<Vec<_>>()});
|
||||
let leaves = targets;
|
||||
if leaves.is_empty() {
|
||||
return Ok(json!({ "changed": 0 }));
|
||||
}
|
||||
let q = json!({"fill": !stroke, "stroke": stroke, "includeImages": false, "includePatterns": false, "ids": leaves.iter().map(|i| i.0).collect::<Vec<_>>()});
|
||||
(super::colorcmds::recolor(s, &q, cmd, label, f)?, None)
|
||||
}
|
||||
};
|
||||
let shown_ids = if shown_item.is_some() { ids } else { leaf_targets(s, &ids)? };
|
||||
let shown_ids = if shown_item.is_some() { ids } else { super::appearance::drop_design_art(&s.doc()?.doc, leaf_targets(s, &ids)?) };
|
||||
if let Some(shown) = shown_ids.first().and_then(|id| s.doc().ok()?.doc.node(*id).map(|n| proxy_paint(n, stroke, shown_item))) {
|
||||
s.remember_paint(&shown);
|
||||
}
|
||||
|
||||
@@ -234,8 +234,11 @@ fn stroke_set(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let item = item_target(s, p, C)?.of_kind(s, false);
|
||||
let mut ids = if item == ItemTarget::Top { own_stroke_or_leaves(s, p)? } else { item.targets(s, p)? };
|
||||
let new_art = no_targets(&ids, p);
|
||||
let given = !ids.is_empty();
|
||||
// The art of a graph design in a series keeps the design's stroke.
|
||||
ids = super::appearance::drop_design_art(&s.doc()?.doc, ids);
|
||||
ids = super::appearance::drop_design_art_rows(s, ids, item, false, C)?;
|
||||
// With only design art, the weight for new art stays as it is too.
|
||||
let only_design_art = given && ids.is_empty();
|
||||
if item == ItemTarget::Top {
|
||||
// Images and symbol instances take no stroke from the panel.
|
||||
let d = &s.doc()?.doc;
|
||||
@@ -327,7 +330,9 @@ fn stroke_set(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
})?;
|
||||
// Commit the new-art template only after the complete request is validated
|
||||
// and the selected artwork edit has succeeded.
|
||||
if let Some(w) = change.weight {
|
||||
if let Some(w) = change.weight
|
||||
&& !only_design_art
|
||||
{
|
||||
s.paint.stroke_width = w;
|
||||
}
|
||||
if new_art && let Some(st) = s.new_art_stroke_mut() {
|
||||
@@ -370,7 +375,7 @@ fn stroke_step(s: &mut Session, p: &Value, up: bool) -> Result<Value> {
|
||||
}
|
||||
return Ok(json!({"objects": 0}));
|
||||
}
|
||||
let ids = super::appearance::drop_design_art(&s.doc()?.doc, ids);
|
||||
let ids = super::appearance::drop_design_art_rows(s, ids, item, false, c)?;
|
||||
let label = if up { "Stroke Weight Up" } else { "Stroke Weight Down" };
|
||||
edit_items(s, &ids, item, c, label, false, |n, index| {
|
||||
if index.is_none()
|
||||
@@ -515,7 +520,7 @@ fn stroke_advanced(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let ids = item.targets(s, p)?;
|
||||
let new_art = no_targets(&ids, p);
|
||||
// The art of a graph design in a series keeps the design's stroke.
|
||||
let ids = super::appearance::drop_design_art(&s.doc()?.doc, ids);
|
||||
let ids = super::appearance::drop_design_art_rows(s, ids, item, false, C)?;
|
||||
let arrows_and_profile = |st: &mut StrokeLayer| {
|
||||
if let Some(sc) = scale {
|
||||
st.arrow_scale = sc;
|
||||
|
||||
+4
-4
@@ -830,11 +830,11 @@ design art is selected or given), `threeD.mapGraphic`,
|
||||
`graphicStyle.apply`, `graphicStyle.addFromLibrary` with `apply`, `graphicStyle.breakLink`, `transparency.set`, the
|
||||
`paint.freeform.*` commands that edit points and lines, and `appearance.copyFrom` as the target.
|
||||
`appearance.transfer` with design art as its `target`, or as its `source` without `copy`, is an error.
|
||||
`paint.setFill`, `paint.setStroke`, `paint.swap`, `paint.default`, `paint.invert` and `paint.complement` with an
|
||||
`item`, `stroke.set`, `stroke.weightUp`, `stroke.weightDown`, `stroke.setAdvanced`, `paint.editGradient`,
|
||||
`paint.setFill`, `paint.setStroke`, `paint.swap`, `paint.default`, `paint.invert`, `paint.complement`,
|
||||
`stroke.set`, `stroke.weightUp`, `stroke.weightDown`, `stroke.setAdvanced`, `paint.editGradient`,
|
||||
`paint.setGradientGeom` and `object.setOverprint` leave the art out without an error. When all their objects are design art,
|
||||
`paint.editGradient`, `paint.swap`, `paint.default`, and `paint.invert` and `paint.complement` with an `item` also leave
|
||||
the paint for new art and the remembered colors as they are. When the first selected object is design art, the commands
|
||||
`paint.editGradient`, `paint.swap`, `paint.default`, `paint.invert`, `paint.complement` and `stroke.set` also leave
|
||||
the paint and stroke weight for new art and the remembered colors as they are. When the first selected object is design art, the commands
|
||||
do not use the Appearance panel's active row. To change the art, edit the design with `graph.design`.
|
||||
|
||||
The graph also stores a paint or stroke weight that one of these commands changes on the topmost visible fill or stroke
|
||||
|
||||
Reference in New Issue
Block a user