class

Tryst::SDL::Font

Inherits Reference < Object

A TrueType/OpenType font at a fixed point size, for rendering text into a Texture via Renderer#load_font.

TTF_RenderText_Blended hands back straight alpha with the foreground colour baked into fully-transparent background pixels - a blend mode that reads source RGB independently of source alpha would show that colour as a solid rect. #render_text premultiplies the surface itself and tags the resulting texture with BlendMode::BlendPremultiplied, which is the exact blend SDL3 ships for this - no custom-composed blend mode needed the way porting this from SDL2 would otherwise call for.

Constructors

new(renderer : Pointer(LibSDL::Renderer), path : String, size : Number)

@api private - use Renderer#load_font, which pairs the font with the renderer its rendered text is turned into a texture on.

Source

Instance methods

ascent

Distance from the baseline to the top of the tallest glyph in this font - useful for cropping rendered text to its visible glyph area rather than the full line height.

Source
destroy
Source
destroyed?
Source
measure(text : String) : Tuple(Int32, Int32)

The pixel size text would occupy if rendered now, without rendering it - for layout math that only needs the dimensions.

Source
render_text(text : String, color : Color) : Texture

Renders text to a new Texture in this font's face and size. The caller owns the texture. For text drawn more than once, prefer rendering once and reusing it over calling this per frame.

Source