Skip to content

Commit

Permalink
[kodi] light font test build
Browse files Browse the repository at this point in the history
  • Loading branch information
Hitcher committed Jul 12, 2015
1 parent 49a5109 commit 03d0b7f
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 3 deletions.
7 changes: 4 additions & 3 deletions xbmc/guilib/GUIFont.h
Expand Up @@ -53,9 +53,10 @@ 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_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 @@ -435,6 +435,8 @@ void GUIFontManager::GetStyle(const TiXmlNode *fontNode, int &iStyle)
iStyle |= FONT_STYLE_BOLD;
else if (*i == "italics")
iStyle |= FONT_STYLE_ITALICS;
else if (*i == "light")
iStyle |= FONT_STYLE_LIGHT;
else if (*i == "bolditalics") // backward compatibility
iStyle |= (FONT_STYLE_BOLD | FONT_STYLE_ITALICS);
else if (*i == "uppercase")
Expand Down
37 changes: 37 additions & 0 deletions xbmc/guilib/GUIFontTTF.cpp
Expand Up @@ -701,6 +701,9 @@ bool CGUIFontTTFBase::CacheCharacter(wchar_t letter, uint32_t style, Character *
// make bold if applicable
if (style & FONT_STYLE_BOLD)
EmboldenGlyph(m_face->glyph);
// make light if applicable
if (style & FONT_STYLE_LIGHT)
LightenGlyph(m_face->glyph);
// and italics if applicable
if (style & FONT_STYLE_ITALICS)
ObliqueGlyph(m_face->glyph);
Expand Down Expand Up @@ -995,3 +998,37 @@ void CGUIFontTTFBase::EmboldenGlyph(FT_GlyphSlot slot)
}


// Embolden 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;
}


1 change: 1 addition & 0 deletions 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 Down
7 changes: 7 additions & 0 deletions xbmc/guilib/GUITextLayout.cpp
Expand Up @@ -389,6 +389,13 @@ void CGUITextLayout::ParseText(const std::wstring &text, uint32_t defaultStyle,
(!on && (currentStyle & FONT_STYLE_ITALICS))) // or matching start point
newStyle = FONT_STYLE_ITALICS;
}
else if (text.compare(pos, 6, L"LIGHT]") == 0)
{ // italics
pos += 6;
if ((on && text.find(L"[/LIGHT]", pos) != std::string::npos) || // check for a matching end point
(!on && (currentStyle & FONT_STYLE_LIGHT))) // or matching start point
newStyle = FONT_STYLE_LIGHT;
}
else if (text.compare(pos, 10, L"UPPERCASE]") == 0)
{
pos += 10;
Expand Down

0 comments on commit 03d0b7f

Please sign in to comment.