mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-06 05:53:08 -05:00
Copy a fallback layer lock only between layers that share a name (#9176)
A PDF part without layers comes in on one layer named for its page. When the editing data is set aside (a stale copy of another page size, say), pairing that layer with the editing data's one layer locked art nothing ties to it. Layers now take locks only by a name unique on both sides.
This commit is contained in:
1 parent
bf5f1a2402
commit
2604dab38a
2 files changed
+34
-15
No files matched your search
@@ -303,17 +303,9 @@ fn unique_name_pairs<T: std::ops::Deref<Target = Node>>(vis_nodes: &[T], priv_no
|
||||
|
||||
/// Apply lock states from private data layers to visible PDF layers.
|
||||
pub(crate) fn apply_private_layer_locks(visible_layers: &mut [Arc<Node>], private_layers: &[LockTree]) {
|
||||
if private_layers.is_empty() || visible_layers.is_empty() {
|
||||
return;
|
||||
}
|
||||
|
||||
// A document with a single visible layer and a single private layer pairs them directly.
|
||||
if visible_layers.len() == 1 && private_layers.len() == 1 {
|
||||
apply_node_locks(Arc::make_mut(&mut visible_layers[0]), &private_layers[0]);
|
||||
return;
|
||||
}
|
||||
|
||||
// Otherwise, match only layers with identifiable correspondence (matching unique names).
|
||||
// Only layers that are evidently the same one (a name unique on both sides) take its locks: one
|
||||
// layer each is no evidence, since a PDF part without layers comes in on a layer named for its
|
||||
// page, and the editing data it was set aside for may not be the art on it.
|
||||
for (v_idx, p_idx) in unique_name_pairs(visible_layers, private_layers) {
|
||||
apply_node_locks(Arc::make_mut(&mut visible_layers[v_idx]), &private_layers[p_idx]);
|
||||
}
|
||||
|
||||
@@ -8841,21 +8841,48 @@ fn ai_reordered_three_children_roads_triangle_circle_preserve_locks() {
|
||||
assert!(!vis_rd.locked, "Roads matched to unlocked private Roads by unique name");
|
||||
}
|
||||
|
||||
/// The PDF part's one layer, named for its page because the PDF part has no layers, isn't the
|
||||
/// editing data's one layer: nothing says the art on it is that layer's, so the layer's lock and
|
||||
/// those of what it holds stay out of it.
|
||||
#[test]
|
||||
fn ai_fallback_with_generated_page_name_preserves_private_layer_lock() {
|
||||
fn ai_fallback_with_generated_page_name_does_not_take_private_layer_lock() {
|
||||
use std::sync::Arc;
|
||||
let mut doc = Document::new(100.0, 100.0);
|
||||
let mut priv_layer = Node::layer(doc.alloc_id(), "Map", LayerColor::Preset(0));
|
||||
priv_layer.locked = true;
|
||||
let mut priv_roads = Node::group(doc.alloc_id(), vec![]);
|
||||
priv_roads.name = Some("Roads".to_string());
|
||||
priv_roads.locked = true;
|
||||
if let NodeKind::Layer { children, .. } = &mut priv_layer.kind {
|
||||
children.push(Arc::new(priv_roads));
|
||||
}
|
||||
let mut vis_layer = Node::layer(doc.alloc_id(), "Page 1", LayerColor::Preset(0));
|
||||
vis_layer.locked = false;
|
||||
let mut vis_roads = Node::group(doc.alloc_id(), vec![]);
|
||||
vis_roads.name = Some("Roads".to_string());
|
||||
if let NodeKind::Layer { children, .. } = &mut vis_layer.kind {
|
||||
children.push(Arc::new(vis_roads));
|
||||
}
|
||||
|
||||
let mut visible_layers = vec![Arc::new(vis_layer)];
|
||||
let private_layers = vec![super::native::layers::LockTree::from_node(&priv_layer)];
|
||||
super::native::layers::apply_private_layer_locks(&mut visible_layers, &private_layers);
|
||||
|
||||
assert_eq!(visible_layers[0].name.as_deref(), Some("Page 1"));
|
||||
assert!(visible_layers[0].locked, "single-layer document pairs visible and private layers");
|
||||
assert!(!visible_layers[0].locked, "the page's layer doesn't take the editing data's layer lock");
|
||||
assert!(!visible_layers[0].children().unwrap()[0].locked, "nor does what it holds");
|
||||
}
|
||||
|
||||
/// An editing copy that doesn't fit the PDF part (a stale copy of another page size) is set aside,
|
||||
/// and the PDF part without layers comes in on one layer named for its page: the editing copy's
|
||||
/// locked layer doesn't lock that art, which nothing ties to it.
|
||||
#[test]
|
||||
fn a_stale_editing_copy_does_not_lock_the_pdf_parts_page_layer() {
|
||||
let art = native(&locked_layer("Map", &square(10, 10)));
|
||||
let mut page = Document::new(300.0, 300.0);
|
||||
std::sync::Arc::make_mut(&mut page.layers[0]).name = Some("Page 1".into());
|
||||
let (d, w, read) = crate::layered_ai(&private(&art), page, vec![], false, false, 1.0);
|
||||
assert!(!read, "the editing copy of another page size is set aside: {w:?}");
|
||||
assert_eq!(names(&d), ["Page 1"], "{w:?}");
|
||||
assert!(!d.layers[0].locked, "the page's layer isn't locked: {w:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in new issue
Block a user