Skip to content

Commit ba5cd30

Browse files
implement annotation renderer
1 parent f9c3c06 commit ba5cd30

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

schemascii/annotation.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import html
12
import re
23
from dataclasses import dataclass
34

@@ -12,6 +13,11 @@
1213
class Annotation(_dc.DataConsumer, namespaces=(":annotation",)):
1314
"""A chunk of text that will be rendered verbatim in the output SVG."""
1415

16+
options = [
17+
("scale",),
18+
_dc.Option("font", str, "Text font", "monospace"),
19+
]
20+
1521
position: complex
1622
content: str
1723

@@ -28,6 +34,10 @@ def find_all(cls, grid: _grid.Grid):
2834
out.append(cls(complex(x, y), text))
2935
return out
3036

31-
def render(self, **options) -> str:
32-
raise NotImplementedError
33-
return _utils.XML.text()
37+
def render(self, scale, font) -> str:
38+
return _utils.XML.text(
39+
html.escape(self.content),
40+
x=self.position.real * scale,
41+
y=self.position.imag * scale,
42+
style=f"font-family:{font}",
43+
alignment__baseline="middle")

0 commit comments

Comments
 (0)