Fix some erroneous removal of default attributes (fxes #66)

This commit is contained in:
Eduard Braun 2016-08-25 19:26:56 +02:00
parent 90910eaa6f
commit beb9823a91

View file

@ -1550,28 +1550,38 @@ def removeDefaultAttributeValues(node, options, tainted=set()):
node.removeAttribute('spreadMethod') node.removeAttribute('spreadMethod')
num += 1 num += 1
# x1: 0% # x1 - line: 0
# linearGradient: 0%
if node.getAttribute('x1') != '': if node.getAttribute('x1') != '':
x1 = SVGLength(node.getAttribute('x1')) x1 = SVGLength(node.getAttribute('x1'))
if x1.value == 0: if x1.value == 0:
node.removeAttribute('x1') node.removeAttribute('x1')
num += 1 num += 1
# y1: 0% # y1 - line: 0
# linearGradient: 0%
if node.getAttribute('y1') != '': if node.getAttribute('y1') != '':
y1 = SVGLength(node.getAttribute('y1')) y1 = SVGLength(node.getAttribute('y1'))
if y1.value == 0: if y1.value == 0:
node.removeAttribute('y1') node.removeAttribute('y1')
num += 1 num += 1
# x2: 100% # x2 - line: 0
# linearGradient: 100% (x2="1" usually equals "1px" which only equals "100%" if gradientUnits="objectBoundingBox")
if node.getAttribute('x2') != '': if node.getAttribute('x2') != '':
x2 = SVGLength(node.getAttribute('x2')) x2 = SVGLength(node.getAttribute('x2'))
if (x2.value == 100 and x2.units == Unit.PCT) or (x2.value == 1 and x2.units == Unit.NONE): if node.nodeName == 'line':
node.removeAttribute('x2') if x2.value == 0:
num += 1 node.removeAttribute('x2')
num += 1
elif node.nodeName == 'linearGradient':
if ( (x2.value == 100 and x2.units == Unit.PCT) or
(x2.value == 1 and x2.units == Unit.NONE and not node.getAttribute('gradientUnits') == 'userSpaceOnUse') ):
node.removeAttribute('x2')
num += 1
# y2: 0% # y2 - line: 0
# linearGradient: 0%
if node.getAttribute('y2') != '': if node.getAttribute('y2') != '':
y2 = SVGLength(node.getAttribute('y2')) y2 = SVGLength(node.getAttribute('y2'))
if y2.value == 0: if y2.value == 0:
@ -1590,26 +1600,42 @@ def removeDefaultAttributeValues(node, options, tainted=set()):
node.removeAttribute('fy') node.removeAttribute('fy')
num += 1 num += 1
# cx: 50% # cx - circle / ellipse: 0
# radialGradient: 50% (cx="0.5" usually equals "0.5px" which only equals "50%" if gradientUnits="objectBoundingBox")
if node.getAttribute('cx') != '': if node.getAttribute('cx') != '':
cx = SVGLength(node.getAttribute('cx')) cx = SVGLength(node.getAttribute('cx'))
if (cx.value == 50 and cx.units == Unit.PCT) or (cx.value == 0.5 and cx.units == Unit.NONE): if node.nodeName in ['circle', 'ellipse']:
node.removeAttribute('cx') if cx.value == 0:
num += 1 node.removeAttribute('cx')
num += 1
elif node.nodeName == "radialGradient":
if ( (cx.value == 50 and cx.units == Unit.PCT) or
(cx.value == 0.5 and cx.units == Unit.NONE and not node.getAttribute('gradientUnits') == 'userSpaceOnUse') ):
node.removeAttribute('cx')
num += 1
# cy: 50% # cy - circle / ellipse: 0
# radialGradient: 50% (cy="0.5" usually equals "0.5px" which only equals "50%" if gradientUnits="objectBoundingBox")
if node.getAttribute('cy') != '': if node.getAttribute('cy') != '':
cy = SVGLength(node.getAttribute('cy')) cy = SVGLength(node.getAttribute('cy'))
if (cy.value == 50 and cy.units == Unit.PCT) or (cy.value == 0.5 and cy.units == Unit.NONE): if node.nodeName in ['circle', 'ellipse']:
node.removeAttribute('cy') if cy.value == 0:
num += 1 node.removeAttribute('cy')
num += 1
elif node.nodeName == "radialGradient":
if ( (cy.value == 50 and cy.units == Unit.PCT) or
(cy.value == 0.5 and cy.units == Unit.NONE and not node.getAttribute('gradientUnits') == 'userSpaceOnUse') ):
node.removeAttribute('cy')
num += 1
# r: 50% # r - radialGradient: 50% (r="0.5" usually equals "0.5px" which only equals "50%" if gradientUnits="objectBoundingBox")
if node.getAttribute('r') != '': if node.getAttribute('r') != '':
r = SVGLength(node.getAttribute('r')) if node.nodeName == 'radialGradient':
if (r.value == 50 and r.units == Unit.PCT) or (r.value == 0.5 and r.units == Unit.NONE): r = SVGLength(node.getAttribute('r'))
node.removeAttribute('r') if ( (r.value == 50 and r.units == Unit.PCT) or
num += 1 (r.value == 0.5 and r.units == Unit.NONE and not node.getAttribute('gradientUnits') == 'userSpaceOnUse') ):
node.removeAttribute('r')
num += 1
# Summarily get rid of some more attributes # Summarily get rid of some more attributes
attributes = [node.attributes.item(i).nodeName attributes = [node.attributes.item(i).nodeName