diff --git a/scour.py b/scour.py
index bcb0b38..60d0311 100755
--- a/scour.py
+++ b/scour.py
@@ -1786,12 +1786,43 @@ def parseListOfPoints(s):
Returns a list of containing an even number of coordinate strings
"""
+ i = 0
+ points = []
+
# (wsp)? comma-or-wsp-separated coordinate pairs (wsp)?
# coordinate-pair = coordinate comma-or-wsp coordinate
# coordinate = sign? integer
- nums = re.split("\\s*\\,?\\s*", s.strip())
+ # comma-wsp: (wsp+ comma? wsp*) | (comma wsp*)
+ ws_nums = re.split("\\s*\\,?\\s*", s.strip())
+ nums = []
+
+ # also, if 100-100 is found, split it into two also
+ #
+ for i in range(len(ws_nums)):
+ negcoords = re.split("\\-", ws_nums[i]);
+
+ # this string didn't have any negative coordinates
+ if len(negcoords) == 1:
+ nums.append(negcoords[0])
+ # we got negative coords
+ else:
+ for j in range(len(negcoords)):
+ # first number could be positive
+ if j == 0:
+ if negcoords[0] != '':
+ nums.append(negcoords[0])
+ # otherwise all other strings will be negative
+ else:
+ # unless we accidentally split a number that was in scientific notation
+ # and had a negative exponent (500.00e-1)
+ prev = nums[len(nums)-1]
+ if prev[len(prev)-1] == 'e' or prev[len(prev)-1] == 'E':
+ nums[len(nums)-1] = prev + '-' + negcoords[j]
+ else:
+ nums.append( '-'+negcoords[j] )
+
+ # now resolve into SVGLength values
i = 0
- points = []
while i < len(nums):
x = SVGLength(nums[i])
# if we had an odd number of points, return empty
@@ -1803,7 +1834,7 @@ def parseListOfPoints(s):
points.append( str(x.value) )
points.append( str(y.value) )
i += 2
-
+
return points
def cleanPolygon(elem):
@@ -1820,14 +1851,14 @@ def cleanPolygon(elem):
if startx == endx and starty == endy:
pts = pts[:-2]
numPointsRemovedFromPolygon += 1
- elem.setAttribute('points', scourCoordinates(pts))
+ elem.setAttribute('points', scourCoordinates(pts,True))
def cleanPolyline(elem):
"""
Scour the polyline points attribute
"""
pts = parseListOfPoints(elem.getAttribute('points'))
- elem.setAttribute('points', scourCoordinates(pts))
+ elem.setAttribute('points', scourCoordinates(pts,True))
def serializePath(pathObj):
"""
diff --git a/testcss.py b/testcss.py
index f6fcaa2..243ab35 100755
--- a/testcss.py
+++ b/testcss.py
@@ -38,7 +38,6 @@ class ElementSelector(unittest.TestCase):
class ElementSelectorWithProperty(unittest.TestCase):
def runTest(self):
r = parseCssString('foo { bar: baz}')
- print r
self.assertEquals( len(r), 1, 'Element selector not returned')
self.assertEquals( r[0]['selector'], 'foo', 'Selector for foo not returned')
self.assertEquals( len(r[0]['properties']), 1, 'Property list for foo did not have 1')
diff --git a/testscour.py b/testscour.py
index 0683666..a1a1105 100755
--- a/testscour.py
+++ b/testscour.py
@@ -654,7 +654,7 @@ class ConvertStraightCurvesToLines(unittest.TestCase):
self.assertEquals(p.getAttribute('d'), 'M10,10l40,40,40-40z',
'Did not convert straight curves into lines')
-class RemoveUnnecessaryPolgonEndPoint(unittest.TestCase):
+class RemoveUnnecessaryPolygonEndPoint(unittest.TestCase):
def runTest(self):
p = scour.scourXmlFile('unittests/polygon.svg').getElementsByTagNameNS(SVGNS, 'polygon')[0]
self.assertEquals(p.getAttribute('points'), '50,50,150,50,150,150,50,150',
@@ -666,18 +666,31 @@ class DoNotRemovePolgonLastPoint(unittest.TestCase):
self.assertEquals(p.getAttribute('points'), '200,50,300,50,300,150,200,150',
'Last point of polygon removed' )
-class ScourPolygonCoordinates(unittest.TestCase):
+class ScourPolygonCoordsSciNo(unittest.TestCase):
def runTest(self):
p = scour.scourXmlFile('unittests/polygon-coord.svg').getElementsByTagNameNS(SVGNS, 'polygon')[0]
- self.assertEquals(p.getAttribute('points'), '1E+4-50',
+ self.assertEquals(p.getAttribute('points'), '1E+4,50',
'Polygon coordinates not scoured')
-class ScourPolylineCoordinates(unittest.TestCase):
+class ScourPolylineCoordsSciNo(unittest.TestCase):
def runTest(self):
p = scour.scourXmlFile('unittests/polyline-coord.svg').getElementsByTagNameNS(SVGNS, 'polyline')[0]
- self.assertEquals(p.getAttribute('points'), '1E+4-50',
+ self.assertEquals(p.getAttribute('points'), '1E+4,50',
'Polyline coordinates not scoured')
+class ScourPolygonNegativeCoords(unittest.TestCase):
+ def runTest(self):
+ p = scour.scourXmlFile('unittests/polygon-coord-neg.svg').getElementsByTagNameNS(SVGNS, 'polygon')[0]
+ # points="100,-100,100-100,100-100-100,-100-100,200" />
+ self.assertEquals(p.getAttribute('points'), '100,-100,100,-100,100,-100,-100,-100,-100,200',
+ 'Negative polygon coordinates not properly parsed')
+
+class ScourPolylineNegativeCoords(unittest.TestCase):
+ def runTest(self):
+ p = scour.scourXmlFile('unittests/polyline-coord-neg.svg').getElementsByTagNameNS(SVGNS, 'polyline')[0]
+ self.assertEquals(p.getAttribute('points'), '100,-100,100,-100,100,-100,-100,-100,-100,200',
+ 'Negative polyline coordinates not properly parsed')
+
class DoNotRemoveGroupsWithIDsInDefs(unittest.TestCase):
def runTest(self):
f = scour.scourXmlFile('unittests/important-groups-in-defs.svg')
diff --git a/unittests/polygon-coord-neg.svg b/unittests/polygon-coord-neg.svg
new file mode 100644
index 0000000..73fe0b9
--- /dev/null
+++ b/unittests/polygon-coord-neg.svg
@@ -0,0 +1,4 @@
+
+
diff --git a/unittests/polygon-coord.svg b/unittests/polygon-coord.svg
index dbd5927..25406b3 100644
--- a/unittests/polygon-coord.svg
+++ b/unittests/polygon-coord.svg
@@ -1,4 +1,4 @@
\ No newline at end of file
diff --git a/unittests/polyline-coord-neg.svg b/unittests/polyline-coord-neg.svg
new file mode 100644
index 0000000..da82dad
--- /dev/null
+++ b/unittests/polyline-coord-neg.svg
@@ -0,0 +1,4 @@
+
+
diff --git a/unittests/polyline-coord.svg b/unittests/polyline-coord.svg
index fb62742..94c0e2f 100644
--- a/unittests/polyline-coord.svg
+++ b/unittests/polyline-coord.svg
@@ -1,4 +1,4 @@
\ No newline at end of file
diff --git a/unittests/refs-in-defs.svg b/unittests/refs-in-defs.svg
new file mode 100644
index 0000000..11ca780
--- /dev/null
+++ b/unittests/refs-in-defs.svg
@@ -0,0 +1,8 @@
+
+
\ No newline at end of file