From bb6784e0e1a385cdd20b41d3254093e89a210332 Mon Sep 17 00:00:00 2001 From: pescuma Date: Wed, 31 Dec 2008 21:12:58 +0000 Subject: skins: Added SkinLib git-svn-id: http://pescuma.googlecode.com/svn/trunk/Miranda@120 c086bb3d-8645-0410-b8da-73a8550f86e7 --- Plugins/skins/SkinLib/FontState.cpp | 185 ++++++++++++++++++++++++++++++++++++ 1 file changed, 185 insertions(+) create mode 100644 Plugins/skins/SkinLib/FontState.cpp (limited to 'Plugins/skins/SkinLib/FontState.cpp') diff --git a/Plugins/skins/SkinLib/FontState.cpp b/Plugins/skins/SkinLib/FontState.cpp new file mode 100644 index 0000000..fdf1e09 --- /dev/null +++ b/Plugins/skins/SkinLib/FontState.cpp @@ -0,0 +1,185 @@ +#include "globals.h" +#include "FontState.h" + +FontState::FontState(HFONT hFont, COLORREF aColor) : hFont(NULL), externalFont(false), color(aColor) +{ + setHFONT(hFont); +} + +FontState::~FontState() +{ + releaseHFONT(); +} + +void FontState::rebuildHFONT() +{ + releaseHFONT(); + buildHFONT(); +} + +void FontState::buildAttribs() +{ + LOGFONT lf; + if (hFont == NULL || GetObject(hFont, sizeof(lf), &lf) == 0) + { + face = _T("Tahoma"); + size = 9; + italic = false; + bold = false; + underline = false; + strikeout = false; + + rebuildHFONT(); + + return; + } + + face = lf.lfFaceName; + italic = (lf.lfItalic != 0); + bold = (lf.lfWeight > FW_NORMAL); + underline = (lf.lfUnderline != 0); + strikeout = (lf.lfStrikeOut != 0); + + HDC hdc = GetDC(NULL); + size = -MulDiv(lf.lfHeight, 72, GetDeviceCaps(hdc, LOGPIXELSY)); + ReleaseDC(NULL, hdc); +} + +void FontState::buildHFONT() +{ + if (hFont != NULL) + return; + + LOGFONT lf; + + _tcscpy(lf.lfFaceName, getFace()); + + lf.lfWidth = lf.lfEscapement = lf.lfOrientation = 0; + lf.lfWeight = isBold() ? FW_BOLD : FW_NORMAL; + lf.lfItalic = isItalic() ? 1 : 0; + lf.lfUnderline = isUnderline() ? 1 : 0; + lf.lfStrikeOut = isStrikeOut() ? 1 : 0; + lf.lfCharSet = DEFAULT_CHARSET; + lf.lfOutPrecision = OUT_DEFAULT_PRECIS; + lf.lfClipPrecision = CLIP_DEFAULT_PRECIS; + lf.lfQuality = DEFAULT_QUALITY; + lf.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE; + + HDC hdc = GetDC(NULL); + lf.lfHeight = -MulDiv(getSize(), GetDeviceCaps(hdc, LOGPIXELSY), 72); + ReleaseDC(NULL, hdc); + + hFont = CreateFontIndirect(&lf); + externalFont = false; +} + +void FontState::releaseHFONT() +{ + if (hFont == NULL) + return; + + if (!externalFont) + DeleteObject(hFont); + + hFont = NULL; +} + + +HFONT FontState::getHFONT() const +{ + return hFont; +} + + +HFONT FontState::createHFONT() const +{ + LOGFONT lf; + if (hFont == NULL || GetObject(hFont, sizeof(lf), &lf) == 0) + return NULL; + else + return CreateFontIndirect(&lf); +} + +void FontState::setHFONT(HFONT hFont) +{ + releaseHFONT(); + this->hFont = hFont; + externalFont = true; + buildAttribs(); +} + +const TCHAR * FontState::getFace() const +{ + return face.c_str(); +} + +void FontState::setFace(const TCHAR * face) +{ + this->face = face; + rebuildHFONT(); +} + +int FontState::getSize() const +{ + return size; +} + +void FontState::setSize(int size) +{ + this->size = size; + rebuildHFONT(); +} + +COLORREF FontState::getColor() const +{ + return color; +} + +void FontState::setColor(COLORREF color) +{ + this->color = color; +} + +bool FontState::isItalic() const +{ + return italic; +} + +void FontState::setItalic(bool italic) +{ + this->italic = italic; + rebuildHFONT(); +} + +bool FontState::isBold() const +{ + return bold; +} + +void FontState::setBold(bool bold) +{ + this->bold = bold; + rebuildHFONT(); +} + +bool FontState::isUnderline() const +{ + return underline; +} + +void FontState::setUnderline(bool underline) +{ + this->underline = underline; + rebuildHFONT(); +} + +bool FontState::isStrikeOut() const +{ + return strikeout; +} + +void FontState::setStrikeOut(bool strikeout) +{ + this->strikeout = strikeout; + rebuildHFONT(); +} -- cgit v1.2.3