winedbg: Add enhanced Coprocessor move operators to Thumb2 disassembler.
[wine.git] / dlls / dwrite / font.c
blob892ee728a7a8c45329d701d50deb4e5aae34244b
1 /*
2 * Font and collections
4 * Copyright 2012 Nikolay Sivov for CodeWeavers
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.
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.
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
21 #define COBJMACROS
23 #include "dwrite.h"
24 #include "dwrite_private.h"
26 #include "wine/debug.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(dwrite);
30 struct dwrite_fontfamily {
31 IDWriteFontFamily IDWriteFontFamily_iface;
32 LONG ref;
35 struct dwrite_font {
36 IDWriteFont IDWriteFont_iface;
37 LONG ref;
39 IDWriteFontFamily *family;
40 DWRITE_FONT_STYLE style;
43 static inline struct dwrite_font *impl_from_IDWriteFont(IDWriteFont *iface)
45 return CONTAINING_RECORD(iface, struct dwrite_font, IDWriteFont_iface);
48 static inline struct dwrite_fontfamily *impl_from_IDWriteFontFamily(IDWriteFontFamily *iface)
50 return CONTAINING_RECORD(iface, struct dwrite_fontfamily, IDWriteFontFamily_iface);
53 static HRESULT WINAPI dwritefont_QueryInterface(IDWriteFont *iface, REFIID riid, void **obj)
55 struct dwrite_font *This = impl_from_IDWriteFont(iface);
57 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), obj);
59 if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IDWriteFont))
61 *obj = iface;
62 IDWriteFont_AddRef(iface);
63 return S_OK;
66 *obj = NULL;
67 return E_NOINTERFACE;
70 static ULONG WINAPI dwritefont_AddRef(IDWriteFont *iface)
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;
78 static ULONG WINAPI dwritefont_Release(IDWriteFont *iface)
80 struct dwrite_font *This = impl_from_IDWriteFont(iface);
81 ULONG ref = InterlockedDecrement(&This->ref);
83 TRACE("(%p)->(%d)\n", This, ref);
85 if (!ref)
87 IDWriteFontFamily_Release(This->family);
88 heap_free(This);
91 return S_OK;
94 static HRESULT WINAPI dwritefont_GetFontFamily(IDWriteFont *iface, IDWriteFontFamily **family)
96 struct dwrite_font *This = impl_from_IDWriteFont(iface);
97 TRACE("(%p)->(%p)\n", This, family);
99 *family = This->family;
100 IDWriteFontFamily_AddRef(*family);
101 return S_OK;
104 static DWRITE_FONT_WEIGHT WINAPI dwritefont_GetWeight(IDWriteFont *iface)
106 struct dwrite_font *This = impl_from_IDWriteFont(iface);
107 FIXME("(%p): stub\n", This);
108 return 0;
111 static DWRITE_FONT_STRETCH WINAPI dwritefont_GetStretch(IDWriteFont *iface)
113 struct dwrite_font *This = impl_from_IDWriteFont(iface);
114 FIXME("(%p): stub\n", This);
115 return DWRITE_FONT_STRETCH_UNDEFINED;
118 static DWRITE_FONT_STYLE WINAPI dwritefont_GetStyle(IDWriteFont *iface)
120 struct dwrite_font *This = impl_from_IDWriteFont(iface);
121 TRACE("(%p)\n", This);
122 return This->style;
125 static BOOL WINAPI dwritefont_IsSymbolFont(IDWriteFont *iface)
127 struct dwrite_font *This = impl_from_IDWriteFont(iface);
128 FIXME("(%p): stub\n", This);
129 return FALSE;
132 static HRESULT WINAPI dwritefont_GetFaceNames(IDWriteFont *iface, IDWriteLocalizedStrings **names)
134 struct dwrite_font *This = impl_from_IDWriteFont(iface);
135 FIXME("(%p)->(%p): stub\n", This, names);
136 return E_NOTIMPL;
139 static HRESULT WINAPI dwritefont_GetInformationalStrings(IDWriteFont *iface,
140 DWRITE_INFORMATIONAL_STRING_ID stringid, IDWriteLocalizedStrings **strings, BOOL *exists)
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;
147 static DWRITE_FONT_SIMULATIONS WINAPI dwritefont_GetSimulations(IDWriteFont *iface)
149 struct dwrite_font *This = impl_from_IDWriteFont(iface);
150 FIXME("(%p): stub\n", This);
151 return DWRITE_FONT_SIMULATIONS_NONE;
154 static void WINAPI dwritefont_GetMetrics(IDWriteFont *iface, DWRITE_FONT_METRICS *metrics)
156 struct dwrite_font *This = impl_from_IDWriteFont(iface);
157 FIXME("(%p)->(%p): stub\n", This, metrics);
160 static HRESULT WINAPI dwritefont_HasCharacter(IDWriteFont *iface, UINT32 value, BOOL *exists)
162 struct dwrite_font *This = impl_from_IDWriteFont(iface);
163 FIXME("(%p)->(0x%08x %p): stub\n", This, value, exists);
164 return E_NOTIMPL;
167 static HRESULT WINAPI dwritefont_CreateFontFace(IDWriteFont *iface, IDWriteFontFace **face)
169 struct dwrite_font *This = impl_from_IDWriteFont(iface);
170 FIXME("(%p)->(%p): stub\n", This, face);
171 return E_NOTIMPL;
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
191 static HRESULT WINAPI dwritefontfamily_QueryInterface(IDWriteFontFamily *iface, REFIID riid, void **obj)
193 struct dwrite_fontfamily *This = impl_from_IDWriteFontFamily(iface);
194 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), obj);
196 if (IsEqualIID(riid, &IID_IUnknown) ||
197 IsEqualIID(riid, &IID_IDWriteFontList) ||
198 IsEqualIID(riid, &IID_IDWriteFontFamily))
200 *obj = iface;
201 IDWriteFontFamily_AddRef(iface);
202 return S_OK;
205 *obj = NULL;
206 return E_NOINTERFACE;
209 static ULONG WINAPI dwritefontfamily_AddRef(IDWriteFontFamily *iface)
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;
217 static ULONG WINAPI dwritefontfamily_Release(IDWriteFontFamily *iface)
219 struct dwrite_fontfamily *This = impl_from_IDWriteFontFamily(iface);
220 ULONG ref = InterlockedDecrement(&This->ref);
222 TRACE("(%p)->(%d)\n", This, ref);
224 if (!ref)
225 heap_free(This);
227 return S_OK;
230 static HRESULT WINAPI dwritefontfamily_GetFontCollection(IDWriteFontFamily *iface, IDWriteFontCollection **collection)
232 struct dwrite_fontfamily *This = impl_from_IDWriteFontFamily(iface);
233 FIXME("(%p)->(%p): stub\n", This, collection);
234 return E_NOTIMPL;
237 static UINT32 WINAPI dwritefontfamily_GetFontCount(IDWriteFontFamily *iface)
239 struct dwrite_fontfamily *This = impl_from_IDWriteFontFamily(iface);
240 FIXME("(%p): stub\n", This);
241 return 0;
244 static HRESULT WINAPI dwritefontfamily_GetFont(IDWriteFontFamily *iface, UINT32 index, IDWriteFont **font)
246 struct dwrite_fontfamily *This = impl_from_IDWriteFontFamily(iface);
247 FIXME("(%p)->(%u %p): stub\n", This, index, font);
248 return E_NOTIMPL;
251 static HRESULT WINAPI dwritefontfamily_GetFamilyNames(IDWriteFontFamily *iface, IDWriteLocalizedStrings **names)
253 struct dwrite_fontfamily *This = impl_from_IDWriteFontFamily(iface);
254 FIXME("(%p)->(%p): stub\n", This, names);
255 return E_NOTIMPL;
258 static HRESULT WINAPI dwritefontfamily_GetFirstMatchingFont(IDWriteFontFamily *iface, DWRITE_FONT_WEIGHT weight,
259 DWRITE_FONT_STRETCH stretch, DWRITE_FONT_STYLE style, IDWriteFont **font)
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;
266 static HRESULT WINAPI dwritefontfamily_GetMatchingFonts(IDWriteFontFamily *iface, DWRITE_FONT_WEIGHT weight,
267 DWRITE_FONT_STRETCH stretch, DWRITE_FONT_STYLE style, IDWriteFontList **fonts)
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;
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
286 static HRESULT create_fontfamily(IDWriteFontFamily **family)
288 struct dwrite_fontfamily *This;
290 *family = NULL;
292 This = heap_alloc(sizeof(struct dwrite_fontfamily));
293 if (!This) return E_OUTOFMEMORY;
295 This->IDWriteFontFamily_iface.lpVtbl = &fontfamilyvtbl;
296 This->ref = 1;
298 *family = &This->IDWriteFontFamily_iface;
300 return S_OK;
303 HRESULT create_font_from_logfont(const LOGFONTW *logfont, IDWriteFont **font)
305 struct dwrite_font *This;
306 IDWriteFontFamily *family;
307 HRESULT hr;
309 *font = NULL;
311 hr = create_fontfamily(&family);
312 if (hr != S_OK) return hr;
314 This = heap_alloc(sizeof(struct dwrite_font));
315 if (!This)
317 IDWriteFontFamily_Release(family);
318 return E_OUTOFMEMORY;
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;
326 *font = &This->IDWriteFont_iface;
328 return S_OK;