-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFont.h
140 lines (120 loc) · 4.92 KB
/
Font.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// Font.h
#ifndef _FONT_h
#define _FONT_h
#if defined(ARDUINO) && ARDUINO >= 100
#include "arduino.h"
#else
#include "WProgram.h"
#endif
#include <fontStruct.h>
/**********************************************************************
* Font Class
**********************************************************************
* Description: The Font class simplifies the use of fonts stored in
* flash. It includes methods to access the font data in
* SRAM.
*
* By storing font data in flash on an Arduino, we can
* free up valuable SRAM. This class allows SRAM access to
* the flash data without needing to copy the entire font
* data into SRAM.
*
* Author: Baron Williams
**********************************************************************/
class Font {
public:
/**********************************************************************
* public byte Font::Font
**********************************************************************
* Description: Constructs a new Font class.
* Sets the font data encapsulated by the font class.
* The font must be stored in flash and specified using
* the fontStruct data type.
*
* Author: Baron Williams
**********************************************************************/
Font ( const fontStruct & fontPROGMEM );
/**********************************************************************
* public byte Font::Font
**********************************************************************
* Description: Constructs a new empty Font class with no associated
* font data.
*
* Use SetData to load font data into the class.
*
* Author: Baron Williams
**********************************************************************/
Font ();
/**********************************************************************
* public byte Font::SetData
**********************************************************************
* Description: Sets the font data encapsulated by the font class.
* The font must be stored in flash and specified using
* the fontStruct data type.
*
* Author: Baron Williams
**********************************************************************/
void SetData ( const fontStruct & fontPROGMEM );
/**********************************************************************
* public byte Font::GetBitmapByte
**********************************************************************
* Description: Returns a byte in SRAM from the font's bitmap data in
* flash. The bitmap byte returned is specified by giving
* the bitmap byte index. Index 0 is the first byte of
* bitmap data used to represent all characters.
*
* Author: Baron Williams
*
* Returns: byte in SRAM from the font's bitmap stored in flash.
**********************************************************************/
byte GetBitmapByte ( int bitmapIndex ) { return GetBitmapByte ( data, bitmapIndex ); }
/**********************************************************************
* public byte Font::GetBitmapByte
**********************************************************************
* Description: Returns a byte in SRAM from the font's bitmap data in
* flash. The bitmap byte returned is specified by giving
* the character and it's bitmap byte index. Index 0 is
* the first byte of bitmap data used to represent the
* character.
*
* Author: Baron Williams
*
* Returns: byte in SRAM from the font's bitmap stored in flash.
**********************************************************************/
byte GetBitmapByte ( int character, int bitmapIndex ) { return GetBitmapByte ( data, character, bitmapIndex ); }
/**********************************************************************
* public byte Font::Start
**********************************************************************
* Description: Returns the first valid character for a font
*
*
* Author: Baron Williams
*
* Returns: byte
**********************************************************************/
byte Start () { return data.start; }
/**********************************************************************
* public byte Font::End
**********************************************************************
* Description: Returns the last valid character for a font
*
*
* Author: Baron Williams
*
* Returns: byte
**********************************************************************/
byte End () { return data.end; }
fontStruct data;
Font & operator=(const Font &newFont);
private:
static void ToRAM ( const fontStruct & fontPROGMEM, fontStruct & fontRAM ){
memcpy_P(&fontRAM, &fontPROGMEM, sizeof(fontStruct));
};
static byte GetBitmapByte ( fontStruct & fontRAM, int index ){
return pgm_read_byte_near(fontRAM.bitmap+index);
};
static byte GetBitmapByte ( fontStruct & fontRAM, int character, int bitmapIndex ){
return pgm_read_byte_near(fontRAM.bitmap+((character-fontRAM.start)*fontRAM.width)+bitmapIndex);
};
};
#endif // _FONT_h