Skip to content

Commit

Permalink
Merge pull request #8182 from HitcherUK/light_font
Browse files Browse the repository at this point in the history
Lets skins use a light font weight
  • Loading branch information
Paxxi committed Oct 10, 2015
2 parents 77a8f09 + fcd54c4 commit 9c5bdda
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 6 deletions.
9 changes: 5 additions & 4 deletions xbmc/guilib/GUIFont.h
Expand Up @@ -53,10 +53,11 @@ class CGUIFontTTFBase;
#define FONT_STYLE_NORMAL 0
#define FONT_STYLE_BOLD 1
#define FONT_STYLE_ITALICS 2
#define FONT_STYLE_UPPERCASE 4
#define FONT_STYLE_LOWERCASE 8
#define FONT_STYLE_CAPITALIZE 16
#define FONT_STYLE_MASK 0xFF
#define FONT_STYLE_LIGHT 4
#define FONT_STYLE_UPPERCASE 8
#define FONT_STYLE_LOWERCASE 16
#define FONT_STYLE_CAPITALIZE 32
#define FONT_STYLE_MASK 0xFF

class CScrollInfo
{
Expand Down
2 changes: 2 additions & 0 deletions xbmc/guilib/GUIFontManager.cpp
Expand Up @@ -441,6 +441,8 @@ void GUIFontManager::GetStyle(const TiXmlNode *fontNode, int &iStyle)
iStyle |= FONT_STYLE_LOWERCASE;
else if (*i == "capitalize")
iStyle |= FONT_STYLE_CAPITALIZE;
else if (*i == "lighten")
iStyle |= FONT_STYLE_LIGHT;
}
}
}
Expand Down
39 changes: 38 additions & 1 deletion xbmc/guilib/GUIFontTTF.cpp
Expand Up @@ -601,7 +601,7 @@ unsigned int CGUIFontTTFBase::GetTextureLineHeight() const
CGUIFontTTFBase::Character* CGUIFontTTFBase::GetCharacter(character_t chr)
{
wchar_t letter = (wchar_t)(chr & 0xffff);
character_t style = (chr & 0x3000000) >> 24;
character_t style = (chr & 0x7000000) >> 24;

// ignore linebreaks
if (letter == L'\r')
Expand Down Expand Up @@ -701,6 +701,9 @@ bool CGUIFontTTFBase::CacheCharacter(wchar_t letter, uint32_t style, Character *
// and italics if applicable
if (style & FONT_STYLE_ITALICS)
ObliqueGlyph(m_face->glyph);
// and light if applicable
if (style & FONT_STYLE_LIGHT)
LightenGlyph(m_face->glyph);
// grab the glyph
if (FT_Get_Glyph(m_face->glyph, &glyph))
{
Expand Down Expand Up @@ -996,5 +999,39 @@ void CGUIFontTTFBase::EmboldenGlyph(FT_GlyphSlot slot)
slot->metrics.vertBearingY += dy;
slot->metrics.vertAdvance += dy;
}

// Lighten code - original taken from freetype2 (ftsynth.c)
void CGUIFontTTFBase::LightenGlyph(FT_GlyphSlot slot)
{
if (slot->format != FT_GLYPH_FORMAT_OUTLINE)
return;

/* some reasonable strength */
FT_Pos strength = FT_MulFix(m_face->units_per_EM,
m_face->size->metrics.y_scale) / -48;

FT_BBox bbox_before, bbox_after;
FT_Outline_Get_CBox(&slot->outline, &bbox_before);
FT_Outline_Embolden(&slot->outline, strength); // ignore error
FT_Outline_Get_CBox(&slot->outline, &bbox_after);

FT_Pos dx = bbox_after.xMax - bbox_before.xMax;
FT_Pos dy = bbox_after.yMax - bbox_before.yMax;

if (slot->advance.x)
slot->advance.x += dx;

if (slot->advance.y)
slot->advance.y += dy;

slot->metrics.width += dx;
slot->metrics.height += dy;
slot->metrics.horiBearingY += dy;
slot->metrics.horiAdvance += dx;
slot->metrics.vertBearingX -= dx / 2;
slot->metrics.vertBearingY += dy;
slot->metrics.vertAdvance += dy;
}



3 changes: 2 additions & 1 deletion xbmc/guilib/GUIFontTTF.h
Expand Up @@ -139,6 +139,7 @@ class CGUIFontTTFBase

// modifying glyphs
void EmboldenGlyph(FT_GlyphSlot slot);
void LightenGlyph(FT_GlyphSlot slot);
static void ObliqueGlyph(FT_GlyphSlot slot);

CBaseTexture* m_texture; // texture that holds our rendered characters (8bit alpha only)
Expand All @@ -157,7 +158,7 @@ class CGUIFontTTFBase
color_t m_color;

Character *m_char; // our characters
Character *m_charquick[256*4]; // ascii chars (4 styles) here
Character *m_charquick[256*7]; // ascii chars (7 styles) here
int m_maxChars; // size of character array (can be incremented)
int m_numChars; // the current number of cached characters

Expand Down
7 changes: 7 additions & 0 deletions xbmc/guilib/GUITextLayout.cpp
Expand Up @@ -408,6 +408,13 @@ void CGUITextLayout::ParseText(const std::wstring &text, uint32_t defaultStyle,
(!on && (currentStyle & FONT_STYLE_CAPITALIZE))) // or matching start point
newStyle = FONT_STYLE_CAPITALIZE;
}
else if (text.compare(pos, 6, L"LIGHT]") == 0)
{
pos += 6;
if ((on && text.find(L"[/LIGHT]", pos) != std::string::npos) ||
(!on && (currentStyle & FONT_STYLE_LIGHT)))
newStyle = FONT_STYLE_LIGHT;
}
else if (text.compare(pos, 3, L"CR]") == 0 && on)
{
newLine = true;
Expand Down

0 comments on commit 9c5bdda

Please sign in to comment.