Comment 11 for bug 541889

Revision history for this message
codedread (codedread) wrote : Re: [Bug 541889] Re: SaveAs Optimized SVG error "AttributeError: 'SVGLength' object has no attribute 'units'"

Matt,

Sorry, but I won't be able to work on this until Thursday-ish or the
weekend. I will update the bug once I get something working in the
script.

Jeff

On Tue, Mar 23, 2010 at 9:37 AM, Matt Sarjent <email address hidden> wrote:
> That's good for me. When fixed, is it possible for me to get it? Do you
> have an idea when it would be fixed?
>
> --
> SaveAs Optimized SVG error "AttributeError: 'SVGLength' object has no attribute 'units'"
> https://bugs.launchpad.net/bugs/541889
> You received this bug notification because you are the registrant for
> Scour.
>
> Status in Inkscape: A Vector Drawing Tool: New
> Status in Scour - Cleaning SVG Files: New
>
> Bug description:
> Hi, love Inkscape, especially using python :-) although i'm post-processing/parsing svg with beautifulSoup.
>
> I have been trying to save a file with the fill attributes separate to the style attributes so i tried to save using the "Optimized SVG" file type option. Unfortunately i keep on getting the error
>
> Traceback (most recent call last):
>  File "C:\Program Files\Inkscape\share\extensions\scour.inkscape.py", line 6, in <module>
>    sys.stdout.write(scourString(input.read()).encode("UTF-8"))
>  File "C:\Program Files\Inkscape\share\extensions\scour.py", line 2245, in scourString
>    cleanPolygon(polygon)
>  File "C:\Program Files\Inkscape\share\extensions\scour.py", line 1803, in cleanPolygon
>    pts = parseListOfPoints(elem.getAttribute('points'))
>  File "C:\Program Files\Inkscape\share\extensions\scour.py", line 1790, in parseListOfPoints
>    if x.units != Unit.NONE or y.units != Unit.NONE: return []
> AttributeError: 'SVGLength' object has no attribute 'units'
>
> so i traced it through to the scour.py where the SVGLength doesn't set the self.units in all cases after a ValueError in thrown.
>
> so i added in the extra case giving the new code
>
> class SVGLength(object):
>        def __init__(self, str):
>                try: # simple unitless and no scientific notation
>                        self.value = float(str)
>                        if int(self.value) == self.value:
>                                self.value = int(self.value)
>                        self.units = Unit.NONE
>                except ValueError:
>                        # we know that the length string has an exponent, a unit, both or is invalid
>
>                        # parse out number, exponent and unit
>                        self.value = 0
>                        unitBegin = 0
>                        scinum = scinumber.match(str)
>                        if scinum != None:
>                                # this will always match, no need to check it
>                                numMatch = number.match(str)
>                                expMatch = sciExponent.search(str, numMatch.start(0))
>                                self.value = (float(numMatch.group(0)) *
>                                        10 ** float(expMatch.group(1)))
>                                unitBegin = expMatch.end(1)
>                        else:
>                                # unit or invalid
>                                numMatch = number.match(str)
>                                if numMatch != None:
>                                        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))
>                                else:                                                                   # new added code
>                                        self.units = Unit.INVALID                               # new added code
>
>                        # invalid
>                        else:
>                                # TODO: this needs to set the default for the given attribute (how?)
>                                self.value = 0
>                                self.units = Unit.INVALID
>
>
>
> Unfortunately i am not allowed to give you the original file until after 6th May. After that, give me an email if you need the file.
>
>
>