-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopaque.py
35 lines (31 loc) · 1.11 KB
/
opaque.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from xml.dom.minidom import parse
from os.path import basename, splitext
def set_opaque(filename):
dom = parse(filename)
svg = dom.getElementsByTagName('svg')[0]
for node in svg.childNodes:
traverse(node)
newFilename = '_opaque'.join(splitext(basename(filename)))
print newFilename
f = open(newFilename, 'w')
f.write(dom.toxml())
f.close()
def traverse(node):
if node.hasChildNodes():
for n in node.childNodes:
traverse(n)
attr = node.attributes
if attr is not None:
for i in range(attr.length):
item = attr.item(i)
if item.name == 'style':
newStyle = []
for style in item.value.split(';'):
if style.find('opacity') != -1:
key, value = style.split(':')
newStyle.append(key + ':1')
else:
newStyle.append(style)
node.setAttribute('style', ';'.join(newStyle))
elif item.name.find('opacity') != -1:
item.value = '1'