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 typedef struct ID3DXFontImpl
31 ID3DXFont ID3DXFont_iface
;
34 IDirect3DDevice9
*device
;
41 static inline ID3DXFontImpl
*impl_from_ID3DXFont(ID3DXFont
*iface
)
43 return CONTAINING_RECORD(iface
, ID3DXFontImpl
, ID3DXFont_iface
);
46 static HRESULT WINAPI
ID3DXFontImpl_QueryInterface(ID3DXFont
*iface
, REFIID riid
, void **out
)
48 TRACE("iface %p, riid %s, out %p.\n", iface
, debugstr_guid(riid
), out
);
50 if (IsEqualGUID(riid
, &IID_ID3DXFont
)
51 || IsEqualGUID(riid
, &IID_IUnknown
))
53 IUnknown_AddRef(iface
);
58 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
64 static ULONG WINAPI
ID3DXFontImpl_AddRef(ID3DXFont
*iface
)
66 ID3DXFontImpl
*This
=impl_from_ID3DXFont(iface
);
67 ULONG ref
=InterlockedIncrement(&This
->ref
);
68 TRACE("(%p)->(): AddRef from %d\n", This
, ref
-1);
72 static ULONG WINAPI
ID3DXFontImpl_Release(ID3DXFont
*iface
)
74 ID3DXFontImpl
*This
=impl_from_ID3DXFont(iface
);
75 ULONG ref
=InterlockedDecrement(&This
->ref
);
77 TRACE("(%p)->(): ReleaseRef to %d\n", This
, ref
);
80 DeleteObject(This
->hfont
);
82 IDirect3DDevice9_Release(This
->device
);
83 HeapFree(GetProcessHeap(), 0, This
);
88 static HRESULT WINAPI
ID3DXFontImpl_GetDevice(ID3DXFont
*iface
, LPDIRECT3DDEVICE9
*device
)
90 ID3DXFontImpl
*This
=impl_from_ID3DXFont(iface
);
92 TRACE("(%p)->(%p)\n", This
, device
);
94 if( !device
) return D3DERR_INVALIDCALL
;
95 *device
= This
->device
;
96 IDirect3DDevice9_AddRef(This
->device
);
101 static HRESULT WINAPI
ID3DXFontImpl_GetDescA(ID3DXFont
*iface
, D3DXFONT_DESCA
*desc
)
103 ID3DXFontImpl
*This
=impl_from_ID3DXFont(iface
);
105 TRACE("(%p)->(%p)\n", This
, desc
);
107 if( !desc
) return D3DERR_INVALIDCALL
;
108 memcpy(desc
, &This
->desc
, FIELD_OFFSET(D3DXFONT_DESCA
, FaceName
));
109 WideCharToMultiByte(CP_ACP
, 0, This
->desc
.FaceName
, -1, desc
->FaceName
, sizeof(desc
->FaceName
) / sizeof(CHAR
), NULL
, NULL
);
114 static HRESULT WINAPI
ID3DXFontImpl_GetDescW(ID3DXFont
*iface
, D3DXFONT_DESCW
*desc
)
116 ID3DXFontImpl
*This
=impl_from_ID3DXFont(iface
);
118 TRACE("(%p)->(%p)\n", This
, desc
);
120 if( !desc
) return D3DERR_INVALIDCALL
;
126 static BOOL WINAPI
ID3DXFontImpl_GetTextMetricsA(ID3DXFont
*iface
, TEXTMETRICA
*metrics
)
128 ID3DXFontImpl
*This
=impl_from_ID3DXFont(iface
);
129 TRACE("(%p)->(%p)\n", This
, metrics
);
130 return GetTextMetricsA(This
->hdc
, metrics
);
133 static BOOL WINAPI
ID3DXFontImpl_GetTextMetricsW(ID3DXFont
*iface
, TEXTMETRICW
*metrics
)
135 ID3DXFontImpl
*This
=impl_from_ID3DXFont(iface
);
136 TRACE("(%p)->(%p)\n", This
, metrics
);
137 return GetTextMetricsW(This
->hdc
, metrics
);
140 static HDC WINAPI
ID3DXFontImpl_GetDC(ID3DXFont
*iface
)
142 ID3DXFontImpl
*This
=impl_from_ID3DXFont(iface
);
143 TRACE("(%p)->()\n", This
);
147 static HRESULT WINAPI
ID3DXFontImpl_GetGlyphData(ID3DXFont
*iface
, UINT glyph
,
148 LPDIRECT3DTEXTURE9
*texture
, RECT
*blackbox
, POINT
*cellinc
)
150 ID3DXFontImpl
*This
=impl_from_ID3DXFont(iface
);
151 FIXME("(%p)->(%u, %p, %p, %p): stub\n", This
, glyph
, texture
, blackbox
, cellinc
);
155 static HRESULT WINAPI
ID3DXFontImpl_PreloadCharacters(ID3DXFont
*iface
, UINT first
, UINT last
)
157 ID3DXFontImpl
*This
=impl_from_ID3DXFont(iface
);
158 FIXME("(%p)->(%u, %u): stub\n", This
, first
, last
);
162 static HRESULT WINAPI
ID3DXFontImpl_PreloadGlyphs(ID3DXFont
*iface
, UINT first
, UINT last
)
164 ID3DXFontImpl
*This
=impl_from_ID3DXFont(iface
);
165 FIXME("(%p)->(%u, %u): stub\n", This
, first
, last
);
169 static HRESULT WINAPI
ID3DXFontImpl_PreloadTextA(ID3DXFont
*iface
, LPCSTR string
, INT count
)
171 ID3DXFontImpl
*This
=impl_from_ID3DXFont(iface
);
172 FIXME("(%p)->(%s, %d): stub\n", This
, string
, count
);
176 static HRESULT WINAPI
ID3DXFontImpl_PreloadTextW(ID3DXFont
*iface
, LPCWSTR string
, INT count
)
178 ID3DXFontImpl
*This
=impl_from_ID3DXFont(iface
);
179 FIXME("(%p)->(%s, %d): stub\n", This
, debugstr_w(string
), count
);
183 static INT WINAPI
ID3DXFontImpl_DrawTextA(ID3DXFont
*iface
, LPD3DXSPRITE sprite
, LPCSTR string
,
184 INT count
, LPRECT rect
, DWORD format
, D3DCOLOR color
)
186 ID3DXFontImpl
*This
=impl_from_ID3DXFont(iface
);
187 FIXME("(%p)->(%p, %s, %d, %p, %d, %#x): stub\n", This
, sprite
, string
, count
, rect
, format
, color
);
191 static INT WINAPI
ID3DXFontImpl_DrawTextW(ID3DXFont
*iface
, LPD3DXSPRITE sprite
, LPCWSTR string
,
192 INT count
, LPRECT rect
, DWORD format
, D3DCOLOR color
)
194 ID3DXFontImpl
*This
=impl_from_ID3DXFont(iface
);
195 FIXME("(%p)->(%p, %s, %d, %p, %d, %#x): stub\n", This
, sprite
, debugstr_w(string
), count
, rect
, format
, color
);
199 static HRESULT WINAPI
ID3DXFontImpl_OnLostDevice(ID3DXFont
*iface
)
201 ID3DXFontImpl
*This
=impl_from_ID3DXFont(iface
);
202 FIXME("(%p)->(): stub\n", This
);
206 static HRESULT WINAPI
ID3DXFontImpl_OnResetDevice(ID3DXFont
*iface
)
208 ID3DXFontImpl
*This
=impl_from_ID3DXFont(iface
);
209 FIXME("(%p)->(): stub\n", This
);
213 static const ID3DXFontVtbl D3DXFont_Vtbl
=
215 /*** IUnknown methods ***/
216 ID3DXFontImpl_QueryInterface
,
217 ID3DXFontImpl_AddRef
,
218 ID3DXFontImpl_Release
,
219 /*** ID3DXFont methods ***/
220 ID3DXFontImpl_GetDevice
,
221 ID3DXFontImpl_GetDescA
,
222 ID3DXFontImpl_GetDescW
,
223 ID3DXFontImpl_GetTextMetricsA
,
224 ID3DXFontImpl_GetTextMetricsW
,
226 ID3DXFontImpl_GetGlyphData
,
227 ID3DXFontImpl_PreloadCharacters
,
228 ID3DXFontImpl_PreloadGlyphs
,
229 ID3DXFontImpl_PreloadTextA
,
230 ID3DXFontImpl_PreloadTextW
,
231 ID3DXFontImpl_DrawTextA
,
232 ID3DXFontImpl_DrawTextW
,
233 ID3DXFontImpl_OnLostDevice
,
234 ID3DXFontImpl_OnResetDevice
237 HRESULT WINAPI
D3DXCreateFontA(LPDIRECT3DDEVICE9 device
, INT height
, UINT width
, UINT weight
, UINT miplevels
, BOOL italic
, DWORD charset
,
238 DWORD precision
, DWORD quality
, DWORD pitchandfamily
, LPCSTR facename
, LPD3DXFONT
*font
)
242 if( !device
|| !font
) return D3DERR_INVALIDCALL
;
247 desc
.MipLevels
=miplevels
;
249 desc
.CharSet
=charset
;
250 desc
.OutputPrecision
=precision
;
251 desc
.Quality
=quality
;
252 desc
.PitchAndFamily
=pitchandfamily
;
253 if(facename
!= NULL
) lstrcpyA(desc
.FaceName
, facename
);
254 else desc
.FaceName
[0] = '\0';
256 return D3DXCreateFontIndirectA(device
, &desc
, font
);
259 HRESULT WINAPI
D3DXCreateFontW(LPDIRECT3DDEVICE9 device
, INT height
, UINT width
, UINT weight
, UINT miplevels
, BOOL italic
, DWORD charset
,
260 DWORD precision
, DWORD quality
, DWORD pitchandfamily
, LPCWSTR facename
, LPD3DXFONT
*font
)
264 if( !device
|| !font
) return D3DERR_INVALIDCALL
;
269 desc
.MipLevels
=miplevels
;
271 desc
.CharSet
=charset
;
272 desc
.OutputPrecision
=precision
;
273 desc
.Quality
=quality
;
274 desc
.PitchAndFamily
=pitchandfamily
;
275 if(facename
!= NULL
) strcpyW(desc
.FaceName
, facename
);
276 else desc
.FaceName
[0] = '\0';
278 return D3DXCreateFontIndirectW(device
, &desc
, font
);
281 /***********************************************************************
282 * D3DXCreateFontIndirectA (D3DX9_36.@)
284 HRESULT WINAPI
D3DXCreateFontIndirectA(LPDIRECT3DDEVICE9 device
, CONST D3DXFONT_DESCA
*desc
, LPD3DXFONT
*font
)
286 D3DXFONT_DESCW widedesc
;
288 if( !device
|| !desc
|| !font
) return D3DERR_INVALIDCALL
;
290 /* Copy everything but the last structure member. This requires the
291 two D3DXFONT_DESC structures to be equal until the FaceName member */
292 memcpy(&widedesc
, desc
, FIELD_OFFSET(D3DXFONT_DESCA
, FaceName
));
293 MultiByteToWideChar(CP_ACP
, 0, desc
->FaceName
, -1,
294 widedesc
.FaceName
, sizeof(widedesc
.FaceName
)/sizeof(WCHAR
));
295 return D3DXCreateFontIndirectW(device
, &widedesc
, font
);
298 /***********************************************************************
299 * D3DXCreateFontIndirectW (D3DX9_36.@)
301 HRESULT WINAPI
D3DXCreateFontIndirectW(LPDIRECT3DDEVICE9 device
, CONST D3DXFONT_DESCW
*desc
, LPD3DXFONT
*font
)
303 D3DDEVICE_CREATION_PARAMETERS cpars
;
305 ID3DXFontImpl
*object
;
309 FIXME("(%p, %p, %p): stub\n", device
, desc
, font
);
311 if( !device
|| !desc
|| !font
) return D3DERR_INVALIDCALL
;
313 /* the device MUST support D3DFMT_A8R8G8B8 */
314 IDirect3DDevice9_GetDirect3D(device
, &d3d
);
315 IDirect3DDevice9_GetCreationParameters(device
, &cpars
);
316 IDirect3DDevice9_GetDisplayMode(device
, 0, &mode
);
317 hr
= IDirect3D9_CheckDeviceFormat(d3d
, cpars
.AdapterOrdinal
, cpars
.DeviceType
, mode
.Format
, 0, D3DRTYPE_TEXTURE
, D3DFMT_A8R8G8B8
);
319 IDirect3D9_Release(d3d
);
320 return D3DXERR_INVALIDDATA
;
322 IDirect3D9_Release(d3d
);
324 object
=HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(ID3DXFontImpl
));
327 return E_OUTOFMEMORY
;
329 object
->ID3DXFont_iface
.lpVtbl
= &D3DXFont_Vtbl
;
331 object
->device
=device
;
334 object
->hdc
= CreateCompatibleDC(NULL
);
336 HeapFree(GetProcessHeap(), 0, object
);
337 return D3DXERR_INVALIDDATA
;
340 object
->hfont
= CreateFontW(desc
->Height
, desc
->Width
, 0, 0, desc
->Weight
, desc
->Italic
, FALSE
, FALSE
, desc
->CharSet
,
341 desc
->OutputPrecision
, CLIP_DEFAULT_PRECIS
, desc
->Quality
, desc
->PitchAndFamily
, desc
->FaceName
);
342 if( !object
->hfont
) {
343 DeleteDC(object
->hdc
);
344 HeapFree(GetProcessHeap(), 0, object
);
345 return D3DXERR_INVALIDDATA
;
347 SelectObject(object
->hdc
, object
->hfont
);
349 IDirect3DDevice9_AddRef(device
);
350 *font
=&object
->ID3DXFont_iface
;