CHGame 0.3.0
Libraries for the CHGame handheld
Loading...
Searching...
No Matches
CHGfx_gfxfont.h
Go to the documentation of this file.
1/**
2 * @file CHGfx_gfxfont.h
3 * @brief The bitmap font container, GFXfont, byte-for-byte Adafruit_GFX's.
4 *
5 * This is deliberately, byte-for-byte, Adafruit_GFX's gfxfont.h layout,
6 * down to the include guard. Two consequences, both wanted:
7 *
8 * 1. Every font header ever generated by Adafruit's fontconvert - the
9 * whole Fonts/ directory of Adafruit_GFX, and the hundreds of
10 * converted fonts floating around - drops straight into
11 * gfx_setFont() with no translation.
12 * 2. Fonts shipped with CHGfx work unchanged under Adafruit_GFX's own
13 * setFont(), including through CHGfx_AdafruitGFX.h.
14 *
15 * The shared `_GFXFONT_H_` guard means whichever header is included first
16 * defines the types and the other one steps aside. That only works
17 * because the definitions match, so do not "improve" the field order.
18 *
19 * CHGfx.h includes it; a sketch never needs to. The bundled fonts are
20 * listed under @ref chgfx_fonts.
21 */
22#ifndef _GFXFONT_H_
23#define _GFXFONT_H_
24
25#include <stdint.h>
26
27/**
28 * @brief One glyph's record in a GFXfont: where its bitmap is, its size,
29 * and where it sits relative to the pen.
30 * @ingroup chgfx_fonts
31 *
32 * A glyph is drawn relative to the pen position (x, y), where y is the
33 * BASELINE, not the top:
34 *
35 * - upper-left corner = (x + xOffset, y + yOffset) (yOffset is negative)
36 * - next pen position = (x + xAdvance, y)
37 * - next line = y + GFXfont::yAdvance
38 */
39typedef struct {
40 uint16_t bitmapOffset; /**< byte offset of this glyph's first row */
41 uint8_t width; /**< bitmap width in pixels */
42 uint8_t height; /**< bitmap height in pixels */
43 uint8_t xAdvance; /**< pen movement after drawing */
44 int8_t xOffset; /**< pen x -> bitmap left edge */
45 int8_t yOffset; /**< baseline -> bitmap top edge (negative up) */
46} GFXglyph;
47
48/**
49 * @brief A whole bitmap font, for gfx_setFont(): glyph bitmaps, glyph
50 * records, the character range and the line spacing.
51 * @ingroup chgfx_fonts
52 *
53 * `first`..`last` is a contiguous character range; glyph[] has
54 * last-first+1 entries. The two pointers are non-const to match
55 * Adafruit's struct, which is why every font header casts on init.
56 *
57 * bitmap is one flat MSB-first bitstream with all glyphs concatenated.
58 * A glyph occupies exactly width*height bits starting at bitmapOffset;
59 * rows are NOT padded to byte boundaries, so glyph row r begins at bit
60 * bitmapOffset*8 + r*width.
61 *
62 * Fonts are made with `extras/fontconvert.py` (or Adafruit's own
63 * fontconvert); see @ref chgfx_fonts.
64 */
65typedef struct {
66 uint8_t *bitmap; /**< concatenated glyph bitstreams */
67 GFXglyph *glyph; /**< glyph records, one per character */
68 uint16_t first; /**< first character code present */
69 uint16_t last; /**< last character code present */
70 uint8_t yAdvance; /**< baseline-to-baseline line spacing */
71} GFXfont;
72
73#endif /* _GFXFONT_H_ */
A whole bitmap font, for gfx_setFont(): glyph bitmaps, glyph records, the character range and the lin...
Definition CHGfx_gfxfont.h:65
uint16_t first
first character code present
Definition CHGfx_gfxfont.h:68
uint8_t * bitmap
concatenated glyph bitstreams
Definition CHGfx_gfxfont.h:66
uint16_t last
last character code present
Definition CHGfx_gfxfont.h:69
uint8_t yAdvance
baseline-to-baseline line spacing
Definition CHGfx_gfxfont.h:70
GFXglyph * glyph
glyph records, one per character
Definition CHGfx_gfxfont.h:67
One glyph's record in a GFXfont: where its bitmap is, its size, and where it sits relative to the pen...
Definition CHGfx_gfxfont.h:39
uint8_t width
bitmap width in pixels
Definition CHGfx_gfxfont.h:41
uint8_t height
bitmap height in pixels
Definition CHGfx_gfxfont.h:42
uint16_t bitmapOffset
byte offset of this glyph's first row
Definition CHGfx_gfxfont.h:40
int8_t yOffset
baseline -> bitmap top edge (negative up)
Definition CHGfx_gfxfont.h:45
uint8_t xAdvance
pen movement after drawing
Definition CHGfx_gfxfont.h:43
int8_t xOffset
pen x -> bitmap left edge
Definition CHGfx_gfxfont.h:44