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 "d3dx9_36_private.h"
24 ID3DXFont ID3DXFont_iface
;
27 IDirect3DDevice9
*device
;
34 static inline struct d3dx_font
*impl_from_ID3DXFont(ID3DXFont
*iface
)
36 return CONTAINING_RECORD(iface
, struct d3dx_font
, ID3DXFont_iface
);
39 static HRESULT WINAPI
ID3DXFontImpl_QueryInterface(ID3DXFont
*iface
, REFIID riid
, void **out
)
41 TRACE("iface %p, riid %s, out %p.\n", iface
, debugstr_guid(riid
), out
);
43 if (IsEqualGUID(riid
, &IID_ID3DXFont
)
44 || IsEqualGUID(riid
, &IID_IUnknown
))
46 IUnknown_AddRef(iface
);
51 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
57 static ULONG WINAPI
ID3DXFontImpl_AddRef(ID3DXFont
*iface
)
59 struct d3dx_font
*This
= impl_from_ID3DXFont(iface
);
60 ULONG ref
=InterlockedIncrement(&This
->ref
);
61 TRACE("%p increasing refcount to %u\n", iface
, ref
);
65 static ULONG WINAPI
ID3DXFontImpl_Release(ID3DXFont
*iface
)
67 struct d3dx_font
*This
= impl_from_ID3DXFont(iface
);
68 ULONG ref
=InterlockedDecrement(&This
->ref
);
70 TRACE("%p decreasing refcount to %u\n", iface
, ref
);
73 DeleteObject(This
->hfont
);
75 IDirect3DDevice9_Release(This
->device
);
76 HeapFree(GetProcessHeap(), 0, This
);
81 static HRESULT WINAPI
ID3DXFontImpl_GetDevice(ID3DXFont
*iface
, IDirect3DDevice9
**device
)
83 struct d3dx_font
*This
= impl_from_ID3DXFont(iface
);
85 TRACE("iface %p, device %p\n", iface
, device
);
87 if( !device
) return D3DERR_INVALIDCALL
;
88 *device
= This
->device
;
89 IDirect3DDevice9_AddRef(This
->device
);
94 static HRESULT WINAPI
ID3DXFontImpl_GetDescA(ID3DXFont
*iface
, D3DXFONT_DESCA
*desc
)
96 struct d3dx_font
*This
= impl_from_ID3DXFont(iface
);
98 TRACE("iface %p, desc %p\n", iface
, desc
);
100 if( !desc
) return D3DERR_INVALIDCALL
;
101 memcpy(desc
, &This
->desc
, FIELD_OFFSET(D3DXFONT_DESCA
, FaceName
));
102 WideCharToMultiByte(CP_ACP
, 0, This
->desc
.FaceName
, -1, desc
->FaceName
, sizeof(desc
->FaceName
) / sizeof(CHAR
), NULL
, NULL
);
107 static HRESULT WINAPI
ID3DXFontImpl_GetDescW(ID3DXFont
*iface
, D3DXFONT_DESCW
*desc
)
109 struct d3dx_font
*This
= impl_from_ID3DXFont(iface
);
111 TRACE("iface %p, desc %p\n", iface
, desc
);
113 if( !desc
) return D3DERR_INVALIDCALL
;
119 static BOOL WINAPI
ID3DXFontImpl_GetTextMetricsA(ID3DXFont
*iface
, TEXTMETRICA
*metrics
)
121 struct d3dx_font
*This
= impl_from_ID3DXFont(iface
);
122 TRACE("iface %p, metrics %p\n", iface
, metrics
);
123 return GetTextMetricsA(This
->hdc
, metrics
);
126 static BOOL WINAPI
ID3DXFontImpl_GetTextMetricsW(ID3DXFont
*iface
, TEXTMETRICW
*metrics
)
128 struct d3dx_font
*This
= impl_from_ID3DXFont(iface
);
129 TRACE("iface %p, metrics %p\n", iface
, metrics
);
130 return GetTextMetricsW(This
->hdc
, metrics
);
133 static HDC WINAPI
ID3DXFontImpl_GetDC(ID3DXFont
*iface
)
135 struct d3dx_font
*This
= impl_from_ID3DXFont(iface
);
136 TRACE("iface %p\n", iface
);
140 static HRESULT WINAPI
ID3DXFontImpl_GetGlyphData(ID3DXFont
*iface
, UINT glyph
,
141 IDirect3DTexture9
**texture
, RECT
*blackbox
, POINT
*cellinc
)
143 FIXME("iface %p, glyph %#x, texture %p, blackbox %p, cellinc %p stub!\n",
144 iface
, glyph
, texture
, blackbox
, cellinc
);
148 static HRESULT WINAPI
ID3DXFontImpl_PreloadCharacters(ID3DXFont
*iface
, UINT first
, UINT last
)
150 FIXME("iface %p, first %u, last %u stub!\n", iface
, first
, last
);
154 static HRESULT WINAPI
ID3DXFontImpl_PreloadGlyphs(ID3DXFont
*iface
, UINT first
, UINT last
)
156 FIXME("iface %p, first %u, last %u stub!\n", iface
, first
, last
);
160 static HRESULT WINAPI
ID3DXFontImpl_PreloadTextA(ID3DXFont
*iface
, const char *string
, INT count
)
162 FIXME("iface %p, string %s, count %d stub!\n", iface
, debugstr_a(string
), count
);
166 static HRESULT WINAPI
ID3DXFontImpl_PreloadTextW(ID3DXFont
*iface
, const WCHAR
*string
, INT count
)
168 FIXME("iface %p, string %s, count %d stub!\n", iface
, debugstr_w(string
), count
);
172 static INT WINAPI
ID3DXFontImpl_DrawTextA(ID3DXFont
*iface
, ID3DXSprite
*sprite
,
173 const char *string
, INT count
, RECT
*rect
, DWORD format
, D3DCOLOR color
)
175 FIXME("iface %p, sprite %p, string %s, count %d, rect %s, format %#x, color 0x%08x stub!\n",
176 iface
, sprite
, debugstr_a(string
), count
, wine_dbgstr_rect(rect
), format
, color
);
180 static INT WINAPI
ID3DXFontImpl_DrawTextW(ID3DXFont
*iface
, ID3DXSprite
*sprite
,
181 const WCHAR
*string
, INT count
, RECT
*rect
, DWORD format
, D3DCOLOR color
)
183 FIXME("iface %p, sprite %p, string %s, count %d, rect %s, format %#x, color 0x%08x stub!\n",
184 iface
, sprite
, debugstr_w(string
), count
, wine_dbgstr_rect(rect
), format
, color
);
188 static HRESULT WINAPI
ID3DXFontImpl_OnLostDevice(ID3DXFont
*iface
)
190 FIXME("iface %p stub!\n", iface
);
194 static HRESULT WINAPI
ID3DXFontImpl_OnResetDevice(ID3DXFont
*iface
)
196 FIXME("iface %p stub\n", iface
);
200 static const ID3DXFontVtbl D3DXFont_Vtbl
=
202 /*** IUnknown methods ***/
203 ID3DXFontImpl_QueryInterface
,
204 ID3DXFontImpl_AddRef
,
205 ID3DXFontImpl_Release
,
206 /*** ID3DXFont methods ***/
207 ID3DXFontImpl_GetDevice
,
208 ID3DXFontImpl_GetDescA
,
209 ID3DXFontImpl_GetDescW
,
210 ID3DXFontImpl_GetTextMetricsA
,
211 ID3DXFontImpl_GetTextMetricsW
,
213 ID3DXFontImpl_GetGlyphData
,
214 ID3DXFontImpl_PreloadCharacters
,
215 ID3DXFontImpl_PreloadGlyphs
,
216 ID3DXFontImpl_PreloadTextA
,
217 ID3DXFontImpl_PreloadTextW
,
218 ID3DXFontImpl_DrawTextA
,
219 ID3DXFontImpl_DrawTextW
,
220 ID3DXFontImpl_OnLostDevice
,
221 ID3DXFontImpl_OnResetDevice
224 HRESULT WINAPI
D3DXCreateFontA(struct IDirect3DDevice9
*device
, INT height
, UINT width
,
225 UINT weight
, UINT miplevels
, BOOL italic
, DWORD charset
, DWORD precision
, DWORD quality
,
226 DWORD pitchandfamily
, const char *facename
, struct ID3DXFont
**font
)
230 if( !device
|| !font
) return D3DERR_INVALIDCALL
;
235 desc
.MipLevels
=miplevels
;
237 desc
.CharSet
=charset
;
238 desc
.OutputPrecision
=precision
;
239 desc
.Quality
=quality
;
240 desc
.PitchAndFamily
=pitchandfamily
;
241 if(facename
!= NULL
) lstrcpyA(desc
.FaceName
, facename
);
242 else desc
.FaceName
[0] = '\0';
244 return D3DXCreateFontIndirectA(device
, &desc
, font
);
247 HRESULT WINAPI
D3DXCreateFontW(IDirect3DDevice9
*device
, INT height
, UINT width
, UINT weight
, UINT miplevels
, BOOL italic
, DWORD charset
,
248 DWORD precision
, DWORD quality
, DWORD pitchandfamily
, const WCHAR
*facename
, ID3DXFont
**font
)
252 if( !device
|| !font
) return D3DERR_INVALIDCALL
;
257 desc
.MipLevels
=miplevels
;
259 desc
.CharSet
=charset
;
260 desc
.OutputPrecision
=precision
;
261 desc
.Quality
=quality
;
262 desc
.PitchAndFamily
=pitchandfamily
;
263 if(facename
!= NULL
) strcpyW(desc
.FaceName
, facename
);
264 else desc
.FaceName
[0] = '\0';
266 return D3DXCreateFontIndirectW(device
, &desc
, font
);
269 /***********************************************************************
270 * D3DXCreateFontIndirectA (D3DX9_36.@)
272 HRESULT WINAPI
D3DXCreateFontIndirectA(IDirect3DDevice9
*device
, const D3DXFONT_DESCA
*desc
, ID3DXFont
**font
)
274 D3DXFONT_DESCW widedesc
;
276 if( !device
|| !desc
|| !font
) return D3DERR_INVALIDCALL
;
278 /* Copy everything but the last structure member. This requires the
279 two D3DXFONT_DESC structures to be equal until the FaceName member */
280 memcpy(&widedesc
, desc
, FIELD_OFFSET(D3DXFONT_DESCA
, FaceName
));
281 MultiByteToWideChar(CP_ACP
, 0, desc
->FaceName
, -1,
282 widedesc
.FaceName
, sizeof(widedesc
.FaceName
)/sizeof(WCHAR
));
283 return D3DXCreateFontIndirectW(device
, &widedesc
, font
);
286 /***********************************************************************
287 * D3DXCreateFontIndirectW (D3DX9_36.@)
289 HRESULT WINAPI
D3DXCreateFontIndirectW(IDirect3DDevice9
*device
, const D3DXFONT_DESCW
*desc
, ID3DXFont
**font
)
291 D3DDEVICE_CREATION_PARAMETERS cpars
;
293 struct d3dx_font
*object
;
297 TRACE("(%p, %p, %p)\n", device
, desc
, font
);
299 if( !device
|| !desc
|| !font
) return D3DERR_INVALIDCALL
;
301 /* the device MUST support D3DFMT_A8R8G8B8 */
302 IDirect3DDevice9_GetDirect3D(device
, &d3d
);
303 IDirect3DDevice9_GetCreationParameters(device
, &cpars
);
304 IDirect3DDevice9_GetDisplayMode(device
, 0, &mode
);
305 hr
= IDirect3D9_CheckDeviceFormat(d3d
, cpars
.AdapterOrdinal
, cpars
.DeviceType
, mode
.Format
, 0, D3DRTYPE_TEXTURE
, D3DFMT_A8R8G8B8
);
307 IDirect3D9_Release(d3d
);
308 return D3DXERR_INVALIDDATA
;
310 IDirect3D9_Release(d3d
);
312 object
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct d3dx_font
));
315 return E_OUTOFMEMORY
;
317 object
->ID3DXFont_iface
.lpVtbl
= &D3DXFont_Vtbl
;
319 object
->device
=device
;
322 object
->hdc
= CreateCompatibleDC(NULL
);
324 HeapFree(GetProcessHeap(), 0, object
);
325 return D3DXERR_INVALIDDATA
;
328 object
->hfont
= CreateFontW(desc
->Height
, desc
->Width
, 0, 0, desc
->Weight
, desc
->Italic
, FALSE
, FALSE
, desc
->CharSet
,
329 desc
->OutputPrecision
, CLIP_DEFAULT_PRECIS
, desc
->Quality
, desc
->PitchAndFamily
, desc
->FaceName
);
330 if( !object
->hfont
) {
331 DeleteDC(object
->hdc
);
332 HeapFree(GetProcessHeap(), 0, object
);
333 return D3DXERR_INVALIDDATA
;
335 SelectObject(object
->hdc
, object
->hfont
);
337 IDirect3DDevice9_AddRef(device
);
338 *font
=&object
->ID3DXFont_iface
;