TGX 1.0.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 ot 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
57typedef 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
74typedef 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
105typedef 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;
124
125#endif
126
127// add alias to make it compatible with projectitis's format...
129
130
131
132namespace tgx
133 {
134
135
145 int fontHeight(const GFXfont& font);
146
147
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 uint32_t fetchbits_signed(const uint8_t* p, uint32_t index, uint32_t required);
206
207 }
208
209 }
210
211
212
213
214#endif
215
2D box class
Anchor
Define the placement of an anchor point inside a box.
Definition: Box2.h:74
iBox2 measureChar(char c, iVec2 pos, const GFXfont &font, Anchor anchor=DEFAULT_TEXT_ANCHOR, int *xadvance=nullptr)
Compute the bounding box of a character.
int fontHeight(const GFXfont &font)
Query the height of a font.
Utility/miscellaneous functions used throughout the library.
2D vector.
GFXFont font format.
Definition: Fonts.h:74
uint8_t last
ASCII extents (last char)
Definition: Fonts.h:78
uint8_t * bitmap
Glyph bitmaps, concatenated.
Definition: Fonts.h:75
uint8_t first
ASCII extents (first char)
Definition: Fonts.h:77
uint8_t yAdvance
Newline distance (y axis)
Definition: Fonts.h:79
GFXglyph * glyph
Glyph array.
Definition: Fonts.h:76
ILI9341_t3 PJRC font format.
Definition: Fonts.h:105
unsigned char bits_yoffset
...
Definition: Fonts.h:119
const unsigned char * index
...
Definition: Fonts.h:106
unsigned char line_space
...
Definition: Fonts.h:121
unsigned char index2_last
...
Definition: Fonts.h:114
unsigned char bits_height
...
Definition: Fonts.h:117
unsigned char reserved
...
Definition: Fonts.h:110
const unsigned char * unicode
...
Definition: Fonts.h:107
unsigned char bits_width
...
Definition: Fonts.h:116
unsigned char index1_first
...
Definition: Fonts.h:111
unsigned char index1_last
...
Definition: Fonts.h:112
unsigned char bits_index
...
Definition: Fonts.h:115
unsigned char cap_height
...
Definition: Fonts.h:122
unsigned char index2_first
...
Definition: Fonts.h:113
unsigned char bits_delta
...
Definition: Fonts.h:120
const unsigned char * data
...
Definition: Fonts.h:108
unsigned char version
...
Definition: Fonts.h:109
unsigned char bits_xoffset
...
Definition: Fonts.h:118
Generic 2D Box [specializations iBox2 , fBox2, dBox2].
Definition: Box2.h:151
Generic 2D vector [specializations iVec2, fVec2, dVec2].
Definition: Vec2.h:64