Skip to content

Commit 6adcdfc

Browse files
committed
Allow fontsize on Asymptote pen creation...
Use that in asy inset_box in creating labels. In general, we trying to make SVG and Aysmptote more the same. In the process add some comments and type annotations.
1 parent bb38d34 commit 6adcdfc

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

mathics/format/asy.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,11 @@ def inset_box(self, **options) -> str:
411411
x, y = self.pos.pos()
412412
opacity_value = self.opacity.opacity if self.opacity else None
413413
content = self.content.boxes_to_tex(evaluation=self.graphics.evaluation)
414-
pen = asy_create_pens(edge_color=self.color, edge_opacity=opacity_value)
414+
# FIXME: don't hard code text_style_opts, but allow these to be adjustable.
415+
font_size = 3
416+
pen = asy_create_pens(
417+
edge_color=self.color, edge_opacity=opacity_value, fontsize=font_size
418+
)
415419
asy = """// InsetBox
416420
label("$%s$", (%s,%s), (%s,%s), %s);\n""" % (
417421
content,

mathics/format/asy_fns.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
"""
66

77
from itertools import chain
8+
from typing import Optional, Type, Union
9+
10+
RealType = Type[Union[int, float]]
811

912

1013
def asy_add_bezier_fn(self) -> str:
@@ -103,13 +106,14 @@ def asy_color(self):
103106

104107

105108
def asy_create_pens(
106-
edge_color=None,
107-
face_color=None,
108-
edge_opacity=None,
109-
face_opacity=None,
109+
edge_color: Optional[str] = None,
110+
face_color: Optional[str] = None,
111+
edge_opacity: Optional[RealType] = None,
112+
face_opacity: Optional[RealType] = None,
110113
stroke_width=None,
111114
is_face_element=False,
112115
dotfactor=None,
116+
fontsize: Optional[RealType] = None,
113117
) -> str:
114118
"""
115119
Return an asymptote string fragment that creates a drawing pen.
@@ -132,6 +136,8 @@ def asy_create_pens(
132136
opacity = edge_opacity
133137
if opacity is not None and opacity != 1:
134138
pen += f"+opacity({asy_number(opacity)})"
139+
if fontsize is not None:
140+
pen += f"+fontsize({fontsize})"
135141
if stroke_width is not None:
136142
pen += f"+linewidth({asy_number(stroke_width)})"
137143
result.append(pen)

0 commit comments

Comments
 (0)