Only attempt to group elements that the content model allows to be children of a <g> when --create-groups is specified. (#98)
(before it could happen that e.g. `tspan` elements were grouped, which is invalid; fixes issues #96 and #97)
This commit is contained in:
parent
419f41cb48
commit
5844076258
4 changed files with 35 additions and 1 deletions
|
|
@ -11,6 +11,8 @@
|
||||||
* Redirect informational output to `stderr` when SVG is output to `stdout`. ([#67](https://github.com/scour-project/scour/issues/67))
|
* Redirect informational output to `stderr` when SVG is output to `stdout`. ([#67](https://github.com/scour-project/scour/issues/67))
|
||||||
* Allow elements to be found via `Document.getElementById()` in the minidom document returned by scourXmlFile(). ([#68](https://github.com/scour-project/scour/issues/68))
|
* Allow elements to be found via `Document.getElementById()` in the minidom document returned by scourXmlFile(). ([#68](https://github.com/scour-project/scour/issues/68))
|
||||||
* Improve code to remove default attribute values and add a lot of new default values. ([#70](https://github.com/scour-project/scour/issues/70))
|
* Improve code to remove default attribute values and add a lot of new default values. ([#70](https://github.com/scour-project/scour/issues/70))
|
||||||
|
* Fix: Only attempt to group elements that the content model allows to be children of a `<g>` when `--create-groups` is specified. (#98)
|
||||||
|
|
||||||
|
|
||||||
## Version 0.34 (2016-07-25)
|
## Version 0.34 (2016-07-25)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1032,7 +1032,24 @@ def createGroupsForCommonAttributes(elem):
|
||||||
while curChild >= 0:
|
while curChild >= 0:
|
||||||
childNode = elem.childNodes.item(curChild)
|
childNode = elem.childNodes.item(curChild)
|
||||||
|
|
||||||
if childNode.nodeType == 1 and childNode.getAttribute(curAttr) != '':
|
if childNode.nodeType == 1 and childNode.getAttribute(curAttr) != '' and \
|
||||||
|
childNode.nodeName in [
|
||||||
|
# only attempt to group elements that the content model allows to be children of a <g>
|
||||||
|
|
||||||
|
# SVG 1.1 (see https://www.w3.org/TR/SVG/struct.html#GElement)
|
||||||
|
'animate', 'animateColor', 'animateMotion', 'animateTransform', 'set', # animation elements
|
||||||
|
'desc', 'metadata', 'title', # descriptive elements
|
||||||
|
'circle', 'ellipse', 'line', 'path', 'polygon', 'polyline', 'rect', # shape elements
|
||||||
|
'defs', 'g', 'svg', 'symbol', 'use', # structural elements
|
||||||
|
'linearGradient', 'radialGradient', # gradient elements
|
||||||
|
'a', 'altGlyphDef', 'clipPath', 'color-profile', 'cursor', 'filter',
|
||||||
|
'font', 'font-face', 'foreignObject', 'image', 'marker', 'mask',
|
||||||
|
'pattern', 'script', 'style', 'switch', 'text', 'view',
|
||||||
|
|
||||||
|
# SVG 1.2 (see https://www.w3.org/TR/SVGTiny12/elementTable.html)
|
||||||
|
'animation', 'audio', 'discard', 'handler', 'listener',
|
||||||
|
'prefetch', 'solidColor', 'textArea', 'video'
|
||||||
|
]:
|
||||||
# We're in a possible run! Track the value and run length.
|
# We're in a possible run! Track the value and run length.
|
||||||
value = childNode.getAttribute(curAttr)
|
value = childNode.getAttribute(curAttr)
|
||||||
runStart, runEnd = curChild, curChild
|
runStart, runEnd = curChild, curChild
|
||||||
|
|
|
||||||
|
|
@ -1222,6 +1222,13 @@ class GroupNoCreation(unittest.TestCase):
|
||||||
self.assertEqual(doc.getElementsByTagName('g').length, 0,
|
self.assertEqual(doc.getElementsByTagName('g').length, 0,
|
||||||
'Created a <g> for a run of elements having dissimilar attributes')
|
'Created a <g> for a run of elements having dissimilar attributes')
|
||||||
|
|
||||||
|
class GroupNoCreationForTspan(unittest.TestCase):
|
||||||
|
def runTest(self):
|
||||||
|
doc = scour.scourXmlFile('unittests/group-no-creation-tspan.svg',
|
||||||
|
scour.parse_args(['--create-groups']))
|
||||||
|
self.assertEqual(doc.getElementsByTagName('g').length, 0,
|
||||||
|
'Created a <g> for a run of <tspan>s that are not allowed as children according to content model')
|
||||||
|
|
||||||
class DoNotCommonizeAttributesOnReferencedElements(unittest.TestCase):
|
class DoNotCommonizeAttributesOnReferencedElements(unittest.TestCase):
|
||||||
def runTest(self):
|
def runTest(self):
|
||||||
doc = scour.scourXmlFile('unittests/commonized-referenced-elements.svg')
|
doc = scour.scourXmlFile('unittests/commonized-referenced-elements.svg')
|
||||||
|
|
|
||||||
8
unittests/group-no-creation-tspan.svg
Normal file
8
unittests/group-no-creation-tspan.svg
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<svg height="100" width="100" xmlns="http://www.w3.org/2000/svg" >
|
||||||
|
<text>
|
||||||
|
<tspan x="10" y="30" style="font-family:sans-serif">text1</tspan>
|
||||||
|
<tspan x="10" y="50" style="font-family:sans-serif">text2</tspan>
|
||||||
|
<tspan x="10" y="70" style="font-family:sans-serif">text3</tspan>
|
||||||
|
</text>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 350 B |
Loading…
Add table
Add a link
Reference in a new issue