![]() |
libdragon
|
Functions | |
uint32_t | __utf8_decode (const char **str) |
UTF-8 decoding. | |
void | rdpq_paragraph_builder_begin (const rdpq_textparms_t *parms, uint8_t initial_font_id, rdpq_paragraph_t *layout) |
Start a paragraph builder. | |
void | rdpq_paragraph_builder_font (uint8_t font_id) |
Change the current font. | |
void | rdpq_paragraph_builder_style (uint8_t style_id) |
Change the current style. | |
void | rdpq_paragraph_builder_span (const char *utf8_text, int nbytes) |
Add a span of text. | |
void | rdpq_paragraph_builder_newline (void) |
Start a new line. | |
rdpq_paragraph_t * | rdpq_paragraph_builder_end (void) |
Finalize the paragraph builder and returns the paragraph. | |
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) |
Inner implementation of rdpq_paragraph_build, with explicit memory handling. | |
rdpq_paragraph_t * | rdpq_paragraph_build (const rdpq_textparms_t *parms, uint8_t initial_font_id, const char *utf8_text, int *nbytes) |
Calculate the layout of a text using the specified parameters. | |
void | rdpq_paragraph_render (const rdpq_paragraph_t *layout, float x0, float y0) |
Render a text that was laid out by rdpq_paragraph_build. | |
void | rdpq_paragraph_free (rdpq_paragraph_t *layout) |
Free the memory allocated by rdpq_paragraph_build or rdpq_paragraph_builder_end. | |
void | __rdpq_paragraph_char_check_bitfield (void) |
Global constructor to perform a sanity check on code generation for rdpq_paragraph. | |
void rdpq_paragraph_builder_begin | ( | const rdpq_textparms_t * | parms, |
uint8_t | initial_font_id, | ||
rdpq_paragraph_t * | layout | ||
) |
Start a paragraph builder.
This function is a lower-level version of rdpq_paragraph_build. It allows to layout multiple "spans" of texts, using different fonts and styles. This function does not support the special escape codes (as described in rdpq_text_printn), but expect the text to be split in "spans", each one using a single font and style that must be specified.
After calling rdpq_paragraph_builder_begin, use rdpq_paragraph_builder_span to add each span of text, and rdpq_paragraph_builder_font or rdpq_paragraph_builder_style to change respectively font and style. It is also required to call rdpq_paragraph_builder_newline to start a new line: the paragraph builder does not otherwise support newlines in the text.
Finally, call rdpq_paragraph_builder_end to retrieve the instance of rdpq_paragraph_t that contains the layout of the text.
parms | Layout parameters |
initial_font_id | Font ID to use to render the text (at least initially; |
layout | Preallocated layout to reuse from scratch. If NULL, the array will be allocated dynamically. |
void rdpq_paragraph_builder_font | ( | uint8_t | font_id | ) |
Change the current font.
Set the current font in the paragraph, that will be used for spans added after this call. Notice that after a font change, the current style is always reset to 0.
font_id | New font ID |
void rdpq_paragraph_builder_style | ( | uint8_t | style_id | ) |
Change the current style.
Set the current font style in the paragraph, that will be used for spans added after this call.
style_id | New style ID |
void rdpq_paragraph_builder_span | ( | const char * | utf8_text, |
int | nbytes | ||
) |
Add a span of text.
This function adds a span of text to the paragraph. The text will use the current font and style. You can call this function multiple times to append multiple spans of text to the paragraph, though it is better to batch calls as much as reasonably possible, at least for text using the same font and style.
utf8_text | Text to add, in UTF-8 encoding |
nbytes | Number of bytes in the text to add |
void rdpq_paragraph_builder_newline | ( | void | ) |
Start a new line.
This function is required to start a new line in the paragraph. Notice that rdpq_paragraph_builder_span does not support newlines, so it is necessary to call this function any time a newline is required.
rdpq_paragraph_t * rdpq_paragraph_builder_end | ( | void | ) |
Finalize the paragraph builder and returns the paragraph.
After calling this function, the paragraph is ready to use. Call rdpq_paragraph_render to render it (even multiple times), and rdpq_paragraph_free to free it when you don't need it anymore
rdpq_paragraph_t * rdpq_paragraph_build | ( | const rdpq_textparms_t * | parms, |
uint8_t | initial_font_id, | ||
const char * | utf8_text, | ||
int * | nbytes | ||
) |
Calculate the layout of a text using the specified parameters.
This function accepts UTF-8 encoded text. It will layout the text according to the parameters provided in rdpq_textparms_t, and return a new instance of rdpq_paragraph_t that can be used to later render the text via rdpq_paragraph_render.
This function is useful if you want to layout a text once, and then draw it multiple times (eg: for multiple frames). Layouting a text isn't necessarily a slow operation (depending on what parameters are used), but it's not free either.
This function is called internally by rdpq_text_printn, rdpq_text_printf, and rdpq_text_print, so it supports the same escape codes that they do, that allow to layout a text using multiple fonts and styles.
The nbytes
parameter is used to specify the number of bytes to layout. It is then modified to provide the number of bytes actually consumed in the input. The consumed bytes can be less than the input when the text is truncated vertically (which requires the height to be specified in the parms
structure), which is useful to implement a pagination system. Notice that horizontal truncation (as obtained using WRAP_NONE or WRAP_ELLIPSES) still result in the whole line being consumed (as in a paragraph, multiple lines could be truncated and thus shown only partially).
parms | Layout parameters |
initial_font_id | Font ID to use to render the text (at least initially; it can modified via escape codes). See rdpq_text_printn for more details. |
utf8_text | Text to render, in UTF-8 encoding. |
nbytes | Number of bytes in the text to render. On return, the number of bytes consumed in the input. |
void rdpq_paragraph_render | ( | const rdpq_paragraph_t * | layout, |
float | x0, | ||
float | y0 | ||
) |
Render a text that was laid out by rdpq_paragraph_build.
This function will render the text that was previously layouted by rdpq_paragraph_build, or via the paragraph builder (rdpq_paragraph_builder_begin / rdpq_paragraph_builder_end). To perform the actual drawing, it will defer to the rdpq_font_render_paragraph. callback of the font(s) the text is using.
layout | Layout to render |
x0 | X coordinate where to start rendering the text |
y0 | Y coordinate where to start rendering the text |
void rdpq_paragraph_free | ( | rdpq_paragraph_t * | layout | ) |
Free the memory allocated by rdpq_paragraph_build or rdpq_paragraph_builder_end.
layout | Paragraph to free |