libgui 3.00
libgui is a GUI library for the GameCube, Wii, and Wii U
 
Loading...
Searching...
No Matches
GuiTextRenderer Class Reference

FreeType2-based glyph shaping/caching. More...

#include <GuiTextRenderer.h>

Public Member Functions

 GuiTextRenderer (const uint8_t *fontBuffer, FT_Long bufferSize, GlyphRenderer *glyphRenderer, float uiScale=1.0f)
 
void setPixelSize (int16_t pixelSize)
 Selects the pixel size subsequent drawText()/getWidth()/getHeight() calls use.
 
void clearGlyphCache ()
 Destroys every cached glyph texture. Glyphs are re-rendered when next used.
 
uint16_t drawText (int16_t x, int16_t y, const wchar_t *text, PixelColor color=black, uint32_t renderFlags=0)
 Draws text at (x, y) using the current pixel size.
 
uint16_t drawText (int16_t x, int16_t y, const char *text, PixelColor color=black, uint32_t renderFlags=0)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
uint16_t getWidth (const wchar_t *text)
 
int fitCount (const wchar_t *text, int maxWidth)
 How many leading characters of text fit in maxWidth (the largest n for which the first n characters measure no wider than that), found in one pass.
 
void scrollWindow (const wchar_t *text, uint32_t textlen, uint32_t pos, int maxWidth, wchar_t *out)
 The part of a horizontally scrolling line that is shown at one scroll position: the text from pos on, two spaces, then the start of the text again, cut to fit maxWidth.
 
uint16_t getWidth (const char *text)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
uint16_t getHeight (const wchar_t *text)
 
uint16_t getLineHeight ()
 The height of a line of text at the current pixel size: from the top of the ascender to the bottom of the descender, the same for every string.
 
uint16_t getHeight (const char *text)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
void getOffset (const wchar_t *text, FontOffset *offset)
 

Static Public Member Functions

static uint32_t getMetricsGeneration ()
 Changes whenever a measurement made earlier could now come out differently (a renderer was made or its glyphs were thrown away).
 
static wchar_t * charToWideChar (const char *p)
 

Detailed Description

FreeType2-based glyph shaping/caching.

Shapes and caches glyphs per pixel size, then delegates only the final rasterized-quad draw to a GlyphRenderer - GuiText calls through this rather than touching FreeType or a platform texture directly.

Examples
demo.cpp.

Definition at line 78 of file GuiTextRenderer.h.

Constructor & Destructor Documentation

◆ GuiTextRenderer()

GuiTextRenderer::GuiTextRenderer ( const uint8_t * fontBuffer,
FT_Long bufferSize,
GlyphRenderer * glyphRenderer,
float uiScale = 1.0f )
Parameters
fontBufferTTF/OTF font data - must remain valid for the lifetime of this GuiTextRenderer, FreeType keeps a pointer into it
bufferSizeLength of fontBuffer in bytes
glyphRendererPlatform renderer rasterized glyph quads are drawn through
uiScalePhysical-pixels-per-design-pixel to rasterize glyphs at (pass VideoDriver::getUIScale()). Sizes, metrics and layout stay in design pixels; only the glyph textures get sharper. 1.0 rasterizes at the design size.

Definition at line 71 of file GuiTextRenderer.cpp.

◆ ~GuiTextRenderer()

GuiTextRenderer::~GuiTextRenderer ( )

Definition at line 80 of file GuiTextRenderer.cpp.

Member Function Documentation

◆ charToWideChar()

wchar_t * GuiTextRenderer::charToWideChar ( const char * p)
static
Returns
a newly-allocated wide-char copy of a UTF-8 string p - caller owns the result (delete[])

Definition at line 409 of file GuiTextRenderer.cpp.

◆ clearGlyphCache()

void GuiTextRenderer::clearGlyphCache ( )
inline

Destroys every cached glyph texture. Glyphs are re-rendered when next used.

Definition at line 143 of file GuiTextRenderer.h.

◆ drawText() [1/2]

uint16_t GuiTextRenderer::drawText ( int16_t x,
int16_t y,
const char * text,
PixelColor color = black,
uint32_t renderFlags = 0 )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 455 of file GuiTextRenderer.cpp.

◆ drawText() [2/2]

uint16_t GuiTextRenderer::drawText ( int16_t x,
int16_t y,
const wchar_t * text,
PixelColor color = black,
uint32_t renderFlags = 0 )

Draws text at (x, y) using the current pixel size.

Parameters
xLeft edge, in pixels
yTop edge, in pixels
textText to draw
colorText color
renderFlagsBitmask of GUI_TEXT_JUSTIFY_*‍/GUI_TEXT_ALIGN_*‍/GUI_TEXT_STYLE_* flags
Returns
the drawn text's width in pixels

Definition at line 336 of file GuiTextRenderer.cpp.

◆ fitCount()

int GuiTextRenderer::fitCount ( const wchar_t * text,
int maxWidth )

How many leading characters of text fit in maxWidth (the largest n for which the first n characters measure no wider than that), found in one pass.

Same answer as trimming the string one character at a time and calling getWidth() each time, without the repeated measuring.

Definition at line 246 of file GuiTextRenderer.cpp.

◆ getHeight() [1/2]

uint16_t GuiTextRenderer::getHeight ( const char * text)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 469 of file GuiTextRenderer.cpp.

◆ getHeight() [2/2]

uint16_t GuiTextRenderer::getHeight ( const wchar_t * text)
Returns
text height in pixels at the current pixel size

Definition at line 322 of file GuiTextRenderer.cpp.

◆ getLineHeight()

uint16_t GuiTextRenderer::getLineHeight ( )

The height of a line of text at the current pixel size: from the top of the ascender to the bottom of the descender, the same for every string.

Definition at line 328 of file GuiTextRenderer.cpp.

◆ getMetricsGeneration()

static uint32_t GuiTextRenderer::getMetricsGeneration ( )
inlinestatic

Changes whenever a measurement made earlier could now come out differently (a renderer was made or its glyphs were thrown away).

Anything that keeps text sizes can compare it.

Definition at line 175 of file GuiTextRenderer.h.

◆ getOffset()

void GuiTextRenderer::getOffset ( const wchar_t * text,
FontOffset * offset )
Parameters
textText to measure
offsetFilled with the ascender/descender/max/min metrics for text at the current pixel size

Definition at line 206 of file GuiTextRenderer.cpp.

◆ getWidth() [1/2]

uint16_t GuiTextRenderer::getWidth ( const char * text)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 462 of file GuiTextRenderer.cpp.

◆ getWidth() [2/2]

uint16_t GuiTextRenderer::getWidth ( const wchar_t * text)
Returns
text width in pixels at the current pixel size

Definition at line 227 of file GuiTextRenderer.cpp.

◆ scrollWindow()

void GuiTextRenderer::scrollWindow ( const wchar_t * text,
uint32_t textlen,
uint32_t pos,
int maxWidth,
wchar_t * out )

The part of a horizontally scrolling line that is shown at one scroll position: the text from pos on, two spaces, then the start of the text again, cut to fit maxWidth.

Measures the line once rather than after every character added or removed, with the same result as doing that.

Parameters
textlenLength of text
outRoom for textlen + 1 characters

Definition at line 267 of file GuiTextRenderer.cpp.

◆ setPixelSize()

void GuiTextRenderer::setPixelSize ( int16_t pixelSize)

Selects the pixel size subsequent drawText()/getWidth()/getHeight() calls use.

Shaped glyphs are cached per size, so switching sizes repeatedly doesn't re-shape glyphs already seen at that size.

Definition at line 100 of file GuiTextRenderer.cpp.


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