libdragon
Loading...
Searching...
No Matches
Functions
rdpq_text.c File Reference

Functions

void rdpq_text_register_font (uint8_t font_id, const rdpq_font_t *font)
 Register a new font into the text engine.
 
void rdpq_text_unregister_font (uint8_t font_id)
 Unregister a font from the text engine.
 
const rdpq_font_trdpq_text_get_font (uint8_t font_id)
 Get a registered font by its ID.
 
rdpq_paragraph_t__rdpq_paragraph_build (const rdpq_textparms_t *parms, uint8_t initial_font_id, const char *utf8_text, int *nbytes, rdpq_paragraph_t *layout, bool optimize)
 Inner implementation of rdpq_text_printn, with explicit memory handling.
 
rdpq_textmetrics_t rdpq_text_printn (const rdpq_textparms_t *parms, uint8_t initial_font_id, float x0, float y0, const char *utf8_text, int nbytes)
 Layout and render a text in a single call.
 
rdpq_textmetrics_t rdpq_text_vprintf (const rdpq_textparms_t *parms, uint8_t font_id, float x0, float y0, const char *utf8_fmt, va_list va)
 Layout and render a formatted text in a single call.
 
rdpq_textmetrics_t rdpq_text_printf (const rdpq_textparms_t *parms, uint8_t font_id, float x0, float y0, const char *utf8_fmt,...)
 Layout and render a formatted text in a single call.
 
rdpq_textmetrics_t rdpq_text_print (const rdpq_textparms_t *parms, uint8_t font_id, float x0, float y0, const char *utf8_text)
 Layout and render a text in a single call.
 

Detailed Description

Author
Giovanni Bajo giova.nosp@m.nnib.nosp@m.ajo@g.nosp@m.mail.nosp@m..com

Function Documentation

◆ rdpq_text_register_font()

void rdpq_text_register_font ( uint8_t  font_id,
const rdpq_font_t font 
)

Register a new font into the text engine.

After this call, the font is available to be used by the text engine for layout and render. If font_id is already registered, this function will fail by asserting.

Parameters
font_idFont ID
fontFont to register
Note
Font ID 0 is reserved and cannot be used.

◆ rdpq_text_unregister_font()

void rdpq_text_unregister_font ( uint8_t  font_id)

Unregister a font from the text engine.

This call will remove the font that was previously registered with font_id from the text engine. Afterwards, font_id can be used again to register other fonts. If font_id is not registered, this function will fail by asserting.

Parameters
font_idFont ID
Note
Font ID 0 is reserved and cannot be used.

◆ rdpq_text_get_font()

const rdpq_font_t * rdpq_text_get_font ( uint8_t  font_id)

Get a registered font by its ID.

Parameters
font_idFont ID
Returns
const rdpq_font_t* Registered font or NULL

◆ rdpq_text_printn()

rdpq_textmetrics_t rdpq_text_printn ( const rdpq_textparms_t parms,
uint8_t  font_id,
float  x0,
float  y0,
const char *  utf8_text,
int  nbytes 
)

Layout and render a text in a single call.

This function accepts UTF-8 encoded text. It will layout the text according to the parameters provided in rdpq_textparms_t, and then render it at the specified coordinates.

The text is layout and rendered using the specified font by default (using its default style 0), but it can contain special escape codes to change the font or its style.

Escape codes are sequences of the form:

$xx Select font "xx", where "xx" is the hexadecimal ID of the font For instance, $04 will switch to font 4. The current style is reset to 0. ^xx Switch to style "xx" of the current font, where "xx" is the hexadecimal ID of the style. For instance, ^02 will switch to style 2. A "style" is an font-dependent rendering style, which can be anything (a color, a faux-italic variant, etc.). It is up the the font to define what styles are available.

To use a stray "$" or "^" character in the text, you can escape it by repeating them twice: "$$" or "^^".

The specified position refers to the "baseline" of the text. This is the line upon which the various glyphs are laid out (just like the line on a handwriting paper); each glyph will extend above or even below the baseline, depending on how the font has been designed.

The return value is the number of bytes printed, and can be useful to provide a pagination system (as the caller will be able to know where the next page would start). Notice that if you ask for horizontal line truncation (via WRAP_NONE or WRAP_ELLIPSES), those lines will be counted as fully printed anyway (so that pagination works as expected).

Parameters
parmsLayout parameters (see rdpq_textparms_t)
font_idFont ID to use to render the text (at least initially; it can modified via escape codes). The initial style will be style 0.
x0X coordinate where to start rendering the text (baseline)
y0Y coordinate where to start rendering the text (baseline)
utf8_textText to render, in UTF-8 encoding. Does not need to be NULL terminated.
nbytesNumber of bytes in the text to render
Returns
int Number of bytes printed
See also
rdpq_text_printf
rdpq_text_print
rdpq_textparms_t

◆ rdpq_text_vprintf()

rdpq_textmetrics_t rdpq_text_vprintf ( const rdpq_textparms_t parms,
uint8_t  font_id,
float  x0,
float  y0,
const char *  utf8_fmt,
va_list  va 
)

Layout and render a formatted text in a single call.

This function is similar to rdpq_text_printf, but it accepts a va_list argument list, similar to vsprintf. The format string is expected to be UTF-8 encoded.

Parameters
parmsLayout parameters
font_idFont ID to use to render the text (at least initially; it can modified via escape codes). The initial style will be style 0.
x0X coordinate where to start rendering the text
y0Y coordinate where to start rendering the text
utf8_fmtFormat string, in UTF-8 encoding
vaArgument list
Returns
rdpq_textmetrics_t Metrics of the text

◆ rdpq_text_printf()

rdpq_textmetrics_t rdpq_text_printf ( const rdpq_textparms_t parms,
uint8_t  font_id,
float  x0,
float  y0,
const char *  utf8_fmt,
  ... 
)

Layout and render a formatted text in a single call.

This function is similar to rdpq_text_print, but it accepts a printf-like format string. The format string is expected to be UTF-8 encoded.

Parameters
parmsLayout parameters
font_idFont ID to use to render the text (at least initially; it can modified via escape codes). The initial style will be style 0.
x0X coordinate where to start rendering the text
y0Y coordinate where to start rendering the text
utf8_fmtFormat string, in UTF-8 encoding
Returns
int Number of bytes printed

◆ rdpq_text_print()

rdpq_textmetrics_t rdpq_text_print ( const rdpq_textparms_t parms,
uint8_t  font_id,
float  x0,
float  y0,
const char *  utf8_text 
)
externinline

Layout and render a text in a single call.

This function is similar to rdpq_text_print, but it accepts a UTF-8 encoded, NULL-terminated string.

Parameters
parmsLayout parameters
font_idFont ID to use to render the text (at least initially; it can modified via escape codes). The initial style will be style 0.
x0X coordinate where to start rendering the text
y0Y coordinate where to start rendering the text
utf8_textText to render, in UTF-8 encoding, NULL terminated.
Returns
int Number of bytes printed