Arial font is now the default font when errors occur. Invalid string styles are now logged.

This commit is contained in:
Brian Ferguson 2012-09-26 00:45:53 -06:00
parent 71025aaf51
commit 6bd978ad21

View File

@ -224,7 +224,7 @@ void CMeterString::Initialize()
// It couldn't find the font family: Log it. // It couldn't find the font family: Log it.
if (Ok != status) if (Ok != status)
{ {
LogWithArgs(LOG_ERROR, L"String: Unable to load font: %s", m_FontFace.c_str()); LogWithArgs(LOG_ERROR, L"Unable to load font: %s", m_FontFace.c_str());
delete m_FontFamily; delete m_FontFamily;
m_FontFamily = NULL; m_FontFamily = NULL;
@ -266,6 +266,18 @@ void CMeterString::Initialize()
REAL size = (REAL)m_FontSize * (96.0f / (REAL)dpi); REAL size = (REAL)m_FontSize * (96.0f / (REAL)dpi);
// Set font defaults
FontFamily defaultFamily(L"Arial");
Gdiplus::Font* defaultFont;
if (defaultFamily.IsAvailable())
{
defaultFont = new Gdiplus::Font(&defaultFamily, size, style);
}
else
{
defaultFont = new Gdiplus::Font(FontFamily::GenericSansSerif(), size, style);
}
// Check if the font is in the cache and use it // Check if the font is in the cache and use it
cacheKey += L'-'; cacheKey += L'-';
cacheKey += FontPropertiesToString(size, style); cacheKey += FontPropertiesToString(size, style);
@ -282,17 +294,7 @@ void CMeterString::Initialize()
} }
else else
{ {
// Use Arial if installed, else use a generic font m_Font = defaultFont;
FontFamily fFamily(L"Arial");
if (fFamily.IsAvailable())
{
m_Font = new Gdiplus::Font(&fFamily, size, style);
}
else
{
m_Font = new Gdiplus::Font(FontFamily::GenericSansSerif(), size, style);
}
} }
Status status = m_Font->GetLastStatus(); Status status = m_Font->GetLastStatus();
@ -304,12 +306,15 @@ void CMeterString::Initialize()
} }
else else
{ {
delete m_Font; m_Font = defaultFont;
m_Font = NULL;
if (m_FontSize != 0) if (FontStyleNotFound == status)
{ {
LogWithArgs(LOG_ERROR, L"String: Invalid font: %s", m_FontFace.c_str()); LogWithArgs(LOG_ERROR, L"Invalid StringStyle for font: %s", m_FontFace.c_str());
}
else
{
LogWithArgs(LOG_ERROR, L"Invalid font: %s", m_FontFace.c_str());
} }
} }
} }