2009-02-10 18:37:48 +00:00
|
|
|
/*
|
|
|
|
Copyright (C) 2001 Kimmo Pekkola
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
2012-01-23 06:36:15 +00:00
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2009-02-10 18:37:48 +00:00
|
|
|
*/
|
|
|
|
|
2009-10-07 16:45:14 +00:00
|
|
|
#include "StdAfx.h"
|
2009-02-10 18:37:48 +00:00
|
|
|
#include "MeterString.h"
|
|
|
|
#include "Rainmeter.h"
|
|
|
|
#include "Measure.h"
|
|
|
|
#include "Error.h"
|
|
|
|
|
|
|
|
using namespace Gdiplus;
|
|
|
|
|
2011-02-18 16:26:58 +00:00
|
|
|
std::unordered_map<std::wstring, Gdiplus::FontFamily*> CMeterString::c_FontFamilies;
|
|
|
|
std::unordered_map<std::wstring, Gdiplus::Font*> CMeterString::c_Fonts;
|
2009-10-07 16:45:14 +00:00
|
|
|
|
2011-06-06 12:27:19 +00:00
|
|
|
#define PI (3.14159265f)
|
|
|
|
#define CONVERT_TO_DEGREES(X) ((X) * (180.0f / PI))
|
|
|
|
|
2010-11-05 03:25:21 +00:00
|
|
|
void StringToUpper(std::wstring& str)
|
|
|
|
{
|
2012-05-13 09:17:00 +00:00
|
|
|
WCHAR* srcAndDest = &str[0];
|
|
|
|
int strAndDestLen = (int)str.length();
|
|
|
|
LCMapString(LOCALE_USER_DEFAULT, LCMAP_UPPERCASE, srcAndDest, strAndDestLen, srcAndDest, strAndDestLen);
|
2010-11-05 03:25:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void StringToLower(std::wstring& str)
|
|
|
|
{
|
2012-05-13 09:17:00 +00:00
|
|
|
WCHAR* srcAndDest = &str[0];
|
|
|
|
int strAndDestLen = (int)str.length();
|
|
|
|
LCMapString(LOCALE_USER_DEFAULT, LCMAP_LOWERCASE, srcAndDest, strAndDestLen, srcAndDest, strAndDestLen);
|
2010-11-05 03:25:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void StringToProper(std::wstring& str)
|
|
|
|
{
|
|
|
|
if (!str.empty())
|
|
|
|
{
|
2012-05-13 09:30:20 +00:00
|
|
|
WCHAR* srcAndDest = &str[0];
|
|
|
|
LCMapString(LOCALE_USER_DEFAULT, LCMAP_UPPERCASE, srcAndDest, 1, srcAndDest, 1);
|
2010-11-05 03:25:21 +00:00
|
|
|
|
|
|
|
for (size_t i = 1; i < str.length(); ++i)
|
|
|
|
{
|
2012-05-13 09:30:20 +00:00
|
|
|
srcAndDest = &str[i];
|
2012-05-13 09:17:00 +00:00
|
|
|
LCMapString(LOCALE_USER_DEFAULT, (str[i - 1] == L' ') ? LCMAP_UPPERCASE : LCMAP_LOWERCASE, srcAndDest, 1, srcAndDest, 1);
|
2010-11-05 03:25:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-03-18 19:48:14 +00:00
|
|
|
|
2009-02-10 18:37:48 +00:00
|
|
|
/*
|
|
|
|
** The constructor
|
|
|
|
**
|
|
|
|
*/
|
2011-02-15 16:26:54 +00:00
|
|
|
CMeterString::CMeterString(CMeterWindow* meterWindow, const WCHAR* name) : CMeter(meterWindow, name),
|
2010-11-11 20:24:59 +00:00
|
|
|
m_Color(Color::White),
|
2011-01-29 00:11:01 +00:00
|
|
|
m_EffectColor(Color::Black),
|
|
|
|
m_AutoScale(AUTOSCALE_OFF),
|
|
|
|
m_Align(ALIGN_LEFT),
|
|
|
|
m_Style(NORMAL),
|
|
|
|
m_Effect(EFFECT_NONE),
|
|
|
|
m_textCase(TEXTCASE_NONE),
|
|
|
|
m_FontSize(10),
|
|
|
|
m_Scale(1.0),
|
|
|
|
m_NoDecimals(true),
|
|
|
|
m_Percentual(true),
|
|
|
|
m_ClipString(false),
|
|
|
|
m_Font(),
|
|
|
|
m_FontFamily(),
|
|
|
|
m_NumOfDecimals(-1),
|
|
|
|
m_Angle()
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** The destructor
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
CMeterString::~CMeterString()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Returns the X-coordinate of the meter
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
int CMeterString::GetX(bool abs)
|
|
|
|
{
|
|
|
|
int x = CMeter::GetX();
|
|
|
|
|
2011-03-29 19:21:57 +00:00
|
|
|
if (!abs)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2011-09-08 14:39:25 +00:00
|
|
|
switch (m_Align)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2012-05-16 18:02:31 +00:00
|
|
|
case ALIGN_CENTER: // Same as ALIGN_CENTERTOP
|
|
|
|
case ALIGN_CENTERBOTTOM:
|
|
|
|
case ALIGN_CENTERCENTER:
|
2011-11-10 13:44:19 +00:00
|
|
|
x -= m_W / 2;
|
2009-02-10 18:37:48 +00:00
|
|
|
break;
|
|
|
|
|
2012-05-16 18:02:31 +00:00
|
|
|
case ALIGN_RIGHT: // Same as ALIGN_RIGHTTOP
|
|
|
|
case ALIGN_RIGHTBOTTOM:
|
|
|
|
case ALIGN_RIGHTCENTER:
|
2009-02-10 18:37:48 +00:00
|
|
|
x -= m_W;
|
|
|
|
break;
|
|
|
|
|
2012-05-16 18:02:31 +00:00
|
|
|
case ALIGN_LEFT: // Same as ALIGN_LEFTTOP
|
|
|
|
case ALIGN_LEFTBOTTOM:
|
|
|
|
case ALIGN_LEFTCENTER:
|
2009-02-10 18:37:48 +00:00
|
|
|
// This is already correct
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
2012-05-16 18:02:31 +00:00
|
|
|
/*
|
|
|
|
** Returns the Y-coordinate of the meter
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
int CMeterString::GetY(bool abs)
|
|
|
|
{
|
|
|
|
int y = CMeter::GetY();
|
|
|
|
|
|
|
|
if (!abs)
|
|
|
|
{
|
|
|
|
switch (m_Align)
|
|
|
|
{
|
|
|
|
case ALIGN_LEFTCENTER:
|
|
|
|
case ALIGN_RIGHTCENTER:
|
|
|
|
case ALIGN_CENTERCENTER:
|
|
|
|
y -= m_H / 2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALIGN_LEFTBOTTOM:
|
|
|
|
case ALIGN_RIGHTBOTTOM:
|
|
|
|
case ALIGN_CENTERBOTTOM:
|
|
|
|
y -= m_H;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return y;
|
|
|
|
}
|
2009-02-10 18:37:48 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
** Create the font that is used to draw the text.
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
void CMeterString::Initialize()
|
|
|
|
{
|
|
|
|
CMeter::Initialize();
|
|
|
|
|
2009-10-07 16:45:14 +00:00
|
|
|
// Check if the font family is in the cache and use it
|
2011-01-17 22:39:40 +00:00
|
|
|
std::wstring cacheKey;
|
|
|
|
std::wstring systemFontFaceKey = FontFaceToString(m_FontFace, NULL);
|
2011-02-18 16:26:58 +00:00
|
|
|
std::unordered_map<std::wstring, Gdiplus::FontFamily*>::const_iterator iter = c_FontFamilies.find(systemFontFaceKey);
|
2009-10-07 16:45:14 +00:00
|
|
|
if (iter != c_FontFamilies.end())
|
|
|
|
{
|
|
|
|
m_FontFamily = (*iter).second;
|
2011-01-17 22:39:40 +00:00
|
|
|
cacheKey = systemFontFaceKey;
|
2009-10-07 16:45:14 +00:00
|
|
|
}
|
|
|
|
else
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2011-01-17 22:39:40 +00:00
|
|
|
m_FontFamily = NULL;
|
2009-09-03 00:33:46 +00:00
|
|
|
|
2011-01-17 22:39:40 +00:00
|
|
|
PrivateFontCollection* collection = m_MeterWindow->GetPrivateFontCollection();
|
|
|
|
std::wstring privateFontFaceKey;
|
|
|
|
|
|
|
|
if (collection)
|
2009-10-07 16:45:14 +00:00
|
|
|
{
|
2011-01-17 22:39:40 +00:00
|
|
|
// Check if the private font family is in the cache and use it
|
|
|
|
privateFontFaceKey = FontFaceToString(m_FontFace, collection);
|
|
|
|
iter = c_FontFamilies.find(privateFontFaceKey);
|
|
|
|
if (iter != c_FontFamilies.end())
|
|
|
|
{
|
|
|
|
m_FontFamily = (*iter).second;
|
|
|
|
cacheKey = privateFontFaceKey;
|
2009-10-07 16:45:14 +00:00
|
|
|
}
|
2009-09-03 00:33:46 +00:00
|
|
|
}
|
2009-10-07 16:45:14 +00:00
|
|
|
|
2011-01-17 22:39:40 +00:00
|
|
|
if (m_FontFamily == NULL) // Not found in the cache
|
2010-02-04 07:16:22 +00:00
|
|
|
{
|
2011-01-17 22:39:40 +00:00
|
|
|
m_FontFamily = new FontFamily(m_FontFace.c_str());
|
|
|
|
Status status = m_FontFamily->GetLastStatus();
|
|
|
|
|
|
|
|
if (Ok == status)
|
|
|
|
{
|
|
|
|
cacheKey = systemFontFaceKey;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
delete m_FontFamily;
|
|
|
|
|
|
|
|
// It couldn't find the font family
|
|
|
|
// Therefore we look in the privatefontcollection of this meters MeterWindow
|
|
|
|
if (collection)
|
|
|
|
{
|
|
|
|
m_FontFamily = new FontFamily(m_FontFace.c_str(), collection);
|
|
|
|
status = m_FontFamily->GetLastStatus();
|
|
|
|
|
|
|
|
if (Ok == status)
|
|
|
|
{
|
|
|
|
cacheKey = privateFontFaceKey;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_FontFamily = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// It couldn't find the font family: Log it.
|
|
|
|
if (Ok != status)
|
2011-03-29 19:21:57 +00:00
|
|
|
{
|
2012-04-06 16:54:20 +00:00
|
|
|
LogWithArgs(LOG_ERROR, L"String: Unable to load font: %s", m_FontFace.c_str());
|
2011-01-17 22:39:40 +00:00
|
|
|
|
|
|
|
delete m_FontFamily;
|
|
|
|
m_FontFamily = NULL;
|
|
|
|
|
|
|
|
cacheKey = L"<>"; // set dummy key
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_FontFamily)
|
|
|
|
{
|
|
|
|
// Cache
|
|
|
|
//LogWithArgs(LOG_DEBUG, L"FontFamilyCache-Add: %s", cacheKey.c_str());
|
|
|
|
c_FontFamilies[cacheKey] = m_FontFamily;
|
|
|
|
}
|
2010-02-04 07:16:22 +00:00
|
|
|
}
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
FontStyle style = FontStyleRegular;
|
|
|
|
|
2011-09-08 14:39:25 +00:00
|
|
|
switch (m_Style)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
|
|
|
case ITALIC:
|
|
|
|
style = FontStyleItalic;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BOLD:
|
|
|
|
style = FontStyleBold;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BOLDITALIC:
|
|
|
|
style = FontStyleBoldItalic;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Adjust the font size with screen DPI
|
2010-11-22 19:52:10 +00:00
|
|
|
HDC dc = GetDC(0);
|
2009-02-10 18:37:48 +00:00
|
|
|
int dpi = GetDeviceCaps(dc, LOGPIXELSX);
|
2010-11-22 19:52:10 +00:00
|
|
|
ReleaseDC(0, dc);
|
2009-02-10 18:37:48 +00:00
|
|
|
|
2009-02-14 10:11:28 +00:00
|
|
|
REAL size = (REAL)m_FontSize * (96.0f / (REAL)dpi);
|
2009-02-10 18:37:48 +00:00
|
|
|
|
2011-01-17 22:39:40 +00:00
|
|
|
// Check if the font is in the cache and use it
|
2011-12-04 22:18:40 +00:00
|
|
|
cacheKey += L'-';
|
2011-01-17 22:39:40 +00:00
|
|
|
cacheKey += FontPropertiesToString(size, style);
|
2011-02-18 16:26:58 +00:00
|
|
|
std::unordered_map<std::wstring, Gdiplus::Font*>::const_iterator iter2 = c_Fonts.find(cacheKey);
|
2009-10-07 16:45:14 +00:00
|
|
|
if (iter2 != c_Fonts.end())
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2009-10-07 16:45:14 +00:00
|
|
|
m_Font = (*iter2).second;
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-10-07 16:45:14 +00:00
|
|
|
if (m_FontFamily)
|
|
|
|
{
|
|
|
|
m_Font = new Gdiplus::Font(m_FontFamily, size, style);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-03-29 19:21:57 +00:00
|
|
|
m_Font = new Gdiplus::Font(FontFamily::GenericSansSerif (), size, style);
|
2009-10-07 16:45:14 +00:00
|
|
|
}
|
2009-02-10 18:37:48 +00:00
|
|
|
|
2009-10-11 13:03:20 +00:00
|
|
|
Status status = m_Font->GetLastStatus();
|
2010-02-04 07:16:22 +00:00
|
|
|
if (Ok == status)
|
2009-10-11 13:03:20 +00:00
|
|
|
{
|
2011-01-17 22:39:40 +00:00
|
|
|
// Cache
|
|
|
|
//LogWithArgs(LOG_DEBUG, L"FontCache-Add: %s", cacheKey.c_str());
|
|
|
|
c_Fonts[cacheKey] = m_Font;
|
2010-02-04 07:16:22 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
delete m_Font;
|
|
|
|
m_Font = NULL;
|
|
|
|
|
2010-02-08 14:12:47 +00:00
|
|
|
if (m_FontSize != 0)
|
2010-02-04 07:16:22 +00:00
|
|
|
{
|
2011-09-09 16:31:55 +00:00
|
|
|
std::wstring error = L"String: Unable to create font: " + m_FontFace;
|
2011-11-09 09:27:06 +00:00
|
|
|
throw CError(error);
|
2010-02-04 07:16:22 +00:00
|
|
|
}
|
2009-10-11 13:03:20 +00:00
|
|
|
}
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Read the meter-specific configs from the ini-file.
|
|
|
|
**
|
|
|
|
*/
|
2011-02-15 16:26:54 +00:00
|
|
|
void CMeterString::ReadConfig(CConfigParser& parser, const WCHAR* section)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2009-08-27 17:05:10 +00:00
|
|
|
// Store the current font values so we know if the font needs to be updated
|
|
|
|
std::wstring oldFontFace = m_FontFace;
|
|
|
|
int oldFontSize = m_FontSize;
|
|
|
|
TEXTSTYLE oldStyle = m_Style;
|
|
|
|
|
2009-02-10 18:37:48 +00:00
|
|
|
// Read common configs
|
2011-02-15 16:26:54 +00:00
|
|
|
CMeter::ReadConfig(parser, section);
|
2009-02-10 18:37:48 +00:00
|
|
|
|
|
|
|
// Check for extra measures
|
2010-12-04 15:07:28 +00:00
|
|
|
if (!m_Initialized && !m_MeasureName.empty())
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2010-12-05 15:34:37 +00:00
|
|
|
ReadMeasureNames(parser, section, m_MeasureNames);
|
2010-11-16 20:12:27 +00:00
|
|
|
}
|
2009-02-10 18:37:48 +00:00
|
|
|
|
2009-09-04 16:37:51 +00:00
|
|
|
m_Color = parser.ReadColor(section, L"FontColor", Color::Black);
|
|
|
|
m_EffectColor = parser.ReadColor(section, L"FontEffectColor", Color::Black);
|
2009-02-10 18:37:48 +00:00
|
|
|
|
2009-09-04 16:37:51 +00:00
|
|
|
m_Prefix = parser.ReadString(section, L"Prefix", L"");
|
|
|
|
m_Postfix = parser.ReadString(section, L"Postfix", L"");
|
|
|
|
m_Text = parser.ReadString(section, L"Text", L"");
|
2009-02-10 18:37:48 +00:00
|
|
|
|
2009-09-04 16:37:51 +00:00
|
|
|
m_Percentual = 0!=parser.ReadInt(section, L"Percentual", 0);
|
|
|
|
m_ClipString = 0!=parser.ReadInt(section, L"ClipString", 0);
|
2009-02-10 18:37:48 +00:00
|
|
|
|
2011-01-17 22:39:40 +00:00
|
|
|
m_FontFace = parser.ReadString(section, L"FontFace", L"Arial");
|
|
|
|
if (m_FontFace.empty())
|
|
|
|
{
|
|
|
|
m_FontFace = L"Arial";
|
|
|
|
}
|
2010-02-08 14:12:47 +00:00
|
|
|
|
2012-04-06 12:16:54 +00:00
|
|
|
m_FontSize = (int)parser.ReadFloat(section, L"FontSize", 10);
|
2010-02-08 14:12:47 +00:00
|
|
|
if (m_FontSize < 0)
|
|
|
|
{
|
|
|
|
m_FontSize = 10;
|
|
|
|
}
|
|
|
|
|
2009-09-04 16:37:51 +00:00
|
|
|
m_NumOfDecimals = parser.ReadInt(section, L"NumOfDecimals", -1);
|
2009-02-10 18:37:48 +00:00
|
|
|
|
2012-04-06 12:16:54 +00:00
|
|
|
m_Angle = (Gdiplus::REAL)parser.ReadFloat(section, L"Angle", 0.0);
|
2009-02-10 18:37:48 +00:00
|
|
|
|
2011-01-24 10:15:05 +00:00
|
|
|
const std::wstring& autoscale = parser.ReadString(section, L"AutoScale", L"0");
|
2011-01-19 15:31:45 +00:00
|
|
|
int autoscaleValue = _wtoi(autoscale.c_str());
|
|
|
|
if (autoscaleValue == 0)
|
|
|
|
{
|
|
|
|
m_AutoScale = AUTOSCALE_OFF;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (autoscale.find_last_of(L"kK") == std::wstring::npos)
|
|
|
|
{
|
|
|
|
m_AutoScale = (autoscaleValue == 2) ? AUTOSCALE_1000 : AUTOSCALE_1024;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_AutoScale = (autoscaleValue == 2) ? AUTOSCALE_1000K : AUTOSCALE_1024K;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-24 10:15:05 +00:00
|
|
|
const std::wstring& scale = parser.ReadString(section, L"Scale", L"1");
|
2012-04-06 12:16:54 +00:00
|
|
|
m_NoDecimals = (scale.find(L'.') == std::wstring::npos);
|
|
|
|
m_Scale = parser.ParseDouble(scale.c_str(), 1);
|
2009-02-10 18:37:48 +00:00
|
|
|
|
2011-11-16 16:47:20 +00:00
|
|
|
const WCHAR* align = parser.ReadString(section, L"StringAlign", L"LEFT").c_str();
|
2012-05-16 18:02:31 +00:00
|
|
|
if (_wcsicmp(align, L"LEFT") == 0 || _wcsicmp(align, L"LEFTTOP") == 0)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
|
|
|
m_Align = ALIGN_LEFT;
|
|
|
|
}
|
2012-05-16 18:02:31 +00:00
|
|
|
else if (_wcsicmp(align, L"RIGHT") == 0 || _wcsicmp(align, L"RIGHTTOP") == 0)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
|
|
|
m_Align = ALIGN_RIGHT;
|
|
|
|
}
|
2012-05-16 18:02:31 +00:00
|
|
|
else if (_wcsicmp(align, L"CENTER") == 0 || _wcsicmp(align, L"CENTERTOP") == 0)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
|
|
|
m_Align = ALIGN_CENTER;
|
|
|
|
}
|
2012-05-16 18:02:31 +00:00
|
|
|
else if (_wcsicmp(align, L"LEFTBOTTOM") == 0)
|
|
|
|
{
|
|
|
|
m_Align = ALIGN_LEFTBOTTOM;
|
|
|
|
}
|
|
|
|
else if (_wcsicmp(align, L"RIGHTBOTTOM") == 0)
|
|
|
|
{
|
|
|
|
m_Align = ALIGN_RIGHTBOTTOM;
|
|
|
|
}
|
|
|
|
else if (_wcsicmp(align, L"CENTERBOTTOM") == 0)
|
|
|
|
{
|
|
|
|
m_Align = ALIGN_CENTERBOTTOM;
|
|
|
|
}
|
|
|
|
else if (_wcsicmp(align, L"LEFTCENTER") == 0)
|
|
|
|
{
|
|
|
|
m_Align = ALIGN_LEFTCENTER;
|
|
|
|
}
|
|
|
|
else if (_wcsicmp(align, L"RIGHTCENTER") == 0)
|
|
|
|
{
|
|
|
|
m_Align = ALIGN_RIGHTCENTER;
|
|
|
|
}
|
|
|
|
else if (_wcsicmp(align, L"CENTERCENTER") == 0)
|
|
|
|
{
|
|
|
|
m_Align = ALIGN_CENTERCENTER;
|
|
|
|
}
|
2009-02-10 18:37:48 +00:00
|
|
|
else
|
|
|
|
{
|
2012-04-06 16:54:20 +00:00
|
|
|
LogWithArgs(LOG_ERROR, L"StringAlign=%s is not valid in [%s]", align, m_Name.c_str());
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
|
2011-11-16 16:47:20 +00:00
|
|
|
const WCHAR* stringCase = parser.ReadString(section, L"StringCase", L"NONE").c_str();
|
|
|
|
if (_wcsicmp(stringCase, L"NONE") == 0)
|
2010-03-18 19:48:14 +00:00
|
|
|
{
|
|
|
|
m_textCase = TEXTCASE_NONE;
|
|
|
|
}
|
2011-11-16 16:47:20 +00:00
|
|
|
else if (_wcsicmp(stringCase, L"UPPER") == 0)
|
2010-03-18 19:48:14 +00:00
|
|
|
{
|
|
|
|
m_textCase = TEXTCASE_UPPER;
|
|
|
|
}
|
2011-11-16 16:47:20 +00:00
|
|
|
else if (_wcsicmp(stringCase, L"LOWER") == 0)
|
2010-03-18 19:48:14 +00:00
|
|
|
{
|
|
|
|
m_textCase = TEXTCASE_LOWER;
|
|
|
|
}
|
2011-11-16 16:47:20 +00:00
|
|
|
else if (_wcsicmp(stringCase, L"PROPER") == 0)
|
2010-03-18 19:48:14 +00:00
|
|
|
{
|
|
|
|
m_textCase = TEXTCASE_PROPER;
|
|
|
|
}
|
2010-09-21 16:45:29 +00:00
|
|
|
else
|
|
|
|
{
|
2012-04-06 16:54:20 +00:00
|
|
|
LogWithArgs(LOG_ERROR, L"StringCase=%s is not valid in [%s]", stringCase, m_Name.c_str());
|
2010-09-21 16:45:29 +00:00
|
|
|
}
|
2010-03-18 19:48:14 +00:00
|
|
|
|
2011-11-16 16:47:20 +00:00
|
|
|
const WCHAR* style = parser.ReadString(section, L"StringStyle", L"NORMAL").c_str();
|
|
|
|
if (_wcsicmp(style, L"NORMAL") == 0)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
|
|
|
m_Style = NORMAL;
|
|
|
|
}
|
2011-11-16 16:47:20 +00:00
|
|
|
else if (_wcsicmp(style, L"BOLD") == 0)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
|
|
|
m_Style = BOLD;
|
|
|
|
}
|
2011-11-16 16:47:20 +00:00
|
|
|
else if (_wcsicmp(style, L"ITALIC") == 0)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
|
|
|
m_Style = ITALIC;
|
|
|
|
}
|
2011-11-16 16:47:20 +00:00
|
|
|
else if (_wcsicmp(style, L"BOLDITALIC") == 0)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
|
|
|
m_Style = BOLDITALIC;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-04-06 16:54:20 +00:00
|
|
|
LogWithArgs(LOG_ERROR, L"StringStyle=%s is not valid in [%s]", style, m_Name.c_str());
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
|
2011-11-16 16:47:20 +00:00
|
|
|
const WCHAR* effect = parser.ReadString(section, L"StringEffect", L"NONE").c_str();
|
|
|
|
if (_wcsicmp(effect, L"NONE") == 0)
|
2009-07-29 12:54:05 +00:00
|
|
|
{
|
|
|
|
m_Effect = EFFECT_NONE;
|
|
|
|
}
|
2011-11-16 16:47:20 +00:00
|
|
|
else if (_wcsicmp(effect, L"SHADOW") == 0)
|
2009-07-29 12:54:05 +00:00
|
|
|
{
|
|
|
|
m_Effect = EFFECT_SHADOW;
|
|
|
|
}
|
2011-11-16 16:47:20 +00:00
|
|
|
else if (_wcsicmp(effect, L"BORDER") == 0)
|
2009-07-29 12:54:05 +00:00
|
|
|
{
|
|
|
|
m_Effect = EFFECT_BORDER;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-04-06 16:54:20 +00:00
|
|
|
LogWithArgs(LOG_ERROR, L"StringEffect=%s is not valid in [%s]", effect, m_Name.c_str());
|
2009-07-29 12:54:05 +00:00
|
|
|
}
|
|
|
|
|
2009-08-27 17:05:10 +00:00
|
|
|
if (m_Initialized &&
|
2011-11-27 08:30:39 +00:00
|
|
|
(wcscmp(oldFontFace.c_str(), m_FontFace.c_str()) != 0 ||
|
2009-08-27 17:05:10 +00:00
|
|
|
oldFontSize != m_FontSize ||
|
|
|
|
oldStyle != m_Style))
|
|
|
|
{
|
|
|
|
Initialize(); // Recreate the font
|
|
|
|
}
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Updates the value(s) from the measures.
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
bool CMeterString::Update()
|
|
|
|
{
|
2010-02-08 14:12:47 +00:00
|
|
|
if (CMeter::Update())
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
|
|
|
std::vector<std::wstring> stringValues;
|
|
|
|
|
2011-01-19 15:31:45 +00:00
|
|
|
int decimals = (m_NumOfDecimals != -1) ? m_NumOfDecimals : (m_NoDecimals && (m_Percentual || m_AutoScale == AUTOSCALE_OFF)) ? 0 : 1;
|
2009-02-10 18:37:48 +00:00
|
|
|
|
|
|
|
if (m_Measure) stringValues.push_back(m_Measure->GetStringValue(m_AutoScale, m_Scale, decimals, m_Percentual));
|
|
|
|
|
|
|
|
// Get the values for the other measures
|
2011-11-08 10:32:57 +00:00
|
|
|
std::vector<CMeasure*>::const_iterator iter = m_Measures.begin();
|
|
|
|
for ( ; iter != m_Measures.end(); ++iter)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2011-11-08 10:32:57 +00:00
|
|
|
stringValues.push_back((*iter)->GetStringValue(m_AutoScale, m_Scale, decimals, m_Percentual));
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Create the text
|
|
|
|
m_String = m_Prefix;
|
|
|
|
if (m_Text.empty())
|
|
|
|
{
|
2011-02-15 13:22:19 +00:00
|
|
|
if (!stringValues.empty())
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2011-03-29 19:21:57 +00:00
|
|
|
m_String += stringValues[0];
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
}
|
2010-11-19 07:33:58 +00:00
|
|
|
else if (!stringValues.empty())
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
|
|
|
std::wstring tmpText = m_Text;
|
2010-11-19 07:33:58 +00:00
|
|
|
ReplaceMeasures(stringValues, tmpText);
|
2009-02-10 18:37:48 +00:00
|
|
|
m_String += tmpText;
|
|
|
|
}
|
2010-11-19 07:33:58 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
m_String += m_Text;
|
|
|
|
}
|
2010-11-05 03:25:21 +00:00
|
|
|
if (!m_Postfix.empty()) m_String += m_Postfix;
|
2009-02-10 18:37:48 +00:00
|
|
|
|
2011-09-08 14:39:25 +00:00
|
|
|
switch (m_textCase)
|
2010-03-18 19:48:14 +00:00
|
|
|
{
|
|
|
|
case TEXTCASE_UPPER:
|
2010-11-05 03:25:21 +00:00
|
|
|
StringToUpper(m_String);
|
2010-03-18 19:48:14 +00:00
|
|
|
break;
|
|
|
|
case TEXTCASE_LOWER:
|
2010-11-05 03:25:21 +00:00
|
|
|
StringToLower(m_String);
|
2010-03-18 19:48:14 +00:00
|
|
|
break;
|
|
|
|
case TEXTCASE_PROPER:
|
2010-11-05 03:25:21 +00:00
|
|
|
StringToProper(m_String);
|
2010-03-18 19:48:14 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-11-01 06:01:12 +00:00
|
|
|
if (!m_WDefined || !m_HDefined)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
|
|
|
// Calculate the text size
|
|
|
|
RectF rect;
|
2009-07-27 11:48:57 +00:00
|
|
|
Graphics graphics(m_MeterWindow->GetDoubleBuffer());
|
2010-02-08 14:12:47 +00:00
|
|
|
if (DrawString(graphics, &rect))
|
|
|
|
{
|
|
|
|
m_W = (int)rect.Width;
|
|
|
|
m_H = (int)rect.Height;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_W = 1;
|
|
|
|
m_H = 1;
|
|
|
|
}
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Draws the meter on the double buffer
|
|
|
|
**
|
|
|
|
*/
|
2009-07-27 11:48:57 +00:00
|
|
|
bool CMeterString::Draw(Graphics& graphics)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2011-03-29 19:21:57 +00:00
|
|
|
if (!CMeter::Draw(graphics)) return false;
|
2009-02-10 18:37:48 +00:00
|
|
|
|
2009-07-27 11:48:57 +00:00
|
|
|
return DrawString(graphics, NULL);
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Draws the string or calculates it's size
|
|
|
|
**
|
|
|
|
*/
|
2009-07-27 11:48:57 +00:00
|
|
|
bool CMeterString::DrawString(Graphics& graphics, RectF* rect)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2010-02-08 14:12:47 +00:00
|
|
|
if (m_Font == NULL) return false;
|
|
|
|
|
2011-06-06 12:27:19 +00:00
|
|
|
LPCWSTR string = m_String.c_str();
|
|
|
|
int stringLen = (int)m_String.length();
|
|
|
|
|
2009-02-10 18:37:48 +00:00
|
|
|
StringFormat stringFormat;
|
2011-03-29 19:21:57 +00:00
|
|
|
|
2009-02-10 18:37:48 +00:00
|
|
|
if (m_AntiAlias)
|
|
|
|
{
|
|
|
|
graphics.SetTextRenderingHint(TextRenderingHintAntiAlias);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
graphics.SetTextRenderingHint(TextRenderingHintSingleBitPerPixelGridFit);
|
|
|
|
}
|
|
|
|
|
2011-09-08 14:39:25 +00:00
|
|
|
switch (m_Align)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2012-05-16 18:02:31 +00:00
|
|
|
case ALIGN_CENTERCENTER:
|
|
|
|
stringFormat.SetAlignment(StringAlignmentCenter);
|
|
|
|
stringFormat.SetLineAlignment(StringAlignmentCenter);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALIGN_RIGHTCENTER:
|
|
|
|
stringFormat.SetAlignment(StringAlignmentFar);
|
|
|
|
stringFormat.SetLineAlignment(StringAlignmentCenter);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALIGN_LEFTCENTER:
|
|
|
|
stringFormat.SetAlignment(StringAlignmentNear);
|
|
|
|
stringFormat.SetLineAlignment(StringAlignmentCenter);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALIGN_CENTERBOTTOM:
|
|
|
|
stringFormat.SetAlignment(StringAlignmentCenter);
|
|
|
|
stringFormat.SetLineAlignment(StringAlignmentFar);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALIGN_RIGHTBOTTOM:
|
|
|
|
stringFormat.SetAlignment(StringAlignmentFar);
|
|
|
|
stringFormat.SetLineAlignment(StringAlignmentFar);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALIGN_LEFTBOTTOM:
|
|
|
|
stringFormat.SetAlignment(StringAlignmentNear);
|
|
|
|
stringFormat.SetLineAlignment(StringAlignmentFar);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ALIGN_CENTER: // Same as CenterTop
|
2009-02-10 18:37:48 +00:00
|
|
|
stringFormat.SetAlignment(StringAlignmentCenter);
|
2012-05-16 18:02:31 +00:00
|
|
|
stringFormat.SetLineAlignment(StringAlignmentNear);
|
2009-02-10 18:37:48 +00:00
|
|
|
break;
|
|
|
|
|
2012-05-16 18:02:31 +00:00
|
|
|
case ALIGN_RIGHT: // Same as RightTop
|
2009-02-10 18:37:48 +00:00
|
|
|
stringFormat.SetAlignment(StringAlignmentFar);
|
2012-05-16 18:02:31 +00:00
|
|
|
stringFormat.SetLineAlignment(StringAlignmentNear);
|
2009-02-10 18:37:48 +00:00
|
|
|
break;
|
|
|
|
|
2012-05-16 18:02:31 +00:00
|
|
|
case ALIGN_LEFT: // Same as LeftTop
|
2009-02-10 18:37:48 +00:00
|
|
|
stringFormat.SetAlignment(StringAlignmentNear);
|
2012-05-16 18:02:31 +00:00
|
|
|
stringFormat.SetLineAlignment(StringAlignmentNear);
|
2009-02-10 18:37:48 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-11-05 03:25:21 +00:00
|
|
|
if (m_ClipString)
|
|
|
|
{
|
|
|
|
stringFormat.SetTrimming(StringTrimmingEllipsisCharacter);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
stringFormat.SetTrimming(StringTrimmingNone);
|
|
|
|
stringFormat.SetFormatFlags(StringFormatFlagsNoClip | StringFormatFlagsNoWrap);
|
|
|
|
}
|
|
|
|
|
2011-06-06 12:27:19 +00:00
|
|
|
CharacterRange range(0, stringLen);
|
2010-11-05 03:25:21 +00:00
|
|
|
stringFormat.SetMeasurableCharacterRanges(1, &range);
|
|
|
|
|
2009-02-14 10:11:28 +00:00
|
|
|
REAL x = (REAL)GetX();
|
|
|
|
REAL y = (REAL)GetY();
|
2009-02-10 18:37:48 +00:00
|
|
|
|
|
|
|
if (rect)
|
|
|
|
{
|
|
|
|
PointF pos(x, y);
|
2011-06-06 12:27:19 +00:00
|
|
|
graphics.MeasureString(string, stringLen, m_Font, pos, &stringFormat, rect);
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-06-06 12:27:19 +00:00
|
|
|
RectF rcDest(x, y, (REAL)m_W, (REAL)m_H);
|
|
|
|
m_Rect = rcDest;
|
2009-02-10 18:37:48 +00:00
|
|
|
|
2010-11-05 03:25:21 +00:00
|
|
|
if (m_Angle != 0.0f)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2010-11-05 03:25:21 +00:00
|
|
|
graphics.TranslateTransform((Gdiplus::REAL)CMeter::GetX(), y);
|
2011-06-06 12:27:19 +00:00
|
|
|
graphics.RotateTransform(CONVERT_TO_DEGREES(m_Angle));
|
2010-11-05 03:25:21 +00:00
|
|
|
graphics.TranslateTransform(-(Gdiplus::REAL)CMeter::GetX(), -y);
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
|
2011-11-01 04:56:46 +00:00
|
|
|
if (m_Effect != EFFECT_NONE)
|
2010-11-11 20:24:59 +00:00
|
|
|
{
|
|
|
|
SolidBrush solidBrush(m_EffectColor);
|
2011-06-06 12:27:19 +00:00
|
|
|
RectF rcEffect(rcDest);
|
|
|
|
|
|
|
|
if (m_Effect == EFFECT_SHADOW)
|
|
|
|
{
|
|
|
|
rcEffect.Offset(1, 1);
|
|
|
|
graphics.DrawString(string, stringLen, m_Font, rcEffect, &stringFormat, &solidBrush);
|
|
|
|
}
|
|
|
|
else //if (m_Effect == EFFECT_BORDER)
|
|
|
|
{
|
|
|
|
rcEffect.Offset(0, 1);
|
|
|
|
graphics.DrawString(string, stringLen, m_Font, rcEffect, &stringFormat, &solidBrush);
|
|
|
|
rcEffect.Offset(1, -1);
|
|
|
|
graphics.DrawString(string, stringLen, m_Font, rcEffect, &stringFormat, &solidBrush);
|
|
|
|
rcEffect.Offset(-1, -1);
|
|
|
|
graphics.DrawString(string, stringLen, m_Font, rcEffect, &stringFormat, &solidBrush);
|
|
|
|
rcEffect.Offset(-1, 1);
|
|
|
|
graphics.DrawString(string, stringLen, m_Font, rcEffect, &stringFormat, &solidBrush);
|
|
|
|
}
|
2009-07-29 12:54:05 +00:00
|
|
|
}
|
2011-03-29 19:21:57 +00:00
|
|
|
|
2009-07-29 12:54:05 +00:00
|
|
|
SolidBrush solidBrush(m_Color);
|
2011-06-06 12:27:19 +00:00
|
|
|
graphics.DrawString(string, stringLen, m_Font, rcDest, &stringFormat, &solidBrush);
|
2009-07-27 11:48:57 +00:00
|
|
|
|
2010-11-05 03:25:21 +00:00
|
|
|
if (m_Angle != 0.0f)
|
|
|
|
{
|
|
|
|
graphics.ResetTransform();
|
|
|
|
}
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Overridden method. The string meters need not to be bound on anything
|
|
|
|
**
|
|
|
|
*/
|
2010-11-19 07:33:58 +00:00
|
|
|
void CMeterString::BindMeasure(const std::list<CMeasure*>& measures)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
|
|
|
if (m_MeasureName.empty()) return; // Allow NULL measure binding
|
|
|
|
|
|
|
|
CMeter::BindMeasure(measures);
|
|
|
|
|
2010-03-30 22:37:05 +00:00
|
|
|
std::vector<std::wstring>::const_iterator j = m_MeasureNames.begin();
|
|
|
|
for (; j != m_MeasureNames.end(); ++j)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
|
|
|
// Go through the list and check it there is a secondary measures for us
|
2011-11-16 16:47:20 +00:00
|
|
|
const WCHAR* name = (*j).c_str();
|
2010-03-30 22:37:05 +00:00
|
|
|
std::list<CMeasure*>::const_iterator i = measures.begin();
|
2011-03-29 19:21:57 +00:00
|
|
|
for ( ; i != measures.end(); ++i)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
2011-11-16 16:47:20 +00:00
|
|
|
if (_wcsicmp((*i)->GetName(), name) == 0)
|
2009-02-10 18:37:48 +00:00
|
|
|
{
|
|
|
|
m_Measures.push_back(*i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i == measures.end())
|
|
|
|
{
|
2010-11-25 22:00:34 +00:00
|
|
|
std::wstring error = L"The meter [" + m_Name;
|
2010-11-25 15:34:49 +00:00
|
|
|
error += L"] cannot be bound with [";
|
|
|
|
error += (*j);
|
2011-11-09 09:27:06 +00:00
|
|
|
error += L"]";
|
|
|
|
throw CError(error);
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
|
|
|
}
|
2010-09-10 17:29:30 +00:00
|
|
|
CMeter::SetAllMeasures(m_Measures);
|
2009-02-10 18:37:48 +00:00
|
|
|
}
|
2009-10-07 16:45:14 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
** Static function which frees the font cache.
|
2011-01-31 19:57:59 +00:00
|
|
|
** If collection is not NULL, frees the private font cache.
|
2009-10-07 16:45:14 +00:00
|
|
|
**
|
|
|
|
*/
|
2011-01-17 22:39:40 +00:00
|
|
|
void CMeterString::FreeFontCache(PrivateFontCollection* collection)
|
2009-10-07 16:45:14 +00:00
|
|
|
{
|
2011-01-17 22:39:40 +00:00
|
|
|
std::wstring prefix;
|
|
|
|
|
|
|
|
if (collection)
|
2009-10-07 16:45:14 +00:00
|
|
|
{
|
2011-01-17 22:39:40 +00:00
|
|
|
WCHAR buffer[32];
|
2011-12-09 19:49:06 +00:00
|
|
|
size_t len = _snwprintf_s(buffer, _TRUNCATE, L"<%p>", collection);
|
|
|
|
|
|
|
|
prefix.assign(buffer, len);
|
2011-01-23 14:24:34 +00:00
|
|
|
StringToLower(prefix);
|
2009-10-07 16:45:14 +00:00
|
|
|
}
|
|
|
|
|
2011-02-18 16:26:58 +00:00
|
|
|
std::unordered_map<std::wstring, Gdiplus::Font*>::iterator iter2 = c_Fonts.begin();
|
2011-01-31 19:57:59 +00:00
|
|
|
while (iter2 != c_Fonts.end())
|
2009-10-07 16:45:14 +00:00
|
|
|
{
|
2011-01-31 19:57:59 +00:00
|
|
|
if (collection == NULL || wcsncmp((*iter2).first.c_str(), prefix.c_str(), prefix.length()) == 0)
|
2011-01-17 22:39:40 +00:00
|
|
|
{
|
|
|
|
//LogWithArgs(LOG_DEBUG, L"FontCache-Remove: %s", (*iter2).first.c_str());
|
|
|
|
delete (*iter2).second;
|
2011-01-31 19:57:59 +00:00
|
|
|
|
|
|
|
if (collection)
|
|
|
|
{
|
|
|
|
c_Fonts.erase(iter2++);
|
|
|
|
continue;
|
|
|
|
}
|
2011-01-17 22:39:40 +00:00
|
|
|
}
|
2011-01-31 19:57:59 +00:00
|
|
|
++iter2;
|
2011-01-17 22:39:40 +00:00
|
|
|
}
|
|
|
|
if (collection == NULL) c_Fonts.clear();
|
|
|
|
|
2011-02-18 16:26:58 +00:00
|
|
|
std::unordered_map<std::wstring, Gdiplus::FontFamily*>::iterator iter = c_FontFamilies.begin();
|
2011-01-31 19:57:59 +00:00
|
|
|
while (iter != c_FontFamilies.end())
|
2011-01-17 22:39:40 +00:00
|
|
|
{
|
2011-01-31 19:57:59 +00:00
|
|
|
if (collection == NULL || wcsncmp((*iter).first.c_str(), prefix.c_str(), prefix.length()) == 0)
|
2011-01-17 22:39:40 +00:00
|
|
|
{
|
|
|
|
//LogWithArgs(LOG_DEBUG, L"FontFamilyCache-Remove: %s", (*iter).first.c_str());
|
|
|
|
delete (*iter).second;
|
2011-01-31 19:57:59 +00:00
|
|
|
|
|
|
|
if (collection)
|
|
|
|
{
|
|
|
|
c_FontFamilies.erase(iter++);
|
|
|
|
continue;
|
|
|
|
}
|
2011-01-17 22:39:40 +00:00
|
|
|
}
|
2011-01-31 19:57:59 +00:00
|
|
|
++iter;
|
2009-10-07 16:45:14 +00:00
|
|
|
}
|
2011-01-17 22:39:40 +00:00
|
|
|
if (collection == NULL) c_FontFamilies.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Static helper to convert font name to a string so it can be used as a key for the cache map.
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
std::wstring CMeterString::FontFaceToString(const std::wstring& fontFace, PrivateFontCollection* collection)
|
|
|
|
{
|
|
|
|
WCHAR buffer[32];
|
2011-12-09 19:49:06 +00:00
|
|
|
size_t len = _snwprintf_s(buffer, _TRUNCATE, L"<%p>", collection);
|
|
|
|
|
|
|
|
std::wstring strTmp;
|
|
|
|
strTmp.reserve(len + fontFace.size());
|
|
|
|
strTmp.assign(buffer, len);
|
|
|
|
strTmp += fontFace;
|
2011-01-23 14:24:34 +00:00
|
|
|
StringToLower(strTmp);
|
2011-01-17 22:39:40 +00:00
|
|
|
return strTmp;
|
2009-10-07 16:45:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Static helper to convert font properties to a string so it can be used as a key for the cache map.
|
|
|
|
**
|
|
|
|
*/
|
2011-01-17 22:39:40 +00:00
|
|
|
std::wstring CMeterString::FontPropertiesToString(REAL size, FontStyle style)
|
2009-10-07 16:45:14 +00:00
|
|
|
{
|
2011-01-17 22:39:40 +00:00
|
|
|
WCHAR buffer[64];
|
2011-12-09 19:49:06 +00:00
|
|
|
size_t len = _snwprintf_s(buffer, _TRUNCATE, L"%.1f-%i", size, (int)style);
|
|
|
|
|
|
|
|
return std::wstring(buffer, len);
|
2009-10-07 16:45:14 +00:00
|
|
|
}
|
|
|
|
|
2010-03-20 19:40:30 +00:00
|
|
|
/*
|
|
|
|
** Static helper to log all installed font families.
|
|
|
|
**
|
|
|
|
*/
|
|
|
|
void CMeterString::EnumerateInstalledFontFamilies()
|
|
|
|
{
|
|
|
|
INT fontCount;
|
|
|
|
InstalledFontCollection fontCollection;
|
|
|
|
|
|
|
|
if (Ok == fontCollection.GetLastStatus())
|
|
|
|
{
|
|
|
|
fontCount = fontCollection.GetFamilyCount();
|
|
|
|
if (fontCount > 0)
|
|
|
|
{
|
|
|
|
INT fontFound;
|
|
|
|
|
|
|
|
FontFamily* fontFamilies = new FontFamily[fontCount];
|
|
|
|
|
|
|
|
if (Ok == fontCollection.GetFamilies(fontCount, fontFamilies, &fontFound))
|
|
|
|
{
|
|
|
|
std::wstring fonts;
|
2010-03-30 22:37:05 +00:00
|
|
|
for (INT i = 0; i < fontCount; ++i)
|
2010-03-20 19:40:30 +00:00
|
|
|
{
|
|
|
|
WCHAR familyName[LF_FACESIZE];
|
|
|
|
if (Ok == fontFamilies[i].GetFamilyName(familyName))
|
|
|
|
{
|
|
|
|
fonts += familyName;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fonts += L"***";
|
|
|
|
}
|
|
|
|
fonts += L", ";
|
|
|
|
}
|
2010-12-20 08:57:37 +00:00
|
|
|
Log(LOG_NOTICE, fonts.c_str());
|
2010-03-20 19:40:30 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-09-09 16:31:55 +00:00
|
|
|
Log(LOG_ERROR, L"Font enumeration: GetFamilies failed");
|
2010-03-20 19:40:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
delete [] fontFamilies;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-09-09 16:31:55 +00:00
|
|
|
Log(LOG_WARNING, L"No installed fonts");
|
2010-03-20 19:40:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-09-09 16:31:55 +00:00
|
|
|
Log(LOG_ERROR, L"Font enumeration: InstalledFontCollection failed");
|
2010-03-20 19:40:30 +00:00
|
|
|
}
|
2010-12-19 23:06:13 +00:00
|
|
|
}
|