1 /**************************************************************************\
2 *
3 * Copyright (c) 1998-2000, Microsoft Corp. All Rights Reserved.
4 *
5 * Module Name:
6 *
7 * GdiplusFont.h
8 *
9 * Abstract:
10 *
11 * Font related declarations
12 *
13 \**************************************************************************/
14
15 #ifndef _GDIPLUSFONT_H
16 #define _GDIPLUSFONT_H
17
18 inline
Font(IN HDC hdc)19 Font::Font(IN HDC hdc)
20 {
21 GpFont *font = NULL;
22 lastResult = DllExports::GdipCreateFontFromDC(hdc, &font);
23
24 #ifndef DCR_USE_NEW_135429
25 if ((INT) lastResult >= 10)
26 lastResult = NotFound;
27 #endif
28
29 SetNativeFont(font);
30 }
31
32 #ifdef DCR_USE_NEW_127084
33 inline
Font(IN HDC hdc,IN const HFONT hfont)34 Font::Font(IN HDC hdc,
35 IN const HFONT hfont)
36 {
37 GpFont *font = NULL;
38
39 if (hfont)
40 {
41 LOGFONTA lf;
42
43 if(GetObjectA(hfont, sizeof(LOGFONTA), &lf))
44 lastResult = DllExports::GdipCreateFontFromLogfontA(hdc, &lf, &font);
45 else
46 lastResult = DllExports::GdipCreateFontFromDC(hdc, &font);
47 }
48 else
49 {
50 lastResult = DllExports::GdipCreateFontFromDC(hdc, &font);
51 }
52
53 #ifndef DCR_USE_NEW_135429
54 if ((INT) lastResult >= 10)
55 lastResult = NotFound;
56 #endif
57
58 SetNativeFont(font);
59 }
60 #endif
61
62 inline
Font(IN HDC hdc,IN const LOGFONTW * logfont)63 Font::Font(IN HDC hdc,
64 IN const LOGFONTW* logfont)
65 {
66 GpFont *font = NULL;
67 if (logfont)
68 {
69 lastResult = DllExports::GdipCreateFontFromLogfontW(hdc, logfont, &font);
70 }
71 else
72 {
73 lastResult = DllExports::GdipCreateFontFromDC(hdc, &font);
74 }
75
76 #ifndef DCR_USE_NEW_135429
77 if ((INT) lastResult >= 10)
78 lastResult = NotFound;
79 #endif
80
81 SetNativeFont(font);
82 }
83
84 inline
Font(IN HDC hdc,IN const LOGFONTA * logfont)85 Font::Font(IN HDC hdc,
86 IN const LOGFONTA* logfont)
87 {
88 GpFont *font = NULL;
89
90 if (logfont)
91 {
92 lastResult = DllExports::GdipCreateFontFromLogfontA(hdc, logfont, &font);
93 }
94 else
95 {
96 lastResult = DllExports::GdipCreateFontFromDC(hdc, &font);
97 }
98
99 #ifndef DCR_USE_NEW_135429
100 if ((INT) lastResult >= 10)
101 lastResult = NotFound;
102 #endif
103
104 SetNativeFont(font);
105 }
106
107 inline
Font(IN const FontFamily * family,IN REAL emSize,IN INT style,IN Unit unit)108 Font::Font(
109 IN const FontFamily * family,
110 IN REAL emSize,
111 IN INT style,
112 IN Unit unit
113 )
114 {
115 GpFont *font = NULL;
116
117 lastResult = DllExports::GdipCreateFont(family ? family->nativeFamily : NULL,
118 emSize,
119 style,
120 unit,
121 &font);
122
123 #ifndef DCR_USE_NEW_135429
124 if ((INT) lastResult >= 10)
125 lastResult = NotFound;
126 #endif
127
128 SetNativeFont(font);
129 }
130
131 inline
Font(IN const WCHAR * familyName,IN REAL emSize,IN INT style,IN Unit unit,IN const FontCollection * fontCollection)132 Font::Font(
133 IN const WCHAR * familyName,
134 IN REAL emSize,
135 IN INT style,
136 IN Unit unit,
137 IN const FontCollection * fontCollection
138 )
139 {
140 FontFamily family(familyName, fontCollection);
141
142 GpFont * font = NULL;
143
144 lastResult = family.GetLastStatus();
145
146 if (lastResult == Ok)
147 {
148 lastResult = DllExports::GdipCreateFont(family.nativeFamily,
149 emSize,
150 style,
151 unit,
152 &font);
153 }
154
155 #ifndef DCR_USE_NEW_135429
156 if ((INT) lastResult >= 10)
157 lastResult = NotFound;
158 #endif
159
160 SetNativeFont(font);
161 }
162
163 inline Status
GetLogFontA(IN const Graphics * g,OUT LOGFONTA * logfontA)164 Font::GetLogFontA(IN const Graphics *g,
165 OUT LOGFONTA *logfontA) const
166 {
167 return SetStatus(DllExports::GdipGetLogFontA(nativeFont, g ? g->nativeGraphics : NULL, logfontA));
168
169 }
170
171 inline Status
GetLogFontW(IN const Graphics * g,OUT LOGFONTW * logfontW)172 Font::GetLogFontW(IN const Graphics *g,
173 OUT LOGFONTW *logfontW) const
174 {
175 return SetStatus(DllExports::GdipGetLogFontW(nativeFont, g ? g->nativeGraphics : NULL, logfontW));
176 }
177
178
179 inline Font*
Clone()180 Font::Clone() const
181 {
182 GpFont *cloneFont = NULL;
183
184 SetStatus(DllExports::GdipCloneFont(nativeFont, &cloneFont));
185
186 return new Font(cloneFont, lastResult);
187 }
188
189 inline
~Font()190 Font::~Font()
191 {
192 DllExports::GdipDeleteFont(nativeFont);
193 }
194
195 // Operations
196
197 inline BOOL
IsAvailable()198 Font::IsAvailable() const
199 {
200 return (nativeFont ? TRUE : FALSE);
201 }
202
203 inline Status
GetFamily(OUT FontFamily * family)204 Font::GetFamily(OUT FontFamily *family) const
205 {
206 if (family == NULL)
207 {
208 return SetStatus(InvalidParameter);
209 }
210
211 Status status = DllExports::GdipGetFamily(nativeFont, &(family->nativeFamily));
212 family->SetStatus(status);
213
214 return SetStatus(status);
215 }
216
217 inline INT
GetStyle()218 Font::GetStyle() const
219 {
220 INT style;
221
222 SetStatus(DllExports::GdipGetFontStyle(nativeFont, &style));
223
224 return style;
225 }
226
227 inline REAL
GetSize()228 Font::GetSize() const
229 {
230 REAL size;
231 SetStatus(DllExports::GdipGetFontSize(nativeFont, &size));
232 return size;
233 }
234
235 inline Unit
GetUnit()236 Font::GetUnit() const
237 {
238 Unit unit;
239 SetStatus(DllExports::GdipGetFontUnit(nativeFont, &unit));
240 return unit;
241 }
242
243 inline REAL
GetHeight(IN const Graphics * graphics)244 Font::GetHeight(IN const Graphics *graphics) const
245 {
246 REAL height;
247 SetStatus(DllExports::GdipGetFontHeight(
248 nativeFont,
249 graphics ? graphics->nativeGraphics : NULL,
250 &height
251 ));
252 return height;
253 }
254
255
256 #ifdef DCR_USE_NEW_125467
257 inline REAL
258 Font::GetHeight(IN REAL dpi = 0) const
259 {
260 REAL height;
261 SetStatus(DllExports::GdipGetFontHeightGivenDPI(nativeFont, dpi, &height));
262 return height;
263 }
264 #endif
265
266
267 // protected method
268 inline
Font(IN GpFont * font,IN Status status)269 Font::Font(IN GpFont* font,
270 IN Status status)
271 {
272 lastResult = status;
273 SetNativeFont(font);
274 }
275
276 // protected method
277 inline VOID
SetNativeFont(GpFont * Font)278 Font::SetNativeFont(GpFont *Font)
279 {
280 nativeFont = Font;
281 }
282
283 inline Status
GetLastStatus(void)284 Font::GetLastStatus(void) const
285 {
286 return lastResult;
287 }
288
289 // protected method
290 inline Status
SetStatus(IN Status status)291 Font::SetStatus(IN Status status) const
292 {
293 if (status != Ok)
294 return (lastResult = status);
295 else
296 return status;
297 }
298
299 #endif
300