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 IDirect3DDevice9_Release(This
->device
);
59 HeapFree(GetProcessHeap(), 0, This
);
64 static HRESULT WINAPI
ID3DXFontImpl_GetDevice(LPD3DXFONT iface
, LPDIRECT3DDEVICE9
*device
)
66 ID3DXFontImpl
*This
=(ID3DXFontImpl
*)iface
;
67 TRACE("(%p)\n", This
);
69 if( !device
) return D3DERR_INVALIDCALL
;
70 *device
= This
->device
;
71 IDirect3DDevice9_AddRef(This
->device
);
76 static HRESULT WINAPI
ID3DXFontImpl_GetDescA(LPD3DXFONT iface
, D3DXFONT_DESCA
*desc
)
78 ID3DXFontImpl
*This
=(ID3DXFontImpl
*)iface
;
79 TRACE("(%p)\n", This
);
81 if( !desc
) return D3DERR_INVALIDCALL
;
82 memcpy(desc
, &This
->desc
, FIELD_OFFSET(D3DXFONT_DESCA
, FaceName
));
83 WideCharToMultiByte(CP_ACP
, 0, This
->desc
.FaceName
, -1, desc
->FaceName
, sizeof(desc
->FaceName
) / sizeof(CHAR
), NULL
, NULL
);
88 static HRESULT WINAPI
ID3DXFontImpl_GetDescW(LPD3DXFONT iface
, D3DXFONT_DESCW
*desc
)
90 ID3DXFontImpl
*This
=(ID3DXFontImpl
*)iface
;
91 TRACE("(%p)\n", This
);
93 if( !desc
) return D3DERR_INVALIDCALL
;
99 static BOOL WINAPI
ID3DXFontImpl_GetTextMetricsA(LPD3DXFONT iface
, TEXTMETRICA
*metrics
)
101 ID3DXFontImpl
*This
=(ID3DXFontImpl
*)iface
;
102 FIXME("(%p): stub\n", This
);
106 static BOOL WINAPI
ID3DXFontImpl_GetTextMetricsW(LPD3DXFONT iface
, TEXTMETRICW
*metrics
)
108 ID3DXFontImpl
*This
=(ID3DXFontImpl
*)iface
;
109 FIXME("(%p): stub\n", This
);
113 static HDC WINAPI
ID3DXFontImpl_GetDC(LPD3DXFONT iface
)
115 ID3DXFontImpl
*This
=(ID3DXFontImpl
*)iface
;
116 FIXME("(%p): stub\n", This
);
120 static HRESULT WINAPI
ID3DXFontImpl_GetGlyphData(LPD3DXFONT iface
, UINT glyph
, LPDIRECT3DTEXTURE9
*texture
, RECT
*blackbox
, POINT
*cellinc
)
122 ID3DXFontImpl
*This
=(ID3DXFontImpl
*)iface
;
123 FIXME("(%p): stub\n", This
);
127 static HRESULT WINAPI
ID3DXFontImpl_PreloadCharacters(LPD3DXFONT iface
, UINT first
, UINT last
)
129 ID3DXFontImpl
*This
=(ID3DXFontImpl
*)iface
;
130 FIXME("(%p): stub\n", This
);
134 static HRESULT WINAPI
ID3DXFontImpl_PreloadGlyphs(LPD3DXFONT iface
, UINT first
, UINT last
)
136 ID3DXFontImpl
*This
=(ID3DXFontImpl
*)iface
;
137 FIXME("(%p): stub\n", This
);
141 static HRESULT WINAPI
ID3DXFontImpl_PreloadTextA(LPD3DXFONT iface
, LPCSTR string
, INT count
)
143 ID3DXFontImpl
*This
=(ID3DXFontImpl
*)iface
;
144 FIXME("(%p): stub\n", This
);
148 static HRESULT WINAPI
ID3DXFontImpl_PreloadTextW(LPD3DXFONT iface
, LPCWSTR string
, INT count
)
150 ID3DXFontImpl
*This
=(ID3DXFontImpl
*)iface
;
151 FIXME("(%p): stub\n", This
);
155 static INT WINAPI
ID3DXFontImpl_DrawTextA(LPD3DXFONT iface
, LPD3DXSPRITE sprite
, LPCSTR string
, INT count
, LPRECT rect
, DWORD format
, D3DCOLOR color
)
157 ID3DXFontImpl
*This
=(ID3DXFontImpl
*)iface
;
158 FIXME("(%p): stub\n", This
);
162 static INT WINAPI
ID3DXFontImpl_DrawTextW(LPD3DXFONT iface
, LPD3DXSPRITE sprite
, LPCWSTR string
, INT count
, LPRECT rect
, DWORD format
, D3DCOLOR color
)
164 ID3DXFontImpl
*This
=(ID3DXFontImpl
*)iface
;
165 FIXME("(%p): stub\n", This
);
169 static HRESULT WINAPI
ID3DXFontImpl_OnLostDevice(LPD3DXFONT iface
)
171 ID3DXFontImpl
*This
=(ID3DXFontImpl
*)iface
;
172 FIXME("(%p): stub\n", This
);
176 static HRESULT WINAPI
ID3DXFontImpl_OnResetDevice(LPD3DXFONT iface
)
178 ID3DXFontImpl
*This
=(ID3DXFontImpl
*)iface
;
179 FIXME("(%p): stub\n", This
);
183 static const ID3DXFontVtbl D3DXFont_Vtbl
=
185 /*** IUnknown methods ***/
186 ID3DXFontImpl_QueryInterface
,
187 ID3DXFontImpl_AddRef
,
188 ID3DXFontImpl_Release
,
189 /*** ID3DXFont methods ***/
190 ID3DXFontImpl_GetDevice
,
191 ID3DXFontImpl_GetDescA
,
192 ID3DXFontImpl_GetDescW
,
193 ID3DXFontImpl_GetTextMetricsA
,
194 ID3DXFontImpl_GetTextMetricsW
,
196 ID3DXFontImpl_GetGlyphData
,
197 ID3DXFontImpl_PreloadCharacters
,
198 ID3DXFontImpl_PreloadGlyphs
,
199 ID3DXFontImpl_PreloadTextA
,
200 ID3DXFontImpl_PreloadTextW
,
201 ID3DXFontImpl_DrawTextA
,
202 ID3DXFontImpl_DrawTextW
,
203 ID3DXFontImpl_OnLostDevice
,
204 ID3DXFontImpl_OnResetDevice
207 HRESULT WINAPI
D3DXCreateFontA(LPDIRECT3DDEVICE9 device
, INT height
, UINT width
, UINT weight
, UINT miplevels
, BOOL italic
, DWORD charset
,
208 DWORD precision
, DWORD quality
, DWORD pitchandfamily
, LPCSTR facename
, LPD3DXFONT
*font
)
212 if( !device
|| !font
) return D3DERR_INVALIDCALL
;
217 desc
.MipLevels
=miplevels
;
219 desc
.CharSet
=charset
;
220 desc
.OutputPrecision
=precision
;
221 desc
.Quality
=quality
;
222 desc
.PitchAndFamily
=pitchandfamily
;
223 if(facename
!= NULL
) lstrcpyA(desc
.FaceName
, facename
);
224 else desc
.FaceName
[0] = '\0';
226 return D3DXCreateFontIndirectA(device
, &desc
, font
);
229 HRESULT WINAPI
D3DXCreateFontW(LPDIRECT3DDEVICE9 device
, INT height
, UINT width
, UINT weight
, UINT miplevels
, BOOL italic
, DWORD charset
,
230 DWORD precision
, DWORD quality
, DWORD pitchandfamily
, LPCWSTR facename
, LPD3DXFONT
*font
)
234 if( !device
|| !font
) return D3DERR_INVALIDCALL
;
239 desc
.MipLevels
=miplevels
;
241 desc
.CharSet
=charset
;
242 desc
.OutputPrecision
=precision
;
243 desc
.Quality
=quality
;
244 desc
.PitchAndFamily
=pitchandfamily
;
245 if(facename
!= NULL
) strcpyW(desc
.FaceName
, facename
);
246 else desc
.FaceName
[0] = '\0';
248 return D3DXCreateFontIndirectW(device
, &desc
, font
);
251 /***********************************************************************
252 * D3DXCreateFontIndirectA (D3DX9_36.@)
254 HRESULT WINAPI
D3DXCreateFontIndirectA(LPDIRECT3DDEVICE9 device
, CONST D3DXFONT_DESCA
*desc
, LPD3DXFONT
*font
)
256 D3DXFONT_DESCW widedesc
;
258 if( !device
|| !desc
|| !font
) return D3DERR_INVALIDCALL
;
260 /* Copy everything but the last structure member. This requires the
261 two D3DXFONT_DESC structures to be equal until the FaceName member */
262 memcpy(&widedesc
, desc
, FIELD_OFFSET(D3DXFONT_DESCA
, FaceName
));
263 MultiByteToWideChar(CP_ACP
, 0, desc
->FaceName
, -1,
264 widedesc
.FaceName
, sizeof(widedesc
.FaceName
)/sizeof(WCHAR
));
265 return D3DXCreateFontIndirectW(device
, &widedesc
, font
);
268 /***********************************************************************
269 * D3DXCreateFontIndirectW (D3DX9_36.@)
271 HRESULT WINAPI
D3DXCreateFontIndirectW(LPDIRECT3DDEVICE9 device
, CONST D3DXFONT_DESCW
*desc
, LPD3DXFONT
*font
)
273 D3DDEVICE_CREATION_PARAMETERS cpars
;
275 ID3DXFontImpl
*object
;
280 if( !device
|| !desc
|| !font
) return D3DERR_INVALIDCALL
;
282 /* the device MUST support D3DFMT_A8R8G8B8 */
283 IDirect3DDevice9_GetDirect3D(device
, &d3d
);
284 IDirect3DDevice9_GetCreationParameters(device
, &cpars
);
285 IDirect3DDevice9_GetDisplayMode(device
, 0, &mode
);
286 hr
= IDirect3D9_CheckDeviceFormat(d3d
, cpars
.AdapterOrdinal
, cpars
.DeviceType
, mode
.Format
, 0, D3DRTYPE_TEXTURE
, D3DFMT_A8R8G8B8
);
288 IDirect3D9_Release(d3d
);
289 return D3DXERR_INVALIDDATA
;
291 IDirect3D9_Release(d3d
);
293 object
=HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(ID3DXFontImpl
));
296 return E_OUTOFMEMORY
;
298 object
->lpVtbl
=&D3DXFont_Vtbl
;
300 object
->device
=device
;
303 IDirect3DDevice9_AddRef(device
);
304 *font
=(LPD3DXFONT
)object
;