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.
This commit is contained in:
Taha-Mahmoodi
2026-10-23 06:13:00 +07:00
committed by bflatastic
parent 38b9cd44b1
commit f365468684
2 changed files with 29 additions and 1 deletions
+7 -1
View File
@@ -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()));
}
+22
View File
@@ -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<_>>(),
_ => Vec::new(),
};
assert!(!runs(&s).is_empty() && runs(&s).iter().all(|c| *c == k), "{:?}", runs(&s));
}