libdragon
Loading...
Searching...
No Matches
Data Structures | Macros | Enumerations | Functions
rdpq_font_internal.h File Reference

Go to the source code of this file.

Data Structures

struct  range_t
 A range of codepoint (part of rdpq_font_t) More...
 
struct  sparse_range_t
 Sparse range table. More...
 
struct  glyph_t
 A glyph in the font (part of rdpq_font_t) More...
 
struct  glyph_krange_t
 For each glyph, range of kerning pairs in the kerning table. More...
 
struct  atlas_t
 A texture atlas (part of rdpq_font_t) More...
 
struct  kerning_t
 Kerning data for a pair of glyphs. More...
 
struct  style_t
 Data related to font styling. More...
 
struct  rdpq_font_t
 A font64 file containing a font. More...
 

Macros

#define FONT_MAGIC   "FNT"
 font64 file magic header
 
#define FONT_MAGIC_LOADED   "FNL"
 font64 loaded font buffer magic
 
#define FONT_MAGIC_OWNED   "FNO"
 font64 owned font buffer magic
 
#define FONT_FLAG_TYPE_MASK   0x0000000F
 Mask for the font type.
 

Enumerations

enum  fonttype_t {
  FONT_TYPE_ALIASED = 0 , FONT_TYPE_MONO = 1 , FONT_TYPE_MONO_OUTLINE = 2 , FONT_TYPE_ALIASED_OUTLINE = 3 ,
  FONT_TYPE_BITMAP = 4
}
 Type of the font. More...
 

Functions

int16_t __rdpq_font_glyph (const rdpq_font_t *font, uint32_t codepoint)
 Look up a glyph in a font.
 
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.
 
float __rdpq_font_kerning (const rdpq_font_t *font, int16_t glyph1, int16_t glyph2)
 Get kerning between two glyphs.
 

Detailed Description

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

Data Structure Documentation

◆ range_t

struct range_t

A range of codepoint (part of rdpq_font_t)

Data Fields
uint32_t first_codepoint First codepoint in the range.
uint32_t num_codepoints Number of codepoints in the range.
int32_t first_glyph Index of the first glyph in the range (-1 if range is sparse)

◆ sparse_range_t

struct sparse_range_t

Sparse range table.

This is a perfect hash table used to encode glyph indices for codepoints. It is used for all sparse ranges, that is ranges where only some codepoints are defined within the min/max of the range, to avoid wasting too much memory in the glyph table for empty entries.

This uses the CHD (compress hash displace) perfect hash table algorithm, that is very fast at runtime and has very little complexity. Since we handle small tables by today's standard, this algorithm is a good fit.

Data Fields
uint32_t seed Seed for the hashing algorithm.
uint32_t r Number of elements in the displacement table.
uint32_t m Number of elements in the values table.
uint16_t * g Displacement table.
int16_t * values Values table (actual glyph indices)

◆ glyph_t

struct glyph_t

A glyph in the font (part of rdpq_font_t)

Data Fields
uint8_t xadvance Number of pixels to advance the cursor after drawing the glyph.
int8_t xoff Offset of the x0 coordinate of the glyph from the cursor.
int8_t yoff Offset of the y0 coordinate of the glyph from the cursor.
int8_t xoff2 Offset of the exclusive x1 coordinate of the glyph from the cursor.
int8_t yoff2 Offset of the exclusive y1 coordinate of the glyph from the cursor.
uint8_t s S texture coordinate of the glyph in the atlas.
uint8_t t T texture coordinate of the glyph in the atlas.
uint8_t natlas: 6 Index of atlas that contains this glyph.
uint8_t ntile: 2 Tile to use to draw the glyph (for multi-layer atlases)

◆ glyph_krange_t

struct glyph_krange_t

For each glyph, range of kerning pairs in the kerning table.

Data Fields
uint16_t kerning_lo Index of the first kerning pair for this glyph.
uint16_t kerning_hi Index of the last kerning pair for this glyph.

◆ atlas_t

struct atlas_t

A texture atlas (part of rdpq_font_t)

Data Fields
sprite_t * sprite Texture sprite.
uint32_t size Size of the sprite in bytes.
rspq_block_t * up RSPQ block that uploads the sprite.

◆ kerning_t

struct kerning_t

Kerning data for a pair of glyphs.

Data Fields
int16_t glyph2 Index of second glyph.
int8_t kerning Signed number of pixels to advance after drawing the glyph (scaled by 127 / point_size)

◆ rdpq_font_t

struct rdpq_font_t

A font64 file containing a font.

Data Fields
char magic[3] Magic header (FONT_MAGIC)
uint8_t version Version number (1)
uint32_t flags Flags.
uint32_t point_size Point size of the font.
int32_t ascent Ascent (number of pixels above baseline)
int32_t descent Descent (number of pixels below baseline)
int32_t line_gap Line gap of the font (spacing between descent and ascent)
int32_t space_width Width of the space character.
int16_t ellipsis_width Width of the ellipsis character.
uint16_t ellipsis_glyph Index of the ellipsis glyph.
uint16_t ellipsis_reps Number of ellipsis glyphs to draw.
uint16_t ellipsis_advance Advance of the ellipsis character.
uint32_t num_ranges Number of ranges in the font.
uint32_t num_glyphs Number of glyphs in the font.
uint32_t num_atlases Number of atlases in the font.
uint32_t num_kerning Number of kerning pairs in the font.
uint32_t num_styles Number of styles in the font.
style_t builtin_style Default style for the font.
range_t * ranges Array of ranges.
sparse_range_t * sparse_range Sparse table of glyph indices.
glyph_t * glyphs Array of glyphs.
glyph_krange_t * glyphs_kranges Array of glyph kerning ranges.
atlas_t * atlases Array of atlases.
kerning_t * kerning Array of kerning pairs.
style_t * styles Array of styles.

Enumeration Type Documentation

◆ fonttype_t

enum fonttype_t

Type of the font.

Enumerator
FONT_TYPE_ALIASED 

Aliased font (I4)

FONT_TYPE_MONO 

Mono font (CI4, which are 4 1bpp layers)

FONT_TYPE_MONO_OUTLINE 

Mono font with outline (CI4, which are 2 2bpp layers)

FONT_TYPE_ALIASED_OUTLINE 

Aliased font with outline (IA8)

FONT_TYPE_BITMAP 

Bitmap font (RGBA32/RGBA16/CI4/CI8)

Function Documentation

◆ __rdpq_font_glyph()

int16_t __rdpq_font_glyph ( const rdpq_font_t font,
uint32_t  codepoint 
)

Look up a glyph in a font.

Parameters
fontFont to look up the glyph in
codepointUnicode codepoint of the glyph
Returns
int16_t Index of the glyph in the font, or -1 if not found

◆ __rdpq_font_glyph_metrics()

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

Get glyph metrics for a font glyph.

Parameters
fntFont to query.
indexIndex of the glyph in the font.
xadvancePointer to store the advance width (can be NULL).
xoffPointer to store the start x offset (can be NULL).
xoff2Pointer to store the end x offset (can be NULL).
has_kerningPointer to store whether the glyph has kerning (can be NULL).
atlas_idPointer to store the atlas ID (can be NULL).