CGVIS Utils
Loading...
Searching...
No Matches
FontRenderer Class Reference

CPU-side text compositor using a bitmap atlas and character boxes. More...

#include <FontRenderer.h>

Public Member Functions

 FontRenderer (const std::string &imageFilename, const std::string &positionFilename)
 Construct from filenames.
 FontRenderer (const Image &fontImage, const std::string &positionFilename)
 Construct from an in-memory font image and a positions file.
 FontRenderer (const Image &fontImage, const std::vector< CharPosition > &positions)
 Construct directly from an image and a vector of positions.
Image render (const std::string &text) const
 Compose a new image containing text using the atlas glyphs.
Image render (uint32_t number) const
 Compose a new image containing the decimal representation of number.
std::string toCode (const std::string &varName) const
 Emit C++ code to recreate the atlas image and positions vector.
std::shared_ptr< FontEngine > generateFontEngine () const
 Create a GPU font engine initialized from this bitmap font.

Static Public Member Functions

static const std::vector< CharPosition > loadPositions (const std::string &positionFilename)
 Load character rectangles from a text file.

Detailed Description

CPU-side text compositor using a bitmap atlas and character boxes.

Loads an atlas image and a set of CharPosition entries (from file or provided vector). The render() functions blit glyph rectangles into a new Image placed tightly around the requested string or number.

Constructor & Destructor Documentation

◆ FontRenderer() [1/3]

FontRenderer::FontRenderer ( const std::string & imageFilename,
const std::string & positionFilename )

Construct from filenames.

Parameters
imageFilenamePath to the bitmap font image (see BMP::load()).
positionFilenamePath to a whitespace-separated list of character boxes.

The positions file expects lines of the form "<char> <x0> <y0> <x1> <y1>" (or a variant with an explicit placeholder).

Here is the call graph for this function:
Here is the caller graph for this function:

◆ FontRenderer() [2/3]

FontRenderer::FontRenderer ( const Image & fontImage,
const std::string & positionFilename )

Construct from an in-memory font image and a positions file.

Here is the call graph for this function:

◆ FontRenderer() [3/3]

FontRenderer::FontRenderer ( const Image & fontImage,
const std::vector< CharPosition > & positions )

Construct directly from an image and a vector of positions.

Member Function Documentation

◆ generateFontEngine()

std::shared_ptr< FontEngine > FontRenderer::generateFontEngine ( ) const

Create a GPU font engine initialized from this bitmap font.

Returns
Shared pointer to a FontEngine with per-character textures.
Here is the call graph for this function:

◆ loadPositions()

const std::vector< CharPosition > FontRenderer::loadPositions ( const std::string & positionFilename)
static

Load character rectangles from a text file.

Parameters
positionFilenamePath to the positions file.
Returns
Parsed vector of CharPosition entries.
Here is the caller graph for this function:

◆ render() [1/2]

Image FontRenderer::render ( const std::string & text) const

Compose a new image containing text using the atlas glyphs.

Returns
An Image with width = sum of glyph widths and height = max glyph height.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ render() [2/2]

Image FontRenderer::render ( uint32_t number) const

Compose a new image containing the decimal representation of number.

Here is the call graph for this function:

◆ toCode()

std::string FontRenderer::toCode ( const std::string & varName) const

Emit C++ code to recreate the atlas image and positions vector.

Parameters
varNamePrefix used for generated symbols (e.g., "myFont").
Here is the call graph for this function:

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