UFO: Alien Invasion
|
font handling with SDL_ttf font engine More...
Go to the source code of this file.
Data Structures | |
struct | chunkCache_t |
This structure holds one piece of text (usually a whole line) and the texture on which it is rendered. It also holds positioning information about the place of this piece in a multiline text. Further information is held in the wrapCache_t struct that points to this struct. More... | |
struct | wrapCache_s |
This structure caches information about rendering a text in one font wrapped to a specific width. It points to structures in the chunkCache that cache detailed information and the textures used. More... | |
struct | fontRenderStyle_t |
Macros | |
#define | MAX_CACHE_STRING 128 |
#define | MAX_CHUNK_CACHE 1024 /* making this bigger uses more GL textures */ |
#define | MAX_WRAP_CACHE 1024 /* making this bigger uses more memory */ |
#define | MAX_WRAP_HASH 4096 /* making this bigger reduces collisions */ |
#define | MAX_FONTS 16 |
#define | MAX_FONTNAME 32 |
#define | MAX_TRUNCMARKER 16 /* enough for 3 chinese chars */ |
#define | BUF_SIZE 4096 |
#define | NUM_FONT_STYLES (sizeof(fontStyle) / sizeof(fontRenderStyle_t)) |
Typedefs | |
typedef struct wrapCache_s | wrapCache_t |
This structure caches information about rendering a text in one font wrapped to a specific width. It points to structures in the chunkCache that cache detailed information and the textures used. More... | |
Functions | |
void | R_FontSetTruncationMarker (const char *marker) |
void | R_FontCleanCache (void) |
Clears font cache and frees memory associated with the cache. More... | |
void | R_FontShutdown (void) |
frees the SDL_ttf fonts More... | |
static font_t * | R_FontAnalyze (const char *name, const char *path, int renderStyle, int size) |
font_t * | R_GetFont (const char *name) |
Searches the array of available fonts (see fonts.ufo) More... | |
void | R_FontListCache_f (void) |
Console command binding to show the font cache. More... | |
static int | R_FontHash (const char *string, const font_t *font) |
static int | R_FontChunkLength (const font_t *f, char *text, int len) |
Calculate the width in pixels needed to render a piece of text. Can temporarily modify the caller's string but leaves it unchanged. More... | |
static int | R_FontFindFit (const font_t *font, char *text, int maxlen, int maxWidth, int *widthp) |
Find longest part of text that fits in maxWidth pixels, with a clean break such as at a word boundary. Can temporarily modify the caller's string but leaves it unchanged. Assumes whole string won't fit. More... | |
static int | R_FontFindTruncFit (const font_t *f, const char *text, int maxlen, int maxWidth, bool mark, int *widthp) |
Find longest part of text that fits in maxWidth pixels, with a marker (ellipsis) at the end to show that part of the text was truncated. Assumes whole string won't fit. More... | |
static int | R_FontMakeChunks (const font_t *f, const char *text, int maxWidth, longlines_t method, int *lines, bool *aborted) |
Split text into chunks that fit on one line, and create cache entries for those chunks. More... | |
static wrapCache_t * | R_FontWrapText (const font_t *f, const char *text, int maxWidth, longlines_t method) |
Wrap text according to provided parameters. Pull wrapping from cache if possible. More... | |
void | R_FontTextSize (const char *fontId, const char *text, int maxWidth, longlines_t method, int *width, int *height, int *lines, bool *isTruncated) |
Supply information about the size of the text when it is linewrapped and rendered, without actually rendering it. Any of the output parameters may be nullptr. More... | |
static void | R_FontGenerateTexture (const font_t *font, const char *text, chunkCache_t *chunk) |
Renders the text surface and converts to 32bit SDL_Surface that is stored in font_t structure. More... | |
static void | R_FontDrawTexture (int texId, int x, int y, int w, int h) |
int | R_FontDrawString (const char *fontId, align_t align, int x, int y, int absX, int maxWidth, int lineHeight, const char *c, int boxHeight, int scrollPos, int *curLine, longlines_t method) |
void | R_FontInit (void) |
void | R_FontRegister (const char *name, int size, const char *path, const char *style) |
Variables | |
static int | numFonts = 0 |
static font_t | fonts [MAX_FONTS] |
static chunkCache_t | chunkCache [MAX_CHUNK_CACHE] |
static wrapCache_t | wrapCache [MAX_WRAP_CACHE] |
static wrapCache_t * | hash [MAX_WRAP_HASH] |
static int | numChunks = 0 |
static int | numWraps = 0 |
static char | truncmarker [MAX_TRUNCMARKER] = "..." |
This string is added at the end of truncated strings. By default it is an ellipsis, but the caller can change that. More... | |
static const fontRenderStyle_t | fontStyle [] |
static const float | font_texcoords [] |
font handling with SDL_ttf font engine
Definition in file r_font.cpp.
#define BUF_SIZE 4096 |
Definition at line 39 of file r_font.cpp.
Referenced by R_FontFindTruncFit(), R_FontGenerateTexture(), and R_FontMakeChunks().
#define MAX_CACHE_STRING 128 |
Definition at line 31 of file r_font.cpp.
#define MAX_CHUNK_CACHE 1024 /* making this bigger uses more GL textures */ |
Definition at line 32 of file r_font.cpp.
Referenced by R_FontListCache_f(), and R_FontMakeChunks().
#define MAX_FONTNAME 32 |
Definition at line 36 of file r_font.cpp.
#define MAX_FONTS 16 |
Definition at line 35 of file r_font.cpp.
Referenced by R_FontAnalyze().
#define MAX_TRUNCMARKER 16 /* enough for 3 chinese chars */ |
Definition at line 37 of file r_font.cpp.
#define MAX_WRAP_CACHE 1024 /* making this bigger uses more memory */ |
Definition at line 33 of file r_font.cpp.
Referenced by R_FontListCache_f(), and R_FontWrapText().
#define MAX_WRAP_HASH 4096 /* making this bigger reduces collisions */ |
Definition at line 34 of file r_font.cpp.
Referenced by R_FontHash().
#define NUM_FONT_STYLES (sizeof(fontStyle) / sizeof(fontRenderStyle_t)) |
Definition at line 102 of file r_font.cpp.
Referenced by R_FontRegister().
typedef struct wrapCache_s wrapCache_t |
This structure caches information about rendering a text in one font wrapped to a specific width. It points to structures in the chunkCache that cache detailed information and the textures used.
|
static |
Definition at line 165 of file r_font.cpp.
References font_s::buffer, Com_Error(), ERR_FATAL, f, font_s::font, FS_LoadFile(), font_s::height, font_s::lineSkip, MAX_FONTS, Mem_Dup, font_s::name, name, numFonts, OBJZERO, font_s::rw, and font_s::style.
Referenced by R_FontRegister().
Calculate the width in pixels needed to render a piece of text. Can temporarily modify the caller's string but leaves it unchanged.
Definition at line 268 of file r_font.cpp.
References font_s::font, and len.
Referenced by R_FontFindFit(), and R_FontMakeChunks().
Clears font cache and frees memory associated with the cache.
Definition at line 121 of file r_font.cpp.
References i, numChunks, numWraps, OBJZERO, and R_CheckError.
Referenced by R_FontMakeChunks(), R_FontShutdown(), R_FontWrapText(), and R_ReinitOpenglContext().
int R_FontDrawString | ( | const char * | fontId, |
align_t | align, | ||
int | x, | ||
int | y, | ||
int | absX, | ||
int | maxWidth, | ||
int | lineHeight, | ||
const char * | c, | ||
int | boxHeight, | ||
int | scrollPos, | ||
int * | curLine, | ||
longlines_t | method | ||
) |
[in] | fontId | the font id (defined in ufos/fonts.ufo) |
align | Alignment of the text inside the text zone | |
[in] | x | Current x position (may differ from absX due to tabs e.g.) |
[in] | y | Current y position (may differ from absY due to linebreaks) |
[in] | absX | Absolute x value for this string |
[in] | maxWidth | Max width - relative from absX |
[in] | lineHeight | The lineheight of that node |
[in] | c | The string to draw |
boxHeight | Number of line the box can contain. If <= 0 the value is autogenerated according to the number of line of the text input | |
[in] | scrollPos | Starting line in this node (due to scrolling) |
[in] | curLine | Current line (see lineHeight) |
method | Explain the way we manage line overflow |
Definition at line 687 of file r_font.cpp.
References wrapCache_s::chunkIdx, i, chunkCache_t::linenum, wrapCache_s::numChunks, wrapCache_s::numLines, R_FontDrawTexture(), R_FontGenerateTexture(), R_FontWrapText(), R_GetFont(), chunkCache_t::texnum, chunkCache_t::texsize, and chunkCache_t::width.
Referenced by UI_BaseInventoryNodeDraw2(), and UI_DrawString().
Definition at line 637 of file r_font.cpp.
References rendererData_t::batchCount, font_texcoords, R_BindTexture, r_state, refdef, viddef_t::rx, viddef_t::ry, texunit_diffuse, rstate_s::vertex_array_2d, rstate_s::vertex_array_3d, and viddef.
Referenced by R_FontDrawString().
|
static |
Find longest part of text that fits in maxWidth pixels, with a clean break such as at a word boundary. Can temporarily modify the caller's string but leaves it unchanged. Assumes whole string won't fit.
[in] | font | The font we are using |
[in] | text | The text to squeeze into maxWidth |
[in] | maxlen | The net length of the text (without trailing spaces) |
[in] | maxWidth | The number of available pixels |
[out] | widthp | Pixel width of part that fits. |
Definition at line 294 of file r_font.cpp.
References len, maxlen, R_FontChunkLength(), and UTF8_CONTINUATION_BYTE.
Referenced by R_FontMakeChunks().
|
static |
Find longest part of text that fits in maxWidth pixels, with a marker (ellipsis) at the end to show that part of the text was truncated. Assumes whole string won't fit.
Definition at line 347 of file r_font.cpp.
References BUF_SIZE, font_s::font, len, maxlen, Q_strncpyz(), truncmarker, and UTF8_CONTINUATION_BYTE.
Referenced by R_FontMakeChunks().
|
static |
Renders the text surface and converts to 32bit SDL_Surface that is stored in font_t structure.
Definition at line 555 of file r_font.cpp.
References BUF_SIZE, Com_Printf(), font_s::font, rconfig_t::gl_alpha_format, rconfig_t::gl_compressed_alpha_format, glGenTextures(), glTexImage2D(), chunkCache_t::len, chunkCache_t::pos, Q_strncpyz(), R_BindTexture, R_CheckError, r_config, chunkCache_t::texnum, chunkCache_t::texsize, chunkCache_t::truncated, truncmarker, Vector2Set, and chunkCache_t::width.
Referenced by R_FontDrawString().
[in] | string | String to build the hash value for |
[in] | font | The font the string uses |
Definition at line 254 of file r_font.cpp.
References fonts, i, and MAX_WRAP_HASH.
Referenced by R_FontWrapText().
Definition at line 722 of file r_font.cpp.
References Com_Error(), Com_Printf(), ERR_FATAL, numChunks, numFonts, numWraps, and OBJZERO.
Referenced by CL_NewLanguage(), R_Init(), ParticleTest::SetUpTestCase(), ScriptTest::SetUpTestCase(), FootStepTest::SetUpTestCase(), MapDefStatsTest::SetUpTestCase(), MapDefMassRMATest::SetUpTestCase(), MapDefTest::SetUpTestCase(), CampaignTest::SetUpTestCase(), and UI_Restart_f().
Console command binding to show the font cache.
Definition at line 228 of file r_font.cpp.
References Com_Printf(), i, MAX_CHUNK_CACHE, MAX_WRAP_CACHE, wrapCache_s::next, numChunks, numWraps, and wrapCache_s::text.
|
static |
Split text into chunks that fit on one line, and create cache entries for those chunks.
Definition at line 378 of file r_font.cpp.
References BUF_SIZE, chunkCache_t::len, len, chunkCache_t::linenum, LONGLINES_PRETTYCHOP, LONGLINES_WRAP, MAX_CHUNK_CACHE, numChunks, chunkCache_t::pos, Q_strncpyz(), R_FontChunkLength(), R_FontCleanCache(), R_FontFindFit(), R_FontFindTruncFit(), chunkCache_t::truncated, UTF8_char_len(), UTF8_CONTINUATION_BYTE, and chunkCache_t::width.
Referenced by R_FontWrapText().
Definition at line 750 of file r_font.cpp.
References i, NUM_FONT_STYLES, Q_strcasecmp, R_FontAnalyze(), and fontRenderStyle_t::renderStyle.
Referenced by UI_RegisterFont().
void R_FontSetTruncationMarker | ( | const char * | marker | ) |
Definition at line 112 of file r_font.cpp.
References Q_strncpyz(), and truncmarker.
Referenced by CL_NewLanguage().
frees the SDL_ttf fonts
Definition at line 144 of file r_font.cpp.
References i, Mem_Free, numFonts, OBJZERO, and R_FontCleanCache().
Referenced by CL_NewLanguage(), R_Shutdown(), and UI_Restart_f().
void R_FontTextSize | ( | const char * | fontId, |
const char * | text, | ||
int | maxWidth, | ||
longlines_t | method, | ||
int * | width, | ||
int * | height, | ||
int * | lines, | ||
bool * | isTruncated | ||
) |
Supply information about the size of the text when it is linewrapped and rendered, without actually rendering it. Any of the output parameters may be nullptr.
[in] | fontId | the font id (defined in ufos/fonts.ufo) |
[in] | text | The text to check |
maxWidth | Max width available | |
method | Line overflow method | |
[out] | width | receives width in pixels of the longest line in the text |
[out] | height | receives height in pixels when rendered with standard line height |
[out] | lines | receives total number of lines in text, including blank ones |
[out] | isTruncated | receives true, if the text must be trucated |
Definition at line 524 of file r_font.cpp.
References wrapCache_s::chunkIdx, font_s::height, i, font_s::lineSkip, wrapCache_s::numChunks, wrapCache_s::numLines, R_FontWrapText(), R_GetFont(), chunkCache_t::truncated, and chunkCache_t::width.
Referenced by uiButtonNode::draw(), uiTabNode::draw(), uiText2Node::drawText(), uiTextNode::drawText(), uiStringNode::drawTooltip(), HUD_UpdateCursor(), UI_BaseInventoryNodeDrawItems(), UI_BaseInventoryNodeGetItem(), UI_DrawNotice(), UI_DrawTooltip(), UI_MessageGetLines(), and UI_TabNodeTabAtPosition().
|
static |
Wrap text according to provided parameters. Pull wrapping from cache if possible.
Definition at line 464 of file r_font.cpp.
References wrapCache_s::aborted, wrapCache_s::chunkIdx, f, wrapCache_s::font, MAX_WRAP_CACHE, wrapCache_s::maxWidth, wrapCache_s::method, wrapCache_s::next, wrapCache_s::numChunks, numChunks, wrapCache_s::numLines, numWraps, R_FontCleanCache(), R_FontHash(), R_FontMakeChunks(), wrapCache_s::text, chunkCache_t::truncated, and chunkCache_t::width.
Referenced by R_FontDrawString(), and R_FontTextSize().
font_t* R_GetFont | ( | const char * | name | ) |
Searches the array of available fonts (see fonts.ufo)
Definition at line 210 of file r_font.cpp.
References Com_Error(), Com_Printf(), ERR_FATAL, i, numFonts, and Q_streq.
Referenced by R_FontDrawString(), R_FontTextSize(), and UI_FontGetHeight().
|
static |
Definition at line 84 of file r_font.cpp.
|
static |
Definition at line 633 of file r_font.cpp.
Referenced by R_FontDrawTexture().
Definition at line 82 of file r_font.cpp.
Referenced by R_FontHash().
|
static |
Definition at line 103 of file r_font.cpp.
|
static |
Definition at line 86 of file r_font.cpp.
Referenced by AddPlaneToHash(), CL_GetMessageID(), CL_ParseMessageID(), Cmd_AddCommand(), Cmd_Alias_f(), Cmd_CompleteCommandParameters(), Cmd_RemoveCommand(), Cmd_TableFind(), Cmd_vExecuteString(), Com_GetConstInt(), Com_GetTerrainType(), Com_ParseTerrain(), Com_RegisterConstInt(), Com_UnregisterConstVariable(), Cvar_Delete(), Cvar_FindVar(), Cvar_Get(), FindOrCreateFloatPlane(), GetPlaneHashValueForDistance(), R_DeleteImage(), R_GetImage(), R_LoadImageData(), RS_GetTechByID(), RS_GetTechByProvided(), RS_GetTechIdxByName(), RS_ParseTechnologies(), S_FindByName(), S_LoadSampleIdx(), SVC_BucketForAddress(), TEST_GetProperty(), TEST_RegisterProperty(), UI_WindowNodeAddIndexedNode(), and UI_WindowNodeGetIndexedChild().
|
static |
Definition at line 87 of file r_font.cpp.
Referenced by R_FontCleanCache(), R_FontInit(), R_FontListCache_f(), R_FontMakeChunks(), and R_FontWrapText().
|
static |
Definition at line 81 of file r_font.cpp.
Referenced by R_FontAnalyze(), R_FontInit(), R_FontShutdown(), and R_GetFont().
|
static |
Definition at line 88 of file r_font.cpp.
Referenced by R_FontCleanCache(), R_FontInit(), R_FontListCache_f(), and R_FontWrapText().
|
static |
This string is added at the end of truncated strings. By default it is an ellipsis, but the caller can change that.
Definition at line 95 of file r_font.cpp.
Referenced by R_FontFindTruncFit(), R_FontGenerateTexture(), and R_FontSetTruncationMarker().
|
static |
Definition at line 85 of file r_font.cpp.