Correct way to add Custom Fonts? #2781
Unanswered
Bwanna
asked this question in
Q&A - Fonts
Replies: 1 comment 1 reply
-
The simplest way to add fonts is in the sketch. See example here: Alternatively you could add them to the TFT_eSPI library or another folder of your choice. If you add them to TFT_eSPI then they will be over-written if you install a different version. To add to TFT_eSPI, add the font file here: |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I've created a few Custom Fonts and am getting 'undefined' error msgs with PlatformIO. Just can't figure out what's missing and any assistance would be appreciated. Is there a step-by-step procedure for all that has to be done when adding a new font? My desire is to make this a global addition to the TFT library for general use with my sketches.
Please let me know if any other files should be checked/shown
THanks!
The key few files:
1. User_Custom_Fonts.h
`
// Custom "Adafruit" compatible font files can be added to the "TFT_eSPI/Fonts/Custom" folder
// Fonts in a suitable format can be created using a Squix blog web based tool here:
/*
https://blog.squix.org/2016/10/font-creator-now-creates-adafruit-gfx-fonts.html
*/
// Note: At the time of writing there is a last character code definition bug in the
// Squix font file format so do NOT try and print the tilda (~) symbol (ASCII 0x7E)
// Alternatively look at the end of the font header file and edit: 0x7E to read 0x7D
/* e.g. vvvv
(uint8_t *)Orbitron_Light_32Bitmaps,(GFXglyph *)Orbitron_Light_32Glyphs,0x20, 0x7D, 32};
^^^^
*/
// When font files are placed in the Custom folder (TFT_eSPI\Fonts\Custom) then they must
// also be #included here:
// The CF_OL24 etc are a shorthand reference, but this is not essential to use the fonts
#ifdef LOAD_GFXFF
// New custom font file #includes
#include <Fonts/Custom/Orbitron_Light_24.h> // CF_OL24
#include <Fonts/Custom/Orbitron_Light_32.h> // CF_OL32
#include <Fonts/Custom/Roboto_Thin_24.h> // CF_RT24
#include <Fonts/Custom/Satisfy_24.h> // CF_S24
#include <Fonts/Custom/Yellowtail_32.h> // CF_Y32
//These are the new custom fonts
#include <Fonts/Custom/FreeSansBold7pt7b.h>
#include <Fonts/Custom/FreeSansBold8pt7b.h>
#include <Fonts/Custom/FreeSansBold10pt7b.h>
#include <Fonts/Custom/FreeSansBold11pt7b.h>
#include <Fonts/Custom/FreeSansBold14pt7b.h>
#endif
// Shorthand references - any coding scheme can be used, here CF_ = Custom Font
// The #defines below MUST be added to sketches to use shorthand references, so
// they are only put here for reference and copy+paste purposes!
/*
#define CF_OL24 &Orbitron_Light_24
#define CF_OL32 &Orbitron_Light_32
#define CF_RT24 &Roboto_Thin_24
#define CF_S24 &Satisfy_24
#define CF_Y32 &Yellowtail_32
#define CFSB77 Fonts/Custom/FreeSansBold7pt7b.h>
#define CFSB87 Fonts/Custom/FreeSansBold8pt7b.h>
#define CFSB107 Fonts/Custom/FreeSansBold10pt7b.h>
#define CFSB117 Fonts/Custom/FreeSansBold11pt7b.h>
#define CFSB147 Fonts/Custom/FreeSansBold14pt7b.h>
*/
`
2. FreeSansBold7pt7b.h
`const uint8_t FreeSansBold7pt7bBitmaps[] PROGMEM = {
0x00, 0xFF, 0xA8, 0xF0, 0xDE, 0xE7, 0x20, 0x16, 0x36, 0x34, 0xFF, 0x24,
0x2C, 0xFE, 0xFE, 0x48, 0x48, 0x38, 0xFD, 0x5A, 0x87, 0x87, 0x85, 0xEB,
0x76, 0xF8, 0x40, 0x80, 0x30, 0x87, 0x88, 0xC9, 0x0C, 0x90, 0x7A, 0x00,
0x6E, 0x05, 0xF0, 0x93, 0x09, 0x31, 0x0E, 0x38, 0x3E, 0x1B, 0x0F, 0x03,
0x07, 0xDB, 0x3D, 0x9C, 0xCE, 0x3D, 0x80, 0xFA, 0x6B, 0x69, 0x24, 0x99,
0x32, 0x46, 0x62, 0x33, 0x33, 0x32, 0x64, 0xC0, 0x27, 0xCC, 0xA0, 0x30,
0xCF, 0xFF, 0x30, 0xC0, 0xF7, 0xFF, 0xF0, 0x12, 0x22, 0x24, 0x44, 0x08,
0x38, 0xF9, 0x9E, 0x3C, 0x78, 0xF1, 0xA3, 0x6E, 0x78, 0x13, 0xF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, 0xC1, 0x83, 0x00, 0x10, 0xF5, 0x9E, 0x3C, 0x38, 0xD9, 0xBD, 0x02,
0x04, 0x08, 0x0F, 0xEC, 0xCC, 0xCC, 0x10, 0xF9, 0x9B, 0x83, 0xE0, 0xF9,
0xBE, 0x66, 0xF6, 0x66, 0x66, 0x70, 0xCF, 0x3C, 0xF3, 0xCF, 0x3F, 0xC0,
0x46, 0xCD, 0x91, 0x63, 0xC7, 0x06, 0x00, 0xCC, 0xC9, 0xD9, 0xBB, 0x35,
0x47, 0xB8, 0x67, 0x0C, 0xE0, 0x6E, 0x78, 0xE0, 0xC3, 0xCD, 0x99, 0x80,
0xE6, 0xCD, 0x91, 0x63, 0xC7, 0x06, 0x0C, 0x30, 0xE0, 0x7C, 0x31, 0x8C,
0x63, 0xFF, 0xC0, 0x33, 0x22, 0x26, 0xE2, 0x22, 0x23, 0x30, 0xFF, 0xF8,
0xC6, 0x66, 0x66, 0x36, 0x66, 0x6E, 0xC0, 0xE6, 0x70 };
const GFXglyph FreeSansBold7pt7bGlyphs[] PROGMEM = {
{ 0, 1, 1, 4, 0, 0 }, // 0x20 ' '
{ 1, 2, 10, 5, 2, -9 }, // 0x21 '!'
{ 4, 5, 4, 7, 1, -9 }, // 0x22 '"'
{ 7, 8, 10, 8, 0, -9 }, // 0x23 '#'
{ 17, 7, 12, 8, 0, -9 }, // 0x24 '$'
{ 28, 12, 10, 12, 0, -9 }, // 0x25 '%'
{ 43, 9, 10, 10, 1, -9 }, // 0x26 '&'
{ 55, 2, 4, 3, 1, -9 }, // 0x27 '''
{ 56, 3, 13, 5, 1, -9 }, // 0x28 '('
{ 61, 4, 13, 5, 0, -9 }, // 0x29 ')'
{ 68, 5, 4, 5, 0, -9 }, // 0x2A '*'
{ 71, 6, 6, 8, 1, -5 }, // 0x2B '+'
{ 76, 2, 4, 4, 1, -1 }, // 0x2C ','
{ 77, 4, 2, 5, 0, -4 }, // 0x2D '-'
{ 78, 2, 2, 4, 1, -1 }, // 0x2E '.'
{ 79, 4, 10, 4, 0, -9 }, // 0x2F '/'
{ 84, 7, 10, 8, 0, -9 }, // 0x30 '0'
{ 93, 4, 10, 8, 1, -9 }, // 0x31 '1'
{ 98, 7, 10, 8, 0, -9 }, // 0x32 '2'
{ 107, 7, 10, 8, 0, -9 }, // 0x33 '3'
{ 116, 7, 10, 8, 0, -9 }, // 0x34 '4'
{ 125, 7, 10, 8, 0, -9 }, // 0x35 '5'
{ 134, 7, 10, 8, 0, -9 }, // 0x36 '6'
{ 143, 7, 10, 8, 0, -9 }, // 0x37 '7'
{ 152, 7, 10, 8, 0, -9 }, // 0x38 '8'
{ 161, 7, 10, 8, 0, -9 }, // 0x39 '9'
{ 170, 2, 7, 5, 2, -6 }, // 0x3A ':'
{ 172, 2, 9, 5, 2, -6 }, // 0x3B ';'
{ 175, 6, 7, 8, 1, -6 }, // 0x3C '<'
{ 181, 6, 5, 8, 1, -5 }, // 0x3D '='
{ 185, 6, 7, 8, 1, -6 }, // 0x3E '>'
{ 191, 7, 10, 8, 1, -9 }, // 0x3F '?'
{ 200, 13, 12, 13, 0, -9 }, // 0x40 '@'
{ 220, 10, 10, 10, 0, -9 }, // 0x41 'A'
{ 233, 8, 10, 10, 1, -9 }, // 0x42 'B'
{ 243, 8, 10, 10, 1, -9 }, // 0x43 'C'
{ 253, 8, 10, 10, 1, -9 }, // 0x44 'D'
{ 263, 8, 10, 9, 1, -9 }, // 0x45 'E'
{ 273, 7, 10, 8, 1, -9 }, // 0x46 'F'
{ 282, 9, 10, 11, 1, -9 }, // 0x47 'G'
{ 294, 8, 10, 10, 1, -9 }, // 0x48 'H'
{ 304, 2, 10, 4, 1, -9 }, // 0x49 'I'
{ 307, 7, 10, 8, 0, -9 }, // 0x4A 'J'
{ 316, 9, 10, 10, 1, -9 }, // 0x4B 'K'
{ 328, 7, 10, 8, 1, -9 }, // 0x4C 'L'
{ 337, 10, 10, 11, 1, -9 }, // 0x4D 'M'
{ 350, 8, 10, 10, 1, -9 }, // 0x4E 'N'
{ 360, 9, 10, 11, 1, -9 }, // 0x4F 'O'
{ 372, 8, 10, 9, 1, -9 }, // 0x50 'P'
{ 382, 9, 11, 11, 1, -9 }, // 0x51 'Q'
{ 395, 8, 10, 10, 1, -9 }, // 0x52 'R'
{ 405, 9, 10, 9, 0, -9 }, // 0x53 'S'
{ 417, 8, 10, 8, 0, -9 }, // 0x54 'T'
{ 427, 8, 10, 10, 1, -9 }, // 0x55 'U'
{ 437, 9, 10, 9, 0, -9 }, // 0x56 'V'
{ 449, 13, 10, 13, 0, -9 }, // 0x57 'W'
{ 466, 9, 10, 9, 0, -9 }, // 0x58 'X'
{ 478, 9, 10, 9, 0, -9 }, // 0x59 'Y'
{ 490, 8, 10, 8, 0, -9 }, // 0x5A 'Z'
{ 500, 3, 13, 5, 1, -9 }, // 0x5B '['
{ 505, 4, 10, 4, 0, -9 }, // 0x5C ''
{ 510, 4, 13, 5, 0, -9 }, // 0x5D ']'
{ 517, 6, 6, 8, 1, -9 }, // 0x5E '^'
{ 522, 8, 1, 8, 0, 3 }, // 0x5F '_'
{ 523, 3, 2, 5, 0, -9 }, // 0x60 '`'
{ 524, 7, 8, 8, 0, -7 }, // 0x61 'a'
{ 531, 7, 10, 8, 1, -9 }, // 0x62 'b'
{ 540, 7, 8, 8, 0, -7 }, // 0x63 'c'
{ 547, 7, 10, 8, 0, -9 }, // 0x64 'd'
{ 556, 7, 8, 8, 0, -7 }, // 0x65 'e'
{ 563, 4, 10, 5, 0, -9 }, // 0x66 'f'
{ 568, 7, 11, 8, 0, -7 }, // 0x67 'g'
{ 578, 6, 10, 8, 1, -9 }, // 0x68 'h'
{ 586, 2, 10, 4, 1, -9 }, // 0x69 'i'
{ 589, 3, 13, 4, 0, -9 }, // 0x6A 'j'
{ 594, 7, 10, 8, 1, -9 }, // 0x6B 'k'
{ 603, 2, 10, 4, 1, -9 }, // 0x6C 'l'
{ 606, 10, 8, 12, 1, -7 }, // 0x6D 'm'
{ 616, 6, 8, 8, 1, -7 }, // 0x6E 'n'
{ 622, 8, 8, 8, 0, -7 }, // 0x6F 'o'
{ 630, 7, 11, 8, 1, -7 }, // 0x70 'p'
{ 640, 7, 11, 8, 0, -7 }, // 0x71 'q'
{ 650, 4, 8, 5, 1, -7 }, // 0x72 'r'
{ 654, 7, 8, 8, 0, -7 }, // 0x73 's'
{ 661, 4, 9, 5, 0, -8 }, // 0x74 't'
{ 666, 6, 7, 8, 1, -6 }, // 0x75 'u'
{ 672, 7, 7, 8, 0, -6 }, // 0x76 'v'
{ 679, 11, 7, 11, 0, -6 }, // 0x77 'w'
{ 689, 7, 7, 8, 0, -6 }, // 0x78 'x'
{ 696, 7, 10, 8, 0, -6 }, // 0x79 'y'
{ 705, 6, 7, 7, 0, -6 }, // 0x7A 'z'
{ 711, 4, 13, 5, 0, -9 }, // 0x7B '{'
{ 718, 1, 13, 4, 1, -9 }, // 0x7C '|'
{ 720, 4, 13, 5, 1, -9 }, // 0x7D '}'
{ 727, 6, 2, 8, 1, -3 } }; // 0x7E '~'
const GFXfont FreeSansBold7pt7b PROGMEM = {
(uint8_t *)FreeSansBold7pt7bBitmaps,
(GFXglyph *)FreeSansBold7pt7bGlyphs,
0x20, 0x7E, 22 };
// Approx. 1401 bytes
`
3. TFT_eSPI.h (Shows the call to the above file)
#ifdef LOAD_GFXFF // We can include all the free fonts and they will only be built into // the sketch if they are used #include <Fonts/GFXFF/gfxfont.h> // Call up any user custom fonts #include <User_Setups/User_Custom_Fonts.h> #endif // #ifdef LOAD_GFXFF
Beta Was this translation helpful? Give feedback.
All reactions