20
20
RectangleBox ,
21
21
_RoundBox ,
22
22
_svg_bezier ,
23
- _SVGTransform ,
24
23
)
25
24
26
25
from mathics .core .formatter import lookup_method , add_conversion_fn
27
26
28
27
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
+
29
52
def create_css (
30
53
edge_color = None , face_color = None , stroke_width = None , font_color = None , opacity = 1.0
31
54
) -> str :
@@ -76,8 +99,8 @@ def polygon(points):
76
99
77
100
78
101
def 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 )
81
104
82
105
svg = ""
83
106
for line in self .lines :
@@ -91,9 +114,9 @@ def beziercurvebox(self, offset=None):
91
114
92
115
93
116
def 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 )
95
118
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
97
120
)
98
121
99
122
def components ():
@@ -110,7 +133,6 @@ def components():
110
133
111
134
add_conversion_fn (FilledCurveBox )
112
135
113
- # FIXME figure out how we can add this.
114
136
def graphicsbox (self , leaves = None , ** options ) -> str :
115
137
if not leaves :
116
138
leaves = self ._leaves
@@ -220,8 +242,8 @@ def insetbox(self, offset=None):
220
242
221
243
222
244
def 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 )
225
247
svg = ""
226
248
for line in self .lines :
227
249
svg += '<polyline points="%s" style="%s" />' % (
@@ -261,13 +283,13 @@ def pointbox(self, offset=None):
261
283
262
284
263
285
def 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 )
265
287
if self .vertex_colors is None :
266
288
face_color = self .face_color
267
289
else :
268
290
face_color = None
269
291
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
271
293
)
272
294
svg = ""
273
295
if self .vertex_colors is not None :
@@ -292,7 +314,7 @@ def polygonbox(self, offset=None):
292
314
293
315
294
316
def 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 )
296
318
x1 , y1 = self .p1 .pos ()
297
319
x2 , y2 = self .p2 .pos ()
298
320
xmin = min (x1 , x2 )
@@ -302,7 +324,7 @@ def rectanglebox(self, offset=None):
302
324
if offset :
303
325
x1 , x2 = x1 + offset [0 ], x2 + offset [0 ]
304
326
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 )
306
328
return '<rect x="%f" y="%f" width="%f" height="%f" style="%s" />' % (
307
329
xmin ,
308
330
ymin ,
@@ -321,8 +343,8 @@ def _roundbox(self, offset=None):
321
343
rx , ry = self .r .pos ()
322
344
rx -= x
323
345
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 )
326
348
return '<ellipse cx="%f" cy="%f" rx="%f" ry="%f" style="%s" />' % (
327
349
x ,
328
350
y ,
0 commit comments