diff --git a/enable/savage/svg/backends/kiva/renderer.py b/enable/savage/svg/backends/kiva/renderer.py index 5d15b9a03..abb4874a5 100644 --- a/enable/savage/svg/backends/kiva/renderer.py +++ b/enable/savage/svg/backends/kiva/renderer.py @@ -166,13 +166,15 @@ class LinearGradientBrush(AbstractGradientBrush): """ A Brush representing a linear gradient. """ def __init__(self, x1,y1, x2,y2, stops, spreadMethod='pad', - transforms=[], units='userSpaceOnUse'): + transforms=None, units='userSpaceOnUse'): self.x1 = x1 self.y1 = y1 self.x2 = x2 self.y2 = y2 self.stops = stops self.spreadMethod = spreadMethod + if transforms is None: + transforms = [] self.transforms = transforms self.units = units @@ -220,7 +222,7 @@ class RadialGradientBrush(AbstractGradientBrush): """ A Brush representing a radial gradient. """ def __init__(self, cx,cy, r, stops, fx=None,fy=None, spreadMethod='pad', - transforms=[], units='userSpaceOnUse'): + transforms=None, units='userSpaceOnUse'): self.cx = cx self.cy = cy self.r = r @@ -232,6 +234,8 @@ def __init__(self, cx,cy, r, stops, fx=None,fy=None, spreadMethod='pad', fy = self.cy self.fy = fy self.spreadMethod = spreadMethod + if transforms is None: + transforms = [] self.transforms = transforms self.units = units @@ -332,7 +336,6 @@ def concatTransform(cls, gc, matrix): def createAffineMatrix(cls, a,b,c,d,x,y): # FIXME: should we create a 6x1 or 3x3 matrix??? return (a,b,c,d,x,y) -# return affine.affine_from_values(a,b,c,d,x,y) @classmethod def createBrush(cls, color_tuple): @@ -341,7 +344,6 @@ def createBrush(cls, color_tuple): @classmethod def createNativePen(cls, pen): # fixme: Not really sure what to do here... - #return wx.GraphicsRenderer_GetDefaultRenderer().CreatePen(pen) return pen @classmethod @@ -350,13 +352,13 @@ def createPen(cls, color_tuple): @classmethod def createLinearGradientBrush(cls, x1,y1,x2,y2, stops, spreadMethod='pad', - transforms=[], units='userSpaceOnUse'): + transforms=None, units='userSpaceOnUse'): return LinearGradientBrush(x1,y1,x2,y2,stops, spreadMethod, transforms, units) @classmethod def createRadialGradientBrush(cls, cx,cy, r, stops, fx=None,fy=None, - spreadMethod='pad', transforms=[], + spreadMethod='pad', transforms=None, units='userSpaceOnUse'): return RadialGradientBrush(cx,cy, r, stops, fx,fy, spreadMethod, transforms, units) @@ -541,12 +543,6 @@ def DrawText(cls, gc, text, x, y, brush, anchor='start'): # text transform matrix to have y going up so the text is rendered # upright. But since, +y is now *up*, we need to draw at -y. - # fixme: There is something wrong with the text matrix. The following - # commands don't work and I would expect them to. - #text_matrix = affine.affine_from_values(1,0,0,-1,x,-y) - #gc.set_text_matrix(text_matrix) - #gc.show_text_at_point(text, 0, 0) - if anchor != 'start': tx, ty, tw, th = gc.get_text_extent(text) if anchor == 'middle': diff --git a/enable/savage/svg/backends/kiva/tests/__init__.py b/enable/savage/svg/backends/kiva/tests/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/enable/savage/svg/backends/kiva/tests/test_renderer.py b/enable/savage/svg/backends/kiva/tests/test_renderer.py new file mode 100644 index 000000000..1525101cd --- /dev/null +++ b/enable/savage/svg/backends/kiva/tests/test_renderer.py @@ -0,0 +1,38 @@ +import unittest + +from enable.savage.svg.backends.kiva.renderer import ( + LinearGradientBrush, + RadialGradientBrush, + Renderer, +) + + +class TestRenderer(unittest.TestCase): + + def test_linear_gradient_brush(self): + lgb = LinearGradientBrush(1,1,2,2,3) + lgb.transforms.append('a') + self.assertEqual(LinearGradientBrush(1,1,2,2,3).transforms, []) + + def test_radial_gradient_brush(self): + rgb = RadialGradientBrush(1,1,2,2,3) + rgb.transforms.append('a') + self.assertEqual(RadialGradientBrush(1,1,2,2,3).transforms, []) + + def test_create_linear_gradient_brush(self): + renderer = Renderer() + lgb = renderer.createLinearGradientBrush(1,1,2,2,3) + lgb.transforms.append('a') + self.assertEqual( + renderer.createLinearGradientBrush(1,1,2,2,3).transforms, + [] + ) + + def test_create_radial_gradient_brush(self): + renderer = Renderer() + rgb = renderer.createRadialGradientBrush(1,1,2,2,3) + rgb.transforms.append('a') + self.assertEqual( + renderer.createRadialGradientBrush(1,1,2,2,3).transforms, + [] + )