source: trunk/contrib/gdiplus/include/GdiplusFont.h @ 980

Last change on this file since 980 was 980, checked in by sam, 11 years ago

contrib: add GDI+ headers and static library for Linux cross-compilation.

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