Fix layers being merged on read when SVG groups share the same inkscape:label#855
Open
abey79 wants to merge 1 commit into
Open
Fix layers being merged on read when SVG groups share the same inkscape:label#855abey79 wants to merge 1 commit into
abey79 wants to merge 1 commit into
Conversation
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Problem
vpype read input.svg splitdist -l 2 N write out.svgfollowed byread out.svgcollapsed 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_svgderived each layer's ID from the first digit group of itsinkscape:label, taking priority over the always-uniqueid="layer{N}".splitdiststamps the source layer's name onto every overflow layer, so the chunks were all written withinkscape: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 justsplitdistoutput.Fix
Gate the label-based numbering on global distinctness: the
inkscape:labelis used to assign layer IDs only when it yields a distinct ID for every group. Otherwise it falls back to theidattribute (which vpype writes aslayer{N}), then to appearance order.This:
splitdistoutput and any duplicate digit-names;multilayer_named_layers.svgfixture, whoseids 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 toidinstead of merging.test_read_layer_id_distinct_labels_take_priority— distinct labels still win over theidattribute.test_splitdist_write_read_roundtrip— fullsplitdist→write→readround-trip preserves the layer count.Each was confirmed to fail on the pre-fix code. Full
test_files.py+test_commands.pysuites pass (1024 passed, 67 skipped).🤖 Generated with Claude Code