2020 RectangleBox ,
2121 _RoundBox ,
2222 _svg_bezier ,
23- _SVGTransform ,
2423)
2524
2625from mathics .core .formatter import lookup_method , add_conversion_fn
2726
2827
28+ class _SVGTransform :
29+ def __init__ (self ):
30+ from trepan .api import debug ; debug ()
31+ self .transforms = []
32+
33+ def matrix (self , a , b , c , d , e , f ):
34+ # a c e
35+ # b d f
36+ # 0 0 1
37+ self .transforms .append ("matrix(%f, %f, %f, %f, %f, %f)" % (a , b , c , d , e , f ))
38+
39+ def translate (self , x , y ):
40+ self .transforms .append ("translate(%f, %f)" % (x , y ))
41+
42+ def scale (self , x , y ):
43+ self .transforms .append ("scale(%f, %f)" % (x , y ))
44+
45+ def rotate (self , x ):
46+ self .transforms .append ("rotate(%f)" % x )
47+
48+ def apply (self , svg ):
49+ return '<g transform="%s">%s</g>' % (" " .join (self .transforms ), svg )
50+
51+
2952def create_css (
3053 edge_color = None , face_color = None , stroke_width = None , font_color = None , opacity = 1.0
3154) -> str :
@@ -76,8 +99,8 @@ def polygon(points):
7699
77100
78101def beziercurvebox (self , offset = None ):
79- l = self .style .get_line_width (face_element = False )
80- style = create_css (edge_color = self .edge_color , stroke_width = l )
102+ line_width = self .style .get_line_width (face_element = False )
103+ style = create_css (edge_color = self .edge_color , stroke_width = line_width )
81104
82105 svg = ""
83106 for line in self .lines :
@@ -91,9 +114,9 @@ def beziercurvebox(self, offset=None):
91114
92115
93116def filledcurvebox (self , offset = None ):
94- l = self .style .get_line_width (face_element = False )
117+ line_width = self .style .get_line_width (face_element = False )
95118 style = create_css (
96- edge_color = self .edge_color , face_color = self .face_color , stroke_width = l
119+ edge_color = self .edge_color , face_color = self .face_color , stroke_width = line_width
97120 )
98121
99122 def components ():
@@ -110,7 +133,6 @@ def components():
110133
111134add_conversion_fn (FilledCurveBox )
112135
113- # FIXME figure out how we can add this.
114136def graphicsbox (self , leaves = None , ** options ) -> str :
115137 if not leaves :
116138 leaves = self ._leaves
@@ -220,8 +242,8 @@ def insetbox(self, offset=None):
220242
221243
222244def linebox (self , offset = None ):
223- l = self .style .get_line_width (face_element = False )
224- style = create_css (edge_color = self .edge_color , stroke_width = l )
245+ line_width = self .style .get_line_width (face_element = False )
246+ style = create_css (edge_color = self .edge_color , stroke_width = line_width )
225247 svg = ""
226248 for line in self .lines :
227249 svg += '<polyline points="%s" style="%s" />' % (
@@ -261,13 +283,13 @@ def pointbox(self, offset=None):
261283
262284
263285def polygonbox (self , offset = None ):
264- l = self .style .get_line_width (face_element = True )
286+ line_width = self .style .get_line_width (face_element = True )
265287 if self .vertex_colors is None :
266288 face_color = self .face_color
267289 else :
268290 face_color = None
269291 style = create_css (
270- edge_color = self .edge_color , face_color = face_color , stroke_width = l
292+ edge_color = self .edge_color , face_color = face_color , stroke_width = line_width
271293 )
272294 svg = ""
273295 if self .vertex_colors is not None :
@@ -292,7 +314,7 @@ def polygonbox(self, offset=None):
292314
293315
294316def rectanglebox (self , offset = None ):
295- l = self .style .get_line_width (face_element = True )
317+ line_width = self .style .get_line_width (face_element = True )
296318 x1 , y1 = self .p1 .pos ()
297319 x2 , y2 = self .p2 .pos ()
298320 xmin = min (x1 , x2 )
@@ -302,7 +324,7 @@ def rectanglebox(self, offset=None):
302324 if offset :
303325 x1 , x2 = x1 + offset [0 ], x2 + offset [0 ]
304326 y1 , y2 = y1 + offset [1 ], y2 + offset [1 ]
305- style = create_css (self .edge_color , self .face_color , l )
327+ style = create_css (self .edge_color , self .face_color , line_width )
306328 return '<rect x="%f" y="%f" width="%f" height="%f" style="%s" />' % (
307329 xmin ,
308330 ymin ,
@@ -321,8 +343,8 @@ def _roundbox(self, offset=None):
321343 rx , ry = self .r .pos ()
322344 rx -= x
323345 ry = y - ry
324- l = self .style .get_line_width (face_element = self .face_element )
325- style = create_css (self .edge_color , self .face_color , stroke_width = l )
346+ line_width = self .style .get_line_width (face_element = self .face_element )
347+ style = create_css (self .edge_color , self .face_color , stroke_width = line_width )
326348 return '<ellipse cx="%f" cy="%f" rx="%f" ry="%f" style="%s" />' % (
327349 x ,
328350 y ,
0 commit comments