libdragon
Loading...
Searching...
No Matches
rdpq_paragraph.h
Go to the documentation of this file.
1
8#ifndef LIBDRAGON_RDPQ_PARAGRAPH_H
9#define LIBDRAGON_RDPQ_PARAGRAPH_H
10
11#include <stdint.h>
12#include <string.h>
13#include <stdbool.h>
14#include <stddef.h>
15
16#ifdef __cplusplus
17extern "C" {
18#endif
19
21struct rdpq_textparms_s;
22typedef struct rdpq_textparms_s rdpq_textparms_t;
24
26typedef struct __attribute__((packed)) rdpq_paragraph_char_s {
27 union {
28 struct __attribute__((packed)) {
29 uint8_t font_id : 8;
30 uint8_t atlas_id : 8;
31 uint8_t style_id : 8;
32 int x : 12;
33 int y : 12;
34 int16_t glyph : 16;
35 };
36 uint32_t sort_key;
37 };
39
40_Static_assert(sizeof(rdpq_paragraph_char_t) == 8, "rdpq_paragraph_char_t is not packed");
41
60
73typedef struct {
74 struct {
75 float x0;
76 float y0;
77 float x1;
78 float y1;
79 } bbox;
80 float advance_x;
81 float advance_y;
82 int nlines;
83 int nchars;
85 float x0, y0;
86 int flags;
89
124rdpq_paragraph_t* rdpq_paragraph_build(const rdpq_textparms_t *parms, uint8_t initial_font_id,
125 const char *utf8_text, int *nbytes);
126
139void rdpq_paragraph_render(const rdpq_paragraph_t *layout, float x0, float y0);
140
147
189void rdpq_paragraph_builder_begin(const rdpq_textparms_t *parms, uint8_t initial_font_id, rdpq_paragraph_t *layout);
190
200void rdpq_paragraph_builder_font(uint8_t font_id);
201
210void rdpq_paragraph_builder_style(uint8_t style_id);
211
227void rdpq_paragraph_builder_span(const char *utf8_text, int nbytes);
228
237
251
256#ifdef __cplusplus
257}
258#endif
259
260#endif
void rdpq_paragraph_render(const rdpq_paragraph_t *layout, float x0, float y0)
Render a text that was laid out by rdpq_paragraph_build.
Definition rdpq_paragraph.c:575
rdpq_paragraph_t * rdpq_paragraph_builder_end(void)
Finalize the paragraph builder and returns the paragraph.
Definition rdpq_paragraph.c:451
int nlines
Number of lines in the text.
Definition rdpq_paragraph.h:82
int nchars
Total number of chars in this layout.
Definition rdpq_paragraph.h:83
rdpq_paragraph_flag_e
Bitmask flags for rdpq_paragraph_t.
Definition rdpq_paragraph.h:43
@ RDPQ_PARAGRAPH_FLAG_MALLOC
Dynamically-allocated layout This flag is set when the layout was allocated dynamically via malloc an...
Definition rdpq_paragraph.h:58
@ RDPQ_PARAGRAPH_FLAG_ANTIALIAS_FIX
Draw a transparent background rectangle to avoid AA artifacts When drawing text on a 3D background us...
Definition rdpq_paragraph.h:53
void rdpq_paragraph_builder_begin(const rdpq_textparms_t *parms, uint8_t initial_font_id, rdpq_paragraph_t *layout)
Start a paragraph builder.
Definition rdpq_paragraph.c:74
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.
Definition rdpq_paragraph.c:570
void rdpq_paragraph_builder_style(uint8_t style_id)
Change the current style.
Definition rdpq_paragraph.c:130
int flags
Flags (see rdpq_paragraph_flag_e)
Definition rdpq_paragraph.h:86
void rdpq_paragraph_builder_newline(void)
Start a new line.
Definition rdpq_paragraph.c:426
float y0
Alignment offset of the text.
Definition rdpq_paragraph.h:85
int capacity
Capacity of the chars array.
Definition rdpq_paragraph.h:84
void rdpq_paragraph_builder_font(uint8_t font_id)
Change the current font.
Definition rdpq_paragraph.c:117
float advance_x
Pen advance in X after drawing the text.
Definition rdpq_paragraph.h:80
void rdpq_paragraph_free(rdpq_paragraph_t *layout)
Free the memory allocated by rdpq_paragraph_build or rdpq_paragraph_builder_end.
Definition rdpq_paragraph.c:602
float advance_y
Pen advance in Y after drawing the text.
Definition rdpq_paragraph.h:81
void rdpq_paragraph_builder_span(const char *utf8_text, int nbytes)
Add a span of text.
Definition rdpq_paragraph.c:184
A single char in a layout.
Definition rdpq_paragraph.h:26
A paragraph of text, fully laid out.
Definition rdpq_paragraph.h:73
Print formatting parameters.
Definition rdpq_text.h:221