Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def optimizeTransforms(element, options) :
"""
Attempts to optimise transform specifications on the given node and its children.
Returns the number of bytes saved after performing these reductions.
"""
num = 0
for transformAttr in ['transform', 'patternTransform', 'gradientTransform']:
val = element.getAttribute(transformAttr)
if val != '':
transform = svg_transform_parser.parse(val)
optimizeTransform(transform)
newVal = serializeTransform(transform)
if len(newVal) < len(val):
if len(newVal):
element.setAttribute(transformAttr, newVal)
else:
element.removeAttribute(transformAttr)
num += len(val) - len(newVal)
for child in element.childNodes:
if child.nodeType == 1:
num += optimizeTransforms(child, options)