Skip to content

text

FreeBodyEngine.graphics.text #

Font(texture, glyphs, distance_range, atlas_em_size, ascender, descender, line_height) #

A ready-to-render MSDF font: an atlas Texture plus, per Unicode codepoint, the Glyph describing where in it and how to draw that character.

Stores the given atlas/glyphs/metrics directly - see the attribute comments below for what each metric means.

ascender = ascender instance-attribute #

atlas_em_size = atlas_em_size instance-attribute #

descender = descender instance-attribute #

distance_range = distance_range instance-attribute #

glyphs = glyphs instance-attribute #

line_height = line_height instance-attribute #

texture = texture instance-attribute #

get_glyph(codepoint) #

Returns the Glyph for codepoint (a Unicode code point, e.g. ord(ch)), or None if this font has no glyph for it.

Glyph(advance, plane_bounds, uv_bounds) #

One character's metrics and atlas location within a Font.

Stores this glyph's advance width plus its already-computed plane/UV bounds - see the attribute comments below for exactly what each represents.

advance = advance instance-attribute #

plane_bounds = plane_bounds instance-attribute #

uv_bounds = uv_bounds instance-attribute #

TextRenderer() #

Bases: Service

The "text_renderer" service - draws MSDF text with the engine's built-in text material, one draw call per glyph (see the module docstring).

Builds the reusable quad mesh every glyph is drawn with; doesn't load the text material yet (see on_initialize()), since that needs the "files" service to already be up.

material = None instance-attribute #

quad = generate_quad() instance-attribute #

draw_text(font, text, x, y, px_size, color=(1.0, 1.0, 1.0, 1.0)) #

Draws text with its baseline start at screen pixel (x, y) - the same top-left-origin, Y-down pixel convention ui/renderer.py's rect uniform already uses - at px_size pixels per em.

measure_text(font, text, px_size) #

Total advance width of text at px_size, in screen pixels.

on_initialize() #

Loads the engine's built-in text.fbmat text material.