Skip to content

Commit

Permalink
Merge pull request xbmc#4740 from jmarshallnz/font_manager_cleanup
Browse files Browse the repository at this point in the history
Font manager cleanup
  • Loading branch information
jmarshallnz committed May 26, 2014
2 parents 84b4e50 + a379d95 commit 14850f6
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 281 deletions.
32 changes: 5 additions & 27 deletions xbmc/Application.cpp
Expand Up @@ -1948,19 +1948,7 @@ bool CApplication::LoadSkin(const SkinPtr& skin)
CLog::Log(LOGINFO, " load fonts for skin...");
g_graphicsContext.SetMediaDir(skin->Path());
g_directoryCache.ClearSubPaths(skin->Path());
if (g_langInfo.ForceUnicodeFont() && !g_fontManager.IsFontSetUnicode(CSettings::Get().GetString("lookandfeel.font")))
{
CLog::Log(LOGINFO, " language needs a ttf font, loading first ttf font available");
CStdString strFontSet;
if (g_fontManager.GetFirstFontSetUnicode(strFontSet))
{
CLog::Log(LOGINFO, " new font is '%s'", strFontSet.c_str());
CSettings::Get().SetString("lookandfeel.font", strFontSet);
CSettings::Get().Save();
}
else
CLog::Log(LOGERROR, " no ttf font found, but needed for the language %s.", CSettings::Get().GetString("locale.language").c_str());
}

g_colorManager.Load(CSettings::Get().GetString("lookandfeel.skincolors"));

