mshtml: Added IHTMLWindow6::get_sessionStorage implementation.
[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_font {
31     IDWriteFont IDWriteFont_iface;
32     LONG ref;
33
34     DWRITE_FONT_STYLE style;
35 };
36
37 static inline struct dwrite_font *impl_from_IDWriteFont(IDWriteFont *iface)
38 {
39     return CONTAINING_RECORD(iface, struct dwrite_font, IDWriteFont_iface);
40 }
41
42 static HRESULT WINAPI dwritefont_QueryInterface(IDWriteFont *iface, REFIID riid, void **obj)
43 {
44     struct dwrite_font *This = impl_from_IDWriteFont(iface);
45
46     TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), obj);
47
48     if (IsEqualIID(riid, &IID_IUnknown) || IsEqualIID(riid, &IID_IDWriteFont))
49     {
50         *obj = iface;
51         IDWriteFont_AddRef(iface);
52         return S_OK;
53     }
54
55     *obj = NULL;
56     return E_NOINTERFACE;
57 }
58
59 static ULONG WINAPI dwritefont_AddRef(IDWriteFont *iface)
60 {
61     struct dwrite_font *This = impl_from_IDWriteFont(iface);
62     ULONG ref = InterlockedIncrement(&This->ref);
63     TRACE("(%p)->(%d)\n", This, ref);
64     return ref;
65 }
66
67 static ULONG WINAPI dwritefont_Release(IDWriteFont *iface)
68 {
69     struct dwrite_font *This = impl_from_IDWriteFont(iface);
70     ULONG ref = InterlockedDecrement(&This->ref);
71
72     TRACE("(%p)->(%d)\n", This, ref);
73
74     if (!ref)
75         heap_free(This);
76
77     return S_OK;
78 }
79
80 static HRESULT WINAPI dwritefont_GetFontFamily(IDWriteFont *iface, IDWriteFontFamily **family)
81 {
82     struct dwrite_font *This = impl_from_IDWriteFont(iface);
83     FIXME("(%p)->(%p): stub\n", This, family);
84     return E_NOTIMPL;
85 }
86
87 static DWRITE_FONT_WEIGHT WINAPI dwritefont_GetWeight(IDWriteFont *iface)
88 {
89     struct dwrite_font *This = impl_from_IDWriteFont(iface);
90     FIXME("(%p): stub\n", This);
91     return 0;
92 }
93
94 static DWRITE_FONT_STRETCH WINAPI dwritefont_GetStretch(IDWriteFont *iface)
95 {
96     struct dwrite_font *This = impl_from_IDWriteFont(iface);
97     FIXME("(%p): stub\n", This);
98     return DWRITE_FONT_STRETCH_UNDEFINED;
99 }
100
101 static DWRITE_FONT_STYLE WINAPI dwritefont_GetStyle(IDWriteFont *iface)
102 {
103     struct dwrite_font *This = impl_from_IDWriteFont(iface);
104     TRACE("(%p)\n", This);
105     return This->style;
106 }
107
108 static BOOL WINAPI dwritefont_IsSymbolFont(IDWriteFont *iface)
109 {
110     struct dwrite_font *This = impl_from_IDWriteFont(iface);
111     FIXME("(%p): stub\n", This);
112     return FALSE;
113 }
114
115 static HRESULT WINAPI dwritefont_GetFaceNames(IDWriteFont *iface, IDWriteLocalizedStrings **names)
116 {
117     struct dwrite_font *This = impl_from_IDWriteFont(iface);
118     FIXME("(%p)->(%p): stub\n", This, names);
119     return E_NOTIMPL;
120 }
121
122 static HRESULT WINAPI dwritefont_GetInformationalStrings(IDWriteFont *iface,
123     DWRITE_INFORMATIONAL_STRING_ID stringid, IDWriteLocalizedStrings **strings, BOOL *exists)
124 {
125     struct dwrite_font *This = impl_from_IDWriteFont(iface);
126     FIXME("(%p)->(%d %p %p): stub\n", This, stringid, strings, exists);
127     return E_NOTIMPL;
128 }
129
130 static DWRITE_FONT_SIMULATIONS WINAPI dwritefont_GetSimulations(IDWriteFont *iface)
131 {
132     struct dwrite_font *This = impl_from_IDWriteFont(iface);
133     FIXME("(%p): stub\n", This);
134     return DWRITE_FONT_SIMULATIONS_NONE;
135 }
136
137 static void WINAPI dwritefont_GetMetrics(IDWriteFont *iface, DWRITE_FONT_METRICS *metrics)
138 {
139     struct dwrite_font *This = impl_from_IDWriteFont(iface);
140     FIXME("(%p)->(%p): stub\n", This, metrics);
141 }
142
143 static HRESULT WINAPI dwritefont_HasCharacter(IDWriteFont *iface, UINT32 value, BOOL *exists)
144 {
145     struct dwrite_font *This = impl_from_IDWriteFont(iface);
146     FIXME("(%p)->(0x%08x %p): stub\n", This, value, exists);
147     return E_NOTIMPL;
148 }
149
150 static HRESULT WINAPI dwritefont_CreateFontFace(IDWriteFont *iface, IDWriteFontFace **face)
151 {
152     struct dwrite_font *This = impl_from_IDWriteFont(iface);
153     FIXME("(%p)->(%p): stub\n", This, face);
154     return E_NOTIMPL;
155 }
156
157 static const IDWriteFontVtbl dwritefontvtbl = {
158     dwritefont_QueryInterface,
159     dwritefont_AddRef,
160     dwritefont_Release,
161     dwritefont_GetFontFamily,
162     dwritefont_GetWeight,
163     dwritefont_GetStretch,
164     dwritefont_GetStyle,
165     dwritefont_IsSymbolFont,
166     dwritefont_GetFaceNames,
167     dwritefont_GetInformationalStrings,
168     dwritefont_GetSimulations,
169     dwritefont_GetMetrics,
170     dwritefont_HasCharacter,
171     dwritefont_CreateFontFace
172 };
173
174 HRESULT create_font_from_logfont(const LOGFONTW *logfont, IDWriteFont **font)
175 {
176     struct dwrite_font *This;
177
178     *font = NULL;
179
180     This = heap_alloc(sizeof(struct dwrite_font));
181     if (!This) return E_OUTOFMEMORY;
182
183     This->IDWriteFont_iface.lpVtbl = &dwritefontvtbl;
184     This->ref = 1;
185
186     This->style = logfont->lfItalic ? DWRITE_FONT_STYLE_ITALIC : DWRITE_FONT_STYLE_NORMAL;
187
188     *font = &This->IDWriteFont_iface;
189
190     return S_OK;
191 }