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

fontpath

list of paths where to look for fonts files

text(text: str, font: Optional[str] = None, size: float = 1, spacing=dvec2(0.05, 0.2), fill=True, align=(0, 0), resolution=None)[source]

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:
  • text – a multiline string to represent
  • font – the string name of a font such as 'NotoMono-Bold' or the path to a .ttf font file
  • size – the character size (metric unit)
  • spacing – spacing ratio between characters vec2(horizontal, vertical)
  • fill – if True, the characters are triangulated and the function returns a Mesh, else it returns its outline as a Web
  • align

    text alignment, the tuple items can be:

    • ’left’ or ‘top’
    • ’center’
    • ’right’ or ‘bottom’
    • any float, as an offset on the position
  • resolution – discretisation setting for the character primitives

Example

>>> part = text('Hello everyone.\nthis is a great font !!',
...             font='NotoSans-Regular',
...             align=('left', 0),
...             fill=True)
../_images/text_mesh.png
TextDisplay(scene, position, text, size=None, color=None, font=None, align=(0, 0), layer=0)[source]

halo display of a monospaced text

This class is usually used through scheme.note_floating()

../_images/note_floating.png