From 52ae4d5dd52f6301b86ee43b8aba839e5bc851eb Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 5 Dec 2026 00:51:41 -0800 Subject: [PATCH 01/41] DXF/DWG import: scaled block inserts scale their dashes and polyline widths A named block becomes a symbol whose art is drawn once, at the import's scale, and each insert becomes an instance that carries the insert's scale. Instances leave the strokes in their art unscaled, so a block inserted at scale 10 drew its geometry 10 times larger but kept its linetype dashes and constant-width polylines at scale 1. When a block (or a block it places) draws dashes or wide polylines, its symbol is now made per insert scale, with the art drawn at that scale and the instance taking the rest of the transform. Inserts at one scale share a symbol, and blocks without dashes or wide polylines keep one symbol for every scale. Lineweights are physical widths and stay unscaled. --- crates/cad/src/import/build.rs | 112 ++++++++++++++++++++++++------ crates/cad/src/import/tests.rs | 122 +++++++++++++++++++++++++++++++++ 2 files changed, 213 insertions(+), 21 deletions(-) diff --git a/crates/cad/src/import/build.rs b/crates/cad/src/import/build.rs index 0b3532ca87..870283af2c 100644 --- a/crates/cad/src/import/build.rs +++ b/crates/cad/src/import/build.rs @@ -67,8 +67,12 @@ pub(crate) struct Build<'d, 'a> { blocks: HashMap>>, bounds: HashMap>, sensitive: HashMap, - /// Symbol names by block and what it inherits (`None`: the block has no art). - symbols: HashMap<(String, Inherit), Option>, + /// Symbol names by block, what it inherits and the scale its art is drawn at (the bits of + /// [`symbol_scale`]'s answer; `None`: the block has no art). + symbols: HashMap<(String, Inherit, u64), Option>, + /// Whether a block placed with what it inherits draws dashes or wide polylines, whose + /// lengths and widths follow the insert's scale. + scaled_looks: HashMap<(String, Inherit), bool>, /// Names of the symbols made so far, and the next suffix to try for each label. symbol_names: HashSet, next_suffix: HashMap, @@ -134,6 +138,7 @@ impl<'d, 'a> Build<'d, 'a> { bounds: HashMap::new(), sensitive: HashMap::new(), symbols: HashMap::new(), + scaled_looks: HashMap::new(), symbol_names: HashSet::new(), next_suffix: HashMap::new(), stack: vec![], @@ -597,24 +602,39 @@ impl<'d, 'a> Build<'d, 'a> { let base = self.d.blocks.get(&ins.block).map_or(Point::ZERO, |b| b.base); let unbase = Affine::translate(-base.to_vec2()); let anonymous = ins.block.starts_with('*'); - let symbol = if anonymous { None } else { self.symbol(&ins.block, &child, depth) }; let mut parts = vec![]; + // An array's cells share their scale: the symbol is looked up again only when it changes. + let mut last: Option<(f64, Option<(String, f64)>)> = None; for cell in &ins.cells { - let node = match &symbol { - Some(name) => { - if self.nodes >= MAX_NODES { - self.warn(TOO_MANY); - break; + let node = if anonymous { + self.art(&ins.block, map * *cell * unbase, &child, depth) + } else { + let scale = symbol_scale(map * *cell, self.symbol_map); + let symbol = match &last { + Some((s, symbol)) if s.to_bits() == scale.to_bits() => symbol.clone(), + _ => { + let symbol = self.symbol(&ins.block, &child, scale, depth); + last = Some((scale, symbol.clone())); + symbol } - if !self.charge_text(name.len()) { - break; + }; + match symbol { + Some((name, drawn_at)) => { + if self.nodes >= MAX_NODES { + self.warn(TOO_MANY); + break; + } + if !self.charge_text(name.len()) { + break; + } + // The symbol's art is drawn `drawn_at` times larger than a drawing unit + // at the import's scale; the instance takes the rest of the transform. + let xf = map * *cell * (self.symbol_map * Affine::scale(drawn_at)).inverse(); + self.nodes += 1; + Some(Node::new(self.doc.alloc_id(), NodeKind::SymbolInstance { symbol: name, xf })) } - let xf = map * *cell * self.symbol_map.inverse(); - self.nodes += 1; - Some(Node::new(self.doc.alloc_id(), NodeKind::SymbolInstance { symbol: name.clone(), xf })) + None => None, } - None if anonymous => self.art(&ins.block, map * *cell * unbase, &child, depth), - None => None, }; parts.extend(node); } @@ -664,15 +684,52 @@ impl<'d, 'a> Build<'d, 'a> { } } - /// The symbol for block `name` placed with `inh` (made once per look). - fn symbol(&mut self, name: &str, inh: &Inherit, depth: u32) -> Option { + /// Does block `name` placed with `inh` draw dashes or wide polylines (its own art or that of + /// the blocks it places)? + fn is_scaled_look(&mut self, name: &str, inh: &Inherit, depth: u32) -> bool { + let key = (name.to_string(), inh.clone()); + if let Some(s) = self.scaled_looks.get(&key) { + return *s; + } + let Some(items) = self.block(name) else { return false }; + if !self.enter(name, depth) { + return false; + } + let mut s = false; + for it in items.iter() { + s = match &it.geom { + Geom::Path { fill: true, .. } => false, + Geom::Path { width, .. } => { + *width > 0.0 || self.d.linetypes.get(&self.linetype(&it.props, inh)).is_some_and(|p| p.iter().take(64).any(|v| *v < 0.0)) + } + Geom::Text(_) => false, + Geom::Insert(ins) => { + let child = self.inherit(&it.props, inh); + let child = if self.is_sensitive(&ins.block, depth + 1) { child } else { Inherit::default() }; + self.is_scaled_look(&ins.block, &child, depth + 1) + } + }; + if s { + break; + } + } + self.stack.pop(); + self.scaled_looks.insert(key, s); + s + } + + /// The symbol for block `name` placed with `inh` at `scale` (from [`symbol_scale`]), made + /// once per look, with the scale its art is drawn at: `scale` when the block draws dashes or + /// wide polylines, else 1. + fn symbol(&mut self, name: &str, inh: &Inherit, scale: f64, depth: u32) -> Option<(String, f64)> { let inh = if self.is_sensitive(name, depth) { inh.clone() } else { Inherit::default() }; - let key = (name.to_string(), inh); + let scale = if self.is_scaled_look(name, &inh, depth) { scale } else { 1.0 }; + let key = (name.to_string(), inh, scale.to_bits()); if let Some(s) = self.symbols.get(&key) { - return s.clone(); + return s.clone().map(|s| (s, scale)); } let base = self.d.blocks.get(name).map_or(Point::ZERO, |b| b.base); - let map = self.symbol_map * Affine::translate(-base.to_vec2()); + let map = self.symbol_map * Affine::scale(scale) * Affine::translate(-base.to_vec2()); let art = self.art(name, map, &key.1, depth); let made = art.and_then(|art| { let label = self.d.blocks.get(name).map_or(name, |b| b.name.as_str()); @@ -686,10 +743,23 @@ impl<'d, 'a> Build<'d, 'a> { Some(symbol) }); self.symbols.insert(key, made.clone()); - made + made.map(|s| (s, scale)) } } +/// How much larger than `symbol_map` an insert copy drawn by `placed` is (the square root of the +/// ratio of their areas), rounded to 9 significant digits so that copies at one scale share a +/// symbol; 1 when either is degenerate. +fn symbol_scale(placed: Affine, symbol_map: Affine) -> f64 { + let s = (placed.determinant().abs() / symbol_map.determinant().abs()).sqrt(); + if !(s.is_finite() && s > 0.0) { + return 1.0; + } + let digits = 10f64.powi(8 - s.log10().floor() as i32); + let r = (s * digits).round() / digits; + if r.is_finite() && r > 0.0 { r } else { 1.0 } +} + /// Fit text stretched or squeezed across, aligned text scaled as a whole, to run its span /// (`s`: points per drawing unit), measured in the font it is set in. fn fill_span(obj: &mut TextObject, span: Span, s: f64) { diff --git a/crates/cad/src/import/tests.rs b/crates/cad/src/import/tests.rs index d53694343a..89f6e81ce8 100644 --- a/crates/cad/src/import/tests.rs +++ b/crates/cad/src/import/tests.rs @@ -858,6 +858,128 @@ fn by_block_colours_make_a_symbol_per_look() { assert_eq!(doc.symbols.len(), 1); } +/// The dash pattern and weight of the stroke of `n` (a path) or its first loop (a compound path). +fn dash_and_weight(n: &Node) -> (Vec, f64) { + let n = match &n.kind { + NodeKind::Path { .. } => n, + _ => n.children().and_then(|c| c.first()).map(|c| &**c).unwrap_or_else(|| panic!("no path: {:?}", n.kind)), + }; + let s = n.appearance.stroke().unwrap_or_else(|| panic!("no stroke: {:?}", n.appearance)); + (s.dash.as_ref().map(|d| d.pattern.clone()).unwrap_or_default(), s.width) +} + +/// The strokes of `inst`'s symbol's art (and of the symbols it places): each path's dash +/// pattern and weight, in paint order. +fn instance_strokes(doc: &Document, inst: &Node) -> Vec<(Vec, f64)> { + let NodeKind::SymbolInstance { symbol, .. } = &inst.kind else { panic!("{:?}", inst.kind) }; + let art = &doc.symbols.iter().find(|s| &s.name == symbol).unwrap().art; + let mut out = vec![]; + let mut walk = vec![art.clone()]; + while let Some(n) = walk.pop() { + match &n.kind { + NodeKind::Path { .. } => out.push(dash_and_weight(&n)), + NodeKind::SymbolInstance { .. } => out.extend(instance_strokes(doc, &n)), + _ => walk.extend(n.children().into_iter().flatten().rev().cloned()), + } + } + out +} + +#[test] +fn scaled_inserts_scale_their_blocks_dashes_and_polyline_widths() { + let tables = [(0, "TABLE"), (2, "LTYPE"), (0, "LTYPE"), (2, "DASHED"), (73, "2"), (40, "15"), (49, "10"), (49, "-5"), (0, "ENDTAB")]; + // "Mark": a dashed line with a 0.5 mm lineweight and a polyline 2 units wide. "Pair" places + // "Mark" at scale 1, so the scale of an insert of "Pair" reaches it. + let blocks = [ + (0, "BLOCK"), + (8, "0"), + (2, "Mark"), + (70, "0"), + (10, "0"), + (20, "0"), + (0, "LINE"), + (8, "0"), + (6, "DASHED"), + (370, "50"), + (10, "0"), + (20, "0"), + (11, "100"), + (21, "0"), + (0, "LWPOLYLINE"), + (8, "0"), + (90, "2"), + (70, "0"), + (43, "2"), + (10, "0"), + (20, "10"), + (10, "100"), + (20, "10"), + (0, "ENDBLK"), + (0, "BLOCK"), + (8, "0"), + (2, "Pair"), + (70, "0"), + (10, "0"), + (20, "0"), + (0, "INSERT"), + (8, "0"), + (2, "Mark"), + (10, "0"), + (20, "0"), + (0, "ENDBLK"), + ]; + let inserts = [ + (0, "INSERT"), + (2, "Mark"), + (10, "0"), + (20, "0"), + (0, "INSERT"), + (2, "Mark"), + (10, "0"), + (20, "100"), + (41, "10"), + (42, "10"), + (0, "INSERT"), + (2, "Pair"), + (10, "0"), + (20, "300"), + (41, "10"), + (42, "10"), + (0, "INSERT"), + (2, "Mark"), + (10, "0"), + (20, "500"), + (41, "10"), + (42, "10"), + ]; + let doc = open(&drawing(&[], &tables, &blocks, &inserts), &points()).document; + let insts = leaves(&doc); + let [one, ten, nested, ten_again] = &insts[..] else { panic!("{insts:?}") }; + let at_one = instance_strokes(&doc, one); + let [(dash, lw), (no_dash, width)] = &at_one[..] else { panic!("{at_one:?}") }; + assert!(dash.len() >= 2 && no_dash.is_empty() && *width > 0.0, "{at_one:?}"); + // Instances leave the strokes in their art as they are, so the art carries the insert's scale. + let tenfold: Vec = dash.iter().map(|v| v * 10.0).collect(); + for inst in [ten, nested] { + let got = instance_strokes(&doc, inst); + let [(d, w_lw), (_, w)] = &got[..] else { panic!("{got:?}") }; + assert_eq!(d.len(), tenfold.len()); + assert!(d.iter().zip(&tenfold).all(|(a, b)| (a - b).abs() < 1e-9), "dashes {d:?}, want {tenfold:?}"); + assert!((w - width * 10.0).abs() < 1e-9, "polyline width {w}, want {}", width * 10.0); + assert!((w_lw - lw).abs() < 1e-12, "a lineweight is a physical width: {w_lw}, want {lw}"); + } + // The copies still land where their inserts put them. + let NodeKind::SymbolInstance { symbol, xf } = &ten.kind else { panic!() }; + let art = &doc.symbols.iter().find(|s| &s.name == symbol).unwrap().art; + let line = art.children().and_then(|c| c.first()).unwrap(); + let end = *xf * *path_points(line).last().unwrap(); + assert!(end.distance(Point::new(1000.0, height(&doc) - 100.0)) < 1e-6, "{end:?}"); + // Inserts at one scale share a symbol. + let symbol_of = |n: &Node| if let NodeKind::SymbolInstance { symbol, .. } = &n.kind { symbol.clone() } else { panic!() }; + assert_eq!(symbol_of(ten), symbol_of(ten_again)); + assert_ne!(symbol_of(one), symbol_of(ten)); +} + #[test] fn many_by_block_looks_import_in_linear_time() { let by_block: &[(i32, &str)] = &[(0, "LINE"), (8, "0"), (62, "0"), (10, "5"), (20, "5"), (11, "15"), (21, "5")]; From de5582cc836c452188edd85de5bf0f277177788e Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 5 Dec 2026 01:49:20 -0800 Subject: [PATCH 02/41] DXF/DWG import: the scale check of blocks skips hidden art and keeps to the work budget The check that decides whether a block's symbol is drawn per insert scale now skips art on hidden layers, which the import does not draw, so a block whose only dashes are hidden keeps one symbol for every scale. The check also counts the items it looks at against the block work budget and stops with the existing warning when the budget runs out. Text in a block drawn at a tiny insert scale is kept: any invertible text transform is accepted, instead of only those above 1e-12 points per unit. --- crates/cad/src/import/build.rs | 26 ++++++- crates/cad/src/import/tests.rs | 126 +++++++++++++++++++++++++++++++++ 2 files changed, 149 insertions(+), 3 deletions(-) diff --git a/crates/cad/src/import/build.rs b/crates/cad/src/import/build.rs index 870283af2c..02da2f46fc 100644 --- a/crates/cad/src/import/build.rs +++ b/crates/cad/src/import/build.rs @@ -24,7 +24,8 @@ const THINNEST: f64 = 0.25; /// The most objects an import makes. const MAX_NODES: usize = 2_000_000; /// The most block work an import does, whatever it produces: one per insert copy drawn, and one -/// per item of the block looked at for it (art on hidden layers too). +/// per item of the block looked at for it (art on hidden layers too), and the same for each block +/// whose dashes and widths are checked for a symbol's scale. const MAX_VISITS: usize = if cfg!(test) { 1_000_000 } else { 20_000_000 }; /// The most path elements an import makes (blocks drawn as art are copied for every placement). pub(crate) const MAX_ELEMENTS: usize = if cfg!(test) { 1_000_000 } else { 4_000_000 }; @@ -568,7 +569,9 @@ impl<'d, 'a> Build<'d, 'a> { // Text space is y-down points; the item's is y-up drawing units. let m = map * t.xf * Affine::FLIP_Y; let s = m.determinant().abs().sqrt(); - if !(s > 1e-12 && s.is_finite()) { + // Any invertible map will do: a symbol drawn at a tiny insert scale draws its text far + // below a point per unit, and its instances scale it back up. + if !(s > 0.0 && s.is_finite() && s.recip().is_finite()) { return None; } let d = self.d; @@ -691,12 +694,27 @@ impl<'d, 'a> Build<'d, 'a> { if let Some(s) = self.scaled_looks.get(&key) { return *s; } - let Some(items) = self.block(name) else { return false }; + let items = self.block(name); + // Looking at a block's items counts against the block work as placing it does, so the + // scan stops at the same limit as `art`. + self.visits = self.visits.saturating_add(1 + items.as_ref().map_or(0, |i| i.len())); + if self.visits > MAX_VISITS { + self.warn(TOO_MUCH_BLOCK_WORK); + return false; + } + let Some(items) = items else { return false }; if !self.enter(name, depth) { return false; } let mut s = false; for it in items.iter() { + #[cfg(test)] + SCALED_LOOK_ITEMS.with(|n| n.set(n.get().saturating_add(1))); + // Art on a hidden layer is not drawn (see `art`), so it does not make the block's + // look depend on its scale. + if self.d.layer(self.layer_name(&it.props, inh)).is_some_and(|l| l.hidden) && it.props.layer != "0" { + continue; + } s = match &it.geom { Geom::Path { fill: true, .. } => false, Geom::Path { width, .. } => { @@ -782,6 +800,8 @@ fn rgb_color([r, g, b]: [u8; 3]) -> Color { thread_local! { /// How many names [`unique`] tried on this thread (tests). pub(crate) static SYMBOL_NAMES_TRIED: std::cell::Cell = const { std::cell::Cell::new(0) }; + /// How many block items [`Build::is_scaled_look`] looked at on this thread (tests). + pub(crate) static SCALED_LOOK_ITEMS: std::cell::Cell = const { std::cell::Cell::new(0) }; } /// Whether `taken` holds `name`, counted as one name tried (tests). diff --git a/crates/cad/src/import/tests.rs b/crates/cad/src/import/tests.rs index 89f6e81ce8..ae3a86d180 100644 --- a/crates/cad/src/import/tests.rs +++ b/crates/cad/src/import/tests.rs @@ -980,6 +980,132 @@ fn scaled_inserts_scale_their_blocks_dashes_and_polyline_widths() { assert_ne!(symbol_of(one), symbol_of(ten)); } +#[test] +fn dashes_on_a_hidden_layer_leave_a_block_one_symbol_for_every_scale() { + let tables = [ + (0, "TABLE"), + (2, "LTYPE"), + (0, "LTYPE"), + (2, "DASHED"), + (73, "2"), + (40, "15"), + (49, "10"), + (49, "-5"), + (0, "ENDTAB"), + (0, "TABLE"), + (2, "LAYER"), + (0, "LAYER"), + (2, "Off"), + (70, "0"), + (62, "-1"), + (0, "ENDTAB"), + ]; + // "Mark": a solid line, and a dashed line on a hidden layer, which is not drawn. + let blocks = [ + (0, "BLOCK"), + (8, "0"), + (2, "Mark"), + (70, "0"), + (10, "0"), + (20, "0"), + (0, "LINE"), + (8, "0"), + (10, "0"), + (20, "0"), + (11, "100"), + (21, "0"), + (0, "LINE"), + (8, "Off"), + (6, "DASHED"), + (10, "0"), + (20, "10"), + (11, "100"), + (21, "10"), + (0, "ENDBLK"), + ]; + let inserts = [(0, "INSERT"), (2, "Mark"), (10, "0"), (20, "0"), (0, "INSERT"), (2, "Mark"), (10, "0"), (20, "100"), (41, "10"), (42, "10")]; + let doc = open(&drawing(&[], &tables, &blocks, &inserts), &points()).document; + assert_eq!(leaves(&doc).len(), 2); + assert_eq!(doc.symbols.len(), 1, "{:?}", doc.symbols.iter().map(|s| &s.name).collect::>()); +} + +#[test] +fn the_scale_check_of_blocks_stops_at_the_work_budget() { + // "Outer" places "Leaf" 1,100 times, each in its own color, and "Leaf" has 1,000 solid + // lines that take their insert's color: 1,100,000 items to look at, past the 1,000,000 + // tests import with. + let mut blocks: Vec<(i32, &'static str)> = vec![(0, "BLOCK"), (8, "0"), (2, "Leaf"), (70, "0"), (10, "0"), (20, "0")]; + for _ in 0..1000 { + blocks.extend([(0, "LINE"), (8, "0"), (62, "0"), (10, "0"), (20, "0"), (11, "1"), (21, "0")]); + } + blocks.extend([(0, "ENDBLK"), (0, "BLOCK"), (8, "0"), (2, "Outer"), (70, "0"), (10, "0"), (20, "0")]); + for i in 0..1100 { + let color: &'static str = Box::leak((i + 1).to_string().into_boxed_str()); + blocks.extend([(0, "INSERT"), (8, "0"), (2, "Leaf"), (420, color), (10, "0"), (20, "0")]); + } + blocks.push((0, "ENDBLK")); + let top = [(0, "INSERT"), (2, "Outer"), (10, "0"), (20, "0")]; + build::SCALED_LOOK_ITEMS.with(|n| n.set(0)); + let r = open(&drawing(&[], &[], &blocks, &top), &points()); + let looked = build::SCALED_LOOK_ITEMS.with(std::cell::Cell::get); + assert!(looked <= 1_000_000, "{looked} items looked at"); + assert!(r.warnings.iter().any(|w| w.contains("too much work")), "{:?}", r.warnings); +} + +#[test] +fn text_in_a_dashed_block_inserted_at_a_tiny_scale_is_kept() { + let tables = [(0, "TABLE"), (2, "LTYPE"), (0, "LTYPE"), (2, "DASHED"), (73, "2"), (40, "15"), (49, "10"), (49, "-5"), (0, "ENDTAB")]; + // "Inner" draws a dashed line and a label; "Outer" places it at 1e-7, and the drawing places + // "Outer" at 1e-7, so "Inner"'s symbol is drawn at 1e-14. + let blocks = [ + (0, "BLOCK"), + (8, "0"), + (2, "Inner"), + (70, "0"), + (10, "0"), + (20, "0"), + (0, "LINE"), + (8, "0"), + (6, "DASHED"), + (10, "0"), + (20, "0"), + (11, "100"), + (21, "0"), + (0, "TEXT"), + (8, "0"), + (10, "0"), + (20, "10"), + (40, "5"), + (1, "Label"), + (0, "ENDBLK"), + (0, "BLOCK"), + (8, "0"), + (2, "Outer"), + (70, "0"), + (10, "0"), + (20, "0"), + (0, "INSERT"), + (8, "0"), + (2, "Inner"), + (10, "0"), + (20, "0"), + (41, "1e-7"), + (42, "1e-7"), + (0, "ENDBLK"), + ]; + let top = [(0, "INSERT"), (2, "Outer"), (10, "0"), (20, "0"), (41, "1e-7"), (42, "1e-7")]; + let doc = open(&drawing(&[], &tables, &blocks, &top), &points()).document; + let mut texts = vec![]; + for s in &doc.symbols { + s.art.walk(&mut |n| { + if let NodeKind::Text(t) = &n.kind { + texts.push(t.plain_text()); + } + }); + } + assert_eq!(texts, ["Label"]); +} + #[test] fn many_by_block_looks_import_in_linear_time() { let by_block: &[(i32, &str)] = &[(0, "LINE"), (8, "0"), (62, "0"), (10, "5"), (20, "5"), (11, "15"), (21, "5")]; From 1da36ce346e60c6cf1a6ad90f2a271690992ed5b Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 5 Dec 2026 02:45:59 -0800 Subject: [PATCH 03/41] DXF/DWG import: block copies drawn at a tiny scale keep a finite transform An instance's transform inverted the symbol map and the scale its art is drawn at as one product. In a fitted drawing with a tiny points-per-unit scale, a dashed block placed at a tiny nested scale made that product's determinant subnormal, its inverse overflowed, and the instance carried NaN coefficients. The two factors are now inverted apart, and a copy whose transform still is not finite is left out with a warning. --- crates/cad/src/import/build.rs | 13 ++++++-- crates/cad/src/import/tests.rs | 56 ++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 3 deletions(-) diff --git a/crates/cad/src/import/build.rs b/crates/cad/src/import/build.rs index 02da2f46fc..2115104bcf 100644 --- a/crates/cad/src/import/build.rs +++ b/crates/cad/src/import/build.rs @@ -46,6 +46,7 @@ const TOO_MANY: &str = "the drawing has more than 2,000,000 objects: the rest ar const TOO_MANY_POINTS: &str = "the drawing has more than 4,000,000 path points: the rest are left out"; const TOO_MUCH_BLOCK_WORK: &str = "the drawing's blocks take too much work to place: the rest are left out"; const TOO_MANY_DASHES: &str = "the drawing has more dashed lines than can be kept: the rest are drawn solid"; +const TOO_SMALL: &str = "block copies drawn too small to place are left out"; const TOO_MUCH_TEXT: &str = "the drawing has more than 64 MB of text and block names: the rest are left out"; /// What a block's art takes from the insert that places it: its colour, lineweight, linetype @@ -627,12 +628,18 @@ impl<'d, 'a> Build<'d, 'a> { self.warn(TOO_MANY); break; } + // The symbol's art is drawn `drawn_at` times larger than a drawing unit + // at the import's scale; the instance takes the rest of the transform. + // The two factors are inverted apart, so a tiny `drawn_at` at a tiny fitted + // scale does not overflow the inverse of their product. + let xf = map * *cell * Affine::scale(drawn_at.recip()) * self.symbol_map.inverse(); + if !xf.as_coeffs().iter().all(|c| c.is_finite()) { + self.warn(TOO_SMALL); + continue; + } if !self.charge_text(name.len()) { break; } - // The symbol's art is drawn `drawn_at` times larger than a drawing unit - // at the import's scale; the instance takes the rest of the transform. - let xf = map * *cell * (self.symbol_map * Affine::scale(drawn_at)).inverse(); self.nodes += 1; Some(Node::new(self.doc.alloc_id(), NodeKind::SymbolInstance { symbol: name, xf })) } diff --git a/crates/cad/src/import/tests.rs b/crates/cad/src/import/tests.rs index ae3a86d180..08f683a65f 100644 --- a/crates/cad/src/import/tests.rs +++ b/crates/cad/src/import/tests.rs @@ -1106,6 +1106,62 @@ fn text_in_a_dashed_block_inserted_at_a_tiny_scale_is_kept() { assert_eq!(texts, ["Label"]); } +#[test] +fn a_dashed_block_at_a_tiny_scale_in_a_huge_fitted_drawing_keeps_a_finite_instance() { + let tables = [(0, "TABLE"), (2, "LTYPE"), (0, "LTYPE"), (2, "DASHED"), (73, "2"), (40, "15"), (49, "10"), (49, "-5"), (0, "ENDTAB")]; + // "G0" draws a line 1e12 long and "G1" to "G6" each place the one before at 1e12, so the + // drawing spans about 1e96 and fits at about 6e-94 points per unit. "D0" draws a dashed line, + // "D1" places it at 1e-4 and "D2" to "D5" each place the one before at 1e-12, so "D0" is drawn + // at about 6e-158 points per unit: the square of that is below the smallest normal number. + let mut blocks: Vec<(i32, &'static str)> = vec![]; + blocks.extend([(0, "BLOCK"), (8, "0"), (2, "G0"), (70, "0"), (10, "0"), (20, "0")]); + blocks.extend([(0, "LINE"), (8, "0"), (10, "0"), (20, "0"), (11, "1e12"), (21, "1e12"), (0, "ENDBLK")]); + blocks.extend([(0, "BLOCK"), (8, "0"), (2, "D0"), (70, "0"), (10, "0"), (20, "0")]); + blocks.extend([(0, "LINE"), (8, "0"), (6, "DASHED"), (10, "0"), (20, "0"), (11, "100"), (21, "0"), (0, "ENDBLK")]); + let names = |p: &str, i: usize| -> &'static str { Box::leak(format!("{p}{i}").into_boxed_str()) }; + for (p, from, to) in [("G", 1, 6), ("D", 1, 5)] { + for i in from..=to { + let scale = match (p, i) { + ("G", _) => "1e12", + (_, 1) => "1e-4", + _ => "1e-12", + }; + blocks.extend([(0, "BLOCK"), (8, "0"), (2, names(p, i)), (70, "0"), (10, "0"), (20, "0")]); + blocks.extend([(0, "INSERT"), (8, "0"), (2, names(p, i - 1)), (10, "0"), (20, "0"), (41, scale), (42, scale), (0, "ENDBLK")]); + } + } + let top = [ + (0, "INSERT"), + (2, "G6"), + (10, "0"), + (20, "0"), + (41, "1e12"), + (42, "1e12"), + (0, "INSERT"), + (2, "D5"), + (10, "0"), + (20, "0"), + (41, "1e-12"), + (42, "1e-12"), + ]; + let o = ImportOptions { fit: true, center: false, ..ImportOptions::default() }; + let doc = open(&drawing(&[], &tables, &blocks, &top), &o).document; + let mut instances = vec![]; + let mut collect = |n: &Node| { + if let NodeKind::SymbolInstance { symbol, xf } = &n.kind { + instances.push((symbol.clone(), *xf)); + } + }; + doc.walk(&mut collect); + for s in &doc.symbols { + s.art.walk(&mut collect); + } + assert!(instances.iter().any(|(symbol, _)| symbol == "D0"), "{instances:?}"); + for (symbol, xf) in &instances { + assert!(xf.as_coeffs().iter().all(|c| c.is_finite()), "{symbol}: {xf:?}"); + } +} + #[test] fn many_by_block_looks_import_in_linear_time() { let by_block: &[(i32, &str)] = &[(0, "LINE"), (8, "0"), (62, "0"), (10, "5"), (20, "5"), (11, "15"), (21, "5")]; From cda16b5163d4f7d9c05b4ce851f4411b6de8b94b Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 5 Dec 2026 04:14:07 -0800 Subject: [PATCH 04/41] Fix #10734: Save asks about a changed file only when its bytes changed Save asked "File changed" on every save of a file in a cloud-sync folder. The save flow counts any new change time or inode as a change by another app, and a sync client sets attributes on the file after uploading it, or puts the same bytes back as a new file. The app now keeps a SHA-256 digest of each document's file as it last read or wrote it, taken on a thread after the open and after each save. When the flow would ask, the file is compared with that digest on a thread; a file that still holds the same bytes becomes the recorded version and is written over without asking. A file whose bytes differ, that changes during the comparison, or that has no digest is asked about as before. Digests of closed documents are dropped. --- Cargo.lock | 1 + crates/ui-egui/Cargo.toml | 3 + crates/ui-egui/src/app.rs | 1 + crates/ui-egui/src/io.rs | 2 + crates/ui-egui/src/io/open.rs | 2 +- crates/ui-egui/src/io/save.rs | 181 +++++++++++++++++++++-- crates/ui-egui/src/io/saved_contents.rs | 185 ++++++++++++++++++++++++ crates/ui-egui/src/tests/save.rs | 56 +++++++ 8 files changed, 415 insertions(+), 16 deletions(-) create mode 100644 crates/ui-egui/src/io/saved_contents.rs diff --git a/Cargo.lock b/Cargo.lock index b878d75456..1395815475 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9289,6 +9289,7 @@ dependencies = [ "rustix 1.1.6", "serde", "serde_json", + "sha2 0.10.9", "toml", "vectorcraft-apischema", "vectorcraft-brush", diff --git a/crates/ui-egui/Cargo.toml b/crates/ui-egui/Cargo.toml index eddc4bf6bd..a94d788e91 100644 --- a/crates/ui-egui/Cargo.toml +++ b/crates/ui-egui/Cargo.toml @@ -87,6 +87,9 @@ craft = { workspace = true, features = ["dialogs", "update", "automation-agents" # The local date and time the status bar's Date and Time readout shows (`chrono::Local`). Already in # Cargo.lock with the time-zone crates `clock` uses. chrono = { workspace = true, features = ["clock"] } +# The digest of each open document's file, which Save compares with the file before asking whether to replace it +# (`src/io/saved_contents.rs`). Already in Cargo.lock (the engine's and the plug-ins' digests). +sha2 = { version = "0.10", default-features = false } [target.'cfg(target_arch = "wasm32")'.dependencies] # The status bar's Date and Time readout reads the page's clock with this crate in the web build. It diff --git a/crates/ui-egui/src/app.rs b/crates/ui-egui/src/app.rs index e2b89abff8..b769dac802 100644 --- a/crates/ui-egui/src/app.rs +++ b/crates/ui-egui/src/app.rs @@ -658,6 +658,7 @@ impl VectorcraftApp { if !self.background.jobs.is_empty() || !self.opening.pending.is_empty() || !self.opening.converting.is_empty() + || io::save::checks_pending(self) || plugin_runs::any_pending(self) || !self.placing.pending.is_empty() || !self.trace_runs.running.is_empty() diff --git a/crates/ui-egui/src/io.rs b/crates/ui-egui/src/io.rs index 8d311212aa..ba7b2d856f 100644 --- a/crates/ui-egui/src/io.rs +++ b/crates/ui-egui/src/io.rs @@ -16,6 +16,8 @@ pub(crate) mod export; mod open; mod read_only_save; pub(crate) mod save; +#[cfg(not(target_arch = "wasm32"))] +mod saved_contents; #[cfg(test)] mod tests_read_only_save; diff --git a/crates/ui-egui/src/io/open.rs b/crates/ui-egui/src/io/open.rs index dce5bac6e5..a536eb1e1c 100644 --- a/crates/ui-egui/src/io/open.rs +++ b/crates/ui-egui/src/io/open.rs @@ -178,7 +178,7 @@ pub(crate) fn opened(app: &mut VectorcraftApp, r: &Value) { if let Some(st) = index.and_then(|i| app.session.documents().get(i)) && let Some(path) = &st.path { - app.saves.watch.known_now(st.uid, Path::new(path)); + app.saves.known_now(st.uid, Path::new(path)); } let notes = open_notes(app, r); crate::dialogs::missing_links::after_open(app, r, notes); diff --git a/crates/ui-egui/src/io/save.rs b/crates/ui-egui/src/io/save.rs index fc42da3c77..c09cbe7106 100644 --- a/crates/ui-egui/src/io/save.rs +++ b/crates/ui-egui/src/io/save.rs @@ -1,14 +1,16 @@ use std::collections::HashMap; -use std::path::PathBuf; -// The save panel's flow is the desktop's (craft-dialogs is native only); the web downloads. +use std::path::{Path, PathBuf}; #[cfg(not(target_arch = "wasm32"))] -use std::path::Path; +use std::sync::mpsc::{Receiver, TryRecvError}; +// The save panel's flow is the desktop's (craft-dialogs is native only); the web downloads. #[cfg(not(target_arch = "wasm32"))] use craft::dialogs::save::{SAVE_IN_PROGRESS, SaveDocument, SaveFlow, SaveStep, SaveTarget}; #[cfg(not(target_arch = "wasm32"))] use craft::host::Files; use craft::host::{FileFilter, PickRequest, Picked, Wake}; +#[cfg(not(target_arch = "wasm32"))] +use craft::platform::watch::FileStamp; use craft::platform::watch::FileWatch; use craft::ui::dialog::DialogId; #[cfg(not(target_arch = "wasm32"))] @@ -48,12 +50,27 @@ struct SaveDone { then: Option, } +/// A save whose flow would ask whether to replace its document's file, waiting for the file to be +/// compared with the bytes the app last read or wrote. +#[cfg(not(target_arch = "wasm32"))] +struct Checking { + path: PathBuf, + /// The file's version when it holds those bytes, else `None`. + answer: Receiver>, +} + /// The saves of the app: one [`SaveFlow`] per document, and what the flows need to ask and write. pub(crate) struct Saves { #[cfg(not(target_arch = "wasm32"))] flows: HashMap>, /// The version of each document's file the app last read or wrote. pub(crate) watch: FileWatch, + /// The digest of the bytes of each document's file, as the app last read or wrote them. + #[cfg(not(target_arch = "wasm32"))] + contents: super::saved_contents::SavedContents, + /// The saves waiting for a comparison of their document's file with those bytes. + #[cfg(not(target_arch = "wasm32"))] + checks: HashMap, /// The files written beside each document's file, which its next save replaces. pub(crate) written_beside: HashMap>, /// The files the OK of the replace question allows the save it runs again to replace. @@ -68,6 +85,10 @@ impl Saves { Self { #[cfg(not(target_arch = "wasm32"))] flows: HashMap::new(), + #[cfg(not(target_arch = "wasm32"))] + contents: super::saved_contents::SavedContents::new(), + #[cfg(not(target_arch = "wasm32"))] + checks: HashMap::new(), watch: FileWatch::new(wake), written_beside: HashMap::new(), replace_files_ok: Vec::new(), @@ -76,12 +97,55 @@ impl Saves { } } + /// The app just read document `uid`'s file at `path`: that version is not a change on disk. + pub(crate) fn known_now(&mut self, uid: u64, path: &Path) { + self.watch.known_now(uid, path); + #[cfg(not(target_arch = "wasm32"))] + self.note_contents(uid, path); + } + + /// Takes the digest of document `uid`'s file at `path`, the version the watcher just recorded. + #[cfg(not(target_arch = "wasm32"))] + fn note_contents(&mut self, uid: u64, path: &Path) { + match FileStamp::at(path) { + // Not differing from the watcher's version: the file has not changed since it was recorded. + Some(stamp) if !self.watch.disk_differs(&uid, path, None) => self.contents.note(uid, path, stamp), + _ => self.contents.forget(uid), + } + } + + /// Stops tracking document `uid`'s file (the document closed). + #[cfg(not(target_arch = "wasm32"))] + fn forget(&mut self, uid: u64) { + self.watch.forget(&uid); + self.contents.forget(uid); + self.checks.remove(&uid); + } + #[cfg(not(target_arch = "wasm32"))] fn start(&mut self, files: &dyn Files, document: SaveDocument, target: SaveTarget) -> SaveStep { let Self { flows, watch, .. } = self; flows.entry(document.key).or_default().start(files, watch, document, target) } + /// The answer of document `uid`'s file comparison, once it has come (with `wait`, once it + /// comes): the file's version when it holds the bytes the app last read or wrote, and the + /// file's path. `None` while there is no answer yet, or no comparison. + #[cfg(not(target_arch = "wasm32"))] + fn answer(&mut self, uid: u64, wait: bool) -> Option<(Option, PathBuf)> { + let check = self.checks.get(&uid)?; + let same = if wait { + check.answer.recv().ok().flatten() + } else { + match check.answer.try_recv() { + Ok(same) => same, + Err(TryRecvError::Empty) => return None, + Err(TryRecvError::Disconnected) => None, + } + }; + self.checks.remove(&uid).map(|c| (same, c.path)) + } + /// Frees the document's flow after a write that wrote nothing. #[cfg(not(target_arch = "wasm32"))] pub(super) fn release(&mut self, uid: u64) { @@ -91,6 +155,18 @@ impl Saves { } } +/// Whether file comparisons need another frame to collect their answers. +#[cfg(not(target_arch = "wasm32"))] +pub(crate) fn checks_pending(app: &VectorcraftApp) -> bool { + !app.saves.checks.is_empty() +} + +/// The web has no file comparisons to collect. +#[cfg(target_arch = "wasm32")] +pub(crate) fn checks_pending(_: &VectorcraftApp) -> bool { + false +} + /// Calls the `then` of the document's save, once. #[cfg(not(target_arch = "wasm32"))] fn terminate(app: &mut VectorcraftApp, uid: u64, r: Result) { @@ -107,7 +183,13 @@ fn finish(app: &mut VectorcraftApp, uid: u64, retargets: bool, out: &Result flow.written(&mut app.saves.watch, uid, Path::new(path)), + Some(path) if flow.is_busy() || retargets => { + flow.written(&mut app.saves.watch, uid, Path::new(path)); + // The document's own file (not a copy's): its digest goes with the version the watcher took. + if app.session.documents().iter().any(|d| d.uid == uid && d.path.as_deref() == Some(path)) { + app.saves.note_contents(uid, Path::new(path)); + } + } _ => flow.failed(&uid), } if !matches!(out, Ok(v) if v.get("pending").is_some()) { @@ -124,10 +206,12 @@ pub(crate) fn allow_replacing(app: &mut VectorcraftApp, files: &[String]) { } } -/// Takes what the flows and their questions have answered since the last pass: the pick, the -/// changed-on-disk question's answer. A save whose document closed is cancelled and forgotten. +/// Takes what the flows and their questions have answered since the last pass: the comparison of +/// a document's file, the pick, the changed-on-disk question's answer. A save whose document +/// closed is cancelled and forgotten. Closed documents' digest state is dropped on every pass. #[cfg(not(target_arch = "wasm32"))] pub(crate) fn pump(app: &mut VectorcraftApp, _ctx: &egui::Context) { + resume_checked(app, false); let busy: Vec = app.saves.flows.iter().filter(|(_, f)| f.is_busy()).map(|(uid, _)| *uid).collect(); for uid in busy { if !app.session.documents().iter().any(|d| d.uid == uid) { @@ -136,7 +220,7 @@ pub(crate) fn pump(app: &mut VectorcraftApp, _ctx: &egui::Context) { if let Some(mut flow) = app.saves.flows.remove(&uid) { flow.cancel(app.host.files()); } - app.saves.watch.forget(&uid); + app.saves.forget(uid); continue; } let (scope, automated) = app.saves.done.get(&uid).map_or_else(|| (ScopeHandle::capture(), app.automation_asked()), |d| d.asked.clone()); @@ -152,6 +236,54 @@ pub(crate) fn pump(app: &mut VectorcraftApp, _ctx: &egui::Context) { app.status(e); } } + app.saves.contents.retain_open(app.session.documents().iter().map(|d| d.uid)); +} + +/// Goes on with the saves whose file comparison has answered (with `wait`, every one, once it +/// answers): an unchanged file is written over, and a changed one is asked about. +#[cfg(not(target_arch = "wasm32"))] +fn resume_checked(app: &mut VectorcraftApp, wait: bool) { + let checking: Vec = app.saves.checks.keys().copied().collect(); + for uid in checking { + // A closed document's save is cancelled with its flow, in [`pump`]. + if !app.session.documents().iter().any(|d| d.uid == uid) { + continue; + } + let (scope, automated) = app.saves.done.get(&uid).map_or_else(|| (ScopeHandle::capture(), app.automation_asked()), |d| d.asked.clone()); + let r = scope.run(|| { + file_asks::as_automated(app, automated, |app| { + let (same, path) = app.saves.answer(uid, wait)?; + // Still that version: a change made since the comparison is asked about. + let Some(stamp) = same.filter(|stamp| FileStamp::at(&path) == Some(*stamp)) else { + let asked = ask_changed_on_disk(app, uid, &path); + return Some(settle(app, uid, asked)); + }; + // The same bytes: the file's version now is the document's, and the flow writes over it. + app.saves.watch.known_as(uid, &path, Some(stamp)); + let step = app.saves.flows.get_mut(&uid).map_or(SaveStep::Busy, SaveFlow::replace); + Some(run_step(app, uid, step)) + }) + }); + if let Some(Err(e)) = r + && e != "cancelled" + { + app.status(e); + } + } +} + +/// Waits for every save's file comparison and goes on with those saves. +#[cfg(all(test, not(target_arch = "wasm32")))] +pub(crate) fn wait_for_checks(app: &mut VectorcraftApp) { + resume_checked(app, true); +} + +/// Waits for the active document's baseline digest and compares it with the file. +#[cfg(all(test, not(target_arch = "wasm32")))] +pub(crate) fn wait_for_contents(app: &VectorcraftApp) -> Option { + let document = app.session.active()?; + let path = Path::new(document.path.as_deref()?); + app.saves.contents.check(document.uid, path)?.recv().ok().flatten() } /// The web has no save flows: nothing answers between passes. @@ -182,6 +314,12 @@ fn next_step(app: &mut VectorcraftApp, uid: u64) -> Option> { /// Runs `step` of the document `uid`'s save; a failure frees the flow and tells the caller. fn run_step(app: &mut VectorcraftApp, uid: u64, step: SaveStep) -> Result { let r = proceed(app, step); + settle(app, uid, r) +} + +#[cfg(not(target_arch = "wasm32"))] +/// The result `r` of a step of document `uid`'s save; a failure frees the flow and tells the caller. +fn settle(app: &mut VectorcraftApp, uid: u64, r: Result) -> Result { if r.is_err() { app.saves.release(uid); terminate(app, uid, r.clone()); @@ -189,19 +327,32 @@ fn run_step(app: &mut VectorcraftApp, uid: u64, step: SaveStep) -> Result Result { + let name = fileio::file_name(&path.to_string_lossy()); + let prompt = StandardPrompt::changed_on_disk(name).instance(("changed-on-disk", key)); + let id = app.dialogs().ok_or("no window to ask in")?.with(|host| host.open(prompt)); + if let Some(done) = app.saves.done.get_mut(&key) { + done.question = Some(id); + } + Ok(json!({ "pending": "changedOnDisk" })) +} + #[cfg(not(target_arch = "wasm32"))] fn proceed(app: &mut VectorcraftApp, step: SaveStep) -> Result { match step { SaveStep::Picking => Ok(json!({ "pending": "fileDialog" })), - SaveStep::AskChangedOnDisk { key, path } => { - let name = fileio::file_name(&path.to_string_lossy()); - let prompt = StandardPrompt::changed_on_disk(name).instance(("changed-on-disk", key)); - let id = app.dialogs().ok_or("no window to ask in")?.with(|host| host.open(prompt)); - if let Some(done) = app.saves.done.get_mut(&key) { - done.question = Some(id); + // Before asking, the file is compared with the bytes the app last read or wrote: a file + // whose metadata alone changed (a cloud-sync folder sets attributes on it, or puts the same + // bytes back as a new file) is written over without asking (#10734). [`pump`] goes on. + SaveStep::AskChangedOnDisk { key, path } => match app.saves.contents.check(key, &path) { + Some(answer) => { + app.saves.checks.insert(key, Checking { path, answer }); + Ok(json!({ "pending": "checkingFile" })) } - Ok(json!({ "pending": "changedOnDisk" })) - } + None => ask_changed_on_disk(app, key, &path), + }, SaveStep::Write { key, path, target, file_type } => write_step(app, key, &path.to_string_lossy(), target, file_type), SaveStep::Cancelled { key } => { terminate(app, key, Err("cancelled".into())); diff --git a/crates/ui-egui/src/io/saved_contents.rs b/crates/ui-egui/src/io/saved_contents.rs new file mode 100644 index 0000000000..3e3ff170b8 --- /dev/null +++ b/crates/ui-egui/src/io/saved_contents.rs @@ -0,0 +1,185 @@ +//! The bytes of each open document's file as the app last read or wrote them, kept as a SHA-256 +//! digest (#10734). Save asks before replacing a file another app changed, and the save flow +//! counts a new change time or a new inode as a change. A cloud-sync folder sets +//! attributes on a file after uploading it, or puts the same bytes back as a new file. When the +//! file on disk still holds the bytes the app wrote, Save writes without asking. +//! +//! Files are read and digested on threads of their own: a file in a cloud folder may have to be +//! downloaded first. + +use std::collections::HashMap; +use std::fs::File; +use std::io::Read; +use std::path::{Path, PathBuf}; +use std::sync::mpsc::{self, Receiver}; +use std::sync::{Arc, Mutex, MutexGuard, PoisonError}; +use std::thread::JoinHandle; + +use craft::platform::watch::FileStamp; +use sha2::{Digest, Sha256}; + +/// A version of a document's file: its path, its stamp when read, and the digest of its bytes. +#[derive(Clone)] +struct Version { + path: PathBuf, + stamp: FileStamp, + digest: [u8; 32], +} + +#[derive(Default)] +struct State { + versions: HashMap, + /// Counts the notes of each document: a digest taken for an older note is dropped. + notes: HashMap, + /// The digest being taken for each document's newest note. + pending: HashMap>, +} + +/// The digests of the open documents' files. +pub(crate) struct SavedContents { + state: Arc>, +} + +fn lock(state: &Mutex) -> MutexGuard<'_, State> { + state.lock().unwrap_or_else(PoisonError::into_inner) +} + +impl SavedContents { + /// No digests yet. + pub(crate) fn new() -> Self { + Self { state: Arc::default() } + } + + /// The app just read or wrote document `key`'s file at `path`, and `stamp` is that version. + /// The file is opened and its digest taken on a thread of its own. Any stamp change + /// before or during the read leaves no digest, so Save asks on a change. + pub(crate) fn note(&self, key: u64, path: &Path, stamp: FileStamp) { + let note = { + let mut state = lock(&self.state); + state.versions.remove(&key); + state.pending.remove(&key); + let note = state.notes.entry(key).or_default(); + *note = note.wrapping_add(1); + *note + }; + let state = Arc::clone(&self.state); + let path = path.to_path_buf(); + let work = move || { + let Ok(file) = File::open(&path) else { return }; + let Some(digest) = digest_of(file, stamp) else { return }; + let mut state = lock(&state); + if state.notes.get(&key) == Some(¬e) { + state.versions.insert(key, Version { path, stamp, digest }); + } + }; + // Without a thread nothing is recorded, and Save asks on any change, as before. + if let Ok(handle) = std::thread::Builder::new().name("vectorcraft-file-digest".into()).spawn(work) { + lock(&self.state).pending.insert(key, handle); + } + } + + /// Starts comparing document `key`'s file at `path` with the version the app last read or + /// wrote, on a thread of its own that first waits for that version's digest. The answer is + /// the file's version now when it holds the same bytes, and `None` when the bytes differ, the + /// file can't be read, or no digest of `path` was taken. `None` here when no thread starts. + pub(crate) fn check(&self, key: u64, path: &Path) -> Option>> { + let pending = lock(&self.state).pending.remove(&key); + let state = Arc::clone(&self.state); + let path = path.to_path_buf(); + let (send, answer) = mpsc::channel(); + let work = move || { + if let Some(handle) = pending { + // A digest thread that panicked recorded nothing. + let _ = handle.join(); + } + // The caller may be gone (its document closed): the answer is dropped. + let _ = send.send(unchanged(&state, key, &path)); + }; + std::thread::Builder::new().name("vectorcraft-file-check".into()).spawn(work).ok().map(|_| answer) + } + + /// Document `key` closed: its digest is dropped, and one still being taken is not recorded. + pub(crate) fn forget(&self, key: u64) { + let mut state = lock(&self.state); + state.versions.remove(&key); + state.pending.remove(&key); + let note = state.notes.entry(key).or_default(); + *note = note.wrapping_add(1); + } + + /// Drops closed documents' versions, pending handles and note counters only when needed. + /// Removing a note counter prevents its digest thread from recording a version later. + pub(crate) fn retain_open(&self, open: impl Iterator + Clone) { + let mut state = lock(&self.state); + let is_open = |key: &u64| open.clone().any(|uid| uid == *key); + if state.notes.keys().any(|key| !is_open(key)) { + state.versions.retain(|key, _| is_open(key)); + state.pending.retain(|key, _| is_open(key)); + state.notes.retain(|key, _| is_open(key)); + } + } +} + +/// [`SavedContents::check`]'s answer, on its thread. +fn unchanged(state: &Mutex, key: u64, path: &Path) -> Option { + let version = lock(state).versions.get(&key).filter(|v| v.path == path).cloned()?; + let now = FileStamp::at(path)?; + if now.len() != version.stamp.len() || digest_of(File::open(path).ok()?, now)? != version.digest || FileStamp::at(path) != Some(now) { + return None; + } + if let Some(v) = lock(state).versions.get_mut(&key).filter(|v| v.digest == version.digest) { + v.stamp = now; + } + Some(now) +} + +/// The digest of `file`, read while its full stamp stays at `stamp`; `None` when the stamp +/// differs or the file can't be read. A Unix change time alone can also signal changed bytes. +fn digest_of(mut file: File, stamp: FileStamp) -> Option<[u8; 32]> { + if !file.metadata().is_ok_and(|m| FileStamp::of(&m) == stamp) { + return None; + } + let mut hasher = Sha256::new(); + let mut buffer = vec![0u8; 64 * 1024]; + loop { + let n = file.read(&mut buffer).ok()?; + if n == 0 { + break; + } + hasher.update(buffer.get(..n)?); + } + file.metadata().is_ok_and(|m| FileStamp::of(&m) == stamp).then(|| hasher.finalize().into()) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn retaining_open_documents_drops_closed_documents_state() { + let folder = crate::tests_folder::Folder::new("saved-contents-retain"); + let file = folder.file("document", b"saved contents"); + let path = Path::new(&file); + let stamp = FileStamp::at(path).unwrap(); + let contents = SavedContents::new(); + for uid in [1, 2] { + contents.note(uid, path, stamp); + assert!(contents.check(uid, path).unwrap().recv().unwrap().is_some()); + } + // A third document closes while its digest handle is still retained. + contents.note(3, path, stamp); + contents.retain_open([2].into_iter()); + + { + let state = lock(&contents.state); + for uid in [1, 3] { + assert!(!state.versions.contains_key(&uid)); + assert!(!state.pending.contains_key(&uid)); + assert!(!state.notes.contains_key(&uid)); + } + } + assert!(contents.check(1, path).unwrap().recv().unwrap().is_none()); + assert!(contents.check(3, path).unwrap().recv().unwrap().is_none()); + assert!(contents.check(2, path).unwrap().recv().unwrap().is_some()); + } +} diff --git a/crates/ui-egui/src/tests/save.rs b/crates/ui-egui/src/tests/save.rs index b1fa7cb347..de7728f9e7 100644 --- a/crates/ui-egui/src/tests/save.rs +++ b/crates/ui-egui/src/tests/save.rs @@ -593,3 +593,59 @@ fn acknowledging_import_loss_does_not_overwrite_the_source_with_another_drawing( assert!(after_switch == saved, "drawing B must never overwrite A's file"); assert!(after_original != saved, "approval in drawing A must still save A"); } + +/// Puts `bytes` at `path` as a new file, as a cloud-sync folder puts a file back after uploading +/// it: the file gets a new inode and new change and modification times. +fn put_back(path: &str, bytes: &[u8]) { + let next = format!("{path}.sync"); + std::fs::write(&next, bytes).unwrap(); + std::fs::rename(&next, path).unwrap(); +} + +/// Once its baseline digest is recorded, Save writes without asking while the file holds the +/// bytes the app last read or wrote (#10734), and asks once they differ, even at the same length. +#[test] +fn save_asks_about_a_changed_file_only_when_its_bytes_changed() { + let d = dir("same-bytes"); + let path = d.join("a.vectorcraft").to_string_lossy().to_string(); + let mut writer = app(); + writer.run("file.new", json!({"width": 100, "height": 100})).unwrap(); + rect(&mut writer); + writer.run("file.saveAs", json!({"path": path})).unwrap(); + crate::background::wait_all(&mut writer); + let mut app = app(); + io::open_path(&mut app, &path).unwrap(); + assert!(io::save::wait_for_contents(&app).is_some(), "the opened file's baseline is recorded before sync"); + + let saved = |app: &VectorcraftApp| vectorcraft_format::load(&std::fs::read(&path).unwrap()).unwrap().node_count() == objects(app); + // File › Save, once the file has been compared: did it ask? + let save = |app: &mut VectorcraftApp| { + rect(app); + assert_eq!(app.run("file.save", json!({})).unwrap()["pending"], "checkingFile"); + io::save::wait_for_checks(app); + crate::background::wait_all(app); + if !app.any_dialog_open() { + assert!(io::save::wait_for_contents(app).is_some(), "the written file's baseline is recorded before sync"); + } + app.any_dialog_open() + }; + + // Read from the file: the same bytes put back. + put_back(&path, &std::fs::read(&path).unwrap()); + assert!(!save(&mut app)); + assert!(saved(&app)); + + // Written by that save: the same bytes put back. + put_back(&path, &std::fs::read(&path).unwrap()); + assert!(!save(&mut app)); + assert!(saved(&app)); + + // Other bytes of the same length. + let mut other = std::fs::read(&path).unwrap(); + let last = other.last_mut().unwrap(); + *last ^= 0xff; + put_back(&path, &other); + assert!(save(&mut app), "asks whether to replace the file"); + assert_eq!(std::fs::read(&path).unwrap(), other, "nothing is written before the answer"); + let _ = std::fs::remove_dir_all(d); +} From e009722fe8f069a1c67adff8360ffe0db896f6d4 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 5 Dec 2026 05:02:06 -0800 Subject: [PATCH 05/41] Canvas: a drag moves the kept anchor marks mesh instead of tessellating it Each step of a drag moved the kept selection marks, but the anchor marks' mesh was keyed on the marks key, which changes with every revision, so every step tessellated the anchors, handles and outlines again and flattened every outline. With about 2,000 paths selected that was the largest part of each step. The kept mesh now moves with the marks when that gives what a new tessellation gives: the move since the mesh was tessellated is a whole number of physical pixels on screen, so pixel rounding lands the same, and every anchor and handle is inside the canvas and the clip before and after the move, so no mark is left out or culled. Otherwise the next paint tessellates the marks as before. A new revision of the same document and selection also keeps the mesh. --- crates/ui-egui/src/canvas/selection.rs | 68 ++++++++++++++++- crates/ui-egui/src/canvas/selection/tests.rs | 77 ++++++++++++++++++++ 2 files changed, 143 insertions(+), 2 deletions(-) diff --git a/crates/ui-egui/src/canvas/selection.rs b/crates/ui-egui/src/canvas/selection.rs index 861eda0790..b6421c882b 100644 --- a/crates/ui-egui/src/canvas/selection.rs +++ b/crates/ui-egui/src/canvas/selection.rs @@ -688,6 +688,59 @@ struct MeshKey { pub(crate) struct KeptMesh { key: MeshKey, mesh: Arc, + /// How far the marks moved on screen since they were tessellated, in physical pixels, unrounded + /// ([`KeptMesh::translate`]). The mesh moved by this distance rounded. + moved: [f64; 2], +} + +/// How far from a whole number of physical pixels the marks' move since they were tessellated may be on screen, and +/// still count as whole: rounding noise of the screen position, well under what the tessellator's `f32` positions hold. +const PIXEL_SLACK: f64 = 1e-6; + +impl KeptMesh { + /// Moves the mesh by `by` in the document when tessellating the moved marks would give the same mesh moved, and + /// returns whether it did. `was` is the box of the marks' points before the move ([`knots_box`]). The mesh moves + /// when the marks' whole move since they were tessellated is a whole number of physical pixels on screen, so the + /// tessellator's rounding to pixels lands the same, and when every point is inside the canvas the marks are drawn + /// near and inside the clip both before and after the move, so no anchor, handle or outline is left out or culled + /// on either side. + fn translate(&mut self, by: Vec2, was: Option) -> bool { + let key = &self.key; + let ppp = f64::from(key.pixels_per_point); + let view = key.view.affine(); + let shift = (view * (Point::ZERO + by)) - (view * Point::ZERO); + let moved = [self.moved[0] + shift.x * ppp, self.moved[1] + shift.y * ppp]; + if moved.iter().any(|p| !p.is_finite() || (p - p.round()).abs() > PIXEL_SLACK) { + return false; + } + if let Some(was) = was { + let area = key.rect.expand(key.look.reach).intersect(key.clip); + let inside = |r: vectorcraft_geom::Rect| { + [(r.x0, r.y0), (r.x1, r.y0), (r.x1, r.y1), (r.x0, r.y1)].into_iter().all(|(x, y)| area.contains(key.view.to_screen(Point::new(x, y)))) + }; + if !(inside(was) && inside(was + by)) { + return false; + } + } + let step = |axis: usize| ((moved[axis].round() - self.moved[axis].round()) / ppp) as f32; + let offset = vec2(step(0), step(1)); + self.moved = moved; + Arc::make_mut(&mut self.mesh).translate(offset); + true + } +} + +/// The box of every anchor and direction handle of `anchors`, in document units, or `None` without any. The outlines +/// lie inside it too, as a curve lies inside the hull of its points. +fn knots_box(anchors: &Anchors) -> Option { + anchors + .paths + .iter() + .chain(&anchors.plain) + .flat_map(|p| &p.subpaths) + .flat_map(|sp| &sp.knots) + .flat_map(|knot| [knot.anchor, knot.in_ctrl, knot.out_ctrl]) + .fold(None, |r: Option, p| Some(r.map_or(vectorcraft_geom::Rect::from_points(p, p), |r| r.union_pt(p)))) } /// One set of anchors as `BezierOverlay` took it: the paths, which anchors are selected and how they show. @@ -809,7 +862,7 @@ impl Component for AnchorMarks<'_> { None => { let shapes = shapes(); let mesh = Arc::new(tessellate(shapes, &key)); - *kept = Some(KeptMesh { key, mesh: Arc::clone(&mesh) }); + *kept = Some(KeptMesh { key, mesh: Arc::clone(&mesh), moved: [0.0; 2] }); mesh } }; @@ -1198,12 +1251,23 @@ impl SelectionMarks { self.from = (moved.from.clone(), moved.by); self.doc = moved.to.clone(); } + // The kept mesh shows these marks, so it stays theirs under the new key. + let was = self.key; + if let Some(kept) = self.mesh.get_mut().as_mut().filter(|kept| kept.key.marks == was) { + kept.key.marks = key; + } self.key = key; Some(self) } - /// Moves every mark by `by`. + /// Moves every mark by `by`, and the kept mesh of the anchor marks with them when it can move as it is + /// ([`KeptMesh::translate`]); otherwise the next paint tessellates the marks again. fn translate(&mut self, by: Vec2) { + let was = knots_box(&self.anchors); + let mesh = self.mesh.get_mut(); + if mesh.as_mut().is_some_and(|kept| !kept.translate(by, was)) { + *mesh = None; + } let shift = vectorcraft_geom::Affine::translate(by); for o in &mut self.outlines { o.paths.iter_mut().chain(o.key.as_mut()).for_each(|path| path.apply_affine(shift)); diff --git a/crates/ui-egui/src/canvas/selection/tests.rs b/crates/ui-egui/src/canvas/selection/tests.rs index 65ca87aff3..f23e4087aa 100644 --- a/crates/ui-egui/src/canvas/selection/tests.rs +++ b/crates/ui-egui/src/canvas/selection/tests.rs @@ -1283,3 +1283,80 @@ fn a_move_of_the_selection_moves_its_marks_without_building_them() { assert_eq!(frames(&mut app, 3), 1, "an undo"); assert!(kept_marks_are_current(&app), "after an undo"); } + +/// The mesh of the anchor marks the canvas keeps. +fn kept_mesh(app: &VectorcraftApp) -> Arc { + let marks = app.canvas.selection_marks.as_ref().expect("the canvas drew the selection's marks"); + let kept = marks.mesh.borrow(); + Arc::clone(&kept.as_ref().expect("the canvas kept the anchor marks' mesh").mesh) +} + +// A drag of the selection moves the kept mesh of its anchor marks instead of tessellating them again: steps of whole +// pixels tessellate nothing and leave the mesh a new tessellation gives, a new revision of the same marks keeps it, and +// a step of part of a pixel or one that takes the marks past the canvas's edge tessellates them once. +#[test] +fn a_drag_of_the_selection_moves_the_anchor_marks_mesh_without_tessellating_it() { + let (mut app, curve) = canvas_app(); + app.select_tool("selection"); + app.run("select.set", json!({"ids": [curve.0]})).unwrap(); + let ctx = crate::testing::ui_context(); + let frames = |app: &mut VectorcraftApp, n: usize| { + let before = MESHES_BUILT.with(std::cell::Cell::get); + for _ in 0..n { + canvas_frame(app, &ctx, vec![]); + } + MESHES_BUILT.with(std::cell::Cell::get) - before + }; + assert_eq!(frames(&mut app, 2), 1, "the first frame tessellates the marks"); + // A document distance that is `px` physical pixels across on screen. + let pixels = |app: &VectorcraftApp, px: f64| px / (app.canvas_view().unwrap().zoom * f64::from(ctx.pixels_per_point())); + let step = |app: &mut VectorcraftApp, dx: f64| { + app.session.preview("object.transform", &json!({"matrix": [1, 0, 0, 1, dx, 0], "copy": false})).unwrap(); + }; + + let layer = app.session.active().unwrap().doc.layers[0].id; + app.run("layer.setCurrent", json!({"id": layer.0})).unwrap(); + assert_eq!(frames(&mut app, 2), 0, "a new revision of the same document and selection"); + + // The kept mesh matches the one marks built now tessellate; the kept marks go back afterwards, so the drag + // goes on moving them. + let matches_new = |app: &mut VectorcraftApp, case: &str| { + let moved = kept_mesh(app); + let kept = app.canvas.selection_marks.take(); + canvas_frame(app, &ctx, vec![]); + let fresh = kept_mesh(app); + app.canvas.selection_marks = kept; + assert!(!fresh.vertices.is_empty(), "{case}: the marks drew something"); + assert_eq!(moved.indices, fresh.indices, "{case}: the moved mesh has the triangles of a new one"); + assert_eq!(moved.vertices.len(), fresh.vertices.len(), "{case}"); + for (a, b) in moved.vertices.iter().zip(&fresh.vertices) { + assert_eq!(a.color, b.color, "{case}"); + assert!((a.pos - b.pos).length() < 1e-3, "{case}: a moved vertex at {:?}, a new one at {:?}", a.pos, b.pos); + } + }; + + app.session.begin_interaction("Move").unwrap(); + let built = MARKS_BUILT.with(std::cell::Cell::get); + for px in [3.0, 10.0, -4.0] { + let dx = pixels(&app, px); + step(&mut app, dx); + assert_eq!(frames(&mut app, 2), 0, "a drag's step to {px} pixels"); + } + assert_eq!(MARKS_BUILT.with(std::cell::Cell::get), built, "the drag moved the kept marks"); + matches_new(&mut app, "after whole pixels"); + + let built = MARKS_BUILT.with(std::cell::Cell::get); + let dx = pixels(&app, -4.5); + step(&mut app, dx); + assert_eq!(frames(&mut app, 2), 1, "a step to part of a pixel"); + let dx = pixels(&app, -3.5); + step(&mut app, dx); + assert_eq!(frames(&mut app, 2), 0, "a whole pixel from the marks tessellated at part of one"); + assert_eq!(MARKS_BUILT.with(std::cell::Cell::get), built, "the drag moved the kept marks"); + matches_new(&mut app, "after part of a pixel and a whole one"); + // Whole pixels from the last step. + let dx = pixels(&app, 1996.5); + step(&mut app, dx); + assert_eq!(frames(&mut app, 2), 1, "a step past the canvas's edge"); + app.session.commit_interaction().unwrap(); +} From 7961e2563b77137edbcbd5b52ca205333847de41 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 5 Dec 2026 05:57:45 -0800 Subject: [PATCH 06/41] Tests: check the imported instance transforms with is_finite The gate's test-lint flagged the coefficient .all() check as unguarded. --- crates/cad/src/import/tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/cad/src/import/tests.rs b/crates/cad/src/import/tests.rs index 08f683a65f..fae4602028 100644 --- a/crates/cad/src/import/tests.rs +++ b/crates/cad/src/import/tests.rs @@ -1158,7 +1158,7 @@ fn a_dashed_block_at_a_tiny_scale_in_a_huge_fitted_drawing_keeps_a_finite_instan } assert!(instances.iter().any(|(symbol, _)| symbol == "D0"), "{instances:?}"); for (symbol, xf) in &instances { - assert!(xf.as_coeffs().iter().all(|c| c.is_finite()), "{symbol}: {xf:?}"); + assert!(xf.is_finite(), "{symbol}: {xf:?}"); } } From c2485d29ef5be4720fb3227b9b2829d409ab2d9a Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 5 Dec 2026 07:05:45 -0800 Subject: [PATCH 07/41] Swatches: a Swatch Strip panel of one-click color chips MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Window › Swatch Strip shows a None chip and then the document's color swatches as a row of chips that wraps to the panel's room and scrolls when the chips do not fit. Docked on the window's bottom edge the chips run across in one line; in a dock column or a narrow floating window they run down it. Gradient and pattern swatches are left out. A click on a chip sets the fill (paint.setFill) and a right-click or an Alt-click sets the stroke (paint.setStroke). Both pass focus: false, so the active Fill or Stroke proxy stays as it was. - window.panel {panel: "swatchStrip"} shows the panel, and window.panel.dock with placement {"Edge": "Bottom"} beside the canvas docks it along the bottom edge. - The Swatches panel's shown() is shared so the strip draws a spot color the way its art shows it. Docs: docs/control-protocol.md, ROADMAP. Fixes #10951 --- ROADMAP.md | 1 + crates/ui-egui/src/menus/tree.rs | 1 + crates/ui-egui/src/panels.rs | 2 + crates/ui-egui/src/panels/swatch_strip.rs | 216 ++++++++++++++++++++++ crates/ui-egui/src/panels/swatches.rs | 2 +- crates/ui-egui/src/state.rs | 1 + docs/control-protocol.md | 7 + 7 files changed, 229 insertions(+), 1 deletion(-) create mode 100644 crates/ui-egui/src/panels/swatch_strip.rs diff --git a/ROADMAP.md b/ROADMAP.md index 9b6adac135..9eb13ef8d4 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -124,6 +124,7 @@ Ranked; detail in [docs/roadmap.md](docs/roadmap.md) and [docs/gaps.md](docs/gap ## Progress log +- 2026-12-05: Window › Swatch Strip shows a None chip and the document's color swatches as a strip of chips that wraps to the panel's room: docked on the window's bottom edge it runs across in one line, and in a dock column or a narrow floating window it runs down. A click sets the fill and a right-click or Alt-click sets the stroke (#10951). A VectorCraft addition: headline numbers unchanged. - 2026-12-04: Raster Settings OK edits the objects selected when the dialog opened. It keeps the dialog open with the reason if its document is not active, was reverted or had an Undo, a Redo or a canceled edit that put back an earlier state, if a target was changed, deleted, locked or hidden, if another edit is in progress, or if the change is refused. Headline numbers unchanged. - 2026-12-04: Paste from CAD apps: on Windows, Paste reads the enhanced metafile CAD and office apps copy as vector art, and a `.dxf`, `.dwg` or HP-GL plot file copied in a file manager pastes as its drawing through the new command `clipboard.importCad` (#10819). Headline numbers unchanged. diff --git a/crates/ui-egui/src/menus/tree.rs b/crates/ui-egui/src/menus/tree.rs index dad0879333..fd144ad2b2 100644 --- a/crates/ui-egui/src/menus/tree.rs +++ b/crates/ui-egui/src/menus/tree.rs @@ -798,6 +798,7 @@ fn built_in_tree(english_names: bool, listed: &Listed) -> Vec<(&'static str, Vec panel("Separations Preview", "separations"), panel("Stroke", "stroke"), panel("SVG Interactivity", crate::panels::svg_interactivity::ID), + panel("Swatch Strip", crate::panels::swatch_strip::ID), panel("Swatches", "swatches"), panel("Symbols", "symbols"), panel("Transform", "transform"), diff --git a/crates/ui-egui/src/panels.rs b/crates/ui-egui/src/panels.rs index cf129bf26c..adbacb0382 100644 --- a/crates/ui-egui/src/panels.rs +++ b/crates/ui-egui/src/panels.rs @@ -46,6 +46,7 @@ pub mod script_console; pub mod separations; pub mod stroke; pub mod svg_interactivity; +pub mod swatch_strip; pub mod swatches; pub mod symbols; pub mod tabs; @@ -568,6 +569,7 @@ pub(crate) fn set_part_hidden(app: &mut VectorcraftApp, key: &'static str, on: b pub fn show_icon_panel(app: &mut VectorcraftApp, ui: &mut Ui, id: &str) { match id { "swatches" => swatches::show(app, ui), + swatch_strip::ID => swatch_strip::show(app, ui), "color" => color::show(app, ui), "colorGuide" => color_guide::show(app, ui), "stroke" => stroke::show(app, ui), diff --git a/crates/ui-egui/src/panels/swatch_strip.rs b/crates/ui-egui/src/panels/swatch_strip.rs new file mode 100644 index 0000000000..f6a5f4e8f2 --- /dev/null +++ b/crates/ui-egui/src/panels/swatch_strip.rs @@ -0,0 +1,216 @@ +//! Swatch Strip panel (Window › Swatch Strip): a None chip, then the document's color swatches, in a row of chips +//! that wraps to the room the panel has. Docked along the bottom of the window (`window.panel.dock {panel: +//! "swatchStrip", anchor: "canvas", placement: {"Edge": "Bottom"}}`, or a drop on the bottom edge) the chips run +//! across in one line; in a dock column or a narrow floating window they wrap down the column, and scroll when they +//! do not fit. +//! +//! A click on a chip sets the fill (`paint.setFill`); a right-click or an Alt-click sets the stroke +//! (`paint.setStroke`). Neither changes which of the Fill and Stroke proxies is active. + +use craft::theme::Srgba; +use craft::ui::choice::Swatch; +use craft::ui::contract::{Props as _, Scroll, Show as _, ShowContainer as _}; +use craft::ui::layout_components::{Row, Stack}; +use egui::{PointerButton, Ui}; +use serde_json::{Value, json}; +use vectorcraft_color::Paint; + +use super::srgba; +use crate::VectorcraftApp; + +/// The panel's id, as `window.panel` takes it. +pub const ID: &str = "swatchStrip"; + +/// One chip: its name, the color it shows (`None`: the None chip) and the paint params a pick sends. +struct Chip { + name: String, + color: Option, + params: Value, +} + +/// The None chip, then each color swatch of the active document in the Swatches panel's order (the swatches outside +/// any color group, then each group's), shown in the color its art shows. Gradient and pattern swatches are left out. +fn chips(app: &VectorcraftApp) -> Vec { + let Some(st) = app.session.active() else { return Vec::new() }; + let d = &st.doc; + let none = Chip { name: tl!("None").to_owned(), color: None, params: json!({"none": true}) }; + let swatches = d.swatches_iter().filter_map(|s| match super::swatches::shown(d, s).0 { + Paint::Solid { color, .. } => Some(Chip { name: s.name.clone(), color: Some(srgba(&color)), params: json!({"swatch": s.name}) }), + _ => None, + }); + std::iter::once(none).chain(swatches).collect() +} + +/// Sets the fill (`stroke`: the stroke) to the chip's paint, leaving the active proxy as it is. +fn apply(app: &mut VectorcraftApp, chip: &Chip, stroke: bool) { + let mut params = chip.params.clone(); + params["focus"] = json!(false); + app.run(if stroke { "paint.setStroke" } else { "paint.setFill" }, params).ok(); +} + +/// The panel's body. +pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) { + if app.session.active().is_none() { + super::empty_state(ui, "swatch-book", tl!("No document"), tl!("Open a document to see its swatches.")); + return; + } + let chips = chips(app); + let mut picked = None; + Stack::new().id_salt(ID).fill().scroll(Scroll::vertical()).show(ui, |ui, _| { + Row::new().fill_width().wrap(true).show(ui, |ui, _| { + for (at, chip) in chips.iter().enumerate() { + let swatch = match chip.color { + Some(color) => Swatch::new(chip.name.clone(), color), + None => Swatch::optional(chip.name.clone(), None::), + }; + let out = swatch.id_salt(at).tooltip(chip.name.clone()).show(ui); + // A right-click ends on the chip, as the framework's swatch palette reads one. + let secondary = out.response.contains_pointer() && ui.input(|i| i.pointer.button_released(PointerButton::Secondary)); + if out.clicked || secondary { + picked = Some((at, secondary || out.activation.is_some_and(|a| a.mods.alt))); + } + } + }); + }); + if let Some((at, stroke)) = picked + && let Some(chip) = chips.get(at) + { + apply(app, chip, stroke); + } +} + +#[cfg(test)] +mod tests { + use craft::behavior::Axis; + use craft::behavior::dock::Node; + use egui::{Modifiers, vec2}; + use serde_json::json; + use vectorcraft_color::Paint; + use vectorcraft_engine::Session; + + use super::show; + use crate::VectorcraftApp; + use crate::tests::panel_harness::Panel; + + /// A document with three global color swatches (art painted with one stays linked to it) and a gradient swatch, + /// and one selected rectangle. + fn app() -> VectorcraftApp { + let mut app = VectorcraftApp::new(Session::new(), Default::default()); + app.run("file.new", json!({"width": 200, "height": 200})).unwrap(); + for (name, color) in [("Strip Red", "#cc2222"), ("Strip Green", "#22aa44"), ("Strip Blue", "#2244cc")] { + app.run("swatch.new", json!({"name": name, "color": color, "global": true})).unwrap(); + } + let ramp = json!({"kind": "linear", "stops": [{"offset": 0, "color": "#000"}, {"offset": 1, "color": "#fff"}]}); + app.run("swatch.new", json!({"name": "Strip Ramp", "gradient": ramp})).unwrap(); + app.run("shape.rectangle", json!({"x": 10, "y": 10, "width": 50, "height": 50})).unwrap(); + app + } + + /// The fill and stroke the Fill and Stroke proxies show: the selected rectangle's. + fn paints(panel: &Panel) -> (Paint, Paint) { + crate::panels::current_paints(&panel.app()) + } + + /// The swatch a solid paint is linked to. + fn swatch_of(paint: &Paint) -> Option { + match paint { + Paint::Solid { swatch, .. } => swatch.clone(), + _ => None, + } + } + + #[test] + fn a_click_sets_the_fill_and_a_right_click_or_alt_click_the_stroke() { + let mut panel = Panel::new(app(), show); + let fill_active = panel.app().session.fill_active; + + panel.click("Strip Red"); + let (fill, stroke) = paints(&panel); + assert_eq!(swatch_of(&fill).as_deref(), Some("Strip Red"), "a click sets the fill"); + assert_ne!(swatch_of(&stroke).as_deref(), Some("Strip Red"), "a click leaves the stroke"); + + panel.secondary_click("Strip Green"); + let (fill, stroke) = paints(&panel); + assert_eq!(swatch_of(&stroke).as_deref(), Some("Strip Green"), "a right-click sets the stroke"); + assert_eq!(swatch_of(&fill).as_deref(), Some("Strip Red"), "a right-click leaves the fill"); + + panel.click_with("Strip Blue", Modifiers::ALT); + let (fill, stroke) = paints(&panel); + assert_eq!(swatch_of(&stroke).as_deref(), Some("Strip Blue"), "an Alt-click sets the stroke"); + assert_eq!(swatch_of(&fill).as_deref(), Some("Strip Red"), "an Alt-click leaves the fill"); + + assert_eq!(panel.app().session.fill_active, fill_active, "the active proxy stays as it was"); + } + + #[test] + fn the_none_chip_comes_first_and_takes_the_paint_off() { + let mut panel = Panel::new(app(), show); + let none = panel.rect("None"); + let red = panel.rect("Strip Red"); + assert!(none.left() < red.left() || none.top() < red.top(), "the None chip comes before the swatches: {none:?} {red:?}"); + + panel.click("Strip Red"); + panel.click("None"); + assert!(paints(&panel).0.is_none(), "a click on None takes the fill off"); + panel.secondary_click("None"); + assert!(paints(&panel).1.is_none(), "a right-click on None takes the stroke off"); + } + + #[test] + fn only_color_swatches_get_chips() { + let panel = Panel::new(app(), show); + assert!(panel.shows("Strip Red"), "a color swatch has a chip"); + assert!(!panel.shows("Strip Ramp"), "a gradient swatch has none"); + } + + #[test] + fn the_chips_run_along_a_wide_strip_and_wrap_down_a_narrow_one() { + let mut panel = Panel::new(app(), show); + let names = ["None", "Strip Red", "Strip Green", "Strip Blue"]; + + panel.room(vec2(4000.0, 200.0)).frame(); + panel.frame(); + let rects: Vec<_> = names.iter().map(|n| panel.rect(n)).collect(); + for pair in rects.windows(2) { + assert!((pair[0].center().y - pair[1].center().y).abs() < 1.0, "the chips share one line: {pair:?}"); + assert!(pair[0].right() <= pair[1].left(), "each chip lies after the one before it without overlapping: {pair:?}"); + } + + let one_chip = rects[0].width(); + panel.room(vec2(one_chip * 2.5, 2000.0)).frame(); + panel.frame(); + let first = panel.rect("None"); + let last = panel.rect("Strip Blue"); + assert!(last.top() >= first.bottom(), "in a narrow column a later chip wraps below the first: {first:?} {last:?}"); + assert!(last.right() <= one_chip * 2.5 + 0.5, "the chips stay inside the column: {last:?}"); + } + + /// Whether `node` holds panel `panel`. + fn holds(node: &Node, panel: &str) -> bool { + match node { + Node::Split { first, second, .. } => holds(first, panel) || holds(second, panel), + Node::Tabs { panels, .. } => panels.iter().any(|p| p == panel), + Node::Stack { entries, .. } => entries.iter().any(|e| e.panel == panel), + Node::Dock { columns, .. } => columns.iter().any(|c| c.panels().any(|p| p == panel)), + _ => false, + } + } + + /// Whether `node` has a split of rows with `upper` in its top part and `lower` in its bottom part. + fn above(node: &Node, upper: &str, lower: &str) -> bool { + match node { + Node::Split { axis: Axis::Y, first, second, .. } if holds(first, upper) && holds(second, lower) => true, + Node::Split { first, second, .. } => above(first, upper, lower) || above(second, upper, lower), + _ => false, + } + } + + #[test] + fn the_strip_docks_along_the_bottom_edge_below_the_canvas() { + let mut app = app(); + app.run("window.panel.dock", json!({"panel": super::ID, "anchor": "canvas", "placement": {"Edge": "Bottom"}})).unwrap(); + let layout = crate::panel_docking::layout_of(&app.ui); + let root = layout.root.as_ref().expect("a docked layout"); + assert!(above(root, crate::panel_docking::CANVAS, super::ID), "the strip lies in a row below the canvas: {root:?}"); + } +} diff --git a/crates/ui-egui/src/panels/swatches.rs b/crates/ui-egui/src/panels/swatches.rs index bea36866bb..8142bc9d33 100644 --- a/crates/ui-egui/src/panels/swatches.rs +++ b/crates/ui-egui/src/panels/swatches.rs @@ -284,7 +284,7 @@ fn highlighted<'a>(d: &'a Document, sel: &'a [String]) -> Vec<&'a str> { /// The `swatch`'s paint as the panel shows it, and whether it is global and spot. A tint swatch shows its base's kind; /// a spot colour shows the colour its art shows (a Lab one's CMYK equivalent when the Spot Colors options use those). -fn shown(d: &Document, s: &Swatch) -> (Paint, bool, bool) { +pub(crate) fn shown(d: &Document, s: &Swatch) -> (Paint, bool, bool) { let (global, spot) = s.tint_of().and_then(|(base, _)| d.swatch(base)).map_or((s.global, s.spot), |b| (b.global, b.spot)); let paint = match s.paint { Paint::Solid { color, swatch: None, .. } if spot => Paint::solid(d.linked_color(color, true)), diff --git a/crates/ui-egui/src/state.rs b/crates/ui-egui/src/state.rs index cfc38a0be6..133f7e97e8 100644 --- a/crates/ui-egui/src/state.rs +++ b/crates/ui-egui/src/state.rs @@ -308,6 +308,7 @@ pub const ICON_PANELS: &[(&str, &str, &str)] = &[ ("color", "Color", "palette"), ("colorGuide", "Color Guide", "dc-color-guide"), ("swatches", "Swatches", "swatch-book"), + (crate::panels::swatch_strip::ID, "Swatch Strip", "swatch-book"), ("brushes", "Brushes", "paintbrush"), ("symbols", "Symbols", "spray-can"), ("patternOptions", "Pattern Options", "grid-3x3"), diff --git a/docs/control-protocol.md b/docs/control-protocol.md index 0f4d35f635..204d98696d 100644 --- a/docs/control-protocol.md +++ b/docs/control-protocol.md @@ -289,6 +289,13 @@ or `rgbPercent` value that is not true or false. The desktop app keeps the four switches R, G and B between percent and 0 to 255 and answers true when they show in percent; a parameter answers an error and changes nothing. +Swatch Strip panel (`window.panel {panel: "swatchStrip"}`): a None chip, then the document's color swatches (the +swatches outside any color group, then each group's; gradient and pattern swatches are left out), in a row of chips +that wraps to the panel's room and scrolls when they do not fit. `window.panel.dock {panel: "swatchStrip", anchor: +"canvas", placement: {"Edge": "Bottom"}}` docks it along the window's bottom edge, where the chips run across in one +line. A click on a chip runs `paint.setFill {swatch}` (`{none: true}` for None) and a right-click or an Alt-click +runs `paint.setStroke`, both with `focus: false`, so the active proxy stays as it was. + Color Themes panel (`window.panel {panel: "colorThemes"}`): its Create tab makes a theme on a harmony wheel and its My Themes tab lists the saved themes; every action runs a command (`colorTheme.save`, `colorTheme.delete`, `colorTheme.addToSwatches`, `swatch.newGroup` for the theme being made), and `colorTheme.list` reads the library. From e90b66052709aff0f3abb10bf525fee747b8c0f8 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 5 Dec 2026 07:35:32 -0800 Subject: [PATCH 08/41] Save: a file comparison waits for another document's dialog and drops a stale file A save waiting for its file comparison now goes on only when no dialog or file picker of another document is open, so writing it does not activate its document under that dialog. While it waits, no frames are requested. A comparison for a file the document no longer uses is dropped and its save canceled, without asking about the old file, and the next Save starts. --- crates/ui-egui/src/io/save.rs | 36 ++++++++++++++- crates/ui-egui/src/tests/save.rs | 76 ++++++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+), 2 deletions(-) diff --git a/crates/ui-egui/src/io/save.rs b/crates/ui-egui/src/io/save.rs index c09cbe7106..1fb7d89d3a 100644 --- a/crates/ui-egui/src/io/save.rs +++ b/crates/ui-egui/src/io/save.rs @@ -158,7 +158,15 @@ impl Saves { /// Whether file comparisons need another frame to collect their answers. #[cfg(not(target_arch = "wasm32"))] pub(crate) fn checks_pending(app: &VectorcraftApp) -> bool { - !app.saves.checks.is_empty() + // A save waiting for a dialog goes on in the frame that closes the dialog. + app.saves.checks.keys().any(|uid| !under_dialog(app, *uid)) +} + +/// Whether a dialog or file picker of a document other than `uid` is open: writing document +/// `uid`'s save would activate it under the dialog. +#[cfg(not(target_arch = "wasm32"))] +fn under_dialog(app: &VectorcraftApp, uid: u64) -> bool { + app.session.active().map(|d| d.uid) != Some(uid) && (app.any_dialog_open() || app.file_dialog_open()) } /// The web has no file comparisons to collect. @@ -246,12 +254,24 @@ fn resume_checked(app: &mut VectorcraftApp, wait: bool) { let checking: Vec = app.saves.checks.keys().copied().collect(); for uid in checking { // A closed document's save is cancelled with its flow, in [`pump`]. - if !app.session.documents().iter().any(|d| d.uid == uid) { + let Some(file) = app.session.documents().iter().find(|d| d.uid == uid).map(|d| d.path.clone()) else { + continue; + }; + // Writing activates the save's document: while a dialog or file picker of another document + // is open, the answer stays in its channel for a later pass. + if !wait && under_dialog(app, uid) { continue; } let (scope, automated) = app.saves.done.get(&uid).map_or_else(|| (ScopeHandle::capture(), app.automation_asked()), |d| d.asked.clone()); let r = scope.run(|| { file_asks::as_automated(app, automated, |app| { + // The document now uses another file (a Save As finished meanwhile): the comparison + // is dropped and its save cancelled, without asking about the old file. + if app.saves.checks.get(&uid).is_some_and(|c| file.as_deref().map(Path::new) != Some(c.path.as_path())) { + app.saves.checks.remove(&uid); + let step = app.saves.flows.get_mut(&uid).and_then(|f| f.cancel(app.host.files())); + return step.map(|step| run_step(app, uid, step)); + } let (same, path) = app.saves.answer(uid, wait)?; // Still that version: a change made since the comparison is asked about. let Some(stamp) = same.filter(|stamp| FileStamp::at(&path) == Some(*stamp)) else { @@ -278,6 +298,18 @@ pub(crate) fn wait_for_checks(app: &mut VectorcraftApp) { resume_checked(app, true); } +/// Waits for every save's file comparison to answer, leaving each answer for the next [`pump`]. +#[cfg(all(test, not(target_arch = "wasm32")))] +pub(crate) fn wait_for_answers(app: &mut VectorcraftApp) { + for check in app.saves.checks.values_mut() { + let (send, answer) = std::sync::mpsc::channel(); + if let Ok(same) = check.answer.recv() { + let _ = send.send(same); + } + check.answer = answer; + } +} + /// Waits for the active document's baseline digest and compares it with the file. #[cfg(all(test, not(target_arch = "wasm32")))] pub(crate) fn wait_for_contents(app: &VectorcraftApp) -> Option { diff --git a/crates/ui-egui/src/tests/save.rs b/crates/ui-egui/src/tests/save.rs index de7728f9e7..d6c1d0b34d 100644 --- a/crates/ui-egui/src/tests/save.rs +++ b/crates/ui-egui/src/tests/save.rs @@ -649,3 +649,79 @@ fn save_asks_about_a_changed_file_only_when_its_bytes_changed() { assert_eq!(std::fs::read(&path).unwrap(), other, "nothing is written before the answer"); let _ = std::fs::remove_dir_all(d); } + +/// Opens a file saved by another app, with the file then put back (with other bytes of the same +/// length unless `same`), and one more object: File › Save compares the file before it writes. +fn opened_then_put_back(tag: &str, same: bool) -> (std::path::PathBuf, String, VectorcraftApp) { + let d = dir(tag); + let path = d.join("a.vectorcraft").to_string_lossy().to_string(); + let mut writer = app(); + writer.run("file.new", json!({"width": 100, "height": 100})).unwrap(); + rect(&mut writer); + writer.run("file.saveAs", json!({"path": path})).unwrap(); + crate::background::wait_all(&mut writer); + let mut app = app(); + io::open_path(&mut app, &path).unwrap(); + assert!(io::save::wait_for_contents(&app).is_some(), "the opened file's baseline is recorded"); + let mut other = std::fs::read(&path).unwrap(); + if !same { + let last = other.last_mut().unwrap(); + *last ^= 0xff; + } + put_back(&path, &other); + rect(&mut app); + (d, path, app) +} + +/// A comparison that answers after the document took another file does not ask about the old one. +#[test] +fn a_comparison_for_a_file_the_document_no_longer_uses_asks_nothing() { + let (d, path, mut app) = opened_then_put_back("compare-retargeted", false); + assert_eq!(app.run("file.save", json!({})).unwrap()["pending"], "checkingFile"); + let other = d.join("b.vectorcraft").to_string_lossy().to_string(); + app.session.doc_mut().unwrap().path = Some(other.clone()); + let before = std::fs::read(&path).unwrap(); + io::save::wait_for_checks(&mut app); + crate::background::wait_all(&mut app); + let asked = app.any_dialog_open(); + let pending = io::save::checks_pending(&app); + let after = std::fs::read(&path).unwrap(); + // The dropped save freed the flow: the next File › Save writes the new file. + let next = app.run("file.save", json!({})); + crate::background::wait_all(&mut app); + let wrote_new = std::path::Path::new(&other).exists(); + let _ = std::fs::remove_dir_all(d); + assert!(next.is_ok(), "the next save starts: {next:?}"); + assert!(wrote_new, "the next save writes the document's new file"); + assert!(!asked, "no changed-on-disk question about a file the document no longer uses"); + assert!(!pending, "the comparison is dropped"); + assert_eq!(after, before, "the old file is not written"); +} + +/// A comparison that answers while a dialog is open over another document waits for it to close, +/// so the save does not activate its own document under the dialog. +#[test] +fn a_comparison_waits_while_a_dialog_is_open_over_another_document() { + let (d, path, mut app) = opened_then_put_back("compare-under-dialog", true); + let before = std::fs::read(&path).unwrap(); + assert_eq!(app.run("file.save", json!({})).unwrap()["pending"], "checkingFile"); + app.run("file.new", json!({"width": 100, "height": 100})).unwrap(); + let prompt = craft::ui::dialog::StandardPrompt::changed_on_disk("other"); + app.dialogs().unwrap().with(|h| h.open(prompt)); + io::save::wait_for_answers(&mut app); + let ctx = egui::Context::default(); + io::save::pump(&mut app, &ctx); + let active = app.session.active_index(); + let pending = io::save::checks_pending(&app); + let unwritten = std::fs::read(&path).unwrap() == before; + // Once the dialog closes, the save goes on and writes the file. + answer_top(&mut app, false); + io::save::pump(&mut app, &ctx); + crate::background::wait_all(&mut app); + let written = std::fs::read(&path).unwrap() != before; + let _ = std::fs::remove_dir_all(d); + assert_eq!(active, Some(1), "the document under the dialog stays active"); + assert!(!pending, "no frames are asked for while the save waits for the dialog"); + assert!(unwritten, "nothing is written while the dialog is open"); + assert!(written, "the save finishes once the dialog closes"); +} From 8ff9a8c9eb59501a8812c052d8ceacd3a4e61eb2 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 5 Dec 2026 08:05:39 -0800 Subject: [PATCH 09/41] Canvas: keep the moved anchor marks mesh only when every mark moves by whole pixels A move of whole pixels on screen did not guarantee that each mark's f32 screen position moved by whole pixels: `CanvasView::to_screen` casts to f32, so a point at x = 255.999991 lands at 255.99998 before a one-pixel move and at 257.0 after it, and its square rounds to other pixels than the moved mesh's. The move now checks every anchor and handle's f32 screen position before and after, and tessellates again when one does not move by the whole pixels. The same pass checks that every point stays inside the canvas, in place of the box of the points. --- crates/ui-egui/src/canvas/selection.rs | 43 +++++++++++--------- crates/ui-egui/src/canvas/selection/tests.rs | 37 +++++++++++++++++ 2 files changed, 60 insertions(+), 20 deletions(-) diff --git a/crates/ui-egui/src/canvas/selection.rs b/crates/ui-egui/src/canvas/selection.rs index b6421c882b..6151e3affb 100644 --- a/crates/ui-egui/src/canvas/selection.rs +++ b/crates/ui-egui/src/canvas/selection.rs @@ -699,12 +699,12 @@ const PIXEL_SLACK: f64 = 1e-6; impl KeptMesh { /// Moves the mesh by `by` in the document when tessellating the moved marks would give the same mesh moved, and - /// returns whether it did. `was` is the box of the marks' points before the move ([`knots_box`]). The mesh moves - /// when the marks' whole move since they were tessellated is a whole number of physical pixels on screen, so the - /// tessellator's rounding to pixels lands the same, and when every point is inside the canvas the marks are drawn - /// near and inside the clip both before and after the move, so no anchor, handle or outline is left out or culled - /// on either side. - fn translate(&mut self, by: Vec2, was: Option) -> bool { + /// returns whether it did. `points` are the marks' anchors and direction handles before the move ([`knot_points`]). + /// The mesh moves when the marks' whole move since they were tessellated is a whole number of physical pixels on + /// screen, and when every point's `f32` screen position moves by this move's whole pixels too, so the tessellator's + /// rounding to pixels lands the same. It also needs every point inside the canvas before and after the move, so the + /// marks are drawn near and inside the clip on both sides and no anchor, handle or outline is left out or culled. + fn translate(&mut self, by: Vec2, points: impl IntoIterator) -> bool { let key = &self.key; let ppp = f64::from(key.pixels_per_point); let view = key.view.affine(); @@ -713,26 +713,31 @@ impl KeptMesh { if moved.iter().any(|p| !p.is_finite() || (p - p.round()).abs() > PIXEL_SLACK) { return false; } - if let Some(was) = was { - let area = key.rect.expand(key.look.reach).intersect(key.clip); - let inside = |r: vectorcraft_geom::Rect| { - [(r.x0, r.y0), (r.x1, r.y0), (r.x1, r.y1), (r.x0, r.y1)].into_iter().all(|(x, y)| area.contains(key.view.to_screen(Point::new(x, y)))) - }; - if !(inside(was) && inside(was + by)) { + // This move in whole physical pixels. + let pixels = [moved[0].round() - self.moved[0].round(), moved[1].round() - self.moved[1].round()]; + let area = key.rect.expand(key.look.reach).intersect(key.clip); + // `CanvasView::to_screen` with the affine computed once. + let screen = |p: Point| { + let s = view * p; + egui::pos2(s.x as f32, s.y as f32) + }; + let whole = |from: f32, to: f32, px: f64| ((f64::from(to) - f64::from(from)) * ppp - px).abs() <= PIXEL_SLACK; + for p in points { + let (from, to) = (screen(p), screen(p + by)); + if !(area.contains(from) && area.contains(to) && whole(from.x, to.x, pixels[0]) && whole(from.y, to.y, pixels[1])) { return false; } } - let step = |axis: usize| ((moved[axis].round() - self.moved[axis].round()) / ppp) as f32; - let offset = vec2(step(0), step(1)); + let offset = vec2((pixels[0] / ppp) as f32, (pixels[1] / ppp) as f32); self.moved = moved; Arc::make_mut(&mut self.mesh).translate(offset); true } } -/// The box of every anchor and direction handle of `anchors`, in document units, or `None` without any. The outlines -/// lie inside it too, as a curve lies inside the hull of its points. -fn knots_box(anchors: &Anchors) -> Option { +/// Every anchor and direction handle of `anchors`, in document units. The outlines lie inside the hull of these +/// points, as a curve lies inside the hull of its points. +fn knot_points(anchors: &Anchors) -> impl Iterator + '_ { anchors .paths .iter() @@ -740,7 +745,6 @@ fn knots_box(anchors: &Anchors) -> Option { .flat_map(|p| &p.subpaths) .flat_map(|sp| &sp.knots) .flat_map(|knot| [knot.anchor, knot.in_ctrl, knot.out_ctrl]) - .fold(None, |r: Option, p| Some(r.map_or(vectorcraft_geom::Rect::from_points(p, p), |r| r.union_pt(p)))) } /// One set of anchors as `BezierOverlay` took it: the paths, which anchors are selected and how they show. @@ -1263,9 +1267,8 @@ impl SelectionMarks { /// Moves every mark by `by`, and the kept mesh of the anchor marks with them when it can move as it is /// ([`KeptMesh::translate`]); otherwise the next paint tessellates the marks again. fn translate(&mut self, by: Vec2) { - let was = knots_box(&self.anchors); let mesh = self.mesh.get_mut(); - if mesh.as_mut().is_some_and(|kept| !kept.translate(by, was)) { + if mesh.as_mut().is_some_and(|kept| !kept.translate(by, knot_points(&self.anchors))) { *mesh = None; } let shift = vectorcraft_geom::Affine::translate(by); diff --git a/crates/ui-egui/src/canvas/selection/tests.rs b/crates/ui-egui/src/canvas/selection/tests.rs index f23e4087aa..3b979256c5 100644 --- a/crates/ui-egui/src/canvas/selection/tests.rs +++ b/crates/ui-egui/src/canvas/selection/tests.rs @@ -1360,3 +1360,40 @@ fn a_drag_of_the_selection_moves_the_anchor_marks_mesh_without_tessellating_it() assert_eq!(frames(&mut app, 2), 1, "a step past the canvas's edge"); app.session.commit_interaction().unwrap(); } + +// A move of whole pixels keeps the mesh only when every point's `f32` screen position moves by those whole pixels: +// at x = 255.999991 the screen position before a one-pixel move is 255.99998 and after it 257.0, so the marks' +// squares would round to other pixels than the moved mesh's. +#[test] +fn a_whole_pixel_move_keeps_the_mesh_only_when_the_screen_positions_move_by_whole_pixels() { + let screen = Rect::from_min_size(egui::pos2(0.0, 0.0), vec2(1000.0, 1000.0)); + let look = MarkLook { + line: Color32::BLACK, + fill: Color32::WHITE, + edge: Color32::BLACK, + anchor: 5.0, + large: 7.0, + thin: 1.0, + medium: 2.0, + thick: 3.0, + reach: 20.0, + }; + let kept = || KeptMesh { + key: MeshKey { + marks: 0, + view: CanvasView::new(screen, Point::new(500.0, 500.0), 1.0), + rect: screen, + clip: screen, + pixels_per_point: 1.0, + options: egui::epaint::TessellationOptions::default(), + look, + }, + mesh: Arc::new(egui::Mesh::default()), + moved: [0.0; 2], + }; + let by = Vec2::new(1.0, 0.0); + assert!(kept().translate(by, [Point::new(255.5, 10.0)]), "a point whose screen position moves one whole pixel"); + let mut off = kept(); + assert!(!off.translate(by, [Point::new(255.5, 10.0), Point::new(255.999_991, 10.0)]), "a point that moves 1.0000153 pixels"); + assert_eq!(off.moved, [0.0; 2], "the refused move leaves the mesh where it was"); +} From 1bc0c5ba7825048b93195848a9ee02904cf6ec6c Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 5 Dec 2026 08:06:12 -0800 Subject: [PATCH 10/41] CI: analyze main in SonarCloud only at the nightly's commit SonarCloud ran a full instrumented analysis for every merge commit on main (about 90 a day, 97 to 191 minutes each). Stage 2 only reads the analysis of the commit the nightly builds, so main is now analyzed once a day: - sonarcloud.yml drops the push trigger and starts when the unsigned nightly starts (workflow_run, requested). A first job fails the run when main has moved past the nightly's commit, so the analysis is never of another commit. Pull request analysis is unchanged. - nightly-dispatch.yml waits, for up to 280 minutes, for the SonarCloud check on the producer's commit to complete before it dispatches the signer. A SonarCloud run that ended without a check stops the wait after 20 minutes. The job gains checks: read and a 300-minute timeout. - packaging/nightly-release-tests.py runs the dispatch script against a fake API: it dispatches only after the check completes, and refuses when the SonarCloud run ended without one or when the deadline passes. - docs/nightly-release-preparation.md describes both workflows. --- .github/workflows/nightly-dispatch.yml | 66 ++++++++++++++---- .github/workflows/sonarcloud.yml | 32 ++++++++- docs/nightly-release-preparation.md | 16 +++-- packaging/nightly-release-tests.py | 92 ++++++++++++++++++++++++++ 4 files changed, 186 insertions(+), 20 deletions(-) diff --git a/.github/workflows/nightly-dispatch.yml b/.github/workflows/nightly-dispatch.yml index 4ef372c40b..4581f75d39 100644 --- a/.github/workflows/nightly-dispatch.yml +++ b/.github/workflows/nightly-dispatch.yml @@ -16,9 +16,11 @@ jobs: github.repository == 'storytold/vectorcraft' && github.event_name == 'workflow_run' runs-on: ubuntu-latest - timeout-minutes: 5 + # Most of the time is the wait for the producer commit's SonarCloud analysis (up to 280 minutes). + timeout-minutes: 300 permissions: actions: write + checks: read steps: - name: Dispatch only the exact completed producer run and attempt shell: python @@ -27,6 +29,10 @@ jobs: run: | import json import os + import re + import time + import urllib.error + import urllib.parse import urllib.request def require(value, message): @@ -51,22 +57,58 @@ jobs: run_id, attempt = producer.get('id'), producer.get('run_attempt') require(type(run_id) is int and run_id > 0, 'invalid producer run id') require(type(attempt) is int and attempt == 1, 'invalid automatic producer attempt') + source = producer.get('head_sha') + require(isinstance(source, str) and re.fullmatch(r'[0-9a-f]{40}', source), 'invalid producer commit') + headers = { + 'Authorization': 'Bearer ' + os.environ['GH_TOKEN'], + 'Accept': 'application/vnd.github+json', + 'X-GitHub-Api-Version': '2022-11-28', + 'User-Agent': 'vectorcraft-nightly-dispatch' + } + class NoRedirect(urllib.request.HTTPRedirectHandler): + def redirect_request(self, req, fp, code, msg, headers, newurl): + raise RuntimeError('dispatch redirects are forbidden') + opener = urllib.request.build_opener(NoRedirect()) + + def read(path): + request = urllib.request.Request('https://api.github.com/repos/storytold/vectorcraft' + path, headers=headers) + with opener.open(request, timeout=20) as response: + require(response.status == 200, 'read was not accepted') + return json.load(response) + + # Stage 2 admits the producer only on its commit's own SonarCloud analysis, which + # sonarcloud.yml starts when the producer starts. Wait for the check that analysis posts; + # a SonarCloud run that ended without one gets 20 minutes before the wait gives up. + checks_path = '/commits/' + source + '/check-runs?' + urllib.parse.urlencode( + {'app_id': 12526, 'check_name': 'SonarCloud Code Analysis', 'filter': 'latest'}) + runs_path = '/actions/workflows/sonarcloud.yml/runs?' + urllib.parse.urlencode( + {'event': 'workflow_run', 'head_sha': source, 'per_page': 1}) + deadline = time.monotonic() + 280 * 60 + ended = None + while True: + try: + checks = read(checks_path).get('check_runs', []) + if any(c.get('head_sha') == source and c.get('status') == 'completed' for c in checks): + break + runs = read(runs_path).get('workflow_runs', []) + if runs and runs[0].get('status') == 'completed' and ended is None: + ended = time.monotonic() + print('SonarCloud run', runs[0].get('id'), 'ended:', runs[0].get('conclusion')) + except (urllib.error.URLError, OSError, ValueError) as error: + print('Read failed, polling again:', error) + require(ended is None or time.monotonic() < ended + 20 * 60, + 'the SonarCloud run for the producer commit ended without an analysis check') + require(time.monotonic() < deadline, 'no SonarCloud analysis of the producer commit in time') + time.sleep(60) + print('SonarCloud analysis check of', source, 'is complete.') + body = json.dumps({'ref': 'refs/heads/nightly-signer', 'inputs': { 'producer_run_id': str(run_id), 'producer_run_attempt': str(attempt) }}).encode('utf-8') request = urllib.request.Request( 'https://api.github.com/repos/storytold/vectorcraft/actions/workflows/nightly-sign.yml/dispatches', - data=body, method='POST', headers={ - 'Authorization': 'Bearer ' + os.environ['GH_TOKEN'], - 'Accept': 'application/vnd.github+json', - 'Content-Type': 'application/json', - 'X-GitHub-Api-Version': '2022-11-28', - 'User-Agent': 'vectorcraft-nightly-dispatch' - }) - class NoRedirect(urllib.request.HTTPRedirectHandler): - def redirect_request(self, req, fp, code, msg, headers, newurl): - raise RuntimeError('dispatch redirects are forbidden') + data=body, method='POST', headers=dict(headers, **{'Content-Type': 'application/json'})) # One bounded request, no retry: duplicate transport is not publication authority. - with urllib.request.build_opener(NoRedirect()).open(request, timeout=20) as response: + with opener.open(request, timeout=20) as response: require(response.status == 204, 'dispatch was not accepted') print('Dispatched producer run/attempt to the release-ref validator; not a signing result.') diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index 98e9c1d00a..312ab1cbda 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -1,8 +1,12 @@ name: SonarCloud +# Main is analyzed once a day, at the commit the nightly builds: Stage 2 admits a nightly only on +# that commit's own analysis, and nightly-dispatch.yml waits for it before dispatching the signer. on: workflow_dispatch: - push: + workflow_run: + workflows: [VectorCraft unsigned nightly] + types: [requested] branches: [main] pull_request: types: [opened, synchronize, reopened] @@ -12,11 +16,35 @@ permissions: concurrency: group: ${{ github.ref == 'refs/heads/main' && format('sonarcloud-main-{0}', github.sha) || format('sonarcloud-{0}', github.ref) }} - # A push to main is the run that publishes coverage; superseded runs there would never finish. + # A main run is the analysis a nightly waits for; superseded runs there would never finish. cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} jobs: + nightly-commit: + name: Nightly commit is main's head + # A workflow_run checks out and analyzes main's head, so main must not have moved since the + # nightly started. + if: github.event_name == 'workflow_run' + runs-on: ubuntu-latest + timeout-minutes: 2 + steps: + - name: Harden runner + uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4 + with: + egress-policy: audit + - name: Require main's head to be the nightly's commit + env: + NIGHTLY_SHA: ${{ github.event.workflow_run.head_sha }} + RUN_SHA: ${{ github.sha }} + run: | + if [ "$NIGHTLY_SHA" != "$RUN_SHA" ]; then + echo "::error::main moved from $NIGHTLY_SHA to $RUN_SHA after the nightly started; this run would not analyze the nightly's commit" + exit 1 + fi + sonarcloud: + needs: nightly-commit + if: ${{ !cancelled() && contains(fromJSON('["success","skipped"]'), needs.nightly-commit.result) }} # Tracked at @main so org-wide CI improvements propagate without PR churn. # The reusable workflow defaults build-jobs to 2 so a cold instrumented # archive stays within hosted-runner memory (craft-common-actions#333). diff --git a/docs/nightly-release-preparation.md b/docs/nightly-release-preparation.md index 29ca838f1d..1074e90299 100644 --- a/docs/nightly-release-preparation.md +++ b/docs/nightly-release-preparation.md @@ -79,7 +79,7 @@ Read on 2026-11-24; re-read anything that may have moved before `nightly-signer` | `max_age_seconds`, `max_artifact_bytes` | `86400`, `2147483648` | Go-live checklist | | `platforms` | three rows | Learning Machines stable identities (Windows Authenticode publisher subject, Linux OpenPGP fingerprint, Apple Developer ID team `DJ6XS33FX8`) | | `candidate_policy.required_workflows` | CI (`ci.yml`, workflow `380135806`), 9 jobs | Workflow list API; jobs that succeeded on recent main push runs | -| `candidate_policy.sonar` | `storytold` / `storytold_vectorcraft`, app `12526` | `sonar-project.properties`; the SonarCloud check on main commits | +| `candidate_policy.sonar` | `storytold` / `storytold_vectorcraft`, app `12526` | `sonar-project.properties`; the SonarCloud check on the nightly's commit | The signer reads the policy from `nightly-signer`, so a candidate whose CI built the tests once (`build`, `lint` and `test 1/5` to `test 5/5`) is admitted only after `nightly-signer` advances to @@ -97,9 +97,12 @@ a main commit with this policy. Candidates whose CI ran six shards (`cache warm` from stable, cancellation is off and `queue: max` must be hosted-qualified. The caller itself passes no credentials; only the shared callee's sign jobs bind the `release` environment, which must admit `nightly-signer` alongside `release` before the first dispatch. -- `.github/workflows/nightly-dispatch.yml`: transport only, never authorization. It is literally - off (`false &&`) and forwards only a first-attempt scheduled producer to `nightly-sign.yml` on - `nightly-signer`. No schedule is registered until activation is reviewed. +- `.github/workflows/nightly-dispatch.yml`: transport only, never authorization. It forwards only + a first-attempt scheduled producer to `nightly-sign.yml` on `nightly-signer`, after the + SonarCloud check on the producer's commit has completed. +- `.github/workflows/sonarcloud.yml`: analyzes main only at the commit a nightly builds. It starts + when the producer starts and fails when main has moved past the producer's commit. Pull requests + are analyzed on every push as before. - Shared reusable entrypoints are `nightly-unsigned.yml` and `nightly-release.yml` in `storytold/craft-common-actions`. Both must resolve to a **real reviewed public immutable commit**; the defining workflow SHA and tooling input must match. @@ -117,8 +120,9 @@ a main commit with this policy. Candidates whose CI ran six shards (`cache warm` - A trust-closure scan reads every workflow: nothing binds an `environment`, only `nightly-sign.yml` calls `nightly-release.yml` (at a full SHA), and the only caller of the shared stable `release.yml` is `release.yml`. -- `nightly-dispatch.yml` keeps a literal-off guard, a `workflow_run`-only trigger and a - `refs/heads/nightly-signer` request. +- `nightly-dispatch.yml` keeps its exact context guard, a `workflow_run`-only trigger and a + `refs/heads/nightly-signer` request, and sends that request only after the SonarCloud check on + the producer's commit has completed. ## The app side of a Nightly build diff --git a/packaging/nightly-release-tests.py b/packaging/nightly-release-tests.py index 2729b40282..ef1003f46e 100755 --- a/packaging/nightly-release-tests.py +++ b/packaging/nightly-release-tests.py @@ -2,10 +2,15 @@ """Local regression checks for VectorCraft nightly workflow and signing-policy contracts.""" import copy from decimal import Decimal +import io import json +import os from pathlib import Path import re +import tempfile +import textwrap import unittest +from unittest import mock ROOT = Path(__file__).resolve().parents[1] INSTALLED_POLICY = ROOT / ".github/nightly-signing-policy.json" @@ -907,5 +912,92 @@ class NightlyDispatchTransport(unittest.TestCase): self.assertIn("repos/storytold/" + APP_NAME + "/actions/workflows/nightly-sign.yml/dispatches", self.source) self.assertNotIn("'ref': 'release'", self.source) + +SONAR_SOURCE = "c" * 40 + + +def dispatch_script(): + """The dispatch job's inline Python, as the runner's `shell: python` step receives it.""" + source = (ROOT / ".github/workflows/nightly-dispatch.yml").read_text() + block = source.split(" run: |\n", 1)[1] + return textwrap.dedent(block) + + +class FakeGitHub: + """Answers the dispatch script's API reads from scripted poll results and records every request.""" + + def __init__(self, polls, run=None): + self.polls = list(polls) + self.run = run + self.requests = [] + self.now = 0.0 + + def open(self, request, timeout): + self.requests.append((request.get_method(), request.full_url)) + if request.get_method() == "POST": + payload = b"" + status = 204 + elif "/check-runs?" in request.full_url: + done = self.polls.pop(0) if self.polls else False + rows = [{"head_sha": SONAR_SOURCE, "status": "completed" if done else "in_progress"}] + payload, status = json.dumps({"check_runs": rows}).encode(), 200 + else: + runs = [self.run] if self.run else [] + payload, status = json.dumps({"workflow_runs": runs}).encode(), 200 + response = io.BytesIO(payload) + response.status = status + return response + + def sleep(self, seconds): + self.now += seconds + + +def run_dispatch(github): + producer = {"head_repository": {"full_name": "storytold/vectorcraft"}, "path": ".github/workflows/nightly.yml", + "head_branch": "main", "status": "completed", "conclusion": "success", "event": "schedule", + "id": 7, "run_attempt": 1, "head_sha": SONAR_SOURCE} + event = {"action": "completed", "repository": {"full_name": "storytold/vectorcraft"}, "workflow_run": producer} + with tempfile.TemporaryDirectory() as folder: + path = Path(folder) / "event.json" + path.write_text(json.dumps(event)) + env = {"GITHUB_REPOSITORY": "storytold/vectorcraft", "GITHUB_EVENT_NAME": "workflow_run", + "GITHUB_EVENT_PATH": str(path), "GH_TOKEN": "token"} + with mock.patch.dict(os.environ, env), \ + mock.patch("urllib.request.build_opener", return_value=github), \ + mock.patch("time.monotonic", side_effect=lambda: github.now), \ + mock.patch("time.sleep", side_effect=github.sleep), \ + mock.patch("builtins.print"): + exec(compile(dispatch_script(), "nightly-dispatch.yml", "exec"), {}) + + +class NightlyDispatchWaitsForSonar(unittest.TestCase): + """The signer is dispatched only after the producer commit's SonarCloud check completes.""" + + def posts(self, github): + return [url for method, url in github.requests if method == "POST"] + + def test_dispatch_waits_for_the_completed_check_of_the_producer_commit(self): + github = FakeGitHub([False, False, True]) + run_dispatch(github) + checks = [url for method, url in github.requests if "/check-runs?" in url] + self.assertEqual(len(checks), 3) + self.assertTrue(all("/commits/" + SONAR_SOURCE + "/" in url and "app_id=12526" in url for url in checks)) + self.assertEqual(len(self.posts(github)), 1) + self.assertEqual(github.requests[-1][0], "POST", "the dispatch comes after the last check read") + + def test_a_sonar_run_that_ended_without_a_check_stops_the_dispatch(self): + github = FakeGitHub([], run={"id": 9, "status": "completed", "conclusion": "failure"}) + with self.assertRaisesRegex(RuntimeError, "ended without an analysis check"): + run_dispatch(github) + self.assertEqual(self.posts(github), []) + self.assertLessEqual(github.now, 21 * 60, "a finished run does not wait for the whole deadline") + + def test_no_analysis_by_the_deadline_stops_the_dispatch(self): + github = FakeGitHub([]) + with self.assertRaisesRegex(RuntimeError, "in time"): + run_dispatch(github) + self.assertEqual(self.posts(github), []) + + if __name__ == "__main__": unittest.main(verbosity=2) From a1e9779fba1212894cd9b518bd026aac1a33c91c Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 5 Dec 2026 07:59:53 -0800 Subject: [PATCH 11/41] Save: a file comparison waits for a drag in another document and wakes after a dialog closes A save whose file comparison answered made its document active even while a drag went on in the active document, and the switch canceled the drag. The save now waits until the drag ends (no interaction and no held press in the active document), as it already waited for another document's dialog or file picker. A save that waited for a dialog went on only at the next input after the dialog closed, because the dialogs close in the UI pass, after the save pump has run. The pass that closes the dialog, or ends the drag, now asks for one more frame, and no frames are asked for while the save waits. --- crates/ui-egui/src/app.rs | 1 + crates/ui-egui/src/io/save.rs | 40 ++++++++++++++---- crates/ui-egui/src/tests/save.rs | 71 ++++++++++++++++++++++++++++++++ 3 files changed, 104 insertions(+), 8 deletions(-) diff --git a/crates/ui-egui/src/app.rs b/crates/ui-egui/src/app.rs index b769dac802..f2ca6fae4d 100644 --- a/crates/ui-egui/src/app.rs +++ b/crates/ui-egui/src/app.rs @@ -777,6 +777,7 @@ impl VectorcraftApp { self.handle_input(&ctx); self.ui_frame(ui); self.window_keys(&ctx); + io::save::after_ui(self, &ctx); // What the canvas, a panel, a dialog or a window key changed in this pass reaches // the plug-ins that react to it now, since an idle app draws no further frame; a // line a handler wrote shows in the next one. The handlers' time counts toward the diff --git a/crates/ui-egui/src/io/save.rs b/crates/ui-egui/src/io/save.rs index 1fb7d89d3a..f373ed900b 100644 --- a/crates/ui-egui/src/io/save.rs +++ b/crates/ui-egui/src/io/save.rs @@ -71,6 +71,10 @@ pub(crate) struct Saves { /// The saves waiting for a comparison of their document's file with those bytes. #[cfg(not(target_arch = "wasm32"))] checks: HashMap, + /// A comparison's save waited in the last pass for a dialog, a file picker or a gesture in + /// another document: [`after_ui`] asks for a frame once it no longer has to. + #[cfg(not(target_arch = "wasm32"))] + held: bool, /// The files written beside each document's file, which its next save replaces. pub(crate) written_beside: HashMap>, /// The files the OK of the replace question allows the save it runs again to replace. @@ -89,6 +93,8 @@ impl Saves { contents: super::saved_contents::SavedContents::new(), #[cfg(not(target_arch = "wasm32"))] checks: HashMap::new(), + #[cfg(not(target_arch = "wasm32"))] + held: false, watch: FileWatch::new(wake), written_beside: HashMap::new(), replace_files_ok: Vec::new(), @@ -158,17 +164,34 @@ impl Saves { /// Whether file comparisons need another frame to collect their answers. #[cfg(not(target_arch = "wasm32"))] pub(crate) fn checks_pending(app: &VectorcraftApp) -> bool { - // A save waiting for a dialog goes on in the frame that closes the dialog. - app.saves.checks.keys().any(|uid| !under_dialog(app, *uid)) + // A save waiting for a dialog or a gesture goes on in the frame after the one that ends it ([`after_ui`]). + app.saves.checks.keys().any(|uid| !held(app, *uid)) } -/// Whether a dialog or file picker of a document other than `uid` is open: writing document -/// `uid`'s save would activate it under the dialog. +/// Whether document `uid`'s save has to wait: writing it activates its document, which would +/// put it under an open dialog or file picker of another document, or cancel a drag in progress +/// in the active one. #[cfg(not(target_arch = "wasm32"))] -fn under_dialog(app: &VectorcraftApp, uid: u64) -> bool { - app.session.active().map(|d| d.uid) != Some(uid) && (app.any_dialog_open() || app.file_dialog_open()) +fn held(app: &VectorcraftApp, uid: u64) -> bool { + let active = app.session.active(); + active.map(|d| d.uid) != Some(uid) + && (app.any_dialog_open() || app.file_dialog_open() || active.is_some_and(|d| d.interaction.is_some()) || app.canvas.grab.is_some()) } +/// Asks for one frame when a save waited in the last pass and this pass's UI closed what it +/// waited for: the dialog pumps and the canvas run after [`pump`], so nothing else would. +#[cfg(not(target_arch = "wasm32"))] +pub(crate) fn after_ui(app: &mut VectorcraftApp, ctx: &egui::Context) { + if app.saves.held && app.saves.checks.keys().any(|uid| !held(app, *uid)) { + app.saves.held = false; + ctx.request_repaint(); + } +} + +/// The web has no saves that wait. +#[cfg(target_arch = "wasm32")] +pub(crate) fn after_ui(_: &mut VectorcraftApp, _: &egui::Context) {} + /// The web has no file comparisons to collect. #[cfg(target_arch = "wasm32")] pub(crate) fn checks_pending(_: &VectorcraftApp) -> bool { @@ -258,8 +281,9 @@ fn resume_checked(app: &mut VectorcraftApp, wait: bool) { continue; }; // Writing activates the save's document: while a dialog or file picker of another document - // is open, the answer stays in its channel for a later pass. - if !wait && under_dialog(app, uid) { + // is open, or a drag goes on in it, the answer stays in its channel for a later pass. + if !wait && held(app, uid) { + app.saves.held = true; continue; } let (scope, automated) = app.saves.done.get(&uid).map_or_else(|| (ScopeHandle::capture(), app.automation_asked()), |d| d.asked.clone()); diff --git a/crates/ui-egui/src/tests/save.rs b/crates/ui-egui/src/tests/save.rs index d6c1d0b34d..912626e647 100644 --- a/crates/ui-egui/src/tests/save.rs +++ b/crates/ui-egui/src/tests/save.rs @@ -725,3 +725,74 @@ fn a_comparison_waits_while_a_dialog_is_open_over_another_document() { assert!(unwritten, "nothing is written while the dialog is open"); assert!(written, "the save finishes once the dialog closes"); } + +/// A context whose first frames have run, so it asks for no more frames of its own. +fn settled() -> egui::Context { + let ctx = egui::Context::default(); + for _ in 0..10 { + if !ctx.has_requested_repaint() { + break; + } + ctx.run_ui(egui::RawInput::default(), |_| {}).textures_delta.clear(); + } + assert!(!ctx.has_requested_repaint(), "the context settled"); + ctx +} + +/// A save that waited for a dialog asks for a frame in the pass whose UI closes the dialog, since +/// its pump ran earlier in that pass and an idle app draws no other frame. +#[test] +fn a_comparison_held_by_a_dialog_asks_for_a_frame_once_the_dialog_closes() { + let (d, _path, mut app) = opened_then_put_back("compare-wake", true); + assert_eq!(app.run("file.save", json!({})).unwrap()["pending"], "checkingFile"); + app.run("file.new", json!({"width": 100, "height": 100})).unwrap(); + let prompt = craft::ui::dialog::StandardPrompt::changed_on_disk("other"); + app.dialogs().unwrap().with(|h| h.open(prompt)); + io::save::wait_for_answers(&mut app); + io::save::pump(&mut app, &egui::Context::default()); + let open = settled(); + io::save::after_ui(&mut app, &open); + let while_open = open.has_requested_repaint(); + // The dialog's own pump, which runs after the save's, takes its answer. + let id = open_dialogs(&app).pop().map(|d| d.id).expect("a dialog is open"); + let window = app.ui_ctx.clone().expect("a window context"); + app.dialogs().unwrap().with(|h| { + assert!(h.cancel_by_id(&window, id)); + let _ = h.take_by_id::(id); + }); + let closed = settled(); + io::save::after_ui(&mut app, &closed); + let after_close = closed.has_requested_repaint(); + io::save::wait_for_checks(&mut app); + crate::background::wait_all(&mut app); + let _ = std::fs::remove_dir_all(d); + assert!(!while_open, "no frame is asked for while the dialog is open"); + assert!(after_close, "a frame is asked for once the dialog has closed"); +} + +/// A comparison that answers while a drag goes on in another document waits for the drag to end, +/// so making the save's document active does not cancel the drag. +#[test] +fn a_comparison_waits_while_a_drag_goes_on_in_another_document() { + let (d, path, mut app) = opened_then_put_back("compare-under-drag", true); + let before = std::fs::read(&path).unwrap(); + assert_eq!(app.run("file.save", json!({})).unwrap()["pending"], "checkingFile"); + app.run("file.new", json!({"width": 100, "height": 100})).unwrap(); + app.begin_interaction("drag").unwrap(); + io::save::wait_for_answers(&mut app); + let ctx = egui::Context::default(); + io::save::pump(&mut app, &ctx); + let active = app.session.active_index(); + let dragging = app.session.active().is_some_and(|d| d.interaction.is_some()); + let unwritten = std::fs::read(&path).unwrap() == before; + // Once the drag ends, the save goes on and writes the file. + app.session.commit_interaction().unwrap(); + io::save::pump(&mut app, &ctx); + crate::background::wait_all(&mut app); + let written = std::fs::read(&path).unwrap() != before; + let _ = std::fs::remove_dir_all(d); + assert_eq!(active, Some(1), "the document with the drag stays active"); + assert!(dragging, "the drag is not canceled"); + assert!(unwritten, "nothing is written while the drag goes on"); + assert!(written, "the save finishes once the drag ends"); +} From d4e73489ef13f27aff14cfd7f39e171d3006fd0e Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 5 Dec 2026 09:07:54 -0800 Subject: [PATCH 12/41] Dependencies: craft-libs pin to main, with the opacity and edit-target workarounds removed Every craft-libs rev moves from 4f3e34d0dd, the head of craft-libs#5489, to craft-libs main. The egui and winit revs are the ones that craft-libs rev pins, unchanged. - Opacity fields (Control bar, Color Wheel, Gradient) show the stored fraction times 100 again. craft-libs#5466 makes the number field step on from a value such as 50.999999 %, so panels::shown_percent is removed. - The Blend Options Ramp and Shift sliders, the Image Trace rows and the Divider field use SliderField::edit_target (craft-libs#5024) in place of the id-salt workarounds. A value typed for one object and not yet committed is still dropped when another is selected. - CDR import: craft-libs now reads bitmaps as their own object kind. They are not placed; the warnings name them with the other objects not read, and a PowerClip frame that clips only a bitmap is named as a frame that opened empty. --- Cargo.lock | 182 +++++++++--------- Cargo.toml | 82 ++++---- apps/vectorcraft-web/Cargo.toml | 2 +- crates/engine/src/cmd/fileio/cdr.rs | 6 +- crates/engine/src/cmd/fileio/cdr/shapes.rs | 4 + crates/engine/src/cmd/fileio/tests_cdr.rs | 39 +++- crates/ui-egui/src/chrome/control_bar.rs | 2 +- crates/ui-egui/src/panels.rs | 9 - crates/ui-egui/src/panels/blend.rs | 84 +------- crates/ui-egui/src/panels/color_wheel.rs | 2 +- crates/ui-egui/src/panels/gradient.rs | 2 +- crates/ui-egui/src/panels/image_trace.rs | 5 +- crates/ui-egui/src/panels/image_trace/rows.rs | 4 +- xtask/src/pdf_deps.rs | 2 +- 14 files changed, 187 insertions(+), 238 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bb23758ef6..522005f52c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1256,7 +1256,7 @@ dependencies = [ [[package]] name = "craft" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "craft-automation", "craft-behavior", @@ -1298,7 +1298,7 @@ dependencies = [ [[package]] name = "craft-affinity" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "crc32fast", "flate2", @@ -1319,7 +1319,7 @@ dependencies = [ [[package]] name = "craft-appkit" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "block2 0.6.2", "objc2 0.6.5", @@ -1331,7 +1331,7 @@ dependencies = [ [[package]] name = "craft-atomic" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "rustix 1.1.6", ] @@ -1339,7 +1339,7 @@ dependencies = [ [[package]] name = "craft-automation" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "base64 0.23.1", "craft-behavior", @@ -1364,7 +1364,7 @@ dependencies = [ [[package]] name = "craft-behavior" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "accesskit", "bitflags 2.13.2", @@ -1383,7 +1383,7 @@ dependencies = [ [[package]] name = "craft-browse" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "craft-behavior", "craft-docpath", @@ -1401,7 +1401,7 @@ dependencies = [ [[package]] name = "craft-cdr" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "crc32fast", "flate2", @@ -1410,7 +1410,7 @@ dependencies = [ [[package]] name = "craft-cloud-ui" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "egui", ] @@ -1418,7 +1418,7 @@ dependencies = [ [[package]] name = "craft-cms" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "md-5", "rayon", @@ -1427,12 +1427,12 @@ dependencies = [ [[package]] name = "craft-codepage" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" [[package]] name = "craft-color-ui" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "craft-behavior", "craft-cms", @@ -1452,7 +1452,7 @@ dependencies = [ [[package]] name = "craft-control" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "craft-ai-agents", "craft-atomic", @@ -1468,7 +1468,7 @@ dependencies = [ [[package]] name = "craft-control-protocol" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "getrandom 0.3.4", "serde_json", @@ -1478,7 +1478,7 @@ dependencies = [ [[package]] name = "craft-dds" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "rayon", ] @@ -1486,7 +1486,7 @@ dependencies = [ [[package]] name = "craft-dialogs" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "block2 0.6.2", "craft-appkit", @@ -1512,7 +1512,7 @@ dependencies = [ [[package]] name = "craft-doc" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "blake3", "craft-ecproj-format", @@ -1528,7 +1528,7 @@ dependencies = [ [[package]] name = "craft-docpath" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "serde", ] @@ -1536,7 +1536,7 @@ dependencies = [ [[package]] name = "craft-draw" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "craft-behavior", "craft-color-ui", @@ -1555,7 +1555,7 @@ dependencies = [ [[package]] name = "craft-dwg" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "acadrust", "craft-dxf", @@ -1565,7 +1565,7 @@ dependencies = [ [[package]] name = "craft-dxf" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "craft-codepage", "encoding_rs", @@ -1577,7 +1577,7 @@ dependencies = [ [[package]] name = "craft-ecproj-format" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "serde", "serde_json", @@ -1587,12 +1587,12 @@ dependencies = [ [[package]] name = "craft-eps" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" [[package]] name = "craft-flags" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "craft-atomic", "dirs", @@ -1602,7 +1602,7 @@ dependencies = [ [[package]] name = "craft-font-catalog" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "fontique", "harfrust 0.13.3", @@ -1617,7 +1617,7 @@ dependencies = [ [[package]] name = "craft-font-manager" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "craft-behavior", "craft-font-catalog", @@ -1636,7 +1636,7 @@ dependencies = [ [[package]] name = "craft-font-os-windows" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "windows-registry", "windows-sys 0.61.2", @@ -1645,7 +1645,7 @@ dependencies = [ [[package]] name = "craft-font-store" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "cap-primitives", "craft-atomic", @@ -1668,12 +1668,12 @@ dependencies = [ [[package]] name = "craft-fonts-build" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" [[package]] name = "craft-gif" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "gif", ] @@ -1681,7 +1681,7 @@ dependencies = [ [[package]] name = "craft-gzip" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "flate2", ] @@ -1689,7 +1689,7 @@ dependencies = [ [[package]] name = "craft-host" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "bitflags 2.13.2", "craft-i18n", @@ -1702,7 +1702,7 @@ dependencies = [ [[package]] name = "craft-i18n" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "brotli 9.1.3", "brotli-decompressor 6.3.2", @@ -1732,7 +1732,7 @@ dependencies = [ [[package]] name = "craft-image-codecs" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "craft-dds", "craft-jpeg", @@ -1759,7 +1759,7 @@ dependencies = [ [[package]] name = "craft-imaging" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "craft-behavior", "craft-color-ui", @@ -1777,7 +1777,7 @@ dependencies = [ [[package]] name = "craft-jpeg" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "thiserror 2.0.21", ] @@ -1785,7 +1785,7 @@ dependencies = [ [[package]] name = "craft-jxl" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "brotli-decompressor 5.0.3", "jixel", @@ -1796,7 +1796,7 @@ dependencies = [ [[package]] name = "craft-keymap" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "craft-host", "craft-i18n", @@ -1811,7 +1811,7 @@ dependencies = [ [[package]] name = "craft-layers" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "craft-behavior", "craft-i18n", @@ -1825,7 +1825,7 @@ dependencies = [ [[package]] name = "craft-menu" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "craft-behavior", "craft-host", @@ -1843,7 +1843,7 @@ dependencies = [ [[package]] name = "craft-metadata" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "brotli-decompressor 6.3.2", "chrono", @@ -1855,7 +1855,7 @@ dependencies = [ [[package]] name = "craft-metafile" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "encoding_rs", "image", @@ -1866,7 +1866,7 @@ dependencies = [ [[package]] name = "craft-mime" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "chrono", "craft-codepage", @@ -1876,7 +1876,7 @@ dependencies = [ [[package]] name = "craft-nightly" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "uds_windows", "winsafe", @@ -1885,7 +1885,7 @@ dependencies = [ [[package]] name = "craft-pages" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "craft-behavior", "craft-keymap", @@ -1901,7 +1901,7 @@ dependencies = [ [[package]] name = "craft-pbr" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "craft-texture", "thiserror 2.0.21", @@ -1910,7 +1910,7 @@ dependencies = [ [[package]] name = "craft-pcraft-format" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "flate2", "serde", @@ -1921,7 +1921,7 @@ dependencies = [ [[package]] name = "craft-pdf" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "hayro-interpret", "hayro-syntax", @@ -1933,7 +1933,7 @@ dependencies = [ [[package]] name = "craft-platform" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "async-channel", "async-io", @@ -1966,7 +1966,7 @@ dependencies = [ [[package]] name = "craft-plotter" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "kurbo 0.13.1", "thiserror 2.0.21", @@ -1975,7 +1975,7 @@ dependencies = [ [[package]] name = "craft-print" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "craft-behavior", "craft-host", @@ -1999,7 +1999,7 @@ dependencies = [ [[package]] name = "craft-proof" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "log", "miniz_oxide 0.9.1", @@ -2010,7 +2010,7 @@ dependencies = [ [[package]] name = "craft-ps" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "craft-eps", "flate2", @@ -2024,7 +2024,7 @@ dependencies = [ [[package]] name = "craft-psd" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "encoding_rs", "flate2", @@ -2035,7 +2035,7 @@ dependencies = [ [[package]] name = "craft-quit" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "dispatch2", "egui", @@ -2048,7 +2048,7 @@ dependencies = [ [[package]] name = "craft-raster3d" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "rayon", "thiserror 2.0.21", @@ -2057,7 +2057,7 @@ dependencies = [ [[package]] name = "craft-review" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "base64 0.23.1", "craft-behavior", @@ -2076,7 +2076,7 @@ dependencies = [ [[package]] name = "craft-settings" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "craft-atomic", "craft-host", @@ -2093,7 +2093,7 @@ dependencies = [ [[package]] name = "craft-stream-codecs" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "fax", "hayro-ccitt", @@ -2104,7 +2104,7 @@ dependencies = [ [[package]] name = "craft-svg" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "craft-image-codecs", "craft-xml", @@ -2125,7 +2125,7 @@ dependencies = [ [[package]] name = "craft-table" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "craft-behavior", "craft-keymap", @@ -2137,7 +2137,7 @@ dependencies = [ [[package]] name = "craft-text" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "craft-behavior", "craft-font-manager", @@ -2162,7 +2162,7 @@ dependencies = [ [[package]] name = "craft-texture" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "thiserror 2.0.21", ] @@ -2170,7 +2170,7 @@ dependencies = [ [[package]] name = "craft-theme" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "bitflags 2.13.2", "craft-tracked", @@ -2185,7 +2185,7 @@ dependencies = [ [[package]] name = "craft-theme-store" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "craft-atomic", "craft-behavior", @@ -2200,7 +2200,7 @@ dependencies = [ [[package]] name = "craft-tiff" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "serde", "thiserror 2.0.21", @@ -2210,7 +2210,7 @@ dependencies = [ [[package]] name = "craft-time" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "serde", "thiserror 2.0.21", @@ -2219,7 +2219,7 @@ dependencies = [ [[package]] name = "craft-timeline" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "craft-behavior", "craft-keymap", @@ -2234,12 +2234,12 @@ dependencies = [ [[package]] name = "craft-tracked" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" [[package]] name = "craft-ui" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "craft-cloud-ui", "craft-ui-canvas", @@ -2253,7 +2253,7 @@ dependencies = [ [[package]] name = "craft-ui-canvas" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "craft-behavior", "craft-font-catalog", @@ -2270,7 +2270,7 @@ dependencies = [ [[package]] name = "craft-ui-contract" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "accesskit", "craft-behavior", @@ -2308,7 +2308,7 @@ dependencies = [ [[package]] name = "craft-ui-macros" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -2319,7 +2319,7 @@ dependencies = [ [[package]] name = "craft-ui-panels" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "craft-behavior", "craft-host", @@ -2337,7 +2337,7 @@ dependencies = [ [[package]] name = "craft-ui-patterns" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "craft-behavior", "craft-host", @@ -2358,7 +2358,7 @@ dependencies = [ [[package]] name = "craft-ui-shell" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "craft-behavior", "craft-host", @@ -2379,7 +2379,7 @@ dependencies = [ [[package]] name = "craft-ui-widgets" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "craft-behavior", "craft-host", @@ -2398,7 +2398,7 @@ dependencies = [ [[package]] name = "craft-update" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "base64 0.22.1", "chrono", @@ -2430,7 +2430,7 @@ dependencies = [ [[package]] name = "craft-vectorcraft-format" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "flate2", "serde", @@ -2441,7 +2441,7 @@ dependencies = [ [[package]] name = "craft-wayland" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "raw-window-handle", "wayland-backend", @@ -2451,7 +2451,7 @@ dependencies = [ [[package]] name = "craft-web-api" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "js-sys", "serde_json", @@ -2462,7 +2462,7 @@ dependencies = [ [[package]] name = "craft-win32" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "winsafe", ] @@ -2470,7 +2470,7 @@ dependencies = [ [[package]] name = "craft-window" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "craft-appkit", "craft-atomic", @@ -2502,7 +2502,7 @@ dependencies = [ [[package]] name = "craft-xml" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "quick-xml 0.41.0", "serde", @@ -3862,7 +3862,7 @@ checksum = "9f4d0e94ddd48749f06bbe4e5389fb9799a0c45bcaf00495042076ef05e3241a" [[package]] name = "hayro-cmap" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "brotli 8.0.4", "hayro-postscript", @@ -3871,7 +3871,7 @@ dependencies = [ [[package]] name = "hayro-interpret" version = "0.7.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "bitflags 2.13.2", "hayro-cmap", @@ -3889,7 +3889,7 @@ dependencies = [ [[package]] name = "hayro-jbig2" version = "0.3.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "fearless_simd", "hayro-ccitt", @@ -3907,12 +3907,12 @@ dependencies = [ [[package]] name = "hayro-postscript" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" [[package]] name = "hayro-syntax" version = "0.7.2" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "flate2", "hayro-ccitt", @@ -4895,7 +4895,7 @@ dependencies = [ [[package]] name = "krilla" version = "0.8.2" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "base64 0.22.1", "bumpalo", @@ -5052,7 +5052,7 @@ checksum = "d4a5ff6bcca6c4867b1c4fd4ef63e4db7436ef363e0ad7531d1558856bae64f4" [[package]] name = "linesweeper" version = "0.5.0" -source = "git+https://github.com/storytold/craft-libs?rev=4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da#4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" +source = "git+https://github.com/storytold/craft-libs?rev=2cab29095590d3681f131e35aab2498e6cd9a0cc#2cab29095590d3681f131e35aab2498e6cd9a0cc" dependencies = [ "arrayvec", "kurbo 0.13.1", diff --git a/Cargo.toml b/Cargo.toml index 73e26d5375..f6b9cc431c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,57 +10,57 @@ license = "MIT OR Apache-2.0" rust-version = "1.95" [workspace.dependencies] -craft-cms = { git = "https://github.com/storytold/craft-libs", rev = "4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" } -craft-pdf = { git = "https://github.com/storytold/craft-libs", rev = "4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da", default-features = false, features = ["interpret", "write"] } -craft-docpath = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" } -craft-proof = { git = "https://github.com/storytold/craft-libs", rev = "4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" } +craft-cms = { git = "https://github.com/storytold/craft-libs", rev = "2cab29095590d3681f131e35aab2498e6cd9a0cc" } +craft-pdf = { git = "https://github.com/storytold/craft-libs", rev = "2cab29095590d3681f131e35aab2498e6cd9a0cc", default-features = false, features = ["interpret", "write"] } +craft-docpath = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "2cab29095590d3681f131e35aab2498e6cd9a0cc" } +craft-proof = { git = "https://github.com/storytold/craft-libs", rev = "2cab29095590d3681f131e35aab2498e6cd9a0cc" } # Language packs: the Craft apps' shared font store installs them (#4936). -craft-font-store = { git = "https://github.com/storytold/craft-libs", rev = "4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" } -craft-font-catalog = { git = "https://github.com/storytold/craft-libs", rev = "4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" } +craft-font-store = { git = "https://github.com/storytold/craft-libs", rev = "2cab29095590d3681f131e35aab2498e6cd9a0cc" } +craft-font-catalog = { git = "https://github.com/storytold/craft-libs", rev = "2cab29095590d3681f131e35aab2498e6cd9a0cc" } # The `.vectorcraft` envelope: its members, version, embedded images and the data after the JSON. -craft-vectorcraft-format = { git = "https://github.com/storytold/craft-libs", rev = "4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" } -craft-gzip = { git = "https://github.com/storytold/craft-libs", rev = "4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" } +craft-vectorcraft-format = { git = "https://github.com/storytold/craft-libs", rev = "2cab29095590d3681f131e35aab2498e6cd9a0cc" } +craft-gzip = { git = "https://github.com/storytold/craft-libs", rev = "2cab29095590d3681f131e35aab2498e6cd9a0cc" } # `.pcraft` documents: their manifest, full-size composite, preview, layer pixels and ICC profile. -craft-doc = { git = "https://github.com/storytold/craft-libs", rev = "4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da", features = ["pcraft-pixels"] } +craft-doc = { git = "https://github.com/storytold/craft-libs", rev = "2cab29095590d3681f131e35aab2498e6cd9a0cc", features = ["pcraft-pixels"] } # Native Affinity documents (craft-libs#914). -craft-affinity = { git = "https://github.com/storytold/craft-libs", rev = "4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" } +craft-affinity = { git = "https://github.com/storytold/craft-libs", rev = "2cab29095590d3681f131e35aab2498e6cd9a0cc" } # Bounded CDR (v1-v27) and CMX (32-bit) reader (craft-libs#778). -craft-cdr = { git = "https://github.com/storytold/craft-libs", rev = "4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" } +craft-cdr = { git = "https://github.com/storytold/craft-libs", rev = "2cab29095590d3681f131e35aab2498e6cd9a0cc" } # SVG parsing, limits, SVGZ and writer (craft-libs#778). -craft-svg = { git = "https://github.com/storytold/craft-libs", rev = "4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da", features = ["tree"] } -craft-mime = { git = "https://github.com/storytold/craft-libs", rev = "4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" } +craft-svg = { git = "https://github.com/storytold/craft-libs", rev = "2cab29095590d3681f131e35aab2498e6cd9a0cc", features = ["tree"] } +craft-mime = { git = "https://github.com/storytold/craft-libs", rev = "2cab29095590d3681f131e35aab2498e6cd9a0cc" } # EPS container, previews, ASCII85 and DSC comments (craft-libs#778). -craft-eps = { git = "https://github.com/storytold/craft-libs", rev = "4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" } +craft-eps = { git = "https://github.com/storytold/craft-libs", rev = "2cab29095590d3681f131e35aab2498e6cd9a0cc" } # DXF tags, reader and writer (craft-libs#778, #926, #927). -craft-plotter = { git = "https://github.com/storytold/craft-libs", rev = "4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" } -craft-dxf = { git = "https://github.com/storytold/craft-libs", rev = "4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" } +craft-plotter = { git = "https://github.com/storytold/craft-libs", rev = "2cab29095590d3681f131e35aab2498e6cd9a0cc" } +craft-dxf = { git = "https://github.com/storytold/craft-libs", rev = "2cab29095590d3681f131e35aab2498e6cd9a0cc" } # DWG to DXF bytes, in a child process on desktop builds (acadrust 0.6.6, MPL-2.0, unmodified). -craft-dwg = { git = "https://github.com/storytold/craft-libs", rev = "4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" } +craft-dwg = { git = "https://github.com/storytold/craft-libs", rev = "2cab29095590d3681f131e35aab2498e6cd9a0cc" } # WMF, EMF and EMF+ reader (craft-libs#778). -craft-metafile = { git = "https://github.com/storytold/craft-libs", rev = "4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" } -craft-xml = { git = "https://github.com/storytold/craft-libs", rev = "4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" } -craft-image-codecs = { git = "https://github.com/storytold/craft-libs", rev = "4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" } -craft-gif = { git = "https://github.com/storytold/craft-libs", rev = "4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" } -craft-tiff = { git = "https://github.com/storytold/craft-libs", rev = "4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" } -craft-ps = { git = "https://github.com/storytold/craft-libs", rev = "4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da", default-features = false, features = ["read", "write"] } -craft-psd = { git = "https://github.com/storytold/craft-libs", rev = "4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" } -craft-stream-codecs = { git = "https://github.com/storytold/craft-libs", rev = "4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" } -craft-jxl = { git = "https://github.com/storytold/craft-libs", rev = "4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" } -craft-codepage = { git = "https://github.com/storytold/craft-libs", rev = "4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" } +craft-metafile = { git = "https://github.com/storytold/craft-libs", rev = "2cab29095590d3681f131e35aab2498e6cd9a0cc" } +craft-xml = { git = "https://github.com/storytold/craft-libs", rev = "2cab29095590d3681f131e35aab2498e6cd9a0cc" } +craft-image-codecs = { git = "https://github.com/storytold/craft-libs", rev = "2cab29095590d3681f131e35aab2498e6cd9a0cc" } +craft-gif = { git = "https://github.com/storytold/craft-libs", rev = "2cab29095590d3681f131e35aab2498e6cd9a0cc" } +craft-tiff = { git = "https://github.com/storytold/craft-libs", rev = "2cab29095590d3681f131e35aab2498e6cd9a0cc" } +craft-ps = { git = "https://github.com/storytold/craft-libs", rev = "2cab29095590d3681f131e35aab2498e6cd9a0cc", default-features = false, features = ["read", "write"] } +craft-psd = { git = "https://github.com/storytold/craft-libs", rev = "2cab29095590d3681f131e35aab2498e6cd9a0cc" } +craft-stream-codecs = { git = "https://github.com/storytold/craft-libs", rev = "2cab29095590d3681f131e35aab2498e6cd9a0cc" } +craft-jxl = { git = "https://github.com/storytold/craft-libs", rev = "2cab29095590d3681f131e35aab2498e6cd9a0cc" } +craft-codepage = { git = "https://github.com/storytold/craft-libs", rev = "2cab29095590d3681f131e35aab2498e6cd9a0cc" } # The metallic-roughness BRDF and environment light the 3D effects' Roughness and Metallic shade with. -craft-pbr = { git = "https://github.com/storytold/craft-libs", rev = "4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" } +craft-pbr = { git = "https://github.com/storytold/craft-libs", rev = "2cab29095590d3681f131e35aab2498e6cd9a0cc" } # The CPU rasterizer that draws a 3D effect's Render Settings › Rendered image: depth-buffered triangles, shadow maps. -craft-raster3d = { git = "https://github.com/storytold/craft-libs", rev = "4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" } +craft-raster3d = { git = "https://github.com/storytold/craft-libs", rev = "2cab29095590d3681f131e35aab2498e6cd9a0cc" } # The framework facade (`craft::ui`, `craft::settings`, `craft::platform`, ...). No default features: each crate names # the members it imports. -craft = { git = "https://github.com/storytold/craft-libs", rev = "4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" } +craft = { git = "https://github.com/storytold/craft-libs", rev = "2cab29095590d3681f131e35aab2498e6cd9a0cc" } # Below the egui layer, so not through the facade: the colour harmony rules and their settings (craft-color-ui # without its `ui` feature), the colour type they work in, and the craft-fonts tables the text crate's build writes. -craft-color-ui = { git = "https://github.com/storytold/craft-libs", rev = "4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" } -craft-theme = { git = "https://github.com/storytold/craft-libs", rev = "4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" } -craft-fonts-build = { git = "https://github.com/storytold/craft-libs", rev = "4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" } +craft-color-ui = { git = "https://github.com/storytold/craft-libs", rev = "2cab29095590d3681f131e35aab2498e6cd9a0cc" } +craft-theme = { git = "https://github.com/storytold/craft-libs", rev = "2cab29095590d3681f131e35aab2498e6cd9a0cc" } +craft-fonts-build = { git = "https://github.com/storytold/craft-libs", rev = "2cab29095590d3681f131e35aab2498e6cd9a0cc" } # Nightly profile isolation, launch protocol, and security fence. -craft-nightly = { git = "https://github.com/storytold/craft-libs", rev = "4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" } +craft-nightly = { git = "https://github.com/storytold/craft-libs", rev = "2cab29095590d3681f131e35aab2498e6cd9a0cc" } # internal vectorcraft-geom = { path = "crates/geom" } vectorcraft-color = { path = "crates/color" } @@ -200,13 +200,13 @@ lto = "thin" codegen-units = 1 [patch.crates-io] -hayro-syntax = { git = "https://github.com/storytold/craft-libs", rev = "4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" } -hayro-interpret = { git = "https://github.com/storytold/craft-libs", rev = "4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" } -hayro-jbig2 = { git = "https://github.com/storytold/craft-libs", rev = "4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" } -hayro-cmap = { git = "https://github.com/storytold/craft-libs", rev = "4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" } -hayro-postscript = { git = "https://github.com/storytold/craft-libs", rev = "4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" } -krilla = { git = "https://github.com/storytold/craft-libs", rev = "4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" } -linesweeper = { git = "https://github.com/storytold/craft-libs", rev = "4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da" } +hayro-syntax = { git = "https://github.com/storytold/craft-libs", rev = "2cab29095590d3681f131e35aab2498e6cd9a0cc" } +hayro-interpret = { git = "https://github.com/storytold/craft-libs", rev = "2cab29095590d3681f131e35aab2498e6cd9a0cc" } +hayro-jbig2 = { git = "https://github.com/storytold/craft-libs", rev = "2cab29095590d3681f131e35aab2498e6cd9a0cc" } +hayro-cmap = { git = "https://github.com/storytold/craft-libs", rev = "2cab29095590d3681f131e35aab2498e6cd9a0cc" } +hayro-postscript = { git = "https://github.com/storytold/craft-libs", rev = "2cab29095590d3681f131e35aab2498e6cd9a0cc" } +krilla = { git = "https://github.com/storytold/craft-libs", rev = "2cab29095590d3681f131e35aab2498e6cd9a0cc" } +linesweeper = { git = "https://github.com/storytold/craft-libs", rev = "2cab29095590d3681f131e35aab2498e6cd9a0cc" } # skrifa 0.44 (epaint, glifo, usvg) with the automatic hinter's long blue-zone exit (craft-libs vendor/skrifa). # It stays at this rev until craft-libs#5222 merges. skrifa = { git = "https://github.com/storytold/craft-libs", rev = "37d0532f42eb3421769c8a454e3e25a20fbcff97" } diff --git a/apps/vectorcraft-web/Cargo.toml b/apps/vectorcraft-web/Cargo.toml index 62605759eb..45c7aad7ed 100644 --- a/apps/vectorcraft-web/Cargo.toml +++ b/apps/vectorcraft-web/Cargo.toml @@ -28,7 +28,7 @@ egui_extras = { workspace = true } # `wgpu` pulls egui-wgpu's defaults: WebGPU plus the WebGL2 fallback. eframe = { workspace = true, features = ["default_fonts", "wgpu", "accesskit"] } # The page command API (storytold/craft-libs#413): the request plumbing behind window.vectorcraft. -craft-web-api = { git = "https://github.com/storytold/craft-libs", rev = "4f3e34d0dda2a6862f5ba5fc4cfe3e323602a2da", version = "0.1.0" } +craft-web-api = { git = "https://github.com/storytold/craft-libs", rev = "2cab29095590d3681f131e35aab2498e6cd9a0cc", version = "0.1.0" } wasm-bindgen = "0.2" serde_json = { workspace = true } diff --git a/crates/engine/src/cmd/fileio/cdr.rs b/crates/engine/src/cmd/fileio/cdr.rs index 04aef3563a..3633d06553 100644 --- a/crates/engine/src/cmd/fileio/cdr.rs +++ b/crates/engine/src/cmd/fileio/cdr.rs @@ -112,7 +112,9 @@ pub(super) fn import(bytes: &[u8]) -> Result<(Document, Vec)> { why => err(format!("this CDR drawing can't be read ({why})")), })?; let (doc, mut warnings) = build(&d, note, PAGES_CUT); - if d.version >= FRAMES_FROM && d.warnings.iter().any(|w| matches!(w, Warning::UnsupportedObjects | Warning::TooDeep)) { + // Objects the reader or the mapping left out (bitmaps are read but not placed), or content past the reader's limits. + let left_out = warnings.iter().any(|w| w == UNSUPPORTED_OBJECTS) || d.warnings.contains(&Warning::TooDeep); + if d.version >= FRAMES_FROM && left_out { warnings.push(EMPTY_FRAMES.to_string()); } Ok((doc, warnings)) @@ -423,6 +425,8 @@ fn copy_cost(objects: &[cd::Object]) -> usize { match o { cd::Object::Group { objects: kids, .. } => stack.extend(kids), cd::Object::Shape(s) => n = n.saturating_add(shape_cost(s)), + // A bitmap is not placed, so it takes nothing past the object itself. + cd::Object::Image(_) => {} cd::Object::Clip { container, objects } => { // A container whose outline is behind its fill is built twice, as that outline // and as the clipping path, inside a group of their own. diff --git a/crates/engine/src/cmd/fileio/cdr/shapes.rs b/crates/engine/src/cmd/fileio/cdr/shapes.rs index 320fda877c..127f97d87c 100644 --- a/crates/engine/src/cmd/fileio/cdr/shapes.rs +++ b/crates/engine/src/cmd/fileio/cdr/shapes.rs @@ -74,6 +74,8 @@ impl Builder { self.learn_spot(c); } } + // Bitmaps are not placed, so their colors add no swatch. + cd::Object::Image(_) => {} cd::Object::Group { objects: kids, .. } => stack.extend(kids), cd::Object::Clip { container, objects } => { for c in container.fill.iter().chain(container.outline.iter().map(|o| &o.color)) { @@ -123,6 +125,8 @@ impl Builder { for o in objects.iter().rev() { match o { cd::Object::Shape(s) => out.extend(self.shape(s, to_doc, false).map(|n| with_flags(n, s.flags))), + // Bitmaps are left out, and the warnings name them with the other objects not read. + cd::Object::Image(_) => self.note(Warning::UnsupportedObjects), cd::Object::Group { objects: kids, flags } => { let children = self.objects_at(kids, to_doc, depth + 1); if !children.is_empty() { diff --git a/crates/engine/src/cmd/fileio/tests_cdr.rs b/crates/engine/src/cmd/fileio/tests_cdr.rs index 2e4d82822b..4728c56065 100644 --- a/crates/engine/src/cmd/fileio/tests_cdr.rs +++ b/crates/engine/src/cmd/fileio/tests_cdr.rs @@ -537,7 +537,7 @@ fn containers_open_as_clipping_groups() { assert!(children[1..].iter().all(|n| matches!(n.kind, NodeKind::Path { clipping: false, .. }))); } -/// A container whose clipped group holds only objects the reader leaves out (a bitmap here), or +/// A container whose clipped group holds only objects the reader leaves out (text here), or /// whose group holds a container of that same group, opens as a plain shape, and the warnings /// say that such frames opened empty. #[test] @@ -554,7 +554,7 @@ fn containers_whose_contents_were_left_out_are_named_in_the_warnings() { super::cdr::import(&synth::riff(1100, &[chunk(b"vrsn", 1100u16.to_le_bytes().to_vec()), doc, page])).unwrap() }; let frames = "PowerClip frames whose contents were left out opened empty"; - let (doc, warnings) = open(vec![synth::object(v, 5, &[(30, v.rect(10.0, 10.0, 0.0))], None)]); + let (doc, warnings) = open(vec![synth::object(v, 4, &[(30, v.rect(10.0, 10.0, 0.0))], None)]); let p = paths(&doc); let [frame] = p.as_slice() else { panic!("{p:?}") }; assert!(matches!(frame.kind, NodeKind::Path { clipping: false, .. }), "{:?}", frame.kind); @@ -566,6 +566,41 @@ fn containers_whose_contents_were_left_out_are_named_in_the_warnings() { assert!(warnings.iter().any(|w| w.contains(frames)), "{warnings:?}"); } +/// A bitmap the reader decodes is not placed: the drawing opens without it, and the warnings name +/// the bitmaps left out. A container that clips only a bitmap opens with its clipping path alone, +/// and the warnings say that such frames opened empty. +#[test] +fn bitmaps_are_left_out_and_named_in_the_warnings() { + let v = V(1300); + let gray = synth::Bitmap { model: 5, bpp: 8, width: 3, height: 2, palette: vec![], rows: vec![vec![0; 3], vec![0; 3]] }; + let open = |bitmaps: Vec, objects: Vec| { + let body = vec![ + chunk(b"vrsn", 1300u16.to_le_bytes().to_vec()), + list(b"bmpt", bitmaps), + synth::page(false, vec![synth::layer(v, [0, 0, 0, 0x98], "Art", objects)]), + ]; + super::cdr::import(&synth::riff(1300, &body)).unwrap() + }; + let rect = || synth::object(v, 1, &[(30, v.rect(40.0, 40.0, 0.0))], None); + let frames = "PowerClip frames whose contents were left out opened empty"; + + let (doc, warnings) = open(vec![synth::bmp(v, 1, &gray, None)], vec![synth::bitmap_object(v, 1, (0.0, 2.0), (3.0, 0.0), None), rect()]); + let p = paths(&doc); + let [shape] = p.as_slice() else { panic!("{p:?}") }; + assert!(matches!(shape.kind, NodeKind::Path { clipping: false, .. }), "{:?}", shape.kind); + assert!(warnings.iter().any(|w| w.contains("text, bitmaps")), "{warnings:?}"); + assert!(warnings.iter().any(|w| w.contains(frames)), "{warnings:?}"); + + let clipped = synth::clpt(vec![(0x77, vec![synth::bitmap_object(v, 1, (0.0, 2.0), (3.0, 0.0), None)])]); + let container = synth::object(v, 1, &[(30, v.rect(40.0, 40.0, 0.0)), synth::container(0x77)], None); + let (doc, warnings) = open(vec![synth::bmp(v, 1, &gray, None), clipped], vec![container]); + let p = paths(&doc); + let [frame] = p.as_slice() else { panic!("{p:?}") }; + assert!(matches!(frame.kind, NodeKind::Path { clipping: true, .. }), "{:?}", frame.kind); + assert!(warnings.iter().any(|w| w.contains("text, bitmaps")), "{warnings:?}"); + assert!(warnings.iter().any(|w| w.contains(frames)), "{warnings:?}"); +} + /// An object with a lens or transparency opens opaque, and the warnings say so. #[test] fn lenses_and_transparency_are_named_in_the_warnings() { diff --git a/crates/ui-egui/src/chrome/control_bar.rs b/crates/ui-egui/src/chrome/control_bar.rs index 266726909a..0c02c32828 100644 --- a/crates/ui-egui/src/chrome/control_bar.rs +++ b/crates/ui-egui/src/chrome/control_bar.rs @@ -289,7 +289,7 @@ fn opacity_field(app: &mut VectorcraftApp, ui: &mut Ui, opacity: f32, selected: let target = crate::panels::transparency_target(app); group(ui, rank::OPACITY, |ui| { Field::new(label).side(SideLabel::new().link().scrub(true)).show(ui, |ui, _| { - let number = NumberField::new(label, Bind::given(Some(crate::panels::shown_percent(opacity)))) + let number = NumberField::new(label, Bind::given(Some(f64::from(opacity) * 100.0))) .range(0.0..=100.0) .unit("%") .scrub_by_label() diff --git a/crates/ui-egui/src/panels.rs b/crates/ui-egui/src/panels.rs index cf129bf26c..689e9a7254 100644 --- a/crates/ui-egui/src/panels.rs +++ b/crates/ui-egui/src/panels.rs @@ -1264,15 +1264,6 @@ pub(crate) fn whole_steps(range: std::ops::RangeInclusive) -> ChannelRule { rule } -/// An opacity stored as an f32 fraction (0 to 1), as the percent an Opacity field shows: the whole percent when it -/// stores as the same f32, so that an arrow key steps on from it, and the exact percent otherwise. 51 % stores as -/// 0.51f32, which reads back as 50.999999 %; an Up press from there would step to 51 % again. -pub(crate) fn shown_percent(fraction: f32) -> f64 { - let percent = f64::from(fraction) * 100.0; - let whole = percent.round(); - if (whole / 100.0) as f32 == fraction { whole } else { percent } -} - /// A section of a panel or dialog under its heading in label text: the reference app's section headings are regular /// weight, not bold. pub(crate) fn section<'a>(title: impl Into