bernhard: thuban/Extensions/svgexport/test test_svgmapwriter.py, 1.5, 1.6

cvs@intevation.de cvs at intevation.de
Mon Nov 22 12:17:49 CET 2004


Author: bernhard

Update of /thubanrepository/thuban/Extensions/svgexport/test
In directory doto:/tmp/cvs-serv8413/Extensions/svgexport/test

Modified Files:
	test_svgmapwriter.py 
Log Message:
Fixing #2698 (transparent polygons are not exported to svg file)

	* Extensions/svgexport/svgmapwriter.py:
	Added verbose variable and some logging depending on it.
	(class VirtualDC(XMLWriter)): Minor improvement in the polygon loop, 
	because counting i is not necessary.
	(class Pen, class Brush): Added simple __str__ methods.
	(SVGRenderer.draw_polygone_shape): Fix #2698 (transparent polygons are
	not exported to svg file) Note: holes still unhandled.

	* Extensions/svgexport/test/test_svgmapwriter.py:
	        Made a baseclass TestWithDC for test needed a DC.
		Added tests for bug #2698 (transparent polygons are not
		exported to svg file):
		Testobjectexport.test_transparent_polygon()


Index: test_svgmapwriter.py
===================================================================
RCS file: /thubanrepository/thuban/Extensions/svgexport/test/test_svgmapwriter.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- test_svgmapwriter.py	27 Sep 2004 09:56:13 -0000	1.5
+++ test_svgmapwriter.py	22 Nov 2004 11:17:47 -0000	1.6
@@ -34,9 +34,9 @@
      Pen, Brush, SOLID,  Point, Font, TRANSPARENT_PEN, TRANSPARENT_BRUSH, \
      SVGRenderer, SVGMapWriterError
 # Color related classes from the model of thuban
-from Thuban.Model.color import Color, Black
+from Thuban.Model.color import Color, Black, Transparent
 
-from Thuban.Model.data import SHAPETYPE_ARC
+from Thuban.Model.data import SHAPETYPE_ARC, SHAPETYPE_POLYGON
 from Thuban.Model.map import Map
 from Thuban.Model.layer import BaseLayer, Layer
 from Thuban.Model.table import MemoryTable, \
@@ -102,6 +102,21 @@
         dc.DrawPolygon(self.polygon, 0)
         self.assertEquals(xmlsupport.sax_eventlist(data = data), 
                           xmlsupport.sax_eventlist(data = file.getvalue()))
+
+    def test_transparent_polygon(self):
+        '''Test dc drawing a transparent polygon.'''
+        data = ('<path style="stroke-linejoin:round; stroke:#ff00ff; '
+                'stroke-width:3; stroke-linecap:round; fill:none" ' 
+                'meta="Object:test; Label:nothing" d="M 5.6 5.5 '
+                'L 95.4 5.3 L 95.2 95.1 L 5.0 95.0 L 5.0 5.0 "/>')
+        file = StringIO.StringIO()
+        dc = VirtualDC(file)
+        dc.SetPen(self.solid_pen)
+        dc.SetMeta(self.meta)
+        dc.SetBrush(self.trans_brush)
+        dc.DrawPolygon(self.polygon, 0)
+        self.assertEquals(xmlsupport.sax_eventlist(data = data), 
+                          xmlsupport.sax_eventlist(data = file.getvalue()))
     
     def test_rect(self):
         '''Set drawing properties and draw a rectangle'''
@@ -168,7 +183,11 @@
         self.assertEquals(xmlsupport.sax_eventlist(data = data), 
                           xmlsupport.sax_eventlist(data = file.getvalue()))
 
-class TestSVGRendererIDHandling(unittest.TestCase):
+class TestWithDC(unittest.TestCase):
+    """Add dc creation and self.to_destroy list to setUp() and tearDown().
+
+    This is a baseclass for test needing a dc.
+    """
 
     def setUp(self):
         """Create dc for testing and set up self.to_destroy.
@@ -186,6 +205,8 @@
         for obj in self.to_destroy:
             obj.Destroy()
 
+class TestSVGRendererIDHandling(TestWithDC):
+
     def test_make_id_nonintegersetid(self):
         """Test that exception is raised when SetID was called with chars."""
         dc=self.dc
@@ -276,6 +297,42 @@
 
         self.assertRaises(SVGMapWriterError,
                 renderer.RenderMap, None, None)
+
+class Testobjectexport(TestWithDC):
+
+    def test_transparent_polygon(self):
+        """ Create layer with non-filled polygon and test svg rendering."""
+
+        data = ('<clipPath id="mapclip">\n'
+                '    <rect x="0" y="0" width="10" height="10"   />\n'
+                '</clipPath>\n'
+                '<g meta="Object:map"  clip-path="url(#mapclip)" '
+                'clip-rule="evenodd" transform=" scale(100.0)">\n'
+                '    <g meta="Layer:P-Layer" >\n'
+                '        <path style="stroke-linejoin:round; stroke:#000000; '
+                'stroke-width:0.01; stroke-linecap:round; fill:none" '
+                'id="P-Layer_0"'
+                '  d="M 0.0 0.0 L 10.0 -10.0 L 0.0 -10.0 L 0.0 0.0 Z"/>\n'
+                '    </g>\n</g>\n')
+        table = MemoryTable([("type", FIELDTYPE_STRING),
+                             ("value", FIELDTYPE_DOUBLE),
+                             ("code", FIELDTYPE_INT)],
+                            [("UNKNOWN", 0.0, 0)])
+        shapes = [[[(0, 0), (10, 10), (0, 10), (0, 0) ]]]
+        store = SimpleShapeStore(SHAPETYPE_POLYGON, shapes, table)
+
+        map = Map("testpolygonexport")
+        self.to_destroy.append(map)
+        layer=Layer("P-Layer", store, fill=Transparent)
+        map.AddLayer(layer)
+
+        renderer = SVGRenderer(self.dc, map,
+                    scale=1.0, offset=(0,0), region=(0,0,10,10))
+        renderer.RenderMap(None, None)
+        print (data)
+        print (self.dc.file.getvalue())
+        self.assertEquals(data, self.dc.file.getvalue())
+
 
 if __name__ == "__main__":
     support.run_tests()





More information about the Thuban-devel mailing list

This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)