gdiplus/tests: Comment out a test that corrupts the stack on Vista.
[wine/multimedia.git] / dlls / d3dx9_36 / font.c
blob1113060ed8f1e9666eaa5f5fd7959258d8713388
1 /*
2 * Copyright (C) 2008 Tony Wasserka
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "config.h"
21 #include "wine/port.h"
23 #include "wine/debug.h"
24 #include "wine/unicode.h"
25 #include "d3dx9_36_private.h"
27 WINE_DEFAULT_DEBUG_CHANNEL(d3dx);
29 static HRESULT WINAPI ID3DXFontImpl_QueryInterface(LPD3DXFONT iface, REFIID riid, LPVOID *object)
31 ID3DXFontImpl *This=(ID3DXFontImpl*)iface;
33 TRACE("(%p): QueryInterface from %s\n", This, debugstr_guid(riid));
34 if(IsEqualGUID(riid, &IID_IUnknown) || IsEqualGUID(riid, &IID_ID3DXFont)) {
35 IUnknown_AddRef(iface);
36 *object=This;
37 return S_OK;
39 WARN("(%p)->(%s, %p): not found\n", iface, debugstr_guid(riid), *object);
40 return E_NOINTERFACE;
43 static ULONG WINAPI ID3DXFontImpl_AddRef(LPD3DXFONT iface)
45 ID3DXFontImpl *This=(ID3DXFontImpl*)iface;
46 ULONG ref=InterlockedIncrement(&This->ref);
47 TRACE("(%p)->(): AddRef from %d\n", This, ref-1);
48 return ref;
51 static ULONG WINAPI ID3DXFontImpl_Release(LPD3DXFONT iface)
53 ID3DXFontImpl *This=(ID3DXFontImpl*)iface;
54 ULONG ref=InterlockedDecrement(&This->ref);
56 TRACE("(%p)->(): ReleaseRef to %d\n", This, ref);
58 if(ref==0) {
59 DeleteObject(This->hfont);
60 DeleteDC(This->hdc);
61 IDirect3DDevice9_Release(This->device);
62 HeapFree(GetProcessHeap(), 0, This);
64 return ref;
67 static HRESULT WINAPI ID3DXFontImpl_GetDevice(LPD3DXFONT iface, LPDIRECT3DDEVICE9 *device)
69 ID3DXFontImpl *This=(ID3DXFontImpl*)iface;
71 TRACE("(%p)->(%p)\n", This, device);
73 if( !device ) return D3DERR_INVALIDCALL;
74 *device = This->device;
75 IDirect3DDevice9_AddRef(This->device);
77 return D3D_OK;
80 static HRESULT WINAPI ID3DXFontImpl_GetDescA(LPD3DXFONT iface, D3DXFONT_DESCA *desc)
82 ID3DXFontImpl *This=(ID3DXFontImpl*)iface;
84 TRACE("(%p)->(%p)\n", This, desc);
86 if( !desc ) return D3DERR_INVALIDCALL;
87 memcpy(desc, &This->desc, FIELD_OFFSET(D3DXFONT_DESCA, FaceName));
88 WideCharToMultiByte(CP_ACP, 0, This->desc.FaceName, -1, desc->FaceName, sizeof(desc->FaceName) / sizeof(CHAR), NULL, NULL);
90 return D3D_OK;
93 static HRESULT WINAPI ID3DXFontImpl_GetDescW(LPD3DXFONT iface, D3DXFONT_DESCW *desc)
95 ID3DXFontImpl *This=(ID3DXFontImpl*)iface;
97 TRACE("(%p)->(%p)\n", This, desc);
99 if( !desc ) return D3DERR_INVALIDCALL;
100 *desc = This->desc;
102 return D3D_OK;
105 static BOOL WINAPI ID3DXFontImpl_GetTextMetricsA(LPD3DXFONT iface, TEXTMETRICA *metrics)
107 ID3DXFontImpl *This=(ID3DXFontImpl*)iface;
108 TRACE("(%p)->(%p)\n", This, metrics);
109 return GetTextMetricsA(This->hdc, metrics);
112 static BOOL WINAPI ID3DXFontImpl_GetTextMetricsW(LPD3DXFONT iface, TEXTMETRICW *metrics)
114 ID3DXFontImpl *This=(ID3DXFontImpl*)iface;
115 TRACE("(%p)->(%p)\n", This, metrics);
116 return GetTextMetricsW(This->hdc, metrics);
119 static HDC WINAPI ID3DXFontImpl_GetDC(LPD3DXFONT iface)
121 ID3DXFontImpl *This=(ID3DXFontImpl*)iface;
122 TRACE("(%p)->()\n", This);
123 return This->hdc;
126 static HRESULT WINAPI ID3DXFontImpl_GetGlyphData(LPD3DXFONT iface, UINT glyph, LPDIRECT3DTEXTURE9 *texture, RECT *blackbox, POINT *cellinc)
128 ID3DXFontImpl *This=(ID3DXFontImpl*)iface;
129 FIXME("(%p)->(%u, %p, %p, %p): stub\n", This, glyph, texture, blackbox, cellinc);
130 return D3D_OK;
133 static HRESULT WINAPI ID3DXFontImpl_PreloadCharacters(LPD3DXFONT iface, UINT first, UINT last)
135 ID3DXFontImpl *This=(ID3DXFontImpl*)iface;
136 FIXME("(%p)->(%u, %u): stub\n", This, first, last);
137 return D3D_OK;
140 static HRESULT WINAPI ID3DXFontImpl_PreloadGlyphs(LPD3DXFONT iface, UINT first, UINT last)
142 ID3DXFontImpl *This=(ID3DXFontImpl*)iface;
143 FIXME("(%p)->(%u, %u): stub\n", This, first, last);
144 return D3D_OK;
147 static HRESULT WINAPI ID3DXFontImpl_PreloadTextA(LPD3DXFONT iface, LPCSTR string, INT count)
149 ID3DXFontImpl *This=(ID3DXFontImpl*)iface;
150 FIXME("(%p)->(%s, %d): stub\n", This, string, count);
151 return D3D_OK;
154 static HRESULT WINAPI ID3DXFontImpl_PreloadTextW(LPD3DXFONT iface, LPCWSTR string, INT count)
156 ID3DXFontImpl *This=(ID3DXFontImpl*)iface;
157 FIXME("(%p)->(%s, %d): stub\n", This, debugstr_w(string), count);
158 return D3D_OK;
161 static INT WINAPI ID3DXFontImpl_DrawTextA(LPD3DXFONT iface, LPD3DXSPRITE sprite, LPCSTR string, INT count, LPRECT rect, DWORD format, D3DCOLOR color)
163 ID3DXFontImpl *This=(ID3DXFontImpl*)iface;
164 FIXME("(%p)->(%p, %s, %d, %p, %d, %#x): stub\n", This, sprite, string, count, rect, format, color);
165 return 1;
168 static INT WINAPI ID3DXFontImpl_DrawTextW(LPD3DXFONT iface, LPD3DXSPRITE sprite, LPCWSTR string, INT count, LPRECT rect, DWORD format, D3DCOLOR color)
170 ID3DXFontImpl *This=(ID3DXFontImpl*)iface;
171 FIXME("(%p)->(%p, %s, %d, %p, %d, %#x): stub\n", This, sprite, debugstr_w(string), count, rect, format, color);
172 return 1;
175 static HRESULT WINAPI ID3DXFontImpl_OnLostDevice(LPD3DXFONT iface)
177 ID3DXFontImpl *This=(ID3DXFontImpl*)iface;
178 FIXME("(%p)->(): stub\n", This);
179 return D3D_OK;
182 static HRESULT WINAPI ID3DXFontImpl_OnResetDevice(LPD3DXFONT iface)
184 ID3DXFontImpl *This=(ID3DXFontImpl*)iface;
185 FIXME("(%p)->(): stub\n", This);
186 return D3D_OK;
189 static const ID3DXFontVtbl D3DXFont_Vtbl =
191 /*** IUnknown methods ***/
192 ID3DXFontImpl_QueryInterface,
193 ID3DXFontImpl_AddRef,
194 ID3DXFontImpl_Release,
195 /*** ID3DXFont methods ***/
196 ID3DXFontImpl_GetDevice,
197 ID3DXFontImpl_GetDescA,
198 ID3DXFontImpl_GetDescW,
199 ID3DXFontImpl_GetTextMetricsA,
200 ID3DXFontImpl_GetTextMetricsW,
201 ID3DXFontImpl_GetDC,
202 ID3DXFontImpl_GetGlyphData,
203 ID3DXFontImpl_PreloadCharacters,
204 ID3DXFontImpl_PreloadGlyphs,
205 ID3DXFontImpl_PreloadTextA,
206 ID3DXFontImpl_PreloadTextW,
207 ID3DXFontImpl_DrawTextA,
208 ID3DXFontImpl_DrawTextW,
209 ID3DXFontImpl_OnLostDevice,
210 ID3DXFontImpl_OnResetDevice
213 HRESULT WINAPI D3DXCreateFontA(LPDIRECT3DDEVICE9 device, INT height, UINT width, UINT weight, UINT miplevels, BOOL italic, DWORD charset,
214 DWORD precision, DWORD quality, DWORD pitchandfamily, LPCSTR facename, LPD3DXFONT *font)
216 D3DXFONT_DESCA desc;
218 if( !device || !font ) return D3DERR_INVALIDCALL;
220 desc.Height=height;
221 desc.Width=width;
222 desc.Weight=weight;
223 desc.MipLevels=miplevels;
224 desc.Italic=italic;
225 desc.CharSet=charset;
226 desc.OutputPrecision=precision;
227 desc.Quality=quality;
228 desc.PitchAndFamily=pitchandfamily;
229 if(facename != NULL) lstrcpyA(desc.FaceName, facename);
230 else desc.FaceName[0] = '\0';
232 return D3DXCreateFontIndirectA(device, &desc, font);
235 HRESULT WINAPI D3DXCreateFontW(LPDIRECT3DDEVICE9 device, INT height, UINT width, UINT weight, UINT miplevels, BOOL italic, DWORD charset,
236 DWORD precision, DWORD quality, DWORD pitchandfamily, LPCWSTR facename, LPD3DXFONT *font)
238 D3DXFONT_DESCW desc;
240 if( !device || !font ) return D3DERR_INVALIDCALL;
242 desc.Height=height;
243 desc.Width=width;
244 desc.Weight=weight;
245 desc.MipLevels=miplevels;
246 desc.Italic=italic;
247 desc.CharSet=charset;
248 desc.OutputPrecision=precision;
249 desc.Quality=quality;
250 desc.PitchAndFamily=pitchandfamily;
251 if(facename != NULL) strcpyW(desc.FaceName, facename);
252 else desc.FaceName[0] = '\0';
254 return D3DXCreateFontIndirectW(device, &desc, font);
257 /***********************************************************************
258 * D3DXCreateFontIndirectA (D3DX9_36.@)
260 HRESULT WINAPI D3DXCreateFontIndirectA(LPDIRECT3DDEVICE9 device, CONST D3DXFONT_DESCA *desc, LPD3DXFONT *font)
262 D3DXFONT_DESCW widedesc;
264 if( !device || !desc || !font ) return D3DERR_INVALIDCALL;
266 /* Copy everything but the last structure member. This requires the
267 two D3DXFONT_DESC structures to be equal until the FaceName member */
268 memcpy(&widedesc, desc, FIELD_OFFSET(D3DXFONT_DESCA, FaceName));
269 MultiByteToWideChar(CP_ACP, 0, desc->FaceName, -1,
270 widedesc.FaceName, sizeof(widedesc.FaceName)/sizeof(WCHAR));
271 return D3DXCreateFontIndirectW(device, &widedesc, font);
274 /***********************************************************************
275 * D3DXCreateFontIndirectW (D3DX9_36.@)
277 HRESULT WINAPI D3DXCreateFontIndirectW(LPDIRECT3DDEVICE9 device, CONST D3DXFONT_DESCW *desc, LPD3DXFONT *font)
279 D3DDEVICE_CREATION_PARAMETERS cpars;
280 D3DDISPLAYMODE mode;
281 ID3DXFontImpl *object;
282 IDirect3D9 *d3d;
283 HRESULT hr;
285 FIXME("(%p, %p, %p): stub\n", device, desc, font);
287 if( !device || !desc || !font ) return D3DERR_INVALIDCALL;
289 /* the device MUST support D3DFMT_A8R8G8B8 */
290 IDirect3DDevice9_GetDirect3D(device, &d3d);
291 IDirect3DDevice9_GetCreationParameters(device, &cpars);
292 IDirect3DDevice9_GetDisplayMode(device, 0, &mode);
293 hr = IDirect3D9_CheckDeviceFormat(d3d, cpars.AdapterOrdinal, cpars.DeviceType, mode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_A8R8G8B8);
294 if(FAILED(hr)) {
295 IDirect3D9_Release(d3d);
296 return D3DXERR_INVALIDDATA;
298 IDirect3D9_Release(d3d);
300 object=HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(ID3DXFontImpl));
301 if(object==NULL) {
302 *font=NULL;
303 return E_OUTOFMEMORY;
305 object->lpVtbl=&D3DXFont_Vtbl;
306 object->ref=1;
307 object->device=device;
308 object->desc=*desc;
310 object->hdc = CreateCompatibleDC(NULL);
311 if( !object->hdc ) {
312 HeapFree(GetProcessHeap(), 0, object);
313 return D3DXERR_INVALIDDATA;
316 object->hfont = CreateFontW(desc->Height, desc->Width, 0, 0, desc->Weight, desc->Italic, FALSE, FALSE, desc->CharSet,
317 desc->OutputPrecision, CLIP_DEFAULT_PRECIS, desc->Quality, desc->PitchAndFamily, desc->FaceName);
318 if( !object->hfont ) {
319 DeleteDC(object->hdc);
320 HeapFree(GetProcessHeap(), 0, object);
321 return D3DXERR_INVALIDDATA;
323 SelectObject(object->hdc, object->hfont);
325 IDirect3DDevice9_AddRef(device);
326 *font=(LPD3DXFONT)object;
328 return D3D_OK;