How to use the 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 nhooey / svg-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
github nhooey / svg-scour / scour.py View on Github external
'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 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:
		if child.nodeType == 1:
			num += reducePrecision(child)
	
	return num
github nhooey / svg-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