• Advertisement

• ### Popular Now

• 10
• 12
• 12
• 14
• 17
• Advertisement
• Advertisement
• Advertisement

# Bizarre character spacing issues with Freetype

This topic is 436 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

## Recommended Posts

Hi Everyone,

I'm trying to render text using OpenGL and the Freetype library. Text rendering is working fine except for one thing. Every now and then, a character is spaced incorrectly:

Above you can see the 'j' in jumps is clashing with the 'u'. I've tried different fonts, but they also produce odd spacing errors:

In that case, the 'p' in jumps and 'g' in dog isn't spaced correctly either.

the way I create the horizontal offsets for characters in the final texture is by using the advance.x property on the resulting glyph and adding any kerning values for the character:

//first get kerning if we're passed the first character and this font has kerning
if ((i >= 1) && (Font->HasKerning == true))
{
FT_Get_Kerning(FontFace, PreviousGlyph, CurrentGlyph, FT_KERNING_DEFAULT, &KerningVector);
HorizontalOffset += KerningVector.x >> 6;
}

/* This is where the pixels are copied from the glyph into the texture */
/* HorizontalOffset is the 'X' value starting point for the new glyph */

//now that we're done copying over the pixel data, we update the Offset based on the glyphs advance
HorizontalOffset += FontFace->glyph->advance.x >> 6


On closer inspection, I noticed the advance.x value for the character 'j' for the font in the first image is much smaller than the other characters, 13 as opposed to the average of +-28. I believe that is the cause of the 'u' overwriting it. If I open both font's in the windows font viewer, they render correctly, they also render correctly in GIMP. It seems to be only my application thats rendering them incorrectly

My question is, how should I go about fixing this issue? Is there something I'm missing here?

Thanks.

#### Share this post

##### Share on other sites
Advertisement

Are you respecting bearingX in the freetype metrics?

In your first image the space between the x and the j looks too large, I suspect you're ignoring a negative bearingX which would make the tail of the j almost hang under the x.

#### Share this post

##### Share on other sites

Are you respecting bearingX in the freetype metrics?

In your first image the space between the x and the j looks too large, I suspect you're ignoring a negative bearingX which would make the tail of the j almost hang under the x.

Damn, good show! You are correct, I wasn't taking the horizontal bearing into consideration! That fixed it:

Thank you very much!

#### Share this post

##### Share on other sites

• Advertisement