import re


def parse_length(value, def_units='px'):
    """Parses value as SVG length and returns it in pixels, or a negative scale (-1 = 100%)."""
    if not value:
        return 0.0
    parts = re.match(r'^\s*(-?\d+(?:\.\d+)?)\s*(in|[cm]m|p[tcx]|%)?', value)
    if not parts:
        raise Exception('Unknown length format: "{}"'.format(value))
    num = float(parts.group(1))
    units = parts.group(2) or def_units
    if units == 'px':
        return num
    elif units == 'pt':
        return num * 1.25
    elif units == 'pc':
        return num * 15.0
    elif units == 'in':
        return num * 90.0
    elif units == 'mm':
        return num * 3.543307
    elif units == 'cm':
        return num * 35.43307
    elif units == '%':
        return -num / 100.0
    else:
        raise Exception('Unknown length units: {}'.format(units))