mlang: Rename IMultiLanguage3 method implementation functions to match interface...
[wine] / dlls / dwrite / font.c
1 /*
2  *    Font and collections
3  *
4  * Copyright 2012 Nikolay Sivov for CodeWeavers
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #define COBJMACROS
22
23 #include "dwrite.h"
24 #include "dwrite_private.h"
25
26 #include "wine/debug.h"
27
28 WINE_DEFAULT_DEBUG_CHANNEL(dwrite);
29
30 struct dwrite_fontfamily {
31     IDWriteFontFamily IDWriteFontFamily_iface;
32     LONG ref;
33 };
34
35 struct dwrite_font {
36     IDWriteFont IDWriteFont_iface;
37     LONG ref;
38
39     IDWriteFontFamily *family;
40     DWRITE_FONT_STYLE style;
41 };
42
43 static inline struct dwrite_font *impl_from_IDWriteFont(IDWriteFont *iface)
44 {
45     return CONTAINING_RECORD(iface, struct dwrite_font, IDWriteFont_iface);
46 }
47
48 static inline struct dwrite_fontfamily *impl_from_IDWriteFontFamily(IDWriteFontFamily *iface)
49 {
50     return CONTAINING_RECORD(iface, struct dwrite_fontfamily, IDWriteFontFamily_iface);
51 }
52
53 static HRESULT WINAPI dwritefont_QueryInterface(IDWriteFont *iface, REFIID riid, void **obj)
54 {
55     struct dwrite_font *This = impl_from_IDWriteFont(iface);
56
57     TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), obj);
58
59     if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IDWriteFont))
60     {
61         *obj = iface;
62         IDWriteFont_AddRef(iface);
63         return S_OK;
64     }
65
66     *obj = NULL;
67     return E_NOINTERFACE;
68 }
69
70 static ULONG WINAPI dwritefont_AddRef(IDWriteFont *iface)
71 {
72     struct dwrite_font *This = impl_from_IDWriteFont(iface);
73     ULONG ref = InterlockedIncrement(&This->ref);
74     TRACE("(%p)->(%d)\n", This, ref);
75     return ref;
76 }
77
78 static ULONG WINAPI dwritefont_Release(IDWriteFont *iface)
79 {
80     struct dwrite_font *This = impl_from_IDWriteFont(iface);
81     ULONG ref = InterlockedDecrement(&This->ref);
82
83     TRACE("(%p)->(%d)\n", This, ref);
84
85     if (!ref)
86     {
87         IDWriteFontFamily_Release(This->family);
88         heap_free(This);
89     }
90
91     return S_OK;
92 }
93
94 static HRESULT WINAPI dwritefont_GetFontFamily(IDWriteFont *iface, IDWriteFontFamily **family)
95 {
96     struct dwrite_font *This = impl_from_IDWriteFont(iface);
97     TRACE("(%p)->(%p)\n", This, family);
98
99     *family = This->family;
100     IDWriteFontFamily_AddRef(*family);
101     return S_OK;
102 }
103
104 static DWRITE_FONT_WEIGHT WINAPI dwritefont_GetWeight(IDWriteFont *iface)
105 {
106     struct dwrite_font *This = impl_from_IDWriteFont(iface);
107     FIXME("(%p): stub\n", This);
108     return 0;
109 }
110
111 static DWRITE_FONT_STRETCH WINAPI dwritefont_GetStretch(IDWriteFont *iface)
112 {
113     struct dwrite_font *This = impl_from_IDWriteFont(iface);
114     FIXME("(%p): stub\n", This);
115     return DWRITE_FONT_STRETCH_UNDEFINED;
116 }
117
118 static DWRITE_FONT_STYLE WINAPI dwritefont_GetStyle(IDWriteFont *iface)
119 {
120     struct dwrite_font *This = impl_from_IDWriteFont(iface);
121     TRACE("(%p)\n", This);
122     return This->style;
123 }
124
125 static BOOL WINAPI dwritefont_IsSymbolFont(IDWriteFont *iface)
126 {
127     struct dwrite_font *This = impl_from_IDWriteFont(iface);
128     FIXME("(%p): stub\n", This);
129     return FALSE;
130 }
131
132 static HRESULT WINAPI dwritefont_GetFaceNames(IDWriteFont *iface, IDWriteLocalizedStrings **names)
133 {
134     struct dwrite_font *This = impl_from_IDWriteFont(iface);
135     FIXME("(%p)->(%p): stub\n", This, names);
136     return E_NOTIMPL;
137 }
138
139 static HRESULT WINAPI dwritefont_GetInformationalStrings(IDWriteFont *iface,
140     DWRITE_INFORMATIONAL_STRING_ID stringid, IDWriteLocalizedStrings **strings, BOOL *exists)
141 {
142     struct dwrite_font *This = impl_from_IDWriteFont(iface);
143     FIXME("(%p)->(%d %p %p): stub\n", This, stringid, strings, exists);
144     return E_NOTIMPL;
145 }
146
147 static DWRITE_FONT_SIMULATIONS WINAPI dwritefont_GetSimulations(IDWriteFont *iface)
148 {
149     struct dwrite_font *This = impl_from_IDWriteFont(iface);
150     FIXME("(%p): stub\n", This);
151     return DWRITE_FONT_SIMULATIONS_NONE;
152 }
153
154 static void WINAPI dwritefont_GetMetrics(IDWriteFont *iface, DWRITE_FONT_METRICS *metrics)
155 {
156     struct dwrite_font *This = impl_from_IDWriteFont(iface);
157     FIXME("(%p)->(%p): stub\n", This, metrics);
158 }
159
160 static HRESULT WINAPI dwritefont_HasCharacter(IDWriteFont *iface, UINT32 value, BOOL *exists)
161 {
162     struct dwrite_font *This = impl_from_IDWriteFont(iface);
163     FIXME("(%p)->(0x%08x %p): stub\n", This, value, exists);
164     return E_NOTIMPL;
165 }
166
167 static HRESULT WINAPI dwritefont_CreateFontFace(IDWriteFont *iface, IDWriteFontFace **face)
168 {
169     struct dwrite_font *This = impl_from_IDWriteFont(iface);
170     FIXME("(%p)->(%p): stub\n", This, face);
171     return E_NOTIMPL;
172 }
173
174 static const IDWriteFontVtbl dwritefontvtbl = {
175     dwritefont_QueryInterface,
176     dwritefont_AddRef,
177     dwritefont_Release,
178     dwritefont_GetFontFamily,
179     dwritefont_GetWeight,
180     dwritefont_GetStretch,
181     dwritefont_GetStyle,
182     dwritefont_IsSymbolFont,
183     dwritefont_GetFaceNames,
184     dwritefont_GetInformationalStrings,
185     dwritefont_GetSimulations,
186     dwritefont_GetMetrics,
187     dwritefont_HasCharacter,
188     dwritefont_CreateFontFace
189 };
190
191 static HRESULT WINAPI dwritefontfamily_QueryInterface(IDWriteFontFamily *iface, REFIID riid, void **obj)
192 {
193     struct dwrite_fontfamily *This = impl_from_IDWriteFontFamily(iface);
194     TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), obj);
195
196     if (IsEqualIID(riid, &IID_IUnknown) ||
197         IsEqualIID(riid, &IID_IDWriteFontList) ||
198         IsEqualIID(riid, &IID_IDWriteFontFamily))
199     {
200         *obj = iface;
201         IDWriteFontFamily_AddRef(iface);
202         return S_OK;
203     }
204
205     *obj = NULL;
206     return E_NOINTERFACE;
207 }
208
209 static ULONG WINAPI dwritefontfamily_AddRef(IDWriteFontFamily *iface)
210 {
211     struct dwrite_fontfamily *This = impl_from_IDWriteFontFamily(iface);
212     ULONG ref = InterlockedIncrement(&This->ref);
213     TRACE("(%p)->(%d)\n", This, ref);
214     return ref;
215 }
216
217 static ULONG WINAPI dwritefontfamily_Release(IDWriteFontFamily *iface)
218 {
219     struct dwrite_fontfamily *This = impl_from_IDWriteFontFamily(iface);
220     ULONG ref = InterlockedDecrement(&This->ref);
221
222     TRACE("(%p)->(%d)\n", This, ref);
223
224     if (!ref)
225         heap_free(This);
226
227     return S_OK;
228 }
229
230 static HRESULT WINAPI dwritefontfamily_GetFontCollection(IDWriteFontFamily *iface, IDWriteFontCollection **collection)
231 {
232     struct dwrite_fontfamily *This = impl_from_IDWriteFontFamily(iface);
233     FIXME("(%p)->(%p): stub\n", This, collection);
234     return E_NOTIMPL;
235 }
236
237 static UINT32 WINAPI dwritefontfamily_GetFontCount(IDWriteFontFamily *iface)
238 {
239     struct dwrite_fontfamily *This = impl_from_IDWriteFontFamily(iface);
240     FIXME("(%p): stub\n", This);
241     return 0;
242 }
243
244 static HRESULT WINAPI dwritefontfamily_GetFont(IDWriteFontFamily *iface, UINT32 index, IDWriteFont **font)
245 {
246     struct dwrite_fontfamily *This = impl_from_IDWriteFontFamily(iface);
247     FIXME("(%p)->(%u %p): stub\n", This, index, font);
248     return E_NOTIMPL;
249 }
250
251 static HRESULT WINAPI dwritefontfamily_GetFamilyNames(IDWriteFontFamily *iface, IDWriteLocalizedStrings **names)
252 {
253     struct dwrite_fontfamily *This = impl_from_IDWriteFontFamily(iface);
254     FIXME("(%p)->(%p): stub\n", This, names);
255     return E_NOTIMPL;
256 }
257
258 static HRESULT WINAPI dwritefontfamily_GetFirstMatchingFont(IDWriteFontFamily *iface, DWRITE_FONT_WEIGHT weight,
259     DWRITE_FONT_STRETCH stretch, DWRITE_FONT_STYLE style, IDWriteFont **font)
260 {
261     struct dwrite_fontfamily *This = impl_from_IDWriteFontFamily(iface);
262     FIXME("(%p)->(%d %d %d %p): stub\n", This, weight, stretch, style, font);
263     return E_NOTIMPL;
264 }
265
266 static HRESULT WINAPI dwritefontfamily_GetMatchingFonts(IDWriteFontFamily *iface, DWRITE_FONT_WEIGHT weight,
267     DWRITE_FONT_STRETCH stretch, DWRITE_FONT_STYLE style, IDWriteFontList **fonts)
268 {
269     struct dwrite_fontfamily *This = impl_from_IDWriteFontFamily(iface);
270     FIXME("(%p)->(%d %d %d %p): stub\n", This, weight, stretch, style, fonts);
271     return E_NOTIMPL;
272 }
273
274 static const IDWriteFontFamilyVtbl fontfamilyvtbl = {
275     dwritefontfamily_QueryInterface,
276     dwritefontfamily_AddRef,
277     dwritefontfamily_Release,
278     dwritefontfamily_GetFontCollection,
279     dwritefontfamily_GetFontCount,
280     dwritefontfamily_GetFont,
281     dwritefontfamily_GetFamilyNames,
282     dwritefontfamily_GetFirstMatchingFont,
283     dwritefontfamily_GetMatchingFonts
284 };
285
286 static HRESULT create_fontfamily(IDWriteFontFamily **family)
287 {
288     struct dwrite_fontfamily *This;
289
290     *family = NULL;
291
292     This = heap_alloc(sizeof(struct dwrite_fontfamily));
293     if (!This) return E_OUTOFMEMORY;
294
295     This->IDWriteFontFamily_iface.lpVtbl = &fontfamilyvtbl;
296     This->ref = 1;
297
298     *family = &This->IDWriteFontFamily_iface;
299
300     return S_OK;
301 }
302
303 HRESULT create_font_from_logfont(const LOGFONTW *logfont, IDWriteFont **font)
304 {
305     struct dwrite_font *This;
306     IDWriteFontFamily *family;
307     HRESULT hr;
308
309     *font = NULL;
310
311     hr = create_fontfamily(&family);
312     if (hr != S_OK) return hr;
313
314     This = heap_alloc(sizeof(struct dwrite_font));
315     if (!This)
316     {
317         IDWriteFontFamily_Release(family);
318         return E_OUTOFMEMORY;
319     }
320
321     This->IDWriteFont_iface.lpVtbl = &dwritefontvtbl;
322     This->ref = 1;
323     This->family = family;
324     This->style = logfont->lfItalic ? DWRITE_FONT_STYLE_ITALIC : DWRITE_FONT_STYLE_NORMAL;
325
326     *font = &This->IDWriteFont_iface;
327
328     return S_OK;
329 }