Hi
I'd like to write a function to center a text on a given space on a display. I assume that I use the Adafruit_GFX library with custom fonts. The text should be centered horizontally at a given position (say x0, y0).
The text is stored in an array of chars.
To do this, I guess that I need to compute the number of pixels used when printing the text on the display. The width of a character can be found in the font file, but I don't understand how it is coded.
For example : I created using the Font Converter a font file called Arimo_Regular_12.h. Here are the first few letters:
// Created by http://oleddisplay.squix.ch/ Consider a donation
// In case of problems make sure that you are using the font file with the correct version!
const uint8_t Arimo_Regular_12Bitmaps[] PROGMEM = {
// Bitmap Data:
0x00, // ' '
0xFE,0x80, // '!'
0x55,0x50, // '"'
0x24,0x4B,0xF9,0x22,0x89,0x3F,0xA4,0x48, // '#'
0x10,0xF9,0x52,0x87,0x07,0x85,0x89,0xD6,0xF8,0x40, // '
After that comes:
const GFXglyph Arimo_Regular_12Glyphs[] PROGMEM = {
// bitmapOffset, width, height, xAdvance, xOffset, yOffset
{ 0, 1, 1, 4, 0, 0 }, // ' '
{ 1, 1, 9, 4, 1, -9 }, // '!'
{ 3, 4, 3, 5, 0, -9 }, // '"'
{ 5, 7, 9, 8, 0, -9 }, // '#'
{ 13, 7, 11, 8, 0, -10 }, // '
And finally:
const GFXfont Arimo_Regular_12 PROGMEM = {
(uint8_t *)Arimo_Regular_12Bitmaps,(GFXglyph *)Arimo_Regular_12Glyphs,0x20, 0x7E, 14};
Can anyone explain to me how the letters are encoded, and how many empty pixels are used between two adjacent letters?
Thanks for your help...
0x71,0x12,0x22,0x48,0x49,0x07,0x5C,0x12,0x42,0x48,0x89,0x11,0xC0, // '%'
0x18,0x24,0x24,0x38,0x72,0x52,0x8C,0x44,0x7B, // '&'
After that comes:
§DISCOURSE_HOISTED_CODE_1§
And finally:
§DISCOURSE_HOISTED_CODE_2§
Can anyone explain to me how the letters are encoded, and how many empty pixels are used between two adjacent letters?
Thanks for your help...
{ 23, 11, 9, 12, 0, -9 }, // '%'
{ 36, 8, 9, 9, 0, -9 }, // '&'
And finally:
§_DISCOURSE_HOISTED_CODE_2_§
Can anyone explain to me how the letters are encoded, and how many empty pixels are used between two adjacent letters?
Thanks for your help...
0x71,0x12,0x22,0x48,0x49,0x07,0x5C,0x12,0x42,0x48,0x89,0x11,0xC0, // '%'
0x18,0x24,0x24,0x38,0x72,0x52,0x8C,0x44,0x7B, // '&'
After that comes:
§DISCOURSE_HOISTED_CODE_1§
And finally:
§DISCOURSE_HOISTED_CODE_2§
Can anyone explain to me how the letters are encoded, and how many empty pixels are used between two adjacent letters?
Thanks for your help...