1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
|
#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 = {0};
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();
}
|