| TGX 1.1.3 A tiny 2D/3D graphics library optimized for 32 bits microcontrollers.

Loading...
Searching...
No Matches
Fonts.h
Go to the documentation of this file.
1
7//
8// Copyright 2021 Arvind Singh
9//
10// This library is free software; you can redistribute it and/or
11// modify it under the terms of the GNU Lesser General Public
12// License as published by the Free Software Foundation; either
13//version 2.1 of the License, or (at your option) any later version.
14//
15// This library is distributed in the hope that it will be useful,
16// but WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the GNU
18// Lesser General Public License for more details.
19//
20// You should have received a copy of the GNU Lesser General Public
21// License along with this library; If not, see <http://www.gnu.org/licenses/>.
22
23
24#ifndef _TGX_FONTS_H_
25#define _TGX_FONTS_H_
26
27#include <stdint.h>
28#include "Misc.h"
29#include "Vec2.h"
30#include "Box2.h"
31
32
33//****************************************************************************
34//****************************************************************************
35//****************************************************************************
36// FONT FORMATS
37//
38// !!! The Adafruit GFX and ILI9341_t3 libraries should be included before
39// this header if you want to use these libraries !!!
40//****************************************************************************
41//****************************************************************************
42//****************************************************************************
43
44
45
46//Should we use the code below to force include whenever possible? probably not...
47//#ifdef __cplusplus
48//#if __has_include(<gfxfont.h>)
49//#include <gfxfont.h>
50//#endif
51//#endif
52
53#ifndef _GFXFONT_H_
54#define _GFXFONT_H_
55
56// Font data stored PER GLYPH
57 typedef struct {
58 uint16_t bitmapOffset;
59 uint8_t width;
60 uint8_t height;
61 uint8_t xAdvance;
62 int8_t xOffset;
63 int8_t yOffset;
64} GFXglyph;
65
66
74 typedef struct {
75 uint8_t* bitmap;
76 GFXglyph* glyph;
77 uint8_t first;
78 uint8_t last;
79 uint8_t yAdvance;
80} GFXfont;
81
82#endif
83
84
85
86
87//Should we use the code below to force include whenever possible? probably not...
88//#ifdef __cplusplus
89//#if __has_include(<ILI9341_t3.h>)
90//#include <ILI9341_t3.h>
91//#endif
92//#endif
93//#ifndef _ILI9341_t3H_
94//#define _ILI9341_t3H_
95
96#ifndef _ILI9341_FONTS_H_
97#define _ILI9341_FONTS_H_
98
105 typedef struct {
106 const unsigned char* index;
107 const unsigned char* unicode;
108 const unsigned char* data;
109 unsigned char version;
110 unsigned char reserved;
111 unsigned char index1_first;
112 unsigned char index1_last;
113 unsigned char index2_first;
114 unsigned char index2_last;
115 unsigned char bits_index;
116 unsigned char bits_width;
117 unsigned char bits_height;
118 unsigned char bits_xoffset;
119 unsigned char bits_yoffset;
120 unsigned char bits_delta;
121 unsigned char line_space;
122 unsigned char cap_height;
123} ILI9341_t3_font_t;
124
125#endif
126
127// add alias to make it compatible with projectitis's format...
128 typedef ILI9341_t3_font_t packedbdf_t;
129
130
131
132 namespace tgx
133 {
134
135
145 int fontHeight(const GFXfont& font);
146
147
157 int fontHeight(const ILI9341_t3_font_t& font);
158
159
173 iBox2 measureChar(char c, iVec2 pos, const GFXfont& font, Anchor anchor = DEFAULT_TEXT_ANCHOR, int* xadvance = nullptr);
174
175
189 iBox2 measureChar(char c, iVec2 pos, const ILI9341_t3_font_t& font, Anchor anchor = DEFAULT_TEXT_ANCHOR, int* xadvance = nullptr);
190
191
192
193
194
195 namespace tgx_internals
196 {
197
199 inline uint32_t fetchbit(const uint8_t* p, uint32_t index) { return (p[index >> 3] & (0x80 >> (index & 7))); } //fetch a single bit from a bit array. (from ili9341_t3.cpp)
200
202 uint32_t fetchbits_unsigned(const uint8_t* p, uint32_t index, uint32_t required);
203
205 int32_t fetchbits_signed(const uint8_t* p, uint32_t index, uint32_t required);
206
207 }
208
209 }
210
211
212
213
214#endif
215
Box2.h
2D box class
tgx::Anchor
Anchor
Define the placement of an anchor point inside a box.
Definition: Box2.h:74
tgx::measureChar
iBox2 measureChar(char c, iVec2 pos, const GFXfont &font, Anchor anchor=DEFAULT_TEXT_ANCHOR, int *xadvance=nullptr)
Compute the bounding box of a character.
tgx::fontHeight
int fontHeight(const GFXfont &font)
Query the height of a font.
Misc.h
Utility/miscellaneous functions used throughout the library.
Vec2.h
2D vector.
GFXfont
GFXFont font format.
Definition: Fonts.h:74
GFXfont::last
uint8_t last
ASCII extents (last char)
Definition: Fonts.h:78
GFXfont::bitmap
uint8_t * bitmap
Glyph bitmaps, concatenated.
Definition: Fonts.h:75
GFXfont::first
uint8_t first
ASCII extents (first char)
Definition: Fonts.h:77
GFXfont::yAdvance
uint8_t yAdvance
Newline distance (y axis)
Definition: Fonts.h:79
GFXfont::glyph
GFXglyph * glyph
Glyph array.
Definition: Fonts.h:76
ILI9341_t3_font_t
ILI9341_t3 PJRC font format.
Definition: Fonts.h:105
ILI9341_t3_font_t::bits_yoffset
unsigned char bits_yoffset
...
Definition: Fonts.h:119
ILI9341_t3_font_t::index
const unsigned char * index
...
Definition: Fonts.h:106
ILI9341_t3_font_t::line_space
unsigned char line_space
...
Definition: Fonts.h:121
ILI9341_t3_font_t::index2_last
unsigned char index2_last
...
Definition: Fonts.h:114
ILI9341_t3_font_t::bits_height
unsigned char bits_height
...
Definition: Fonts.h:117
ILI9341_t3_font_t::reserved
unsigned char reserved
...
Definition: Fonts.h:110
ILI9341_t3_font_t::unicode
const unsigned char * unicode
...
Definition: Fonts.h:107
ILI9341_t3_font_t::bits_width
unsigned char bits_width
...
Definition: Fonts.h:116
ILI9341_t3_font_t::index1_first
unsigned char index1_first
...
Definition: Fonts.h:111
ILI9341_t3_font_t::index1_last
unsigned char index1_last
...
Definition: Fonts.h:112
ILI9341_t3_font_t::bits_index
unsigned char bits_index
...
Definition: Fonts.h:115
ILI9341_t3_font_t::cap_height
unsigned char cap_height
...
Definition: Fonts.h:122
ILI9341_t3_font_t::index2_first
unsigned char index2_first
...
Definition: Fonts.h:113
ILI9341_t3_font_t::bits_delta
unsigned char bits_delta
...
Definition: Fonts.h:120
ILI9341_t3_font_t::data
const unsigned char * data
...
Definition: Fonts.h:108
ILI9341_t3_font_t::version
unsigned char version
...
Definition: Fonts.h:109
ILI9341_t3_font_t::bits_xoffset
unsigned char bits_xoffset
...
Definition: Fonts.h:118
tgx::Box2
Generic 2D Box [specializations iBox2 , fBox2, dBox2].
Definition: Box2.h:151
tgx::Vec2
Generic 2D vector [specializations iVec2, fVec2, dVec2].
Definition: Vec2.h:64