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

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_trdpq_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_trdpq_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.
 

Detailed Description

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

Function Documentation

◆ rdpq_paragraph_builder_begin()

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.

Parameters
parmsLayout parameters
initial_font_idFont ID to use to render the text (at least initially;
layoutPreallocated layout to reuse from scratch. If NULL, the array will be allocated dynamically.
See also
rdpq_paragraph_build
rdpq_paragraph_builder_span
rdpq_paragraph_builder_font
rdpq_paragraph_builder_style
rdpq_paragraph_builder_newline
rdpq_paragraph_builder_end

◆ rdpq_paragraph_builder_font()

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.

Parameters
font_idNew font ID

◆ rdpq_paragraph_builder_style()

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.

Parameters
style_idNew style ID

◆ rdpq_paragraph_builder_span()

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.

Note
This function does not support newlines. Use rdpq_paragraph_builder_newline to start a new line.
Parameters
utf8_textText to add, in UTF-8 encoding
nbytesNumber of bytes in the text to add

◆ rdpq_paragraph_builder_newline()

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_builder_end()

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

Returns
The generated paragraph
See also
rdpq_paragraph_render
rdpq_paragraph_free

◆ rdpq_paragraph_build()

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).

Parameters
parmsLayout parameters
initial_font_idFont ID to use to render the text (at least initially; it can modified via escape codes). See rdpq_text_printn for more details.
utf8_textText to render, in UTF-8 encoding.
nbytesNumber of bytes in the text to render. On return, the number of bytes consumed in the input.
Returns
Calculated layout. Free it with rdpq_paragraph_free when not needed anymore.

◆ rdpq_paragraph_render()

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.

Parameters
layoutLayout to render
x0X coordinate where to start rendering the text
y0Y coordinate where to start rendering the text

◆ rdpq_paragraph_free()

void rdpq_paragraph_free ( rdpq_paragraph_t layout)

Free the memory allocated by rdpq_paragraph_build or rdpq_paragraph_builder_end.

Parameters
layoutParagraph to free