aboutsummaryrefslogtreecommitdiff
path: root/guilib/GUIFontTTF.cpp
diff options
context:
space:
mode:
authoryuvalt <yuvalt@svn>2009-09-30 12:55:03 +0000
committeryuvalt <yuvalt@svn>2009-09-30 12:55:03 +0000
commit8928a671fb420425f8a211bc3de6ab2d1628c30d (patch)
tree07f64e777ca874949f9a3f07f035a191617a814e /guilib/GUIFontTTF.cpp
parent09cdd291730a04812443bfc25c07f13a0925a350 (diff)
support proper kerning of fonts
git-svn-id: https://xbmc.svn.sourceforge.net/svnroot/xbmc/trunk@23267 568bbfeb-2a22-0410-94d2-cc84cf5bfa90
Diffstat (limited to 'guilib/GUIFontTTF.cpp')
-rw-r--r--guilib/GUIFontTTF.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/guilib/GUIFontTTF.cpp b/guilib/GUIFontTTF.cpp
index 91dd551bcf..65abaf59e6 100644
--- a/guilib/GUIFontTTF.cpp
+++ b/guilib/GUIFontTTF.cpp
@@ -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
@@ -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 )
{
@@ -389,6 +399,8 @@ void CGUIFontTTFBase::DrawTextInternal(float x, float y, const vecColors &colors
}
else
cursorX += ch->advance;
+
+ previousCh = ch;
}
End();
@@ -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)