text -- Text rendering and meshing¶
This file is to render floating texts and mesh texts
The current implementation of floating texts uses a bitmap font texture baked at program start. It's following the first technique described in this tutorial: https://learnopengl.com/In-Practice/Text-Rendering
For mesh texts, freetype (https://freetype.org/) is used to read the font files and extract curve primitives from it. The primitives are then discretized and triangulated using the madcad functions.
When specified by their name, fonts are searched in the system font directories plus the directories in module variable fontpath
text(text, font=None, size=1, spacing=vec2(0.05, 0.2), fill=True, align=(0, 0), resolution=None)
¶
return a Mesh/Web containing the given text written using the given font

The meshed font is cached so long texts are still fast to mesh
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
a multiline string to represent |
required |
font
|
str
|
the string name of a font such as |
None
|
size
|
float
|
the character size (metric unit) |
1
|
spacing
|
spacing ratio between characters |
vec2(0.05, 0.2)
|
|
fill
|
if True, the characters are triangulated and the function returns a |
True
|
|
align
|
text alignment, the tuple items can be:
|
(0, 0)
|
|
resolution
|
discretisation setting for the character primitives |
None
|
Examples:
>>> part = text('Hello everyone.\nthis is a great font !!',
... font='NotoSans-Regular',
... align=('left', 0),
... fill=True)
Source code in madcad/text/__init__.py
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 | |
TextDisplay(scene, position, text, size=None, color=None, font=None, align=(0, 0), layer=0)
¶
Bases: Display
halo display of a monospaced text

This class is usually used through scheme.note_floating()
Source code in madcad/text/displays.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | |
pointsdef = [[0, 0], [0, -1], [1, -1], [0, 0], [1, -1], [1, 0]]
class-attribute
instance-attribute
¶
position = fvec3(position)
instance-attribute
¶
color = fvec3(color)
instance-attribute
¶
size = size
instance-attribute
¶
layer = layer
instance-attribute
¶
selected = False
instance-attribute
¶
hovered = False
instance-attribute
¶
shader = scene.share('shader_font', load)
instance-attribute
¶
textsize = (mc, l)
instance-attribute
¶
visualsize = (-align[0], -align[1], mc // 2 - align[0], l - align[1])
instance-attribute
¶
vb_points = scene.context.buffer(points)
instance-attribute
¶
vb_faces = scene.context.buffer(np.arange(points.shape[0], dtype='u4'))
instance-attribute
¶
va = scene.context.vertex_array(self.shader, [(self.vb_points, '2f 2f', 'v_position', 'v_uv')])
instance-attribute
¶
stack(view)
¶
Source code in madcad/text/displays.py
125 126 | |