How to use the scour.scour.Unit.INVALID 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
or anything that isn't an SVGLength.

   Returns the number of bytes saved after performing these reductions.
   """
   num = 0

   styles = _getStyle(element)
   for lengthAttr in ['opacity', 'flood-opacity', 'fill-opacity',
                  'stroke-opacity', 'stop-opacity', 'stroke-miterlimit',
                  'stroke-dashoffset', 'letter-spacing', 'word-spacing',
                  'kerning', 'font-size-adjust', 'font-size',
                  'stroke-width']:
      val = element.getAttribute(lengthAttr)
      if val != '':
         valLen = SVGLength(val)
         if valLen.units != Unit.INVALID: # not an absolute/relative size or inherit, can be % though
            newVal = scourLength(val)
            if len(newVal) < len(val):
               num += len(val) - len(newVal)
               element.setAttribute(lengthAttr, newVal)
      # repeat for attributes hidden in styles
      if lengthAttr in list(styles.keys()):
         val = styles[lengthAttr]
         valLen = SVGLength(val)
         if valLen.units != Unit.INVALID:
            newVal = scourLength(val)
            if len(newVal) < len(val):
               num += len(val) - len(newVal)
               styles[lengthAttr] = newVal
   _setStyle(element, styles)

   for child in element.childNodes:
github scour-project / scour / scour / scour.py View on Github external
def get(unitstr):
      if unitstr is None: return Unit.NONE
      try:
         return Unit.s2u[unitstr]
      except KeyError:
         return Unit.INVALID
github scour-project / scour / scour / scour.py View on Github external
self.value = float(numMatch.group(0))
               unitBegin = numMatch.end(0)

         if int(self.value) == self.value:
            self.value = int(self.value)

         if unitBegin != 0 :
            unitMatch = unit.search(str, unitBegin)
            if unitMatch != None :
               self.units = Unit.get(unitMatch.group(0))

         # invalid
         else:
            # TODO: this needs to set the default for the given attribute (how?)
            self.value = 0
            self.units = Unit.INVALID