Skip to content

Commit

Permalink
[fonts] make m_cellHeight actually reference the cell height, and hav…
Browse files Browse the repository at this point in the history
…e the padded version be generated by a function
  • Loading branch information
Jonathan Marshall committed Oct 31, 2012
1 parent fcc1090 commit dbd786f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
20 changes: 12 additions & 8 deletions xbmc/guilib/GUIFontTTF.cpp
Expand Up @@ -196,7 +196,7 @@ void CGUIFontTTFBase::ClearCharacterCache()
m_maxChars = CHAR_CHUNK;
// set the posX and posY so that our texture will be created on first character write.
m_posX = m_textureWidth;
m_posY = -(int)m_cellHeight;
m_posY = -(int)GetTextureLineHeight();
m_textureHeight = 0;
}

Expand Down Expand Up @@ -267,7 +267,6 @@ bool CGUIFontTTFBase::Load(const CStdString& strFilename, float height, float as

// increment for good measure to give space in our texture
m_cellWidth++;
m_cellHeight+=2;
m_cellBaseLine++;

// CLog::Log(LOGDEBUG, "%s Scaled size of font %s (%f): width = %i, height = %i, lineheight = %li",
Expand Down Expand Up @@ -295,7 +294,7 @@ bool CGUIFontTTFBase::Load(const CStdString& strFilename, float height, float as

// set the posX and posY so that our texture will be created on first character write.
m_posX = m_textureWidth;
m_posY = -(int)m_cellHeight;
m_posY = -(int)GetTextureLineHeight();

// cache the ellipses width
Character *ellipse = GetCharacter(L'.');
Expand Down Expand Up @@ -326,7 +325,7 @@ void CGUIFontTTFBase::DrawTextInternal(float x, float y, const vecColors &colors

// calculate sizing information
float startX = 0;
float startY = (alignment & XBFONT_CENTER_Y) ? -0.5f*(m_cellHeight-2) : 0; // vertical centering
float startY = (alignment & XBFONT_CENTER_Y) ? -0.5f*m_cellHeight : 0; // vertical centering

if ( alignment & (XBFONT_RIGHT | XBFONT_CENTER_X) )
{
Expand Down Expand Up @@ -433,7 +432,7 @@ float CGUIFontTTFBase::GetCharWidthInternal(character_t ch)

float CGUIFontTTFBase::GetTextHeight(float lineSpacing, int numLines) const
{
return (float)(numLines - 1) * GetLineHeight(lineSpacing) + (m_cellHeight - 2); // -2 as we increment this for space in our texture
return (float)(numLines - 1) * GetLineHeight(lineSpacing) + m_cellHeight;
}

float CGUIFontTTFBase::GetLineHeight(float lineSpacing) const
Expand All @@ -443,6 +442,11 @@ float CGUIFontTTFBase::GetLineHeight(float lineSpacing) const
return 0.0f;
}

unsigned int CGUIFontTTFBase::GetTextureLineHeight() const
{
return m_cellHeight + 2;
}

CGUIFontTTFBase::Character* CGUIFontTTFBase::GetCharacter(character_t chr)
{
wchar_t letter = (wchar_t)(chr & 0xffff);
Expand Down Expand Up @@ -570,14 +574,14 @@ bool CGUIFontTTFBase::CacheCharacter(wchar_t letter, uint32_t style, Character *
if (m_posX + bitGlyph->left + bitmap.width > (int)m_textureWidth)
{ // no space - gotta drop to the next line (which means creating a new texture and copying it across)
m_posX = 0;
m_posY += m_cellHeight;
m_posY += GetTextureLineHeight();
if (bitGlyph->left < 0)
m_posX += -bitGlyph->left;

if(m_posY + m_cellHeight >= m_textureHeight)
if(m_posY + GetTextureLineHeight() >= m_textureHeight)
{
// create the new larger texture
unsigned int newHeight = m_posY + m_cellHeight;
unsigned int newHeight = m_posY + GetTextureLineHeight();
// check for max height
if (newHeight > g_Windowing.GetMaxTextureSize())
{
Expand Down
5 changes: 5 additions & 0 deletions xbmc/guilib/GUIFontTTF.h
Expand Up @@ -126,6 +126,11 @@ class CGUIFontTTFBase
int m_posX; // current position in the texture
int m_posY;

/*! \brief the height of each line in the texture.
Accounts for spacing between lines to avoid characters overlapping.
*/
unsigned int GetTextureLineHeight() const;

color_t m_color;

Character *m_char; // our characters
Expand Down

0 comments on commit dbd786f

Please sign in to comment.