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) |
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.
Definition at line 78 of file GuiTextRenderer.h.
| GuiTextRenderer::GuiTextRenderer | ( | const uint8_t * | fontBuffer, |
| FT_Long | bufferSize, | ||
| GlyphRenderer * | glyphRenderer, | ||
| float | uiScale = 1.0f ) |
| fontBuffer | TTF/OTF font data - must remain valid for the lifetime of this GuiTextRenderer, FreeType keeps a pointer into it |
| bufferSize | Length of fontBuffer in bytes |
| glyphRenderer | Platform renderer rasterized glyph quads are drawn through |
| uiScale | Physical-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 | ( | ) |
Definition at line 80 of file GuiTextRenderer.cpp.
|
static |
Definition at line 409 of file GuiTextRenderer.cpp.
|
inline |
Destroys every cached glyph texture. Glyphs are re-rendered when next used.
Definition at line 143 of file GuiTextRenderer.h.
| 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.
| 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.
| x | Left edge, in pixels |
| y | Top edge, in pixels |
| text | Text to draw |
| color | Text color |
| renderFlags | Bitmask of GUI_TEXT_JUSTIFY_*/GUI_TEXT_ALIGN_*/GUI_TEXT_STYLE_* flags |
Definition at line 336 of file GuiTextRenderer.cpp.
| 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.
| 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.
| uint16_t GuiTextRenderer::getHeight | ( | const wchar_t * | text | ) |
Definition at line 322 of file GuiTextRenderer.cpp.
| 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.
|
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.
| void GuiTextRenderer::getOffset | ( | const wchar_t * | text, |
| FontOffset * | offset ) |
| text | Text to measure |
| offset | Filled with the ascender/descender/max/min metrics for text at the current pixel size |
Definition at line 206 of file GuiTextRenderer.cpp.
| 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.
| uint16_t GuiTextRenderer::getWidth | ( | const wchar_t * | text | ) |
Definition at line 227 of file GuiTextRenderer.cpp.
| 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.
| textlen | Length of text |
| out | Room for textlen + 1 characters |
Definition at line 267 of file GuiTextRenderer.cpp.
| 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.