font handling with SDL_ttf font engine More...
#include "r_local.h"
#include "r_font.h"
#include "r_error.h"
#include "../../shared/utf8.h"
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 |
Defines | |
#define | MAX_CACHE_STRING 128 |
#define | MAX_CHUNK_CACHE 1024 |
#define | MAX_WRAP_CACHE 1024 |
#define | MAX_WRAP_HASH 4096 |
#define | MAX_FONTS 16 |
#define | MAX_FONTNAME 32 |
#define | MAX_TRUNCMARKER 16 |
#define | BUF_SIZE 2048 |
#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. | |
Functions | |
void | R_FontSetTruncationMarker (const char *marker) |
static void | R_FontCleanCache (void) |
Clears font cache and frees memory associated with the cache. | |
void | R_FontShutdown (void) |
frees the SDL_ttf fonts | |
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). | |
void | R_FontListCache_f (void) |
Console command binding to show the font cache. | |
static int | R_FontHash (const char *string) |
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. | |
static int | R_FontFindFit (const font_t *f, 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. | |
static int | R_FontFindTruncFit (const font_t *f, const char *text, int maxlen, int maxWidth, qboolean 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. | |
static int | R_FontMakeChunks (const font_t *f, const char *text, int maxWidth, longlines_t method, int *lines, qboolean *aborted) |
Split text into chunks that fit on one line, and create cache entries for those chunks. | |
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. | |
void | R_FontTextSize (const char *fontId, const char *text, int maxWidth, longlines_t method, int *width, int *height, int *lines, qboolean *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 NULL. | |
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. | |
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. | |
static const fontRenderStyle_t | fontStyle [] |
static const float | font_texcoords [] |
font handling with SDL_ttf font engine
Definition in file r_font.c.
#define BUF_SIZE 2048 |
Definition at line 39 of file r_font.c.
Referenced by R_FontFindTruncFit(), R_FontGenerateTexture(), and R_FontMakeChunks().
#define MAX_CHUNK_CACHE 1024 |
Definition at line 32 of file r_font.c.
Referenced by R_FontListCache_f(), and R_FontMakeChunks().
#define MAX_FONTS 16 |
Definition at line 35 of file r_font.c.
Referenced by R_FontAnalyze(), and UI_ParseFont().
#define MAX_WRAP_CACHE 1024 |
Definition at line 33 of file r_font.c.
Referenced by R_FontListCache_f(), and R_FontWrapText().
#define MAX_WRAP_HASH 4096 |
Definition at line 34 of file r_font.c.
Referenced by R_FontHash().
#define NUM_FONT_STYLES (sizeof(fontStyle) / sizeof(fontRenderStyle_t)) |
Definition at line 102 of file r_font.c.
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 font_t* R_FontAnalyze | ( | const char * | name, | |
const char * | path, | |||
int | renderStyle, | |||
int | size | |||
) | [static] |
Definition at line 169 of file r_font.c.
References font_s::buffer, Com_Error(), ERR_FATAL, f, font_s::font, FS_LoadFile(), font_s::height, font_s::lineSkip, MAX_FONTS, font_s::name, numFonts, font_s::rw, and font_s::style.
Referenced by R_FontRegister().
static int R_FontChunkLength | ( | const font_t * | f, | |
char * | text, | |||
int | len | |||
) | [static] |
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 266 of file r_font.c.
References font_s::font.
Referenced by R_FontFindFit(), and R_FontMakeChunks().
static void R_FontCleanCache | ( | void | ) | [static] |
Clears font cache and frees memory associated with the cache.
Definition at line 121 of file r_font.c.
References i, numChunks, numWraps, and R_CheckError.
Referenced by R_FontMakeChunks(), R_FontShutdown(), and R_FontWrapText().
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) |
[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] | absY | Absolute y value for this string |
[in] | maxWidth | Max width - relative from absX |
[in] | lineHeight | The lineheight of that node |
[in] | c | The string to draw |
[in] | scrollPos | Starting line in this node (due to scrolling) |
[in] | curLine | Current line (see lineHeight) |
Definition at line 675 of file r_font.c.
References chunk(), 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().
static void R_FontDrawTexture | ( | int | texId, | |
int | x, | |||
int | y, | |||
int | w, | |||
int | h | |||
) | [static] |
Definition at line 630 of file r_font.c.
References font_texcoords, R_BindTexture, r_state, viddef_t::rx, viddef_t::ry, texunit_diffuse, rstate_t::vertex_array_2d, rstate_t::vertex_array_3d, and viddef.
Referenced by R_FontDrawString().
static int R_FontFindFit | ( | const font_t * | f, | |
char * | text, | |||
int | maxlen, | |||
int | maxWidth, | |||
int * | widthp | |||
) | [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.
[out] | widthp | Pixel width of part that fits. |
Definition at line 290 of file r_font.c.
References len, R_FontChunkLength(), and UTF8_CONTINUATION_BYTE.
Referenced by R_FontMakeChunks().
static int R_FontFindTruncFit | ( | const font_t * | f, | |
const char * | text, | |||
int | maxlen, | |||
int | maxWidth, | |||
qboolean | mark, | |||
int * | widthp | |||
) | [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 345 of file r_font.c.
References BUF_SIZE, font_s::font, len, Q_strncpyz(), truncmarker, and UTF8_CONTINUATION_BYTE.
Referenced by R_FontMakeChunks().
static void R_FontGenerateTexture | ( | const font_t * | font, | |
const char * | text, | |||
chunkCache_t * | chunk | |||
) | [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.c.
References BUF_SIZE, Com_Printf(), font_s::font, rconfig_t::gl_alpha_format, rconfig_t::gl_compressed_alpha_format, chunkCache_t::len, chunkCache_t::pos, Q_strncpyz(), R_BindTexture, R_CheckError, r_config, chunkCache_t::texnum, TEXNUM_FONTS, chunkCache_t::texsize, chunkCache_t::truncated, truncmarker, Vector2Set, and chunkCache_t::width.
Referenced by R_FontDrawString().
static int R_FontHash | ( | const char * | string | ) | [static] |
[in] | string | String to build the hash value for |
Definition at line 250 of file r_font.c.
References i, and MAX_WRAP_HASH.
Referenced by R_FontWrapText().
void R_FontInit | ( | void | ) |
Definition at line 713 of file r_font.c.
References Com_Error(), Com_Printf(), ERR_FATAL, numChunks, numFonts, and numWraps.
Referenced by CL_NewLanguage(), and R_Init().
void R_FontListCache_f | ( | void | ) |
Console command binding to show the font cache.
Definition at line 223 of file r_font.c.
References Com_Printf(), i, MAX_CHUNK_CACHE, MAX_WRAP_CACHE, wrapCache_s::next, numChunks, numWraps, and wrapCache_s::text.
static int R_FontMakeChunks | ( | const font_t * | f, | |
const char * | text, | |||
int | maxWidth, | |||
longlines_t | method, | |||
int * | lines, | |||
qboolean * | aborted | |||
) | [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.c.
References BUF_SIZE, chunkCache_t::len, len, chunkCache_t::linenum, LONGLINES_PRETTYCHOP, LONGLINES_WRAP, MAX_CHUNK_CACHE, numChunks, chunkCache_t::pos, pos, Q_strncpyz(), qfalse, qtrue, 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().
void R_FontRegister | ( | const char * | name, | |
int | size, | |||
const char * | path, | |||
const char * | style | |||
) |
Definition at line 741 of file r_font.c.
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.c.
References Q_strncpyz(), and truncmarker.
Referenced by CL_NewLanguage().
void R_FontShutdown | ( | void | ) |
frees the SDL_ttf fonts
Definition at line 146 of file r_font.c.
References FS_FreeFile(), i, numFonts, and R_FontCleanCache().
Referenced by CL_NewLanguage(), and R_Shutdown().
void R_FontTextSize | ( | const char * | fontId, | |
const char * | text, | |||
int | maxWidth, | |||
longlines_t | method, | |||
int * | width, | |||
int * | height, | |||
int * | lines, | |||
qboolean * | 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 NULL.
[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 |
Definition at line 523 of file r_font.c.
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 HUD_DrawMouseCursorText(), HUD_UpdateCursor(), UI_BaseInventoryNodeDrawItems(), UI_BaseInventoryNodeGetItem(), UI_DrawNotice(), UI_DrawTooltip(), UI_MessageGetLines(), UI_StringNodeDrawTooltip(), UI_TabNodeDraw(), UI_TabNodeTabAtPosition(), and UI_TextNodeDrawText().
static wrapCache_t* R_FontWrapText | ( | const font_t * | f, | |
const char * | text, | |||
int | maxWidth, | |||
longlines_t | method | |||
) | [static] |
Wrap text according to provided parameters. Pull wrapping from cache if possible.
Definition at line 467 of file r_font.c.
References wrapCache_s::aborted, wrapCache_s::chunkIdx, wrapCache_s::font, MAX_WRAP_CACHE, wrapCache_s::maxWidth, wrapCache_s::method, wrapCache_s::next, numChunks, wrapCache_s::numChunks, wrapCache_s::numLines, numWraps, qfalse, 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 208 of file r_font.c.
References Com_Error(), ERR_FATAL, i, and numFonts.
Referenced by R_FontDrawString(), R_FontTextSize(), and UI_FontGetHeight().
chunkCache_t chunkCache[MAX_CHUNK_CACHE] [static] |
const float font_texcoords[] [static] |
{ 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0 }
Definition at line 626 of file r_font.c.
Referenced by R_FontDrawTexture().
const fontRenderStyle_t fontStyle[] [static] |
wrapCache_t* hash[MAX_WRAP_HASH] [static] |
int numChunks = 0 [static] |
Definition at line 87 of file r_font.c.
Referenced by R_FontCleanCache(), R_FontInit(), R_FontListCache_f(), R_FontMakeChunks(), and R_FontWrapText().
int numFonts = 0 [static] |
Definition at line 81 of file r_font.c.
Referenced by R_FontAnalyze(), R_FontInit(), R_FontShutdown(), and R_GetFont().
int numWraps = 0 [static] |
Definition at line 88 of file r_font.c.
Referenced by R_FontCleanCache(), R_FontInit(), R_FontListCache_f(), and R_FontWrapText().
char truncmarker[MAX_TRUNCMARKER] = "..." [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.c.
Referenced by R_FontFindTruncFit(), R_FontGenerateTexture(), and R_FontSetTruncationMarker().
wrapCache_t wrapCache[MAX_WRAP_CACHE] [static] |