-
Notifications
You must be signed in to change notification settings - Fork 33
5.Font Header File Layout
All the example font header files I have provided on my GitHub are declared as a const uint8_t [] array. Following this method will ensure that your font data is placed in Program/ROM memory which is usually much larger than RAM. The first four values of this array control how the remainder of it is interpreted. e.g.
const uint8_t RobotronFontData[] = {
7, // Font Width
7, // Font Height
32, // Font First Character
96, // Font Last Character
...................
The Width is limited to <= 127 but the height can be up to 255. This is due to the FONT_PROPORTIONAL define which can be added to the Width to tell the class that the font is proportional. The next two values declare the first & last character codes.
Note If the last character is defined as >= 216 you will loose the ability to use some of the special character codes in your text array.
Following these four values is then the font data which will vary in length depending on these values.
To work out how many uint8_t's are needed for a character you should round up the width to the next multiple of 8, then divide it by 8, then multiply this by the height. So in the above example this would be 7 uint8_t's per character.
Note The character data is left justified within the uint8_t's so for example, if your font width is 12, all 8 bits of the first uint8_t are used but only the upper 4 bits of the next uint8_t are used.
When FONT_PROPORTIONAL is being used the first uint8_t of each character's data specifies the width for that character.
e.g.
const uint8_t FontP16x16Data[] = {
FONT_PROPORTIONAL | 16,
16,
32,
127,
8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
2,0xc0,0x00,0xc0,0x00,0xc0,0x00,0xc0,0x00,0xc0,0x00,0xc0,0x00,0xc0,0x00,0xc0,0x00,0x00,0x00,0x00,0x00,0xc0,0x00,0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
.............
To make hand coding of a font in the header file easier I have provided a few macros which can be used. These are B8(), B16() and B24() e.g.
B8(11111100) results in 252
B16(11111111, 11110000) results in 255, 240
B24(11111111, 11111111, 11111000) results in 255, 255, 248
The FontRobotron.h file is a good example of this method.