Skip to content

Commit

Permalink
[PATCH] text rendering: dont change character spacing on justify, onl…
Browse files Browse the repository at this point in the history
…y word spacing
  • Loading branch information
tamland authored and popcornmix committed Jan 8, 2015
1 parent 28a6676 commit 224e3bf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
20 changes: 9 additions & 11 deletions xbmc/guilib/GUIFontTTF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ using namespace std;
#define CHARS_PER_TEXTURE_LINE 20 // number of characters to cache per texture line
#define CHAR_CHUNK 64 // 64 chars allocated at a time (1024 bytes)

int CGUIFontTTFBase::justification_word_weight = 6; // weight of word spacing over letter spacing when justifying.
// A larger number means more of the "dead space" is placed between
// words rather than between letters.

class CFreeTypeLibrary
{
Expand Down Expand Up @@ -421,23 +418,24 @@ void CGUIFontTTFBase::DrawTextInternal(float x, float y, const vecColors &colors
startX -= w;
}

float spacePerLetter = 0; // for justification effects
float spacePerSpaceCharacter = 0; // for justification effects
if ( alignment & XBFONT_JUSTIFIED )
{
// first compute the size of the text to render in both characters and pixels
unsigned int lineChars = 0;
unsigned int numSpaces = 0;
float linePixels = 0;
for (vecText::const_iterator pos = text.begin(); pos != text.end(); ++pos)
{
Character *ch = GetCharacter(*pos);
if (ch)
{ // spaces have multiple times the justification spacing of normal letters
lineChars += ((*pos & 0xffff) == L' ') ? justification_word_weight : 1;
{
if ((*pos & 0xffff) == L' ')
numSpaces += 1;
linePixels += ch->advance;
}
}
if (lineChars > 1)
spacePerLetter = (maxPixelWidth - linePixels) / (lineChars - 1);
if (numSpaces > 0)
spacePerSpaceCharacter = (maxPixelWidth - linePixels) / numSpaces;
}
float cursorX = 0; // current position along the line

Expand Down Expand Up @@ -480,9 +478,9 @@ void CGUIFontTTFBase::DrawTextInternal(float x, float y, const vecColors &colors
if ( alignment & XBFONT_JUSTIFIED )
{
if ((*pos & 0xffff) == L' ')
cursorX += ch->advance + spacePerLetter * justification_word_weight;
cursorX += ch->advance + spacePerSpaceCharacter;
else
cursorX += ch->advance + spacePerLetter;
cursorX += ch->advance;
}
else
cursorX += ch->advance;
Expand Down
2 changes: 0 additions & 2 deletions xbmc/guilib/GUIFontTTF.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,6 @@ class CGUIFontTTFBase
float m_textureScaleX;
float m_textureScaleY;

static int justification_word_weight;

std::string m_strFileName;
XUTILS::auto_buffer m_fontFileInMemory; // used only in some cases, see CFreeTypeLibrary::GetFont()

Expand Down

0 comments on commit 224e3bf

Please sign in to comment.