From f36546868412031a7c37b6e77ea554b689ba34d7 Mon Sep 17 00:00:00 2001 From: Taha-Mahmoodi <85902429+Taha-Mahmoodi@users.noreply.github.com> Date: Fri, 23 Oct 2026 02:11:26 +0430 Subject: [PATCH] Fix #3233: an opened dimension whose label characters are off the colour mode is redrawn too Review follow-up (CodeRabbit): a text node's characters carry their own fill (CharStyle), saved apart from the node's appearance, so conform also checks the runs of the label. dimension_colours_follow_the_document_colour_model opens a CMYK document whose label characters alone are RGB; without the change they stay RGB. --- crates/engine/src/cmd/dimension.rs | 8 +++++++- crates/engine/tests/dimensions.rs | 22 ++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/crates/engine/src/cmd/dimension.rs b/crates/engine/src/cmd/dimension.rs index 62b268d50..ec1f91f20 100644 --- a/crates/engine/src/cmd/dimension.rs +++ b/crates/engine/src/cmd/dimension.rs @@ -254,7 +254,13 @@ pub(crate) fn conform(doc: &mut Document) { doc.walk(|n| { if let Some(d) = &n.extras().dimension { let mut off = false; - n.walk(&mut |c| off |= [c.appearance.fill_paint(), c.appearance.stroke_paint()].iter().filter_map(|p| p.color()).any(|c| off_mode(&c))); + n.walk(&mut |c| { + off |= [c.appearance.fill_paint(), c.appearance.stroke_paint()].iter().filter_map(|p| p.color()).any(|c| off_mode(&c)); + // The label's characters carry their own fill. + if let NodeKind::Text(t) = &c.kind { + off |= t.runs.iter().filter_map(|r| r.style.fill.color()).any(|c| off_mode(&c)); + } + }); if off { stale.push((n.id, (**d).clone())); } diff --git a/crates/engine/tests/dimensions.rs b/crates/engine/tests/dimensions.rs index 2c99eec0b..8413aef71 100644 --- a/crates/engine/tests/dimensions.rs +++ b/crates/engine/tests/dimensions.rs @@ -520,4 +520,26 @@ fn dimension_colours_follow_the_document_colour_model() { s.add_document(old, None); let opened = colours(&s, id); assert!(!opened.is_empty() && opened.iter().all(|c| *c == k), "{opened:?}"); + // Only the label's characters in RGB (their fill is saved apart from the node's): redrawn too. + let mut old = (*s.doc().unwrap().doc).clone(); + let label = { + let mut found = None; + old.node(NodeId(id)).unwrap().walk(&mut |n| { + if matches!(n.kind, vectorcraft_doc::NodeKind::Text(_)) { + found = Some(n.id); + } + }); + found.expect("a dimension label") + }; + if let Some(vectorcraft_doc::NodeKind::Text(t)) = old.node_mut(label).map(|n| &mut n.kind) { + for r in &mut t.runs { + r.style.fill = vectorcraft_color::Paint::solid(vectorcraft_color::Color::rgb8(0, 0, 0)); + } + } + s.add_document(old, None); + let runs = |s: &Session| match &s.doc().unwrap().doc.node(label).unwrap().kind { + vectorcraft_doc::NodeKind::Text(t) => t.runs.iter().filter_map(|r| r.style.fill.color()).collect::>(), + _ => Vec::new(), + }; + assert!(!runs(&s).is_empty() && runs(&s).iter().all(|c| *c == k), "{:?}", runs(&s)); }