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
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);
39 WARN("(%p)->(%s, %p): not found\n", iface, debugstr_guid(riid), *object);
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);
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);
59 DeleteObject(This->hfont);
61 IDirect3DDevice9_Release(This->device);
62 HeapFree(GetProcessHeap(), 0, This);
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);
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);
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;
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);
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);
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);
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);
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);
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);
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);
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);
175 static HRESULT WINAPI ID3DXFontImpl_OnLostDevice(LPD3DXFONT iface)
177 ID3DXFontImpl *This=(ID3DXFontImpl*)iface;
178 FIXME("(%p)->(): stub\n", This);
182 static HRESULT WINAPI ID3DXFontImpl_OnResetDevice(LPD3DXFONT iface)
184 ID3DXFontImpl *This=(ID3DXFontImpl*)iface;
185 FIXME("(%p)->(): stub\n", This);
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,
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)
218 if( !device || !font ) return D3DERR_INVALIDCALL;
223 desc.MipLevels=miplevels;
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)
240 if( !device || !font ) return D3DERR_INVALIDCALL;
245 desc.MipLevels=miplevels;
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;
281 ID3DXFontImpl *object;
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);
295 IDirect3D9_Release(d3d);
296 return D3DXERR_INVALIDDATA;
298 IDirect3D9_Release(d3d);
300 object=HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(ID3DXFontImpl));
303 return E_OUTOFMEMORY;
305 object->lpVtbl=&D3DXFont_Vtbl;
307 object->device=device;
310 object->hdc = CreateCompatibleDC(NULL);
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;