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);
55 TRACE("(%p): ReleaseRef to %d\n", This, ref);
58 DeleteObject(This->hfont);
60 IDirect3DDevice9_Release(This->device);
61 HeapFree(GetProcessHeap(), 0, This);
66 static HRESULT WINAPI ID3DXFontImpl_GetDevice(LPD3DXFONT iface, LPDIRECT3DDEVICE9 *device)
68 ID3DXFontImpl *This=(ID3DXFontImpl*)iface;
69 TRACE("(%p)\n", This);
71 if( !device ) return D3DERR_INVALIDCALL;
72 *device = This->device;
73 IDirect3DDevice9_AddRef(This->device);
78 static HRESULT WINAPI ID3DXFontImpl_GetDescA(LPD3DXFONT iface, D3DXFONT_DESCA *desc)
80 ID3DXFontImpl *This=(ID3DXFontImpl*)iface;
81 TRACE("(%p)\n", This);
83 if( !desc ) return D3DERR_INVALIDCALL;
84 memcpy(desc, &This->desc, FIELD_OFFSET(D3DXFONT_DESCA, FaceName));
85 WideCharToMultiByte(CP_ACP, 0, This->desc.FaceName, -1, desc->FaceName, sizeof(desc->FaceName) / sizeof(CHAR), NULL, NULL);
90 static HRESULT WINAPI ID3DXFontImpl_GetDescW(LPD3DXFONT iface, D3DXFONT_DESCW *desc)
92 ID3DXFontImpl *This=(ID3DXFontImpl*)iface;
93 TRACE("(%p)\n", This);
95 if( !desc ) return D3DERR_INVALIDCALL;
101 static BOOL WINAPI ID3DXFontImpl_GetTextMetricsA(LPD3DXFONT iface, TEXTMETRICA *metrics)
103 ID3DXFontImpl *This=(ID3DXFontImpl*)iface;
104 TRACE("(%p)\n", This);
105 return GetTextMetricsA(This->hdc, metrics);
108 static BOOL WINAPI ID3DXFontImpl_GetTextMetricsW(LPD3DXFONT iface, TEXTMETRICW *metrics)
110 ID3DXFontImpl *This=(ID3DXFontImpl*)iface;
111 TRACE("(%p)\n", This);
112 return GetTextMetricsW(This->hdc, metrics);
115 static HDC WINAPI ID3DXFontImpl_GetDC(LPD3DXFONT iface)
117 ID3DXFontImpl *This=(ID3DXFontImpl*)iface;
118 TRACE("(%p)\n", This);
122 static HRESULT WINAPI ID3DXFontImpl_GetGlyphData(LPD3DXFONT iface, UINT glyph, LPDIRECT3DTEXTURE9 *texture, RECT *blackbox, POINT *cellinc)
124 ID3DXFontImpl *This=(ID3DXFontImpl*)iface;
125 FIXME("(%p): stub\n", This);
129 static HRESULT WINAPI ID3DXFontImpl_PreloadCharacters(LPD3DXFONT iface, UINT first, UINT last)
131 ID3DXFontImpl *This=(ID3DXFontImpl*)iface;
132 FIXME("(%p): stub\n", This);
136 static HRESULT WINAPI ID3DXFontImpl_PreloadGlyphs(LPD3DXFONT iface, UINT first, UINT last)
138 ID3DXFontImpl *This=(ID3DXFontImpl*)iface;
139 FIXME("(%p): stub\n", This);
143 static HRESULT WINAPI ID3DXFontImpl_PreloadTextA(LPD3DXFONT iface, LPCSTR string, INT count)
145 ID3DXFontImpl *This=(ID3DXFontImpl*)iface;
146 FIXME("(%p): stub\n", This);
150 static HRESULT WINAPI ID3DXFontImpl_PreloadTextW(LPD3DXFONT iface, LPCWSTR string, INT count)
152 ID3DXFontImpl *This=(ID3DXFontImpl*)iface;
153 FIXME("(%p): stub\n", This);
157 static INT WINAPI ID3DXFontImpl_DrawTextA(LPD3DXFONT iface, LPD3DXSPRITE sprite, LPCSTR string, INT count, LPRECT rect, DWORD format, D3DCOLOR color)
159 ID3DXFontImpl *This=(ID3DXFontImpl*)iface;
160 FIXME("(%p): stub\n", This);
164 static INT WINAPI ID3DXFontImpl_DrawTextW(LPD3DXFONT iface, LPD3DXSPRITE sprite, LPCWSTR string, INT count, LPRECT rect, DWORD format, D3DCOLOR color)
166 ID3DXFontImpl *This=(ID3DXFontImpl*)iface;
167 FIXME("(%p): stub\n", This);
171 static HRESULT WINAPI ID3DXFontImpl_OnLostDevice(LPD3DXFONT iface)
173 ID3DXFontImpl *This=(ID3DXFontImpl*)iface;
174 FIXME("(%p): stub\n", This);
178 static HRESULT WINAPI ID3DXFontImpl_OnResetDevice(LPD3DXFONT iface)
180 ID3DXFontImpl *This=(ID3DXFontImpl*)iface;
181 FIXME("(%p): stub\n", This);
185 static const ID3DXFontVtbl D3DXFont_Vtbl =
187 /*** IUnknown methods ***/
188 ID3DXFontImpl_QueryInterface,
189 ID3DXFontImpl_AddRef,
190 ID3DXFontImpl_Release,
191 /*** ID3DXFont methods ***/
192 ID3DXFontImpl_GetDevice,
193 ID3DXFontImpl_GetDescA,
194 ID3DXFontImpl_GetDescW,
195 ID3DXFontImpl_GetTextMetricsA,
196 ID3DXFontImpl_GetTextMetricsW,
198 ID3DXFontImpl_GetGlyphData,
199 ID3DXFontImpl_PreloadCharacters,
200 ID3DXFontImpl_PreloadGlyphs,
201 ID3DXFontImpl_PreloadTextA,
202 ID3DXFontImpl_PreloadTextW,
203 ID3DXFontImpl_DrawTextA,
204 ID3DXFontImpl_DrawTextW,
205 ID3DXFontImpl_OnLostDevice,
206 ID3DXFontImpl_OnResetDevice
209 HRESULT WINAPI D3DXCreateFontA(LPDIRECT3DDEVICE9 device, INT height, UINT width, UINT weight, UINT miplevels, BOOL italic, DWORD charset,
210 DWORD precision, DWORD quality, DWORD pitchandfamily, LPCSTR facename, LPD3DXFONT *font)
214 if( !device || !font ) return D3DERR_INVALIDCALL;
219 desc.MipLevels=miplevels;
221 desc.CharSet=charset;
222 desc.OutputPrecision=precision;
223 desc.Quality=quality;
224 desc.PitchAndFamily=pitchandfamily;
225 if(facename != NULL) lstrcpyA(desc.FaceName, facename);
226 else desc.FaceName[0] = '\0';
228 return D3DXCreateFontIndirectA(device, &desc, font);
231 HRESULT WINAPI D3DXCreateFontW(LPDIRECT3DDEVICE9 device, INT height, UINT width, UINT weight, UINT miplevels, BOOL italic, DWORD charset,
232 DWORD precision, DWORD quality, DWORD pitchandfamily, LPCWSTR facename, LPD3DXFONT *font)
236 if( !device || !font ) return D3DERR_INVALIDCALL;
241 desc.MipLevels=miplevels;
243 desc.CharSet=charset;
244 desc.OutputPrecision=precision;
245 desc.Quality=quality;
246 desc.PitchAndFamily=pitchandfamily;
247 if(facename != NULL) strcpyW(desc.FaceName, facename);
248 else desc.FaceName[0] = '\0';
250 return D3DXCreateFontIndirectW(device, &desc, font);
253 /***********************************************************************
254 * D3DXCreateFontIndirectA (D3DX9_36.@)
256 HRESULT WINAPI D3DXCreateFontIndirectA(LPDIRECT3DDEVICE9 device, CONST D3DXFONT_DESCA *desc, LPD3DXFONT *font)
258 D3DXFONT_DESCW widedesc;
260 if( !device || !desc || !font ) return D3DERR_INVALIDCALL;
262 /* Copy everything but the last structure member. This requires the
263 two D3DXFONT_DESC structures to be equal until the FaceName member */
264 memcpy(&widedesc, desc, FIELD_OFFSET(D3DXFONT_DESCA, FaceName));
265 MultiByteToWideChar(CP_ACP, 0, desc->FaceName, -1,
266 widedesc.FaceName, sizeof(widedesc.FaceName)/sizeof(WCHAR));
267 return D3DXCreateFontIndirectW(device, &widedesc, font);
270 /***********************************************************************
271 * D3DXCreateFontIndirectW (D3DX9_36.@)
273 HRESULT WINAPI D3DXCreateFontIndirectW(LPDIRECT3DDEVICE9 device, CONST D3DXFONT_DESCW *desc, LPD3DXFONT *font)
275 D3DDEVICE_CREATION_PARAMETERS cpars;
277 ID3DXFontImpl *object;
282 if( !device || !desc || !font ) return D3DERR_INVALIDCALL;
284 /* the device MUST support D3DFMT_A8R8G8B8 */
285 IDirect3DDevice9_GetDirect3D(device, &d3d);
286 IDirect3DDevice9_GetCreationParameters(device, &cpars);
287 IDirect3DDevice9_GetDisplayMode(device, 0, &mode);
288 hr = IDirect3D9_CheckDeviceFormat(d3d, cpars.AdapterOrdinal, cpars.DeviceType, mode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_A8R8G8B8);
290 IDirect3D9_Release(d3d);
291 return D3DXERR_INVALIDDATA;
293 IDirect3D9_Release(d3d);
295 object=HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(ID3DXFontImpl));
298 return E_OUTOFMEMORY;
300 object->lpVtbl=&D3DXFont_Vtbl;
302 object->device=device;
305 object->hdc = CreateCompatibleDC(NULL);
307 HeapFree(GetProcessHeap(), 0, object);
308 return D3DXERR_INVALIDDATA;
311 object->hfont = CreateFontW(desc->Height, desc->Width, 0, 0, desc->Weight, desc->Italic, FALSE, FALSE, desc->CharSet,
312 desc->OutputPrecision, CLIP_DEFAULT_PRECIS, desc->Quality, desc->PitchAndFamily, desc->FaceName);
313 if( !object->hfont ) {
314 DeleteDC(object->hdc);
315 HeapFree(GetProcessHeap(), 0, object);
316 return D3DXERR_INVALIDDATA;
318 SelectObject(object->hdc, object->hfont);
320 IDirect3DDevice9_AddRef(device);
321 *font=(LPD3DXFONT)object;