Why are fonts drawn slightly offset from the origin?

When you draw fonts with a call to drawString(), the resulting typography is always slightly offset to the right of the origin you pass it. Any idea why this is? Any way to calculate the width of this offset?

I think you are not considering the fact that the letter “H” has also a padding left and a padding right, as each of the letters of this font. The distance from your point(500, 500) and the beginning of the letter H is exactly the half of the distance between the letter H and E.

I see, is there any way to obtain the size of that padding so you can compensate for it?

you can get the bounding box of the text and it’s x will be that offset:

float offset = font.getBoundingBox("HELLO WORLD", 0, 0).x;
1 Like

Thanks @arturo, that works, although I discoverd the function call is actually getStringBoundingBox()

float offset = font.getStringBoundingBox("HELLO WORLD", 0, 0).x;