Easy3D 3.0.0
Loading...
Searching...
No Matches
TextLayoutEngine Class Reference

Rasterize TrueType glyphs and produce backend-independent text commands. More...

#include <text_layout.h>

Public Member Functions

 TextLayoutEngine (unsigned atlas_size=512)
 Create a text layout engine.
 
 ~TextLayoutEngine ()
 Destroy the engine; already returned layouts remain valid.
 
 TextLayoutEngine (const TextLayoutEngine &)=delete
 Copying is disabled because the engine owns mutable font and glyph caches.
 
TextLayoutEngine & operator= (const TextLayoutEngine &)=delete
 
std::size_t add_font (const std::string &filename)
 Load a TrueType font.
 
const std::vector< std::string > & font_names () const
 
TextLayout layout (const std::string &utf8, unsigned width, unsigned height, const TextOptions &options={})
 Lay out UTF-8 text into immutable glyph draw commands.
 
void clear_cache ()
 Release cached glyphs and atlas pages.
 

Detailed Description

Rasterize TrueType glyphs and produce backend-independent text commands.

Layout is performed on the CPU and requires no graphics context. Input is decoded as UTF-8 Unicode scalar values; a missing glyph uses the font's glyph zero. This engine provides basic horizontal layout only: it does not perform script shaping, bidirectional reordering, or font fallback. Returned layouts own immutable geometry and atlas snapshots and remain valid after the engine is destroyed or its cache is cleared. Calls on one engine must be externally synchronized.

Examples
Tutorial_309_TextRendering.

Constructor & Destructor Documentation

◆ TextLayoutEngine()

TextLayoutEngine ( unsigned  atlas_size = 512)
explicit

Create a text layout engine.

Parameters
atlas_sizeRequested glyph-atlas page size in pixels.

Member Function Documentation

◆ add_font()

std::size_t add_font ( const std::string &  filename)

Load a TrueType font.

Parameters
filenamePath to the font file.
Returns
Font index to use in TextOptions::font.
Exceptions
std::runtime_errorif the file is unreadable or unsupported.

◆ clear_cache()

void clear_cache ( )

Release cached glyphs and atlas pages.

Loaded fonts and previously returned layouts are retained.

◆ font_names()

const std::vector< std::string > & font_names ( ) const

Return the loaded font names in font-index order.

Returns
Font names.

◆ layout()

TextLayout layout ( const std::string &  utf8,
unsigned  width,
unsigned  height,
const TextOptions &  options = {} 
)

Lay out UTF-8 text into immutable glyph draw commands.

Parameters
utf8Text to decode and lay out.
widthTarget framebuffer width in pixels.
heightTarget framebuffer height in pixels.
optionsFont, size, placement, spacing, and alignment options.
Returns
Glyph commands and their layout metrics.

The documentation for this class was generated from the following files: