Add optimization that prunes nested <g>-tags
An optimization that prunes nested <g>-tags when they contain exactly one <g> and nothing else (except whitespace nodes). This looks a bit like `removeNestedGroups` except it only touches <g> tags without attributes (but can remove <g>-tags completely from a tree, whereas this optimization always leaves at least one <g> tag behind). Closes: #215 Signed-off-by: Niels Thykier <niels@thykier.net>
This commit is contained in:
parent
7e917c9ca0
commit
e8e104d8b8
5 changed files with 216 additions and 0 deletions
15
unittests/group-parent-merge.svg
Normal file
15
unittests/group-parent-merge.svg
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'>
|
||||
<svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
|
||||
<g font-family="Liberation Sans,Arial,Helvetica,sans-serif">
|
||||
<g text-anchor="middle">
|
||||
<g font-weight="400">
|
||||
<g font-size="24">
|
||||
<text x="50" y="30">Text1</text>
|
||||
<text x="50" y="55">Text2</text>
|
||||
<text x="50" y="80">Text3</text>
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 491 B |
15
unittests/group-parent-merge2.svg
Normal file
15
unittests/group-parent-merge2.svg
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'>
|
||||
<svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
|
||||
<g font-family="Liberation Sans,Arial,Helvetica,sans-serif">
|
||||
<g text-anchor="middle">
|
||||
<g font-weight="400">
|
||||
<text x="50" y="30">Text1</text>
|
||||
<g font-size="24">
|
||||
<text x="50" y="55">Text2</text>
|
||||
<text x="50" y="80">Text3</text>
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 489 B |
15
unittests/group-parent-merge3.svg
Normal file
15
unittests/group-parent-merge3.svg
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'>
|
||||
<svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
|
||||
<g font-family="Liberation Sans,Arial,Helvetica,sans-serif">
|
||||
<g text-anchor="middle">
|
||||
<g font-weight="400">
|
||||
<g id="foo" font-size="24">
|
||||
<text x="50" y="30">Text1</text>
|
||||
<text x="50" y="55">Text2</text>
|
||||
<text x="50" y="80">Text3</text>
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 500 B |
Loading…
Add table
Add a link
Reference in a new issue