libdragon
Loading...
Searching...
No Matches
rdpq_font_internal.h
Go to the documentation of this file.
1
5#ifndef __RDPQ_FONT_INTERNAL_H
6#define __RDPQ_FONT_INTERNAL_H
7
8#include <stdint.h>
9#include <stdbool.h>
10#include "../../include/graphics.h"
11
13typedef struct rspq_block_s rspq_block_t;
15
17#define FONT_MAGIC "FNT"
18
20#define FONT_MAGIC_LOADED "FNL"
21
23#define FONT_MAGIC_OWNED "FNO"
24
25#define FONT_FLAG_TYPE_MASK 0x0000000F
26
37
39typedef struct {
40 uint32_t first_codepoint;
41 uint32_t num_codepoints;
42 int32_t first_glyph;
43} range_t;
44
57typedef struct {
58 uint32_t seed;
59 uint32_t r;
60 uint32_t m;
61 uint16_t *g;
62 int16_t *values;
64
66typedef struct glyph_s {
67 uint8_t xadvance;
68 int8_t xoff;
69 int8_t yoff;
70 int8_t xoff2;
71 int8_t yoff2;
72 uint8_t s;
73 uint8_t t;
74 uint8_t natlas : 6;
75 uint8_t ntile : 2;
76} glyph_t;
77
79typedef struct glyph_krange_s {
80 uint16_t kerning_lo;
81 uint16_t kerning_hi;
83
85typedef struct atlas_s {
87 uint32_t size;
89} atlas_t;
90
92typedef struct kerning_s {
93 int16_t glyph2;
94 int8_t kerning;
95} __attribute__((packed)) kerning_t;
96
98typedef struct style_s {
101 void (*custom)(void* arg);
103} style_t;
104
133
141int16_t __rdpq_font_glyph(const rdpq_font_t *font, uint32_t codepoint);
142
154inline void __rdpq_font_glyph_metrics(const rdpq_font_t *fnt, int16_t index, float *xadvance, int8_t *xoff, int8_t *xoff2, bool *has_kerning, uint8_t *atlas_id)
155{
156 glyph_t *g = &fnt->glyphs[index];
157 if (xadvance) *xadvance = g->xadvance;
158 if (xoff) *xoff = g->xoff;
159 if (xoff2) *xoff2 = g->xoff2;
160 if (has_kerning) *has_kerning = fnt->glyphs_kranges && fnt->glyphs_kranges[index].kerning_lo != 0;
161 if (atlas_id) *atlas_id = g->natlas;
162}
163
164float __rdpq_font_kerning(const rdpq_font_t *font, int16_t glyph1, int16_t glyph2);
165
166#endif
Generic color structure.
Definition graphics.h:54
rspq_block_t * up
RSPQ block that uploads the sprite.
Definition rdpq_font_internal.h:88
uint32_t num_kerning
Number of kerning pairs in the font.
Definition rdpq_font_internal.h:122
uint32_t size
Size of the sprite in bytes.
Definition rdpq_font_internal.h:87
void __rdpq_font_glyph_metrics(const rdpq_font_t *fnt, int16_t index, float *xadvance, int8_t *xoff, int8_t *xoff2, bool *has_kerning, uint8_t *atlas_id)
Get glyph metrics for a font glyph.
Definition rdpq_font_internal.h:154
uint8_t ntile
Tile to use to draw the glyph (for multi-layer atlases)
Definition rdpq_font_internal.h:75
uint32_t point_size
Point size of the font.
Definition rdpq_font_internal.h:110
int32_t space_width
Width of the space character.
Definition rdpq_font_internal.h:114
uint32_t num_ranges
Number of ranges in the font.
Definition rdpq_font_internal.h:119
uint8_t t
T texture coordinate of the glyph in the atlas.
Definition rdpq_font_internal.h:73
uint32_t seed
Seed for the hashing algorithm.
Definition rdpq_font_internal.h:58
sparse_range_t * sparse_range
Sparse table of glyph indices.
Definition rdpq_font_internal.h:126
float __rdpq_font_kerning(const rdpq_font_t *font, int16_t glyph1, int16_t glyph2)
Get kerning between two glyphs.
Definition rdpq_font.c:377
int8_t kerning
Signed number of pixels to advance after drawing the glyph (scaled by 127 / point_size)
Definition rdpq_font_internal.h:94
uint8_t version
Version number (1)
Definition rdpq_font_internal.h:108
int8_t xoff2
Offset of the exclusive x1 coordinate of the glyph from the cursor.
Definition rdpq_font_internal.h:70
uint32_t num_atlases
Number of atlases in the font.
Definition rdpq_font_internal.h:121
uint32_t first_codepoint
First codepoint in the range.
Definition rdpq_font_internal.h:40
atlas_t * atlases
Array of atlases.
Definition rdpq_font_internal.h:129
uint8_t xadvance
Number of pixels to advance the cursor after drawing the glyph.
Definition rdpq_font_internal.h:67
range_t * ranges
Array of ranges.
Definition rdpq_font_internal.h:125
uint32_t m
Number of elements in the values table.
Definition rdpq_font_internal.h:60
sprite_t * sprite
Texture sprite.
Definition rdpq_font_internal.h:86
int16_t * values
Values table (actual glyph indices)
Definition rdpq_font_internal.h:62
int16_t glyph2
Index of second glyph.
Definition rdpq_font_internal.h:93
style_t builtin_style
Default style for the font.
Definition rdpq_font_internal.h:124
uint16_t ellipsis_advance
Advance of the ellipsis character.
Definition rdpq_font_internal.h:118
uint32_t num_codepoints
Number of codepoints in the range.
Definition rdpq_font_internal.h:41
uint32_t num_glyphs
Number of glyphs in the font.
Definition rdpq_font_internal.h:120
int32_t descent
Descent (number of pixels below baseline)
Definition rdpq_font_internal.h:112
int32_t ascent
Ascent (number of pixels above baseline)
Definition rdpq_font_internal.h:111
int32_t first_glyph
Index of the first glyph in the range (-1 if range is sparse)
Definition rdpq_font_internal.h:42
int16_t ellipsis_width
Width of the ellipsis character.
Definition rdpq_font_internal.h:115
uint8_t natlas
Index of atlas that contains this glyph.
Definition rdpq_font_internal.h:74
glyph_t * glyphs
Array of glyphs.
Definition rdpq_font_internal.h:127
uint16_t ellipsis_glyph
Index of the ellipsis glyph.
Definition rdpq_font_internal.h:116
uint16_t ellipsis_reps
Number of ellipsis glyphs to draw.
Definition rdpq_font_internal.h:117
glyph_krange_t * glyphs_kranges
Array of glyph kerning ranges.
Definition rdpq_font_internal.h:128
fonttype_t
Type of the font.
Definition rdpq_font_internal.h:30
@ FONT_TYPE_MONO
Mono font (CI4, which are 4 1bpp layers)
Definition rdpq_font_internal.h:32
@ FONT_TYPE_ALIASED
Aliased font (I4)
Definition rdpq_font_internal.h:31
@ FONT_TYPE_MONO_OUTLINE
Mono font with outline (CI4, which are 2 2bpp layers)
Definition rdpq_font_internal.h:33
@ FONT_TYPE_BITMAP
Bitmap font (RGBA32/RGBA16/CI4/CI8)
Definition rdpq_font_internal.h:35
@ FONT_TYPE_ALIASED_OUTLINE
Aliased font with outline (IA8)
Definition rdpq_font_internal.h:34
uint32_t flags
Flags.
Definition rdpq_font_internal.h:109
style_t * styles
Array of styles.
Definition rdpq_font_internal.h:131
int8_t xoff
Offset of the x0 coordinate of the glyph from the cursor.
Definition rdpq_font_internal.h:68
uint32_t num_styles
Number of styles in the font.
Definition rdpq_font_internal.h:123
uint16_t * g
Displacement table.
Definition rdpq_font_internal.h:61
uint16_t kerning_hi
Index of the last kerning pair for this glyph.
Definition rdpq_font_internal.h:81
kerning_t * kerning
Array of kerning pairs.
Definition rdpq_font_internal.h:130
int8_t yoff2
Offset of the exclusive y1 coordinate of the glyph from the cursor.
Definition rdpq_font_internal.h:71
int16_t __rdpq_font_glyph(const rdpq_font_t *font, uint32_t codepoint)
Look up a glyph in a font.
Definition rdpq_font.c:360
uint16_t kerning_lo
Index of the first kerning pair for this glyph.
Definition rdpq_font_internal.h:80
uint32_t r
Number of elements in the displacement table.
Definition rdpq_font_internal.h:59
int8_t yoff
Offset of the y0 coordinate of the glyph from the cursor.
Definition rdpq_font_internal.h:69
uint8_t s
S texture coordinate of the glyph in the atlas.
Definition rdpq_font_internal.h:72
int32_t line_gap
Line gap of the font (spacing between descent and ascent)
Definition rdpq_font_internal.h:113
A texture atlas (part of rdpq_font_t)
Definition rdpq_font_internal.h:85
For each glyph, range of kerning pairs in the kerning table.
Definition rdpq_font_internal.h:79
A glyph in the font (part of rdpq_font_t)
Definition rdpq_font_internal.h:66
Kerning data for a pair of glyphs.
Definition rdpq_font_internal.h:92
A range of codepoint (part of rdpq_font_t)
Definition rdpq_font_internal.h:39
A font64 file containing a font.
Definition rdpq_font_internal.h:106
Sparse range table.
Definition rdpq_font_internal.h:57
A rspq block: pre-recorded array of commands.
Definition rspq_internal.h:162
Sprite structure.
Definition sprite.h:42
Data related to font styling.
Definition rdpq_font_internal.h:98
color_t color
Color of the text.
Definition rdpq_font_internal.h:99
color_t outline_color
Color of the outline (if any)
Definition rdpq_font_internal.h:100
void * custom_arg
Argument to pass to the custom function.
Definition rdpq_font_internal.h:102