How to use the scour.svg_transform.svg_transform_parser.parse function in scour

To help you get started, we’ve selected a few scour examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github scour-project / scour / scour / scour.py View on Github external
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)