Adafruit_GFX space between characters

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...

xAdvance

You can use the regular getTextBounds() method to calculate the extent of your text.
Use this to create rightAligned or centerAligned text.

David.

That was soooo easy, thanks David. BTW, why didn't they add such a function in the library?

What do you mean?
Adafruit_GFX class contains many useful methods.

Note that Adafruit_GFX comes with several other classes that people do not notice
e.g. Adafruit_GFX_Button, GFXcanvas1, GFXcanvas8, GFXcanvas16, GFXfont

The snidey addition is Adafruit_SPITFT class.

There are many issues when it comes to rendering text and different Fonts.

David.

I mean: why didn't they add a function to center a text at a given location of a display?

It is simple enough to create your own alignment functions.

GFX provides "brain-dead" text functions i.e. they simply plot pixel by pixel.

I and other hardware library authors could render the text in hardware. It would be massively faster.
Marek and Bodmer both provide many text features. Some of which are not available from GFX.

But I am pretty certain that if GFX-style libraries altered/extended the GFX text, it would unleash unparalleled whingeing. Hence my reluctance.

Anyway, it would be unnoticeable for most apps. After all, you draw the bulk of any screen as a one-off.
With small fields that might be updated regularly.

David.