libdragon
Loading...
Searching...
No Matches
rdpq_font.h
Go to the documentation of this file.
1
8#ifndef LIBDRAGON_RDPQ_FONT_H
9#define LIBDRAGON_RDPQ_FONT_H
10
11#include "graphics.h"
12#include "debug.h"
13
14#ifdef __cplusplus
15extern "C" {
16#endif
17
19typedef struct rdpq_font_s rdpq_font_t;
20typedef struct rdpq_paragraph_char_s rdpq_paragraph_char_t;
24
26typedef struct {
27 float xadvance;
28 int8_t x0;
29 int8_t y0;
30 int8_t x1;
31 int8_t y1;
33
43rdpq_font_t* rdpq_font_load(const char *fn);
44
59rdpq_font_t* rdpq_font_load_buf(void *buf, int sz);
60
78
93 switch (font) {
98 default:
99 assertf(false, "Invalid builtin font");
100 return NULL;
101 }
102}
103
113void rdpq_font_free(rdpq_font_t *fnt);
114
121typedef struct rdpq_fontstyle_s {
124 void (*custom)(void* arg);
127
144void rdpq_font_style(rdpq_font_t *font, uint8_t style_id, const rdpq_fontstyle_t *style);
145
163int rdpq_font_render_paragraph(const rdpq_font_t *fnt, const rdpq_paragraph_char_t *chars, float x0, float y0);
164
191bool rdpq_font_get_glyph_ranges(const rdpq_font_t *fnt, int idx, uint32_t *start, uint32_t *end, bool *sparse);
192
211int rdpq_font_get_glyph_index(const rdpq_font_t *fnt, uint32_t codepoint);
212
225bool rdpq_font_get_glyph_metrics(const rdpq_font_t *fnt, uint32_t codepoint, rdpq_font_gmetrics_t *metrics);
226
227
228#ifdef __cplusplus
229}
230#endif
231
232#endif
Debugging Support.
#define assertf(expr, msg,...)
assertf() is like assert() with an attached printf().
Definition debug.h:196
2D Graphics
Generic color structure.
Definition graphics.h:54
rdpq_font_t * __rdpq_font_load_builtin_1(void)
Load built-in font 1 (monogram)
Definition rdpq_font.c:532
rdpq_font_t * __rdpq_font_load_builtin_2(void)
Load built-in font 2 (At01)
Definition rdpq_font.c:538
rdpq_font_t * rdpq_font_load_builtin(rdpq_font_builtin_t font)
Load a builtin font provided by libdragon.
Definition rdpq_font.h:92
float xadvance
Advance after drawing the glyph.
Definition rdpq_font.h:27
int8_t x0
Top-left X coordinate of the bbox of the glyph (relative to the pen position)
Definition rdpq_font.h:28
int8_t y0
Top-left Y coordinate of the bbox of the glyph (relative to the pen position)
Definition rdpq_font.h:29
int rdpq_font_get_glyph_index(const rdpq_font_t *fnt, uint32_t codepoint)
Get the internal index of a glyoh given the codepoint.
Definition rdpq_font.c:511
int rdpq_font_render_paragraph(const rdpq_font_t *fnt, const rdpq_paragraph_char_t *chars, float x0, float y0)
Render a certain number of chars from a paragraph.
Definition rdpq_font.c:423
rdpq_font_t * rdpq_font_load(const char *fn)
Load a font from a file (.font64 format).
Definition rdpq_font.c:274
bool rdpq_font_get_glyph_ranges(const rdpq_font_t *fnt, int idx, uint32_t *start, uint32_t *end, bool *sparse)
Get information on the Unicode codepoint ranges covered by a font.
Definition rdpq_font.c:501
rdpq_font_t * rdpq_font_load_buf(void *buf, int sz)
Load a font from a buffer in memory (.font64 format).
Definition rdpq_font.c:165
void rdpq_font_free(rdpq_font_t *fnt)
Free a font.
Definition rdpq_font.c:308
rdpq_font_builtin_t
Builtin fonts, shipped with libdragon.
Definition rdpq_font.h:67
@ FONT_BUILTIN_DEBUG_VAR
Definition rdpq_font.h:76
@ FONT_BUILTIN_DEBUG_MONO
Definition rdpq_font.h:71
void rdpq_font_style(rdpq_font_t *font, uint8_t style_id, const rdpq_fontstyle_t *style)
Create a style for a font.
Definition rdpq_font.c:399
bool rdpq_font_get_glyph_metrics(const rdpq_font_t *fnt, uint32_t codepoint, rdpq_font_gmetrics_t *metrics)
Get the metrics of a glyph in a font.
Definition rdpq_font.c:516
int8_t y1
Bottom-right exclusive Y coordinate of the bbox of the glyph (relative to the pen position)
Definition rdpq_font.h:31
int8_t x1
Bottom-right exclusive X coordinate of the bbox of the glyph (relative to the pen position)
Definition rdpq_font.h:30
Metrics of a glyph in the font.
Definition rdpq_font.h:26
A font64 file containing a font.
Definition rdpq_font_internal.h:106
A single char in a layout.
Definition rdpq_paragraph.h:26
A style for a font.
Definition rdpq_font.h:121
void * custom_arg
Argument to pass to the custom function.
Definition rdpq_font.h:125
color_t color
Color of the text.
Definition rdpq_font.h:122
color_t outline_color
Color of the outline (if any)
Definition rdpq_font.h:123