1/**************************************************************************\
2*
3* Copyright (c) 1998-2000, Microsoft Corp.  All Rights Reserved.
4*
5* Module Name:
6*
7*   GdiplusFontFamily.h
8*
9* Abstract:
10*
11*   Font family API related declarations
12*
13\**************************************************************************/
14
15#ifndef _GDIPLUS_FONT_FAMILY_H
16#define _GDIPLUS_FONT_FAMILY_H
17
18inline
19FontFamily::FontFamily() :
20    nativeFamily (NULL),
21    lastResult    (Ok)
22{
23}
24
25inline
26FontFamily::FontFamily(
27    IN const WCHAR*          name,
28    IN const FontCollection* fontCollection
29)
30{
31    nativeFamily = NULL;
32    lastResult = DllExports::GdipCreateFontFamilyFromName(
33        name,
34        fontCollection ? fontCollection->nativeFontCollection : NULL,
35        &nativeFamily
36    );
37
38#ifndef DCR_USE_NEW_135429
39    if ((INT) lastResult >= 10)
40        lastResult = NotFound;
41#endif
42}
43
44// private method
45inline
46FontFamily::FontFamily(
47    IN GpFontFamily *nativeOrig,
48    IN Status status
49)
50{
51    lastResult    = status;
52    nativeFamily = nativeOrig;
53}
54
55// Generic font family access
56
57inline const FontFamily *
58FontFamily::GenericSansSerif()
59{
60    if (GenericSansSerifFontFamily != NULL)
61    {
62        return GenericSansSerifFontFamily;
63    }
64
65    GenericSansSerifFontFamily =
66        (FontFamily*) GenericSansSerifFontFamilyBuffer;
67
68    GenericSansSerifFontFamily->lastResult =
69        DllExports::GdipGetGenericFontFamilySansSerif(
70            &(GenericSansSerifFontFamily->nativeFamily)
71        );
72
73#ifndef DCR_USE_NEW_135429
74    if ((INT) GenericSansSerifFontFamily->lastResult >= 10)
75        GenericSansSerifFontFamily->lastResult = NotFound;
76#endif
77
78    return GenericSansSerifFontFamily;
79}
80
81inline const FontFamily *
82FontFamily::GenericSerif()
83{
84    if (GenericSerifFontFamily != NULL)
85    {
86        return GenericSerifFontFamily;
87    }
88
89    GenericSerifFontFamily =
90        (FontFamily*) GenericSerifFontFamilyBuffer;
91
92    GenericSerifFontFamily->lastResult =
93        DllExports::GdipGetGenericFontFamilySerif(
94            &(GenericSerifFontFamily->nativeFamily)
95        );
96
97#ifndef DCR_USE_NEW_135429
98    if ((INT) GenericSerifFontFamily->lastResult >= 10)
99        GenericSerifFontFamily->lastResult = NotFound;
100#endif
101
102    return GenericSerifFontFamily;
103}
104
105inline const FontFamily *
106FontFamily::GenericMonospace()
107{
108    if (GenericMonospaceFontFamily != NULL)
109    {
110        return GenericMonospaceFontFamily;
111    }
112
113    GenericMonospaceFontFamily =
114        (FontFamily*) GenericMonospaceFontFamilyBuffer;
115
116    GenericMonospaceFontFamily->lastResult =
117        DllExports::GdipGetGenericFontFamilyMonospace(
118            &(GenericMonospaceFontFamily->nativeFamily)
119        );
120
121#ifndef DCR_USE_NEW_135429
122    if ((INT) GenericMonospaceFontFamily->lastResult >= 10)
123        GenericMonospaceFontFamily->lastResult = NotFound;
124#endif
125
126    return GenericMonospaceFontFamily;
127}
128
129inline FontFamily::~FontFamily()
130{
131    DllExports::GdipDeleteFontFamily (nativeFamily);
132}
133
134inline FontFamily *
135FontFamily::Clone() const
136{
137    GpFontFamily * clonedFamily = NULL;
138
139    SetStatus(DllExports::GdipCloneFontFamily (nativeFamily, &clonedFamily));
140
141    return new FontFamily(clonedFamily, lastResult);
142}
143
144inline Status
145FontFamily::GetFamilyName(
146    IN WCHAR name[LF_FACESIZE],
147    IN LANGID language
148) const
149{
150    return SetStatus(DllExports::GdipGetFamilyName(nativeFamily,
151                                                   name,
152                                                   language));
153}
154
155inline BOOL
156FontFamily::IsStyleAvailable(IN INT style) const
157{
158    BOOL    StyleAvailable;
159    Status  status;
160
161    status = SetStatus(DllExports::GdipIsStyleAvailable(nativeFamily, style, &StyleAvailable));
162
163    if (status != Ok)
164        StyleAvailable = FALSE;
165
166    return StyleAvailable;
167}
168
169
170inline UINT16
171FontFamily::GetEmHeight(IN INT style) const
172{
173    UINT16  EmHeight;
174
175    SetStatus(DllExports::GdipGetEmHeight(nativeFamily, style, &EmHeight));
176
177    return EmHeight;
178}
179
180inline UINT16
181FontFamily::GetCellAscent(IN INT style) const
182{
183    UINT16  CellAscent;
184
185    SetStatus(DllExports::GdipGetCellAscent(nativeFamily, style, &CellAscent));
186
187    return CellAscent;
188}
189
190inline UINT16
191FontFamily::GetCellDescent(IN INT style) const
192{
193    UINT16  CellDescent;
194
195    SetStatus(DllExports::GdipGetCellDescent(nativeFamily, style, &CellDescent));
196
197    return CellDescent;
198}
199
200
201inline UINT16
202FontFamily::GetLineSpacing(IN INT style) const
203{
204    UINT16  LineSpacing;
205
206    SetStatus(DllExports::GdipGetLineSpacing(nativeFamily, style, &LineSpacing));
207
208    return LineSpacing;
209
210}
211
212#ifdef TEXTV2
213
214// The following APIs return data from the font OS/2 table
215
216inline INT16
217FontFamily::GetTypographicAscent(IN INT style) const
218{
219    INT16  TypographicAscent;
220
221    SetStatus(DllExports::GdipGetTypographicAscent(nativeFamily, style, &TypographicAscent));
222
223    return TypographicAscent;
224}
225
226inline INT16
227FontFamily::GetTypographicDescent(IN INT style) const
228{
229    INT16   TypographicDescent;
230
231    SetStatus(DllExports::GdipGetTypographicDescent(nativeFamily, style, &TypographicDescent));
232
233    return TypographicDescent;
234}
235
236inline INT16
237FontFamily::GetTypographicLineGap(IN INT style) const
238{
239    INT16   TypographicLineGap;
240
241    SetStatus(DllExports::GdipGetTypographicLineGap(nativeFamily, style, &TypographicLineGap));
242
243    return TypographicLineGap;
244}
245
246#endif
247
248///////////////////////////////////////////////////////////
249
250// GetLastStatus - return last error code and clear error code
251
252inline Status
253FontFamily::GetLastStatus() const
254{
255    Status lastStatus = lastResult;
256    lastResult = Ok;
257
258    return lastStatus;
259}
260
261// protected method
262inline Status
263FontFamily::SetStatus(Status status) const
264{
265    if (status != Ok)
266        return (lastResult = status);
267    else
268        return status;
269}
270
271#endif
272