// AsFontInfo.cpp
//
#include "stdafx.h"
#include "AsFontInfo.h"
CAsFontInfo::CAsFontInfo():
fontName_("tahoma"),
fontSize_(8),
fontBold_(false),
font_(NULL),
updatePending_(true)
{}
CAsFontInfo::CAsFontInfo(const CAsFontInfo& fontInfo)
{
Copy(fontInfo);
}
CAsFontInfo::~CAsFontInfo()
{
ReleaseFont();
}
CAsFontInfo& CAsFontInfo::operator=(const CAsFontInfo& fontInfo)
{
Copy(fontInfo);
return *this;
}
void CAsFontInfo::SetFontName(const string& fontName)
{
fontName_ = fontName;
updatePending_ = true;
}
string CAsFontInfo::GetFontName() const
{
return fontName_;
}
void CAsFontInfo::SetFontSize(int fontSize)
{
fontSize_ = fontSize;
updatePending_ = true;
}
int CAsFontInfo::GetFontSize() const
{
return fontSize_;
}
void CAsFontInfo::SetFontBold(bool fontBold)
{
fontBold_ = fontBold;
updatePending_ = true;
}
bool CAsFontInfo::GetFontBold() const
{
return fontBold_;
}
void CAsFontInfo::Copy(const CAsFontInfo& fontInfo)
{
fontName_ = fontInfo.fontName_;
fontSize_ = fontInfo.fontSize_;
fontBold_ = fontInfo.fontBold_;
updatePending_ = true;
}
CFont* CAsFontInfo::CreateFont()
{
if (!updatePending_ && font_)
return font_;
ReleaseFont();
font_ = new CFont;
font_->CreateFont(-fontSize_,
0, /* width */
0, /* escapement */
0, /* orientation */
fontBold_ ? FW_BOLD : FW_NORMAL, /* weight*/
0, /* italic*/
0, /* underline */
0, /* strikeout */
ANSI_CHARSET, /* charset */
OUT_DEFAULT_PRECIS, /* out precision */
CLIP_DEFAULT_PRECIS, /* clip precision */
DEFAULT_QUALITY, /* quality */
DEFAULT_PITCH, /* pitch family */
fontName_.c_str());
updatePending_ = false;
return font_;
}
void CAsFontInfo::ReleaseFont()
{
if (font_) {
font_->DeleteObject();
delete font_;
font_ = NULL;
}
}
CFont* CAsFontInfo::GetFont()
{
return font_;
}