VectorCraft: An open-source, vector art tool written by scratch in pure Rust
Merge wp/F2: knockout groups, knockout shape, page groups (M3.46-M3.48)
bflatasticabd77d58b063
diff --cc crates/doc/src/lib.rsindex d62a52dff,1cfce9c65..a52743143--- a/crates/doc/src/lib.rs+++ b/crates/doc/src/lib.rs@@@ -259,44 -260,6 +260,44 @@@ impl Default for GridPrefspub struct GraphicStyle {pub name: String,pub appearance: Appearance,+ /// Stable id linked objects refer to ([`Node::graphic_style`]); 0 until first needed (styles+ /// from older files get one when an object is first linked to them).+ #[serde(default, skip_serializing_if = "skip::is_default")]+ pub id: u32,+ #[serde(default = "one", skip_serializing_if = "skip::is_one")]+ pub opacity: f32,+ #[serde(default, skip_serializing_if = "skip::is_default")]+ pub blend: vectorcraft_color::BlendMode,+ #[serde(default, skip_serializing_if = "skip::is_default")]+ pub isolate: bool,+ #[serde(default, skip_serializing_if = "skip::is_default")]- pub knockout: bool,++ pub knockout: Knockout,+}++fn one() -> f32 {+ 1.0+}++/// The name of the style new documents list first (Sort by Name keeps it first).+pub const DEFAULT_GRAPHIC_STYLE: &str = "Default Graphic Style";++impl GraphicStyle {+ /// A style with `appearance` and default transparency (no id yet).+ pub fn new(name: impl Into<String>, appearance: Appearance) -> Self {- Self { name: name.into(), appearance, id: 0, opacity: 1.0, blend: Default::default(), isolate: false, knockout: false }++ Self { name: name.into(), appearance, id: 0, opacity: 1.0, blend: Default::default(), isolate: false, knockout: Knockout::Neutral }+ }+ /// A style capturing `n`'s transparency and `appearance`.+ pub fn of(name: impl Into<String>, appearance: Appearance, n: &Node) -> Self {+ Self { opacity: n.opacity, blend: n.blend, isolate: n.isolate, knockout: n.knockout, ..Self::new(name, appearance) }+ }+ /// Give `n` this style's transparency.+ pub fn apply_transparency(&self, n: &mut Node) {+ (n.opacity, n.blend, n.isolate, n.knockout) = (self.opacity, self.blend, self.isolate, self.knockout);+ }+ /// Does `n` have this style's transparency?+ pub fn transparency_matches(&self, n: &Node) -> bool {+ (n.opacity, n.blend, n.isolate, n.knockout) == (self.opacity, self.blend, self.isolate, self.knockout)+ }}/// A symbol definition.diff --cc crates/engine/src/cmd/style.rsindex 08adc46c3,6e8d80b0d..323cde949--- a/crates/engine/src/cmd/style.rs+++ b/crates/engine/src/cmd/style.rs@@@ -15,88 -7,10 +15,88 @@@ use crate::EngineErrorpub fn specs() -> Vec<CommandSpec> {vec![- cmd!("graphicStyle.apply", "Apply Graphic Style", ["Window", "Graphic Styles"], None, "{name}", has_selection, style_apply),- cmd!("graphicStyle.new", "New Graphic Style", ["Window", "Graphic Styles"], None, "{name?} from the selection", has_selection, style_new),- cmd!("graphicStyle.delete", "Delete Graphic Style", ["Window", "Graphic Styles"], None, "{name}", has_doc, style_delete),- cmd!("graphicStyle.duplicate", "Duplicate Graphic Style", ["Window", "Graphic Styles"], None, "{name}", has_doc, style_duplicate),+ cmd!(+ "graphicStyle.apply",+ "Apply Graphic Style",+ ["Window", "Graphic Styles"],+ None,+ "{name, add?: bool, ids?} give the objects (default: the selection; a group's contents) the style's appearance, and themselves its opacity, blend mode, isolate and knockout, and link them to it; add: true (Alt-click) adds its fills, strokes and effects on top of the existing appearance instead and unlinks",+ has_doc,+ style_apply+ ),+ cmd!(+ "graphicStyle.new",+ "New Graphic Style",+ ["Window", "Graphic Styles"],+ None,+ "{name?, id?} a style from object `id` or the first selected object: its appearance, opacity, blend mode, isolate and knockout (a group without fills or strokes of its own lends its topmost object's, type its characters'); links the object. Names are made unique → {name}",+ has_doc,+ style_new+ ),+ cmd!(+ "graphicStyle.delete",+ "Delete Graphic Style",+ ["Window", "Graphic Styles"],+ None,+ "{name} | {names: [name…]} delete styles; their objects keep their look but are unlinked",+ has_doc,+ style_delete+ ),+ cmd!("graphicStyle.duplicate", "Duplicate Graphic Style", ["Window", "Graphic Styles"], None, "{name} → {name}", has_doc, style_duplicate),+ cmd!(+ query "graphicStyle.list",+ "List Graphic Styles",+ [],+ None,- "{} → {styles: [{id, name, fill, stroke, strokeWidth, fills, strokes, effects: [effect id…], opacity: 0..100, blend, isolate, knockout, linked: [object ids]}], selected: the style the first selected object is linked to, or null}",++ "{} → {styles: [{id, name, fill, stroke, strokeWidth, fills, strokes, effects: [effect id…], opacity: 0..100, blend, isolate, knockout: \"on\"|\"off\"|\"neutral\", linked: [object ids]}], selected: the style the first selected object is linked to, or null}",+ has_doc,+ style_list+ ),+ cmd!(+ "graphicStyle.redefine",+ "Redefine Graphic Style",+ ["Window", "Appearance"],+ None,+ "{name?, id?} replace the style (default: the one the object was last linked to) with the look of object `id` or the first selected object; the objects still linked to it update, and that object becomes linked → {name}",+ has_doc,+ style_redefine+ ),+ cmd!(+ "graphicStyle.breakLink",+ "Break Link to Graphic Style",+ ["Window", "Graphic Styles"],+ None,+ "{ids?} unlink the objects (default: the selection) from their graphic style; they keep their look",+ has_doc,+ style_break_link+ ),+ cmd!(+ "graphicStyle.rename",+ "Rename Graphic Style",+ ["Window", "Graphic Styles"],+ None,+ "{name, to} (Graphic Style Options; names are unique and linked objects stay linked) → {name}",+ has_doc,+ style_rename+ ),+ cmd!(+ query "graphicStyle.unused",+ "Select All Unused",+ ["Window", "Graphic Styles"],+ None,+ "{} → {names: [the styles no object is linked to]} (the panel selects them)",+ has_doc,+ style_unused+ ),+ cmd!(+ "graphicStyle.sortByName",+ "Sort by Name",+ ["Window", "Graphic Styles"],+ None,+ "{} sort the styles by name (the Default Graphic Style stays first)",+ has_doc,+ style_sort+ ),]}@@@ -320,104 -70,3 +320,104 @@@ fn style_duplicate(s: &mut Session, p:})?;Ok(json!({"name": new}))}++fn style_list(s: &mut Session, _: &Value) -> Result<Value> {+ let d = &s.doc()?.doc;+ let links = links(d);+ let styles: Vec<Value> = d+ .graphic_styles+ .iter()+ .map(|g| {+ let ap = &g.appearance;+ let count = |fill: bool| ap.items.iter().filter(|i| i.is_fill() == fill).count();+ json!({+ "id": g.id,+ "name": g.name,+ "fill": ap.fill_paint().label(),+ "stroke": ap.stroke_paint().label(),+ "strokeWidth": ap.stroke_width(),+ "fills": count(true),+ "strokes": count(false),+ "effects": ap.effects.iter().map(|e| e.id.as_str()).collect::<Vec<_>>(),+ "opacity": (g.opacity * 100.0).round(),+ "blend": g.blend.label(),+ "isolate": g.isolate,- "knockout": g.knockout,++ "knockout": g.knockout.label(),+ "linked": links.get(&g.id).map(|v| v.iter().map(|i| i.0).collect::<Vec<_>>()).unwrap_or_default(),+ })+ })+ .collect();+ let selected = s.selection_graphic_style().filter(|(_, linked)| *linked).map(|(g, _)| g.name.clone());+ Ok(json!({ "styles": styles, "selected": selected }))+}++fn style_redefine(s: &mut Session, p: &Value) -> Result<Value> {+ let cmd = "graphicStyle.redefine";+ let (src, n) = source(s, p, cmd)?;+ let d = &s.doc()?.doc;+ let i = match str_param(p, "name") {+ Some(name) => style_index(d, name)?,+ None => n+ .graphic_style+ .and_then(|id| d.graphic_style_by_id(id))+ .and_then(|g| d.graphic_style_index(&g.name))+ .ok_or_else(|| bad(cmd, "the object has no graphic style (pass `name`)"))?,+ };+ let look = GraphicStyle::of(String::new(), captured(n), n);+ let name = d.graphic_styles[i].name.clone();+ s.edit(&format!("Redefine Graphic Style \u{201c}{name}\u{201d}"), |d, _| {+ let id = d.graphic_style_id(i);+ let old = std::mem::replace(&mut d.graphic_styles[i], GraphicStyle { name: name.clone(), id, ..look });+ // Objects still linked follow the new definition; edited ones are unlinked (they keep+ // their look), and the source keeps its own.+ let linked = objects_where(d, |n| n.graphic_style == Some(id) && n.id != src);+ let (follow, edited): (Vec<NodeId>, Vec<NodeId>) = linked.into_iter().partition(|nid| d.node(*nid).is_some_and(|n| in_sync(n, &old)));+ set_link(d, &edited, None);+ let g = d.graphic_styles[i].clone();+ for nid in follow {+ apply_style(d, nid, &g);+ }+ set_link(d, &[src], Some(id));+ Ok(())+ })?;+ Ok(json!({ "name": name }))+}++fn style_break_link(s: &mut Session, p: &Value) -> Result<Value> {+ let ids = super::appearance::appearance_targets(s, p)?;+ s.edit("Break Link to Graphic Style", |d, _| {+ set_link(d, &ids, None);+ Ok(())+ })?;+ ok()+}++fn style_rename(s: &mut Session, p: &Value) -> Result<Value> {+ let cmd = "graphicStyle.rename";+ let name = str_param(p, "name").ok_or_else(|| bad(cmd, "missing name"))?.to_string();+ let to = str_param(p, "to").map(str::trim).filter(|t| !t.is_empty()).ok_or_else(|| bad(cmd, "missing `to`"))?.to_string();+ s.edit("Graphic Style Options", |d, _| {+ let i = style_index(d, &name)?;+ if to != name && d.graphic_style(&to).is_some() {+ return Err(EngineError::Other(format!("a graphic style named `{to}` already exists")));+ }+ d.graphic_styles[i].name = to.clone();+ Ok(())+ })?;+ Ok(json!({ "name": to }))+}++fn style_unused(s: &mut Session, _: &Value) -> Result<Value> {+ let d = &s.doc()?.doc;+ let links = links(d);+ let names: Vec<&str> = d.graphic_styles.iter().filter(|g| !links.contains_key(&g.id)).map(|g| g.name.as_str()).collect();+ Ok(json!({ "names": names }))+}++fn style_sort(s: &mut Session, _: &Value) -> Result<Value> {+ s.edit("Sort by Name", |d, _| {+ d.graphic_styles.sort_by_cached_key(|g| (g.name != DEFAULT_GRAPHIC_STYLE, g.name.to_lowercase()));+ Ok(())+ })?;+ ok()+}diff --cc crates/engine/src/tests_styles.rsindex b1a9ba1cf,000000000..d9cec0786mode 100644,000000..100644--- a/crates/engine/src/tests_styles.rs+++ b/crates/engine/src/tests_styles.rs@@@ -1,253 -1,0 +1,253 @@@+//! Graphic styles: transparency, capture from groups and type, add-apply, unique names, links+//! (redefine, break link, delete, rename), Select All Unused, Sort by Name and Select > Same.++use serde_json::{Value, json};+use vectorcraft_color::{BlendMode, Color, Paint};- use vectorcraft_doc::{GraphicStyle, Node};++use vectorcraft_doc::{GraphicStyle, Knockout, Node};++use super::*;++fn session() -> Session {+ let mut s = Session::new();+ s.execute("file.new", &json!({"width": 600, "height": 400})).unwrap();+ s+}++fn run(s: &mut Session, id: &str, p: Value) -> Value {+ s.execute(id, &p).unwrap_or_else(|e| panic!("{id} {p}: {e}"))+}++/// A selected 50×50 rectangle at `x` with the default appearance.+fn rect(s: &mut Session, x: f64) -> NodeId {+ let id = NodeId(run(s, "shape.rectangle", json!({"x": x, "y": 10, "width": 50, "height": 50}))["id"].as_u64().unwrap());+ run(s, "select.set", json!({"ids": [id.0]}));+ id+}++fn node(s: &Session, id: NodeId) -> Node {+ s.doc().unwrap().doc.node(id).unwrap().clone()+}++fn style(s: &Session, name: &str) -> GraphicStyle {+ s.doc().unwrap().doc.graphic_style(name).unwrap_or_else(|| panic!("no style {name}")).clone()+}++fn fill(s: &Session, id: NodeId) -> Paint {+ node(s, id).appearance.fill_paint()+}++fn set_fill(s: &mut Session, id: NodeId, hex: &str) {+ run(s, "paint.setFill", json!({"color": hex, "ids": [id.0]}));+}++fn linked(s: &mut Session, name: &str) -> Vec<u64> {+ let l = run(s, "graphicStyle.list", json!({}));+ let st = l["styles"].as_array().unwrap().iter().find(|g| g["name"] == name).unwrap_or_else(|| panic!("{name} not listed")).clone();+ st["linked"].as_array().unwrap().iter().map(|v| v.as_u64().unwrap()).collect()+}++#[test]+fn styles_carry_opacity_and_blend_through_a_save() {+ let mut s = session();+ let a = rect(&mut s, 10.0);+ run(&mut s, "transparency.set", json!({"item": null, "opacity": 50, "blend": "multiply", "knockout": true}));+ run(&mut s, "graphicStyle.new", json!({"name": "Half"}));+ let g = style(&s, "Half");- assert_eq!((g.opacity, g.blend, g.knockout), (0.5, BlendMode::Multiply, true));++ assert_eq!((g.opacity, g.blend, g.knockout), (0.5, BlendMode::Multiply, Knockout::On));+ let b = rect(&mut s, 100.0);+ run(&mut s, "graphicStyle.apply", json!({"name": "Half"}));+ let nb = node(&s, b);- assert_eq!((nb.opacity, nb.blend, nb.knockout), (0.5, BlendMode::Multiply, true));++ assert_eq!((nb.opacity, nb.blend, nb.knockout), (0.5, BlendMode::Multiply, Knockout::On));+ let l = run(&mut s, "graphicStyle.list", json!({}));+ let half = l["styles"].as_array().unwrap().iter().find(|g| g["name"] == "Half").unwrap();+ assert_eq!((half["opacity"].as_f64(), half["blend"].as_str()), (Some(50.0), Some("Multiply")));+ assert_eq!(linked(&mut s, "Half"), vec![a.0, b.0]);+ assert_eq!(l["selected"], "Half");++ // Native round trip: the style's transparency, its id and the objects' links survive.+ let doc = s.doc().unwrap().doc.clone();+ let back = vectorcraft_format::load(&vectorcraft_format::save(&doc, false)).unwrap();+ assert_eq!(back.graphic_styles, doc.graphic_styles);+ assert_eq!(back.node(b).unwrap().graphic_style, Some(g.id));+ // Styles and objects from files without links still load (and get an id when first linked).+ let old: GraphicStyle = serde_json::from_value(json!({"name": "Old", "appearance": {"items": []}})).unwrap();+ assert_eq!((old.id, old.opacity, old.blend, old.isolate), (0, 1.0, BlendMode::Normal, false));+ let mut d = (*doc).clone();+ d.graphic_styles.push(old);+ let i = d.graphic_styles.len() - 1;+ assert_eq!(d.graphic_style_id(i), d.graphic_styles.iter().map(|g| g.id).max().unwrap());+ assert!(!serde_json::to_string(&GraphicStyle::new("Plain", Default::default())).unwrap().contains("opacity"));+}++#[test]+fn a_style_from_a_group_or_type_is_not_empty() {+ let mut s = session();+ let a = rect(&mut s, 10.0);+ let b = rect(&mut s, 100.0);+ run(&mut s, "select.set", json!({"ids": [a.0, b.0]}));+ run(&mut s, "paint.setFill", json!({"color": "#ff0000"}));+ let g = NodeId(run(&mut s, "object.group", json!({}))["id"].as_u64().unwrap());+ assert!(node(&s, g).appearance.items.is_empty());+ run(&mut s, "graphicStyle.new", json!({"name": "Group Look"}));+ let gs = style(&s, "Group Look");+ assert_eq!(gs.appearance.fill_paint(), Paint::solid(Color::from_hex("#ff0000").unwrap()));+ // Both members share the look, so the group is linked.+ assert_eq!(linked(&mut s, "Group Look"), vec![g.0]);++ let t = NodeId(run(&mut s, "text.create", json!({"x": 10, "y": 200, "text": "Hi"}))["id"].as_u64().unwrap());+ run(&mut s, "select.set", json!({"ids": [t.0]}));+ run(&mut s, "graphicStyle.new", json!({"name": "Type Look"}));+ assert!(!style(&s, "Type Look").appearance.fill_paint().is_none());++ // Applying to a group styles its contents and links the group.+ let c = rect(&mut s, 200.0);+ run(&mut s, "graphicStyle.apply", json!({"name": "Black Outline", "ids": [g.0]}));+ assert_eq!(node(&s, a).appearance, style(&s, "Black Outline").appearance);+ assert_eq!(node(&s, g).graphic_style, Some(style(&s, "Black Outline").id));+ assert_ne!(node(&s, c).appearance, style(&s, "Black Outline").appearance);+}++#[test]+fn alt_apply_adds_the_style_on_top() {+ let mut s = session();+ rect(&mut s, 10.0);+ run(&mut s, "appearance.clear", json!({}));+ run(&mut s, "paint.setFill", json!({"color": "#00ff00"}));+ run(&mut s, "effect.apply", json!({"effect": "distort.roughen"}));+ run(&mut s, "graphicStyle.new", json!({"name": "Rough"}));+ let rough = style(&s, "Rough");+ let b = rect(&mut s, 100.0);+ let before = node(&s, b).appearance;+ run(&mut s, "graphicStyle.apply", json!({"name": "Rough", "add": true}));+ let after = node(&s, b).appearance;+ assert_eq!(after.items.len(), before.items.len() + rough.appearance.items.len());+ assert_eq!(after.items[..before.items.len()], before.items[..]);+ assert_eq!(after.items.last(), rough.appearance.items.last());+ assert_eq!(after.effects.len(), before.effects.len() + 1);+ assert_eq!(node(&s, b).graphic_style, None);+ // One undo step.+ run(&mut s, "edit.undo", json!({}));+ assert_eq!(node(&s, b).appearance, before);+}++#[test]+fn style_names_are_unique() {+ let mut s = session();+ rect(&mut s, 10.0);+ assert_eq!(run(&mut s, "graphicStyle.new", json!({"name": "X"}))["name"], "X");+ assert_eq!(run(&mut s, "graphicStyle.new", json!({"name": "X"}))["name"], "X 2");+ let n = s.doc().unwrap().doc.graphic_styles.len();+ assert_eq!(run(&mut s, "graphicStyle.new", json!({}))["name"], format!("Graphic Style {}", n + 1));+ assert!(s.execute("graphicStyle.rename", &json!({"name": "X 2", "to": "X"})).is_err());+ assert!(s.execute("graphicStyle.rename", &json!({"name": "X 2", "to": " "})).is_err());+ assert_eq!(run(&mut s, "graphicStyle.rename", json!({"name": "X 2", "to": "Y"}))["name"], "Y");+ assert_eq!(run(&mut s, "graphicStyle.duplicate", json!({"name": "Y"}))["name"], "Y copy");+ assert_ne!(style(&s, "Y copy").id, style(&s, "Y").id);+}++/// Three rectangles: `a` (the source of style "S"), `b` and `c`, all linked to "S".+fn linked_three(s: &mut Session) -> (NodeId, NodeId, NodeId) {+ let a = rect(s, 10.0);+ run(s, "graphicStyle.new", json!({"name": "S"}));+ let b = rect(s, 100.0);+ let c = rect(s, 200.0);+ run(s, "graphicStyle.apply", json!({"name": "S", "ids": [b.0, c.0]}));+ assert_eq!(linked(s, "S"), vec![a.0, b.0, c.0]);+ (a, b, c)+}++#[test]+fn redefine_updates_every_linked_object() {+ let mut s = session();+ let (a, b, c) = linked_three(&mut s);+ set_fill(&mut s, a, "#0000ff");+ // Editing the source broke its link, but it remembers the style Redefine replaces.+ assert_eq!(linked(&mut s, "S"), vec![b.0, c.0]);+ run(&mut s, "select.set", json!({"ids": [a.0]}));+ assert_eq!(s.selection_graphic_style().map(|(g, linked)| (g.name.clone(), linked)), Some(("S".into(), false)));+ run(&mut s, "graphicStyle.redefine", json!({}));+ let blue = Paint::solid(Color::from_hex("#0000ff").unwrap());+ assert_eq!((fill(&s, b), fill(&s, c)), (blue.clone(), blue));+ assert_eq!(linked(&mut s, "S"), vec![a.0, b.0, c.0]);+ run(&mut s, "edit.undo", json!({}));+ assert_eq!(fill(&s, b), Paint::solid(Color::WHITE));+}++#[test]+fn redefine_leaves_unlinked_and_edited_objects_alone() {+ let mut s = session();+ let (a, b, c) = linked_three(&mut s);+ run(&mut s, "graphicStyle.breakLink", json!({"ids": [c.0]}));+ assert_eq!(node(&s, c).graphic_style, None);+ let d = rect(&mut s, 300.0);+ run(&mut s, "graphicStyle.apply", json!({"name": "S"}));+ set_fill(&mut s, d, "#00ff00");+ set_fill(&mut s, a, "#0000ff");+ run(&mut s, "graphicStyle.redefine", json!({"name": "S", "id": a.0}));+ assert_eq!(fill(&s, b), Paint::solid(Color::from_hex("#0000ff").unwrap()));+ assert_eq!(fill(&s, c), Paint::solid(Color::WHITE));+ // The edited object keeps its look and is unlinked.+ assert_eq!(fill(&s, d), Paint::solid(Color::from_hex("#00ff00").unwrap()));+ assert_eq!(node(&s, d).graphic_style, None);+ assert!(s.execute("graphicStyle.redefine", &json!({"id": c.0})).is_err());+}++#[test]+fn deleting_a_style_unlinks_and_renaming_keeps_links() {+ let mut s = session();+ let (_, b, c) = linked_three(&mut s);+ run(&mut s, "graphicStyle.rename", json!({"name": "S", "to": "T"}));+ assert_eq!(linked(&mut s, "T").len(), 3);+ run(&mut s, "select.set", json!({"ids": [b.0]}));+ assert_eq!(run(&mut s, "select.same.graphicStyle", json!({}))["count"], 3);+ let look = node(&s, c).appearance;+ run(&mut s, "graphicStyle.delete", json!({"name": "T"}));+ assert_eq!((node(&s, b).graphic_style, node(&s, c).graphic_style), (None, None));+ assert_eq!(node(&s, c).appearance, look);+ run(&mut s, "select.set", json!({"ids": [b.0]}));+ assert!(s.execute("select.same.graphicStyle", &json!({})).is_err());+}++#[test]+fn unused_styles_and_sort_by_name() {+ let mut s = session();+ linked_three(&mut s);+ let unused = run(&mut s, "graphicStyle.unused", json!({}));+ let names: Vec<&str> = unused["names"].as_array().unwrap().iter().filter_map(Value::as_str).collect();+ assert!(names.contains(&"Sunshine") && !names.contains(&"S"));+ run(&mut s, "graphicStyle.delete", json!({"names": names}));+ assert_eq!(s.doc().unwrap().doc.graphic_styles.len(), 1);+ run(&mut s, "edit.undo", json!({}));+ run(&mut s, "graphicStyle.sortByName", json!({}));+ let names: Vec<String> = s.doc().unwrap().doc.graphic_styles.iter().map(|g| g.name.clone()).collect();+ assert_eq!(names, ["Default Graphic Style", "Black Outline", "Heavy Ink", "S", "Sunshine"]);+}++#[test]+fn select_same_appearance_attribute() {+ let mut s = session();+ let a = rect(&mut s, 10.0);+ run(&mut s, "effect.apply", json!({"effect": "distort.roughen"}));+ let b = rect(&mut s, 100.0);+ set_fill(&mut s, b, "#ff0000");+ run(&mut s, "effect.apply", json!({"effect": "distort.roughen"}));+ let c = rect(&mut s, 200.0);+ // The shared effect.+ run(&mut s, "select.set", json!({"ids": [a.0]}));+ run(&mut s, "select.same.appearanceAttribute", json!({}));+ assert_eq!(s.doc().unwrap().selection.objects, vec![a, b]);+ // The shared stroke (item 1).+ run(&mut s, "select.set", json!({"ids": [a.0]}));+ run(&mut s, "select.same.appearanceAttribute", json!({"item": 1}));+ assert_eq!(s.doc().unwrap().selection.objects, vec![a, b, c]);+}++#[test]+fn document_info_lists_style_names() {+ let mut s = session();+ let (a, ..) = linked_three(&mut s);+ let i = run(&mut s, "document.info", json!({}));+ assert_eq!(i["graphicStyleNames"].as_array().unwrap().len(), 5);+ run(&mut s, "select.set", json!({"ids": [a.0]}));+ assert_eq!(run(&mut s, "document.info", json!({"selectionOnly": true}))["graphicStyleNames"], json!(["S"]));+}diff --cc crates/pdf/src/export.rsindex f90b59535,ad0cff066..e1a72e89d--- a/crates/pdf/src/export.rs+++ b/crates/pdf/src/export.rs@@@ -71,7 -70,7 +71,7 @@@ pub fn export_with_report(doc: &Documen}pdf.set_metadata(meta);- let mut ex = Exporter { doc, warnings: vec![], images: HashMap::new(), brushes: None };- let mut ex = Exporter { doc, warnings: vec![], images: HashMap::new(), knockout: doc.page_knockout };++ let mut ex = Exporter { doc, warnings: vec![], images: HashMap::new(), brushes: None, knockout: doc.page_knockout };for i in indices {let ab = &doc.artboards[i];let r = ab.rect;@@@ -130,8 -136,8 +137,10 @@@ struct Exporter<'a>doc: &'a Document,warnings: Vec<String>,images: HashMap<String, Option<Image>>,+ /// The brush library, parsed when the first brushed stroke is written.+ brushes: Option<Vec<vectorcraft_brush::Brush>>,+ /// Whether the group being written is a knockout group (what its neutral children inherit).+ knockout: bool,}fn xf(a: Affine) -> Transform {diff --cc crates/svg/src/export.rsindex db75cf0d1,8c4e0753e..5a47e031e--- a/crates/svg/src/export.rs+++ b/crates/svg/src/export.rs@@@ -45,11 -44,22 +45,23 @@@ pub(crate) fn export(doc: &Document, opdepth: 1,patterns: HashMap::new(),pattern_nest: 0,+ brushes: None,+ knockout: doc.page_knockout,+ anonymous: false,+ knockout_filter: None,};w.assign_name_ids();- for l in &doc.layers {- w.node(l);+ // Page Isolated Blending / Page Knockout Group: the page content is one isolated group.+ let page_group = doc.page_isolate || doc.page_knockout;+ if page_group {+ let a = w.attrs(&vec![("isolation", "isolate".into())]);+ w.line(&format!("<g{a}>"));+ w.depth += 1;+ }+ w.children(&doc.layers);+ if page_group {+ w.depth -= 1;+ w.line("</g>");}let nl = if opts.minify { "" } else { "\n" };@@@ -103,17 -113,17 +115,26 @@@ struct Writer<'a>/// `<pattern>` def ids by pattern name + placement.patterns: HashMap<String, String>,pattern_nest: u32,+ /// Whether the group being written is a knockout group (what its neutral children inherit).+ knockout: bool,+ /// Writing a copy of an object (a knockout mask): no object ids, so they stay unique.+ anonymous: bool,+ /// The filter that paints art black keeping its alpha (knockout masks), once defined.+ knockout_filter: Option<String>,+ /// The brush library, parsed when the first brushed stroke is written.+ brushes: Option<Vec<vectorcraft_brush::Brush>>,+}++/// How one stroke is written.+enum StrokePlan {+ /// Its brush art (document space).+ Brush(Vec<Node>),+ Written(Written),}+ /// A region covering any artwork (mask and filter extents).+ const BIG: &str = "x=\"-100000\" y=\"-100000\" width=\"200000\" height=\"200000\"";+pub(crate) fn blend_css(b: BlendMode) -> &'static str {match b {BlendMode::Normal => "normal",