Prevent fonts from being removed inside a <defs>
This commit is contained in:
parent
72363ec24b
commit
8d0bb8fe55
4 changed files with 47 additions and 1 deletions
3
scour.py
3
scour.py
|
|
@ -215,12 +215,13 @@ def removeUnreferencedIDs(referencedIDs, identifiedElements):
|
||||||
# returns the number of unreferenced children removed from defs elements
|
# returns the number of unreferenced children removed from defs elements
|
||||||
def vacuumDefs(doc):
|
def vacuumDefs(doc):
|
||||||
global numElemsRemoved
|
global numElemsRemoved
|
||||||
|
keepTags = ['font', 'style', 'metadata' ]
|
||||||
num = 0
|
num = 0
|
||||||
defs = doc.documentElement.getElementsByTagNameNS(NS['SVG'], 'defs')
|
defs = doc.documentElement.getElementsByTagNameNS(NS['SVG'], 'defs')
|
||||||
for aDef in defs:
|
for aDef in defs:
|
||||||
elemsToRemove = []
|
elemsToRemove = []
|
||||||
for elem in aDef.childNodes:
|
for elem in aDef.childNodes:
|
||||||
if elem.nodeType == 1 and elem.getAttribute('id') == '' :
|
if elem.nodeType == 1 and elem.getAttribute('id') == '' and not elem.nodeName in keepTags:
|
||||||
elemsToRemove.append(elem)
|
elemsToRemove.append(elem)
|
||||||
for elem in elemsToRemove:
|
for elem in elemsToRemove:
|
||||||
aDef.removeChild(elem)
|
aDef.removeChild(elem)
|
||||||
|
|
|
||||||
13
testscour.py
13
testscour.py
|
|
@ -195,6 +195,19 @@ class NoInkscapeAttributes(unittest.TestCase):
|
||||||
findInkscapeAttr), False,
|
findInkscapeAttr), False,
|
||||||
'Found Inkscape attributes' )
|
'Found Inkscape attributes' )
|
||||||
|
|
||||||
|
class KeepReferencedFonts(unittest.TestCase):
|
||||||
|
def runTest(self):
|
||||||
|
doc = scour.scourXmlFile('unittests/referenced-font.svg')
|
||||||
|
fonts = doc.documentElement.getElementsByTagNameNS('http://www.w3.org/2000/svg','font')
|
||||||
|
self.assertEquals(len(fonts), 1,
|
||||||
|
"Font wrongly removed from <defs>" )
|
||||||
|
|
||||||
|
class RemoveUnreferencedFonts(unittest.TestCase):
|
||||||
|
def runTest(self):
|
||||||
|
doc = scour.scourXmlFile('unittests/unreferenced-font.svg')
|
||||||
|
fonts = doc.documentElement.getElementsByTagNameNS('http://www.w3.org/2000/svg','font')
|
||||||
|
self.assertEquals(len(fonts), 0,
|
||||||
|
"Font was not removed from <defs>" )
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
||||||
16
unittests/referenced-font.svg
Normal file
16
unittests/referenced-font.svg
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
<svg xmlns='http://www.w3.org/2000/svg'>
|
||||||
|
<defs>
|
||||||
|
<font id="Font1" horiz-adv-x="1000">
|
||||||
|
<font-face font-family="Super Sans" font-weight="bold" font-style="normal"
|
||||||
|
units-per-em="1000" cap-height="600" x-height="400"
|
||||||
|
ascent="700" descent="300"
|
||||||
|
alphabetic="0" mathematical="350" ideographic="400" hanging="500">
|
||||||
|
<font-face-src>
|
||||||
|
<font-face-name name="Super Sans Bold"/>
|
||||||
|
</font-face-src>
|
||||||
|
</font-face>
|
||||||
|
<missing-glyph><path d="M0,0h200v200h-200z"/></missing-glyph>
|
||||||
|
</font>
|
||||||
|
</defs>
|
||||||
|
<text x="100" y="100" style="font-family: 'Super Sans', Helvetica, sans-serif">Text</text>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 657 B |
16
unittests/unreferenced-font.svg
Normal file
16
unittests/unreferenced-font.svg
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
<svg xmlns='http://www.w3.org/2000/svg'>
|
||||||
|
<defs>
|
||||||
|
<font id="Font1" horiz-adv-x="1000">
|
||||||
|
<font-face font-family="Super Sans" font-weight="bold" font-style="normal"
|
||||||
|
units-per-em="1000" cap-height="600" x-height="400"
|
||||||
|
ascent="700" descent="300"
|
||||||
|
alphabetic="0" mathematical="350" ideographic="400" hanging="500">
|
||||||
|
<font-face-src>
|
||||||
|
<font-face-name name="Super Sans Bold"/>
|
||||||
|
</font-face-src>
|
||||||
|
</font-face>
|
||||||
|
<missing-glyph><path d="M0,0h200v200h-200z"/></missing-glyph>
|
||||||
|
</font>
|
||||||
|
</defs>
|
||||||
|
<text x="100" y="100" style="font-family: Helvetica, sans-serif">Text</text>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 643 B |
Loading…
Add table
Add a link
Reference in a new issue