mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-10-24 09:46:59 -06:00
Merge pull request #3727 from Taha-Mahmoodi/fix/3233-label-runs
Fix #3233: an opened dimension whose label characters are off the colour mode is redrawn too
This commit is contained in:
@@ -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()));
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user