From 14c404bbaf9f2e3bf5c53581620dee76b9f6cbe1 Mon Sep 17 00:00:00 2001 From: Aaron Ayres Date: Fri, 4 Dec 2020 14:51:07 -0600 Subject: [PATCH 1/4] add failing tests --- .../svg/backends/kiva/tests/__init__.py | 0 .../svg/backends/kiva/tests/test_renderer.py | 30 +++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 enable/savage/svg/backends/kiva/tests/__init__.py create mode 100644 enable/savage/svg/backends/kiva/tests/test_renderer.py 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..eaae13ddf --- /dev/null +++ b/enable/savage/svg/backends/kiva/tests/test_renderer.py @@ -0,0 +1,30 @@ +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, []) From 55ef1d2c7f4c6e7f52111889c43a8d13ff7f0b54 Mon Sep 17 00:00:00 2001 From: Aaron Ayres Date: Fri, 4 Dec 2020 14:52:32 -0600 Subject: [PATCH 2/4] use None as default instead of [] --- enable/savage/svg/backends/kiva/renderer.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/enable/savage/svg/backends/kiva/renderer.py b/enable/savage/svg/backends/kiva/renderer.py index 5d15b9a03..cee495e23 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 @@ -350,13 +354,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) From 3bb481a243fc18d45996824ea76a67de3781467c Mon Sep 17 00:00:00 2001 From: Aaron Ayres Date: Fri, 4 Dec 2020 14:54:02 -0600 Subject: [PATCH 3/4] remove some commented out code --- enable/savage/svg/backends/kiva/renderer.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/enable/savage/svg/backends/kiva/renderer.py b/enable/savage/svg/backends/kiva/renderer.py index cee495e23..abb4874a5 100644 --- a/enable/savage/svg/backends/kiva/renderer.py +++ b/enable/savage/svg/backends/kiva/renderer.py @@ -336,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): @@ -345,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 @@ -545,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': From 4eac0347dcb2f7ad7cdb091932c80bdc1aa2edfa Mon Sep 17 00:00:00 2001 From: Aaron Ayres Date: Fri, 4 Dec 2020 14:57:32 -0600 Subject: [PATCH 4/4] some style fixes --- .../savage/svg/backends/kiva/tests/test_renderer.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/enable/savage/svg/backends/kiva/tests/test_renderer.py b/enable/savage/svg/backends/kiva/tests/test_renderer.py index eaae13ddf..1525101cd 100644 --- a/enable/savage/svg/backends/kiva/tests/test_renderer.py +++ b/enable/savage/svg/backends/kiva/tests/test_renderer.py @@ -1,10 +1,12 @@ import unittest + from enable.savage.svg.backends.kiva.renderer import ( LinearGradientBrush, RadialGradientBrush, Renderer, ) + class TestRenderer(unittest.TestCase): def test_linear_gradient_brush(self): @@ -21,10 +23,16 @@ 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, []) + 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, []) + self.assertEqual( + renderer.createRadialGradientBrush(1,1,2,2,3).transforms, + [] + )