g_fontManager.LoadFonts(CSettings::Get().GetString("lookandfeel.font"));
Expand Down Expand Up @@ -5822,25 +5810,15 @@ CPerformanceStats &CApplication::GetPerformanceStats()
bool CApplication::SetLanguage(const CStdString &strLanguage)
{
CStdString strPreviousLanguage = CSettings::Get().GetString("locale.language");
CStdString strNewLanguage = strLanguage;
if (strNewLanguage != strPreviousLanguage)
if (strLanguage != strPreviousLanguage)
{
CStdString strLangInfoPath = StringUtils::Format("special://xbmc/language/%s/langinfo.xml", strNewLanguage.c_str());
CStdString strLangInfoPath = StringUtils::Format("special://xbmc/language/%s/langinfo.xml", strLanguage.c_str());
if (!g_langInfo.Load(strLangInfoPath))
return false;

if (g_langInfo.ForceUnicodeFont() && !g_fontManager.IsFontSetUnicode())
{
CLog::Log(LOGINFO, "Language needs a ttf font, loading first ttf font available");
CStdString strFontSet;
if (g_fontManager.GetFirstFontSetUnicode(strFontSet))
strNewLanguage = strFontSet;
else
CLog::Log(LOGERROR, "No ttf font found but needed: %s", strFontSet.c_str());
}
CSettings::Get().SetString("locale.language", strNewLanguage);
CSettings::Get().SetString("locale.language", strLanguage);

if (!g_localizeStrings.Load("special://xbmc/language/", strNewLanguage))
if (!g_localizeStrings.Load("special://xbmc/language/", strLanguage))
return false;

// also tell our weather and skin to reload as these are localized
Expand Down
9 changes: 0 additions & 9 deletions xbmc/LangInfo.cpp
Expand Up @@ -24,7 +24,6 @@
#include "FileItem.h"
#include "Util.h"
#include "filesystem/Directory.h"
#include "guilib/GUIFontManager.h"
#include "guilib/LocalizeStrings.h"
#include "pvr/PVRManager.h"
#include "settings/AdvancedSettings.h"
Expand Down Expand Up @@ -449,14 +448,6 @@ bool CLangInfo::SetLanguage(const std::string &strLanguage)
if (!Load(strLangInfoPath))
return false;

if (ForceUnicodeFont() && !g_fontManager.IsFontSetUnicode())
{
CLog::Log(LOGINFO, "Language needs a ttf font, loading first ttf font available");
CStdString strFontSet;
if (!g_fontManager.GetFirstFontSetUnicode(strFontSet))
CLog::Log(LOGERROR, "No ttf font found but needed: %s", strFontSet.c_str());
}

if (!g_localizeStrings.Load("special://xbmc/language/", strLanguage))
return false;

Expand Down
55 changes: 18 additions & 37 deletions xbmc/addons/Skin.cpp
Expand Up @@ -317,7 +317,7 @@ void CSkinInfo::SettingOptionsSkinColorsFiller(const CSetting *setting, std::vec

void CSkinInfo::SettingOptionsSkinFontsFiller(const CSetting *setting, std::vector< std::pair<std::string, std::string> > &list, std::string &current, void *data)
{
CStdString settingValue = ((const CSettingString*)setting)->GetValue();
std::string settingValue = ((const CSettingString*)setting)->GetValue();
bool currentValueSet = false;
std::string strPath = g_SkinInfo->GetSkinPath("Font.xml");

Expand All @@ -328,52 +328,33 @@ void CSkinInfo::SettingOptionsSkinFontsFiller(const CSetting *setting, std::vect
return;
}

TiXmlElement* pRootElement = xmlDoc.RootElement();

std::string strValue = pRootElement->ValueStr();
if (strValue != "fonts")
const TiXmlElement* pRootElement = xmlDoc.RootElement();
if (!pRootElement || pRootElement->ValueStr() != "fonts")
{
CLog::Log(LOGERROR, "FillInSkinFonts: file %s doesn't start with <fonts>", strPath.c_str());
return;
}

const TiXmlNode *pChild = pRootElement->FirstChild();
strValue = pChild->ValueStr();
if (strValue == "fontset")
const TiXmlElement *pChild = pRootElement->FirstChildElement("fontset");
while (pChild)
{
while (pChild)
const char* idAttr = pChild->Attribute("id");
const char* idLocAttr = pChild->Attribute("idloc");
if (idAttr != NULL)
{
strValue = pChild->ValueStr();
if (strValue == "fontset")
{
const char* idAttr = ((TiXmlElement*) pChild)->Attribute("id");
const char* idLocAttr = ((TiXmlElement*) pChild)->Attribute("idloc");
const char* unicodeAttr = ((TiXmlElement*) pChild)->Attribute("unicode");

bool isUnicode = (unicodeAttr && stricmp(unicodeAttr, "true") == 0);

bool isAllowed = true;
if (g_langInfo.ForceUnicodeFont() && !isUnicode)
isAllowed = false;

if (idAttr != NULL && isAllowed)
{
if (idLocAttr)
list.push_back(make_pair(g_localizeStrings.Get(atoi(idLocAttr)), idAttr));
else
list.push_back(make_pair(idAttr, idAttr));

if (StringUtils::EqualsNoCase(idAttr, settingValue.c_str()))
currentValueSet = true;
}
}
if (idLocAttr)
list.push_back(make_pair(g_localizeStrings.Get(atoi(idLocAttr)), idAttr));
else
list.push_back(make_pair(idAttr, idAttr));

pChild = pChild->NextSibling();
if (StringUtils::EqualsNoCase(idAttr, settingValue))
currentValueSet = true;
}
pChild = pChild->NextSiblingElement("fontset");
}
else
{
// Since no fontset is defined, there is no selection of a fontset, so disable the component

if (list.empty())
{ // Since no fontset is defined, there is no selection of a fontset, so disable the component
list.push_back(make_pair(g_localizeStrings.Get(13278), ""));
current = "";
currentValueSet = true;
Expand Down
1 change: 0 additions & 1 deletion xbmc/epg/GUIEPGGridContainer.cpp
Expand Up @@ -21,7 +21,6 @@
#include "guilib/Key.h"
#include "guilib/GUIControlFactory.h"
#include "guilib/GUIListItem.h"
#include "guilib/GUIFontManager.h"
#include "guilib/LocalizeStrings.h"
#include "guilib/DirtyRegion.h"
#include <tinyxml.h>
Expand Down

0 comments on commit 14850f6

Please sign in to comment.