77
88from mathics .builtin .drawing .graphics3d import Graphics3DElements
99from mathics .builtin .graphics import (
10- # _ArcBox,
1110 ArrowBox ,
1211 BezierCurveBox ,
1312 FilledCurveBox ,
2928
3029def create_css (
3130 edge_color = None , face_color = None , stroke_width = None , font_color = None , opacity = 1.0
32- ):
31+ ) -> str :
32+ """
33+ Return a string suitable for CSS inclusion setting the various parameters passed.
34+ """
3335 css = []
3436 if edge_color is not None :
3537 color , stroke_opacity = edge_color .to_css ()
@@ -52,29 +54,6 @@ def create_css(
5254 return "; " .join (css )
5355
5456
55- # def arcbox(self, offset=None):
56- # if self.arc is None:
57- # raise RuntimeError(f"{self}.arc should not be none")
58-
59- # x, y, rx, ry, sx, sy, ex, ey, large_arc = self._arc_params()
60-
61- # def path(closed):
62- # if closed:
63- # yield "M %f,%f" % (x, y)
64- # yield "L %f,%f" % (sx, sy)
65- # else:
66- # yield "M %f,%f" % (sx, sy)
67-
68- # yield "A %f,%f,0,%d,0,%f,%f" % (rx, ry, large_arc, ex, ey)
69-
70- # if closed:
71- # yield "Z"
72-
73- # l = self.style.get_line_width(face_element=self.face_element)
74- # style = create_css(self.edge_color, self.face_color, stroke_width=l)
75- # return '<path d="%s" style="%s" />' % (" ".join(path(self.face_element)), style)
76-
77-
7857def arrowbox (self , offset = None ):
7958 width = self .style .get_line_width (face_element = False )
8059 style = create_css (edge_color = self .edge_color , stroke_width = width )
@@ -91,8 +70,11 @@ def polygon(points):
9170 default_arrow = self ._default_arrow (polygon )
9271 custom_arrow = self ._custom_arrow ("svg" , _SVGTransform )
9372 return "" .join (self ._draw (polyline , default_arrow , custom_arrow , extent ))
73+
74+
9475add_conversion_fn (ArrowBox )
9576
77+
9678def beziercurvebox (self , offset = None ):
9779 l = self .style .get_line_width (face_element = False )
9880 style = create_css (edge_color = self .edge_color , stroke_width = l )
@@ -103,8 +85,11 @@ def beziercurvebox(self, offset=None):
10385 svg += '<path d="%s" style="%s"/>' % (s , style )
10486 # print("XXX bezier", svg)
10587 return svg
88+
89+
10690add_conversion_fn (BezierCurveBox )
10791
92+
10893def filledcurvebox (self , offset = None ):
10994 l = self .style .get_line_width (face_element = False )
11095 style = create_css (
@@ -121,6 +106,8 @@ def components():
121106 " " .join (components ()),
122107 style ,
123108 )
109+
110+
124111add_conversion_fn (FilledCurveBox )
125112
126113# def graphicsbox(self, leaves=None, **options) -> str:
@@ -174,21 +161,25 @@ def components():
174161# )
175162# return svg # , width, height
176163
164+
177165def graphicselements (self , offset = None ):
178166 result = []
179167 for element in self .elements :
180168 format_fn = lookup_method (element , "svg" )
181- if format_fn is not None :
182- result .append (format_fn (element , offset ))
183- else :
169+ if format_fn is None :
184170 result .append (element .to_svg (offset ))
171+ else :
172+ result .append (format_fn (element , offset ))
185173
186174 return "\n " .join (result )
175+
176+
187177add_conversion_fn (GraphicsElements )
188178graphics3delements = graphicselements
189179
190180add_conversion_fn (Graphics3DElements )
191181
182+
192183def insetbox (self , offset = None ):
193184 x , y = self .pos .pos ()
194185 if offset :
@@ -218,8 +209,11 @@ def insetbox(self, offset=None):
218209 # "<math>%s</math></foreignObject>")
219210
220211 return svg
212+
213+
221214add_conversion_fn (InsetBox )
222215
216+
223217def linebox (self , offset = None ):
224218 l = self .style .get_line_width (face_element = False )
225219 style = create_css (edge_color = self .edge_color , stroke_width = l )
@@ -231,6 +225,8 @@ def linebox(self, offset=None):
231225 )
232226 # print("XXX linebox", svg)
233227 return svg
228+
229+
234230add_conversion_fn (LineBox )
235231
236232
@@ -254,8 +250,11 @@ def pointbox(self, offset=None):
254250 )
255251 # print("XXX PointBox", svg)
256252 return svg
253+
254+
257255add_conversion_fn (PointBox )
258256
257+
259258def polygonbox (self , offset = None ):
260259 l = self .style .get_line_width (face_element = True )
261260 if self .vertex_colors is None :
@@ -282,6 +281,8 @@ def polygonbox(self, offset=None):
282281 )
283282 # print("XXX PolygonBox", svg)
284283 return svg
284+
285+
285286add_conversion_fn (PolygonBox )
286287
287288
@@ -305,6 +306,8 @@ def rectanglebox(self, offset=None):
305306 style ,
306307 )
307308 "\n " .join (element .to_svg () for element in self .elements )
309+
310+
308311add_conversion_fn (RectangleBox )
309312
310313
@@ -322,4 +325,6 @@ def _roundbox(self, offset=None):
322325 ry ,
323326 style ,
324327 )
328+
329+
325330add_conversion_fn (_RoundBox )
0 commit comments