3 from .font
import FontStyle
4 from ..nvector
import NVector
5 from ..parsers.svg.importer
import parse_color
6 from ..objects.shapes
import Group, Fill
10 def __init__(self, font: FontStyle, color: NVector, font_size: float, offset: NVector, scale: NVector, rotation: float):
21 def render(self, text, pos, start_x):
23 g = self.
fontfont.renderer.render(text, self.
font_sizefont_size, pos,
True, start_x)
26 center = g.bounding_box().center()
27 g.transform.anchor_point.value = center
28 g.transform.position.value += center
29 g.transform.scale.value = self.
scalescale * 100
30 g.transform.rotation.value = self.
rotationrotation
36 _regex = re.compile(
r'\\([a-z0-9]+)(?:\{([^}]*)\})?')
38 def __init__(self, font: FontStyle, default_color: NVector, font_size: float):
45 def _int_arg(value, default=0):
48 except (ValueError, TypeError):
51 def render(self, text: str, pos: NVector =
None):
57 style = default_style.clone()
61 for match
in self.
_regex_regex.finditer(text):
62 prev_text = text[last_pos:match.start()]
63 last_pos = match.end()
65 container.insert_shape(0, style.render(prev_text, pos, line_start))
69 command = match.group(1)
72 if command ==
"color":
77 elif command ==
"huge":
78 style.font_size = self.
font_sizefont_size * 2
79 elif command ==
"large":
80 style.font_size = self.
font_sizefont_size * 1.5
81 elif command ==
"normal":
83 elif command ==
"small":
84 style.font_size = self.
font_sizefont_size / 1.5
85 elif command ==
"tiny":
86 style.font_size = self.
font_sizefont_size / 2
87 elif command ==
"super":
88 style.offset.y -= self.
font_sizefont_size / 2
89 elif command ==
"sub":
90 style.offset.y += self.
font_sizefont_size / 2
91 elif command ==
"center":
93 elif command ==
"clear":
94 style = default_style.clone()
95 elif command ==
"flip":
97 elif command ==
"vflip":
103 pos.y += self.
fontfont.line_height
104 elif command ==
"hspace":
106 elif command ==
"rot":
107 style.rotation = self.
_int_arg_int_arg(arg)
110 if arg
is None and len(text) > last_pos
and text[last_pos] ==
' ':
113 last_text = text[last_pos:]
115 container.insert_shape(0, style.render(last_text, pos, line_start))
117 if len(container.shapes) > 1:
118 container.next_x = container.shapes[-2].next_x
120 container.next_x = pos.x
125 def render_fancy_text(text: str, font: FontStyle, default_color: NVector, font_size: float, pos: NVector =
None):
127 return renderer.render(text, pos)
ShapeElement that can contain other shapes.
def render(self, text, pos, start_x)
def __init__(self, FontStyle font, NVector color, float font_size, NVector offset, NVector scale, float rotation)
def _int_arg(value, default=0)
def render(self, str text, NVector pos=None)
def __init__(self, FontStyle font, NVector default_color, float font_size)
def render_fancy_text(str text, FontStyle font, NVector default_color, float font_size, NVector pos=None)