Skip to content

Fix layers being merged on read when SVG groups share the same inkscape:label#855

Open
abey79 wants to merge 1 commit into
masterfrom
no-merge-layer
Open

Fix layers being merged on read when SVG groups share the same inkscape:label#855
abey79 wants to merge 1 commit into
masterfrom
no-merge-layer

Conversation

@abey79

@abey79 abey79 commented Jun 24, 2026

Copy link
Copy Markdown
Owner

Problem

vpype read input.svg splitdist -l 2 N write out.svg followed by read out.svg collapsed the split layers back together. For example, with a 3-layer input where layer 2 is split into 4 parts (6 layers in memory), re-reading the written SVG yielded only 3 layers, silently merging the four chunks of layer 2 back into one (62+79+92+30 → 263 paths).

The bug was on the read side, not write. read_multilayer_svg derived each layer's ID from the first digit group of its inkscape:label, taking priority over the always-unique id="layer{N}". splitdist stamps the source layer's name onto every overflow layer, so the chunks were all written with inkscape:label="2" and collapsed to a single layer on read. The same footgun hit any document with two layers sharing a digit-containing name (pen2, layer2, …), not just splitdist output.

Fix

Gate the label-based numbering on global distinctness: the inkscape:label is used to assign layer IDs only when it yields a distinct ID for every group. Otherwise it falls back to the id attribute (which vpype writes as layer{N}), then to appearance order.

This:

  • makes the write→read round-trip lossless for splitdist output and any duplicate digit-names;
  • preserves the Inkscape "rename a layer to a number" semantics for the common distinct case (verified against the existing multilayer_named_layers.svg fixture, whose ids are off-by-one — labels correctly still win there).

Tests

  • test_read_layer_id_colliding_labels_fall_back_to_id — groups sharing a label fall back to id instead of merging.
  • test_read_layer_id_distinct_labels_take_priority — distinct labels still win over the id attribute.
  • test_splitdist_write_read_roundtrip — full splitdistwriteread round-trip preserves the layer count.

Each was confirmed to fail on the pre-fix code. Full test_files.py + test_commands.py suites pass (1024 passed, 67 skipped).

🤖 Generated with Claude Code

@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant