From c461369421b12fc3506c3d5b4b33aceaa712a2cb Mon Sep 17 00:00:00 2001 From: shmuelbiller1 Date: Fri, 9 Oct 2026 11:27:13 -0400 Subject: [PATCH] feat(doc): allow portable relinking of images and placed documents --- crates/doc/src/links.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/crates/doc/src/links.rs b/crates/doc/src/links.rs index d32ab9937..398b9171e 100644 --- a/crates/doc/src/links.rs +++ b/crates/doc/src/links.rs @@ -255,6 +255,32 @@ impl Align { } impl Document { + /// Rewrite linked file locations in both raster images and placed VectorCraft documents, + /// including those inside symbols, patterns and opacity masks. Used to make packages portable. + pub fn update_links(&mut self, mut f: impl FnMut(&mut LinkInfo)) { + fn walk(n: &mut Arc, f: &mut dyn FnMut(&mut LinkInfo)) { + let n = Arc::make_mut(n); + match &mut n.kind { + NodeKind::Image(image) => { + if let Some(link) = &mut image.link { + f(link); + } + } + NodeKind::PlacedDocument(placed) => f(&mut placed.link), + _ => {} + } + if let Some(mask) = &mut n.mask { + walk(&mut mask.art, f); + } + for child in n.children_mut().into_iter().flatten() { + walk(child, f); + } + } + for root in self.layers.iter_mut().chain(self.symbols.iter_mut().map(|s| &mut s.art)).chain(self.patterns.iter_mut().flat_map(|p| &mut p.art)) { + walk(root, &mut f); + } + } + /// Change every image object (in the layers, symbol definitions and pattern swatches, opacity-mask /// art included) for which `pick` holds; only the subtrees holding one are copied. pub fn update_images(&mut self, pick: impl Fn(&ImageObject) -> bool, mut f: impl FnMut(&mut ImageObject)) {