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
18inline
19Font::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
33inline
34Font::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
62inline
63Font::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
84inline
85Font::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
107inline
108Font::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
131inline
132Font::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
163inline Status
164Font::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
171inline Status
172Font::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
179inline Font*
180Font::Clone() const
181{
182    GpFont *cloneFont = NULL;
183
184    SetStatus(DllExports::GdipCloneFont(nativeFont, &cloneFont));
185
186    return new Font(cloneFont, lastResult);
187}
188
189inline
190Font::~Font()
191{
192    DllExports::GdipDeleteFont(nativeFont);
193}
194
195// Operations
196
197inline BOOL
198Font::IsAvailable() const
199{
200    return (nativeFont ? TRUE : FALSE);
201}
202
203inline Status
204Font::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
217inline INT
218Font::GetStyle() const
219{
220    INT style;
221
222    SetStatus(DllExports::GdipGetFontStyle(nativeFont, &style));
223
224    return style;
225}
226
227inline REAL
228Font::GetSize() const
229{
230    REAL size;
231    SetStatus(DllExports::GdipGetFontSize(nativeFont, &size));
232    return size;
233}
234
235inline Unit
236Font::GetUnit() const
237{
238    Unit unit;
239    SetStatus(DllExports::GdipGetFontUnit(nativeFont, &unit));
240    return unit;
241}
242
243inline REAL
244Font::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
257inline REAL
258Font::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
268inline
269Font::Font(IN GpFont* font,
270           IN Status status)
271{
272    lastResult = status;
273    SetNativeFont(font);
274}
275
276// protected method
277inline VOID
278Font::SetNativeFont(GpFont *Font)
279{
280    nativeFont = Font;
281}
282
283inline Status
284Font::GetLastStatus(void) const
285{
286    return lastResult;
287}
288
289// protected method
290inline Status
291Font::SetStatus(IN Status status) const
292{
293    if (status != Ok)
294        return (lastResult = status);
295    else
296        return status;
297}
298
299#endif
300