Skip to content

Commit

Permalink
support proper kerning of fonts
Browse files Browse the repository at this point in the history
git-svn-id: https://xbmc.svn.sourceforge.net/svnroot/xbmc/trunk@23267 568bbfeb-2a22-0410-94d2-cc84cf5bfa90
  • Loading branch information
yuvalt committed Sep 30, 2009
1 parent 09cdd29 commit 8928a67
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
13 changes: 13 additions & 0 deletions guilib/GUIFontTTF.cpp
Expand Up @@ -344,6 +344,9 @@ void CGUIFontTTFBase::DrawTextInternal(float x, float y, const vecColors &colors
}
float cursorX = 0; // current position along the line

Character* previousCh = NULL;
FT_Vector delta;

for (vecText::const_iterator pos = text.begin(); pos != text.end(); pos++)
{
// If starting text on a new line, determine justification effects
Expand Down Expand Up @@ -379,6 +382,13 @@ void CGUIFontTTFBase::DrawTextInternal(float x, float y, const vecColors &colors
else if (maxPixelWidth > 0 && cursorX > maxPixelWidth)
break; // exceeded max allowed width - stop rendering

if (previousCh)
{
FT_Get_Kerning(m_face, previousCh->glyphIndex, ch->glyphIndex,
FT_KERNING_DEFAULT, &delta);
cursorX += (float) (delta.x / 64);
}

RenderCharacter(startX + cursorX, startY, ch, color, !scrolling);
if ( alignment & XBFONT_JUSTIFIED )
{
Expand All @@ -389,6 +399,8 @@ void CGUIFontTTFBase::DrawTextInternal(float x, float y, const vecColors &colors
}
else
cursorX += ch->advance;

previousCh = ch;
}

End();
Expand Down Expand Up @@ -586,6 +598,7 @@ bool CGUIFontTTFBase::CacheCharacter(wchar_t letter, uint32_t style, Character *
ch->right = ch->left + bitmap.width;
ch->bottom = ch->top + bitmap.rows;
ch->advance = (float)MathUtils::round_int( (float)m_face->glyph->advance.x / 64 );
ch->glyphIndex = glyph_index;

// we need only render if we actually have some pixels
if (bitmap.width * bitmap.rows)
Expand Down
1 change: 1 addition & 0 deletions guilib/GUIFontTTF.h
Expand Up @@ -84,6 +84,7 @@ class CGUIFontTTFBase
float left, top, right, bottom;
float advance;
character_t letterAndStyle;
int glyphIndex;
};
void AddReference();
void RemoveReference();
Expand Down

0 comments on commit 8928a67

Please sign in to comment.