Get all elements of tag name from the default namespace now
This commit is contained in:
parent
0bf1e8942c
commit
b0788ba18a
2 changed files with 173 additions and 15 deletions
158
fulltests/ocal.svg
Normal file
158
fulltests/ocal.svg
Normal file
|
|
@ -0,0 +1,158 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN"
|
||||
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
|
||||
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||
<svg:svg
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns:xlink="http://www.w3.org/1999/xlink"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:cc="http://creativecommons.org/ns#"
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
version="1.0"
|
||||
x="0.00000000"
|
||||
y="0.00000000"
|
||||
width="990.00000"
|
||||
height="765.00000"
|
||||
id="svg6221">
|
||||
<metadata
|
||||
id="metadata4">
|
||||
<rdf:RDF
|
||||
id="RDF5">
|
||||
<cc:Work
|
||||
rdf:about=""
|
||||
id="Work6">
|
||||
<dc:format
|
||||
id="format7">image/svg+xml</dc:format>
|
||||
<dc:type
|
||||
id="type9"
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||
<dc:title
|
||||
id="title6241">Open Clip Art Logo</dc:title>
|
||||
|
||||
<dc:date
|
||||
id="date6243">10-01-2004</dc:date>
|
||||
<dc:creator
|
||||
id="creator6245">
|
||||
<cc:Agent
|
||||
id="Agent6246">
|
||||
<dc:title
|
||||
id="title6247">Andreas Nilsson</dc:title>
|
||||
</cc:Agent>
|
||||
</dc:creator>
|
||||
<cc:license
|
||||
id="license6249"
|
||||
rdf:resource="http://web.resource.org/cc/PublicDomain" />
|
||||
<dc:contributor
|
||||
id="contributor6254">
|
||||
|
||||
<cc:Agent
|
||||
id="Agent6255">
|
||||
<dc:title
|
||||
id="title6256">Jon Phillips, Tobias Jakobs</dc:title>
|
||||
</cc:Agent>
|
||||
</dc:contributor>
|
||||
<dc:description
|
||||
id="description6258">This is one version of the official Open Clip Art Library logo.</dc:description>
|
||||
<dc:subject
|
||||
id="subject6260">logo, open clip art library logo, logotype</dc:subject>
|
||||
</cc:Work>
|
||||
|
||||
<cc:License
|
||||
rdf:about="http://web.resource.org/cc/PublicDomain"
|
||||
id="License6250">
|
||||
<cc:permits
|
||||
rdf:resource="http://web.resource.org/cc/Reproduction"
|
||||
id="permits6251" />
|
||||
<cc:permits
|
||||
rdf:resource="http://web.resource.org/cc/Distribution"
|
||||
id="permits6252" />
|
||||
<cc:permits
|
||||
rdf:resource="http://web.resource.org/cc/DerivativeWorks"
|
||||
id="permits6253" />
|
||||
</cc:License>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
|
||||
<svg:defs
|
||||
id="defs3" />
|
||||
|
||||
<svg:rect
|
||||
width="120.10877"
|
||||
height="82.679825"
|
||||
x="226.95515"
|
||||
y="219.17554"
|
||||
style="fill:#3c5889;fill-opacity:1.0000000;fill-rule:evenodd;stroke:none;stroke-width:2.7679743pt;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1.0000000"
|
||||
id="rect2983" />
|
||||
<svg:path
|
||||
d="M 292.22326,227.11481 C 290.65833,226.69203 289.05229,227.61238 288.62951,229.17731 L 274.87951,280.02106 C 274.45673,281.58599 275.37708,283.16078 276.94201,283.58356 L 327.78576,297.33356 C 329.35068,297.75634 330.95673,296.83599 331.37951,295.27106 L 345.12950,244.42731 C 345.32880,243.68960 345.20376,242.95991 344.87950,242.33356 L 344.87950,242.30231 L 344.84825,242.23981 L 344.84825,242.20856 C 344.84099,242.19593 344.82445,242.18983 344.81700,242.17731 L 342.47325,237.33356 L 331.84826,237.80231 L 292.22326,227.11481 z "
|
||||
style="fill:#000000;fill-opacity:0.20000000;fill-rule:evenodd;stroke:none;stroke-width:1.6789947;stroke-miterlimit:4.0000000;stroke-opacity:0.20000000"
|
||||
id="rect6080" />
|
||||
<svg:rect
|
||||
width="58.520977"
|
||||
height="58.520977"
|
||||
rx="2.9260476"
|
||||
ry="2.9260476"
|
||||
x="334.73752"
|
||||
y="139.84927"
|
||||
transform="matrix(0.965391,0.260807,-0.260807,0.965391,0.000000,0.000000)"
|
||||
style="fill:#ffffff;fill-rule:evenodd;stroke:#ffffff;stroke-width:1.2500001;stroke-miterlimit:4.0000000;stroke-opacity:1.0000000"
|
||||
id="rect911" />
|
||||
<svg:rect
|
||||
width="46.473278"
|
||||
height="46.473278"
|
||||
rx="2.3236642"
|
||||
ry="2.3236642"
|
||||
x="340.42499"
|
||||
y="146.20937"
|
||||
transform="matrix(0.965391,0.260807,-0.260807,0.965391,0.000000,0.000000)"
|
||||
style="fill:#f3e533;fill-opacity:1.0000000;fill-rule:evenodd;stroke-width:0.79413080pt"
|
||||
id="rect912" />
|
||||
<svg:path
|
||||
d="M 315.84938,224.49429 L 305.16076,227.93179 L 305.25451,227.96304 L 264.75451,227.96304 C 263.13349,227.96304 261.84826,229.24826 261.84826,230.86929 L 261.84826,283.55679 C 261.84826,285.17783 263.13348,286.46304 264.75451,286.46304 L 317.44201,286.46304 C 319.06305,286.46304 320.34826,285.17782 320.34826,283.55679 L 320.34826,230.86929 C 320.34826,230.03343 320.00037,229.30777 319.44201,228.77554 L 315.84938,224.49429 z "
|
||||
style="fill:#000000;fill-opacity:0.20000000;fill-rule:evenodd;stroke:none;stroke-width:1.6789950;stroke-miterlimit:4.0000000;stroke-opacity:1.0000000"
|
||||
id="rect6079" />
|
||||
<svg:rect
|
||||
width="58.520931"
|
||||
height="58.520931"
|
||||
rx="2.9260466"
|
||||
ry="2.9260466"
|
||||
x="257.85516"
|
||||
y="224.22110"
|
||||
style="fill:#ffffff;fill-rule:evenodd;stroke:#ffffff;stroke-width:1.2500000;stroke-miterlimit:4.0000000;stroke-opacity:1.0000000"
|
||||
id="rect913" />
|
||||
<svg:rect
|
||||
width="46.473267"
|
||||
height="46.473267"
|
||||
rx="2.3236635"
|
||||
ry="2.3236635"
|
||||
x="263.54269"
|
||||
y="230.58127"
|
||||
style="fill:#ff7f00;fill-rule:evenodd;stroke-width:0.79413080pt"
|
||||
id="rect914" />
|
||||
<svg:path
|
||||
d="M 282.94201,223.90054 L 273.75451,230.02554 L 276.00451,230.27554 L 235.81701,244.61929 C 234.29000,245.16331 233.49174,246.81103 234.03576,248.33804 L 249.22326,290.99429 L 248.16076,290.96304 L 247.47326,297.49429 L 253.19201,299.61929 L 253.25451,299.61929 C 253.92083,299.91880 254.69965,300.00877 255.44201,299.74429 L 305.06701,282.05679 C 306.59401,281.51277 307.36103,279.83381 306.81701,278.30679 L 289.16076,228.71304 C 288.91024,228.00987 288.38928,227.51441 287.78576,227.18179 L 282.94201,223.90054 z "
|
||||
style="fill:#000000;fill-opacity:0.20000000;fill-rule:evenodd;stroke:none;stroke-width:1.2500002;stroke-miterlimit:4.0000000;stroke-opacity:1.0000000"
|
||||
id="rect6078" />
|
||||
<svg:rect
|
||||
width="58.520813"
|
||||
height="58.520813"
|
||||
rx="2.9260395"
|
||||
ry="2.9260395"
|
||||
x="133.37415"
|
||||
y="305.62302"
|
||||
transform="matrix(0.942003,-0.335604,0.335604,0.942003,0.000000,0.000000)"
|
||||
style="fill:#ffffff;fill-rule:evenodd;stroke:#ffffff;stroke-width:1.2499988;stroke-miterlimit:4.0000000;stroke-opacity:1.0000000"
|
||||
id="rect915" />
|
||||
|
||||
<svg:rect
|
||||
width="46.473221"
|
||||
height="46.473221"
|
||||
rx="2.3236601"
|
||||
ry="2.3236601"
|
||||
x="139.06171"
|
||||
y="311.98343"
|
||||
transform="matrix(0.942003,-0.335604,0.335604,0.942003,0.000000,0.000000)"
|
||||
style="fill:#bf0000;fill-rule:evenodd;stroke-width:0.79413080pt"
|
||||
id="rect916" />
|
||||
</svg:svg>
|
||||
|
After Width: | Height: | Size: 6.6 KiB |
30
scour.py
30
scour.py
|
|
@ -56,7 +56,7 @@
|
|||
# - analyze all children of a group, if they have common attributes, then move them to the group
|
||||
# - analyze a group and its children, if a group's attribute is not being used by any children
|
||||
# (or descendants?) then remove it
|
||||
# - crunch *opacity, offset values (remove trailing zeros, reduce prec, integerize)
|
||||
# - crunch *opacity, offset, svg:x,y, transform numbers (remove trailing zeros, reduce prec, integerize)
|
||||
# - add an option to remove ids if they match the Inkscape-style of IDs
|
||||
# - investigate point-reducing algorithms
|
||||
# - parse transform attribute
|
||||
|
|
@ -542,7 +542,7 @@ def removeUnreferencedElements(doc):
|
|||
|
||||
# TODO: should also go through defs and vacuum it
|
||||
num = 0
|
||||
defs = doc.documentElement.getElementsByTagNameNS(NS['SVG'], 'defs')
|
||||
defs = doc.documentElement.getElementsByTagName('defs')
|
||||
for aDef in defs:
|
||||
elemsToRemove = removeUnusedDefs(doc, aDef)
|
||||
for elem in elemsToRemove:
|
||||
|
|
@ -645,10 +645,10 @@ def removeDuplicateGradientStops(doc):
|
|||
num = 0
|
||||
|
||||
for gradType in ['linearGradient', 'radialGradient']:
|
||||
for grad in doc.getElementsByTagNameNS(NS['SVG'], gradType):
|
||||
for grad in doc.getElementsByTagName(gradType):
|
||||
stops = {}
|
||||
stopsToRemove = []
|
||||
for stop in grad.getElementsByTagNameNS(NS['SVG'], 'stop'):
|
||||
for stop in grad.getElementsByTagName('stop'):
|
||||
# convert percentages into a floating point number
|
||||
offsetU = SVGLength(stop.getAttribute('offset'))
|
||||
if offsetU.units == Unit.PCT:
|
||||
|
|
@ -696,8 +696,8 @@ def collapseSinglyReferencedGradients(doc):
|
|||
# elem is a gradient referenced by only one other gradient (refElem)
|
||||
|
||||
# add the stops to the referencing gradient (this removes them from elem)
|
||||
if len(refElem.getElementsByTagNameNS(NS['SVG'], 'stop')) == 0:
|
||||
stopsToAdd = elem.getElementsByTagNameNS(NS['SVG'], 'stop')
|
||||
if len(refElem.getElementsByTagName('stop')) == 0:
|
||||
stopsToAdd = elem.getElementsByTagName('stop')
|
||||
for stop in stopsToAdd:
|
||||
refElem.appendChild(stop)
|
||||
|
||||
|
|
@ -738,7 +738,7 @@ def removeDuplicateGradients(doc):
|
|||
duplicateToMaster = {}
|
||||
|
||||
for gradType in ['linearGradient', 'radialGradient']:
|
||||
grads = doc.getElementsByTagNameNS(NS['SVG'], gradType)
|
||||
grads = doc.getElementsByTagName(gradType)
|
||||
for grad in grads:
|
||||
# TODO: should slice grads from 'grad' here to optimize
|
||||
for ograd in grads:
|
||||
|
|
@ -760,8 +760,8 @@ def removeDuplicateGradients(doc):
|
|||
continue
|
||||
|
||||
# all gradient properties match, now time to compare stops
|
||||
stops = grad.getElementsByTagNameNS(NS['SVG'], 'stop')
|
||||
ostops = ograd.getElementsByTagNameNS(NS['SVG'], 'stop')
|
||||
stops = grad.getElementsByTagName('stop')
|
||||
ostops = ograd.getElementsByTagName('stop')
|
||||
|
||||
if stops.length != ostops.length: continue
|
||||
|
||||
|
|
@ -2045,7 +2045,7 @@ def scourString(in_string, options=None):
|
|||
# NOTE: these elements will be removed even if they have (invalid) text nodes
|
||||
elemsToRemove = []
|
||||
for tag in ['defs', 'metadata', 'g'] :
|
||||
for elem in doc.documentElement.getElementsByTagNameNS(NS['SVG'], tag) :
|
||||
for elem in doc.documentElement.getElementsByTagName(tag) :
|
||||
removeElem = not elem.hasChildNodes()
|
||||
if removeElem == False :
|
||||
for child in elem.childNodes :
|
||||
|
|
@ -2084,23 +2084,23 @@ def scourString(in_string, options=None):
|
|||
pass
|
||||
|
||||
# clean path data
|
||||
for elem in doc.documentElement.getElementsByTagNameNS(NS['SVG'], 'path') :
|
||||
for elem in doc.documentElement.getElementsByTagName('path') :
|
||||
if elem.getAttribute('d') == '':
|
||||
elem.parentNode.removeChild(elem)
|
||||
else:
|
||||
cleanPath(elem)
|
||||
|
||||
# remove unnecessary closing point of polygons and scour points
|
||||
for polygon in doc.documentElement.getElementsByTagNameNS(NS['SVG'], 'polygon') :
|
||||
for polygon in doc.documentElement.getElementsByTagName('polygon') :
|
||||
cleanPolygon(polygon)
|
||||
|
||||
# scour points of polyline
|
||||
for polyline in doc.documentElement.getElementsByTagNameNS(NS['SVG'], 'polyline') :
|
||||
for polyline in doc.documentElement.getElementsByTagName('polyline') :
|
||||
cleanPolygon(polyline)
|
||||
|
||||
# scour lengths (including coordinates)
|
||||
for type in ['svg', 'image', 'rect', 'circle', 'ellipse', 'line', 'linearGradient', 'radialGradient', 'stop']:
|
||||
for elem in doc.documentElement.getElementsByTagNameNS(NS['SVG'], type):
|
||||
for elem in doc.documentElement.getElementsByTagName(type):
|
||||
for attr in ['x', 'y', 'width', 'height', 'cx', 'cy', 'r', 'rx', 'ry', 'x1', 'y1', 'x2', 'y2', 'fx', 'fy', 'offset']:
|
||||
if elem.getAttribute(attr) != '':
|
||||
elem.setAttribute(attr, scourLength(elem.getAttribute(attr)))
|
||||
|
|
@ -2110,7 +2110,7 @@ def scourString(in_string, options=None):
|
|||
|
||||
# convert rasters references to base64-encoded strings
|
||||
if options.embed_rasters:
|
||||
for elem in doc.documentElement.getElementsByTagNameNS(NS['SVG'], 'image') :
|
||||
for elem in doc.documentElement.getElementsByTagName('image') :
|
||||
embedRasters(elem, options)
|
||||
|
||||
# properly size the SVG document (ideally width/height should be 100% with a viewBox)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue