bernhard: thuban/Extensions/svgexport svgmapwriter.py,1.8,1.9
cvs@intevation.de
cvs at intevation.de
Sat Dec 11 03:03:49 CET 2004
Author: bernhard
Update of /thubanrepository/thuban/Extensions/svgexport
In directory doto:/tmp/cvs-serv29643/Extensions/svgexport
Modified Files:
svgmapwriter.py
Log Message:
* Doc/technotes/coding_guidelines.txt: easy typo fixed.
* Extensions/svgexport/test/test_svgmapwriter.py:
Removed test_drawbezier in favour of new test_drawspline3 and
test_drawspline4 within new class TestDrawSplines(TestVirtualDC).
All only to test DrawSpline.
* Extensions/svgexport/svgmapwriter.py(DrawSpline):
New implementation now really using the strange algorithm of
xfig 3.1's approximated splines and its conversion to postscript
with one twist: SVG can do quadratic beziers, so skipped translation
to cubic beziers.
(TestWithDC): Typo in comment fixed.
Index: svgmapwriter.py
===================================================================
RCS file: /thubanrepository/thuban/Extensions/svgexport/svgmapwriter.py,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- svgmapwriter.py 7 Dec 2004 11:19:38 -0000 1.8
+++ svgmapwriter.py 11 Dec 2004 02:03:47 -0000 1.9
@@ -701,14 +701,50 @@
self.make_meta(), join(data, '') ) )
def DrawSpline(self, points, closed=0):
- """Draw a spline object.
+ """Calculate square bezier points for an xfig approximated spline.
+
+ DrawSpline() needs to do the same as the function of the Device Context
+ of wxWidgets. Code inspection shows it uses the "approximated
+ splines" of xfig <= 3.1. This can be mapped
+ on SVG's squared bezier curves,
+ by doing the same calculation like wxPostScriptDC::DoDrawSpline() in
+ wxWidgets src/generic/dcpsg.cpp.
+ Which is derived from xfig's 3.1.4 u_draw.c(draw_open_spline()).
+
+ And then leave out the last translation to cubic beziers
+ done in the postscript code of DrawSplineSection.
"""
self.write_indent('<path %s ' % (self.make_style(1,1,0)))
datastr = ""
- # we have four points: start, control, control, end
- datastr+=('M %s %s C' % (points[0].x, points[0].y))
- for i in (1,2,3):
- datastr+=(' %s %s' % (points[i].x,points[i].y))
+
+ x1=points[0].x
+ y1=points[0].y
+
+ datastr+=('M %s %s ' % (x1, y1))
+
+ c=points[1].x
+ d=points[1].y
+
+ x3 = (x1 + c) / 2;
+ y3 = (y1 + d) / 2;
+
+ datastr+=('L %s %s ' % (x3,y3))
+
+ for point in points[2:]:
+ x2 = c
+ y2 = d
+ c = point.x
+ d = point.y
+ x3 = (x2 + c) / 2;
+ y3 = (y2 + d) / 2;
+
+ # With SVG's bezier commands, the last point becomes the next start
+ # so no new L necessary
+ # SVG Spec 1.1 recommends to not uses lines longer than 255 chars
+ datastr+=('Q %s %s %s %s\n' % (x2,y2,x3,y3))
+
+ datastr+=('L %s %s' % (c,d))
+
self.file.write('%s %s d="%s"/>\n' % (self.make_id(),
self.make_meta(), datastr ) )
More information about the Thuban-devel
mailing list
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)