From 8928a671fb420425f8a211bc3de6ab2d1628c30d Mon Sep 17 00:00:00 2001 From: yuvalt Date: Wed, 30 Sep 2009 12:55:03 +0000 Subject: [PATCH] support proper kerning of fonts git-svn-id: https://xbmc.svn.sourceforge.net/svnroot/xbmc/trunk@23267 568bbfeb-2a22-0410-94d2-cc84cf5bfa90 --- guilib/GUIFontTTF.cpp | 13 +++++++++++++ guilib/GUIFontTTF.h | 1 + 2 files changed, 14 insertions(+) diff --git a/guilib/GUIFontTTF.cpp b/guilib/GUIFontTTF.cpp index 91dd551bcfbf3..65abaf59e6697 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) diff --git a/guilib/GUIFontTTF.h b/guilib/GUIFontTTF.h index 098fbe0c0abc3..c14466188739b 100644 --- a/guilib/GUIFontTTF.h +++ b/guilib/GUIFontTTF.h @@ -84,6 +84,7 @@ class CGUIFontTTFBase float left, top, right, bottom; float advance; character_t letterAndStyle; + int glyphIndex; }; void AddReference(); void RemoveReference();