d3d8: Stop setting the device state in d3d8_device_SetPixelShaderConstant().
[wine.git] / dlls / d3dx9_36 / font.c
blobcb09af22f576e06903c75622f3bede796403d079
1 /*
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 "d3dx9_private.h"
23 WINE_DEFAULT_DEBUG_CHANNEL(d3dx);
25 struct d3dx_font
27 ID3DXFont ID3DXFont_iface;
28 LONG ref;
30 IDirect3DDevice9 *device;
31 D3DXFONT_DESCW desc;
33 HDC hdc;
34 HFONT hfont;
37 static inline struct d3dx_font *impl_from_ID3DXFont(ID3DXFont *iface)
39 return CONTAINING_RECORD(iface, struct d3dx_font, ID3DXFont_iface);
42 static HRESULT WINAPI ID3DXFontImpl_QueryInterface(ID3DXFont *iface, REFIID riid, void **out)
44 TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
46 if (IsEqualGUID(riid, &IID_ID3DXFont)
47 || IsEqualGUID(riid, &IID_IUnknown))
49 IUnknown_AddRef(iface);
50 *out = iface;
51 return S_OK;
54 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
56 *out = NULL;
57 return E_NOINTERFACE;
60 static ULONG WINAPI ID3DXFontImpl_AddRef(ID3DXFont *iface)
62 struct d3dx_font *This = impl_from_ID3DXFont(iface);
63 ULONG ref=InterlockedIncrement(&This->ref);
64 TRACE("%p increasing refcount to %u\n", iface, ref);
65 return ref;
68 static ULONG WINAPI ID3DXFontImpl_Release(ID3DXFont *iface)
70 struct d3dx_font *This = impl_from_ID3DXFont(iface);
71 ULONG ref=InterlockedDecrement(&This->ref);
73 TRACE("%p decreasing refcount to %u\n", iface, ref);
75 if(ref==0) {
76 DeleteObject(This->hfont);
77 DeleteDC(This->hdc);
78 IDirect3DDevice9_Release(This->device);
79 HeapFree(GetProcessHeap(), 0, This);
81 return ref;
84 static HRESULT WINAPI ID3DXFontImpl_GetDevice(ID3DXFont *iface, IDirect3DDevice9 **device)
86 struct d3dx_font *This = impl_from_ID3DXFont(iface);
88 TRACE("iface %p, device %p\n", iface, device);
90 if( !device ) return D3DERR_INVALIDCALL;
91 *device = This->device;
92 IDirect3DDevice9_AddRef(This->device);
94 return D3D_OK;
97 static HRESULT WINAPI ID3DXFontImpl_GetDescA(ID3DXFont *iface, D3DXFONT_DESCA *desc)
99 struct d3dx_font *This = impl_from_ID3DXFont(iface);
101 TRACE("iface %p, desc %p\n", iface, desc);
103 if( !desc ) return D3DERR_INVALIDCALL;
104 memcpy(desc, &This->desc, FIELD_OFFSET(D3DXFONT_DESCA, FaceName));
105 WideCharToMultiByte(CP_ACP, 0, This->desc.FaceName, -1, desc->FaceName, ARRAY_SIZE(desc->FaceName), NULL, NULL);
107 return D3D_OK;
110 static HRESULT WINAPI ID3DXFontImpl_GetDescW(ID3DXFont *iface, D3DXFONT_DESCW *desc)
112 struct d3dx_font *This = impl_from_ID3DXFont(iface);
114 TRACE("iface %p, desc %p\n", iface, desc);
116 if( !desc ) return D3DERR_INVALIDCALL;
117 *desc = This->desc;
119 return D3D_OK;
122 static BOOL WINAPI ID3DXFontImpl_GetTextMetricsA(ID3DXFont *iface, TEXTMETRICA *metrics)
124 struct d3dx_font *This = impl_from_ID3DXFont(iface);
125 TRACE("iface %p, metrics %p\n", iface, metrics);
126 return GetTextMetricsA(This->hdc, metrics);
129 static BOOL WINAPI ID3DXFontImpl_GetTextMetricsW(ID3DXFont *iface, TEXTMETRICW *metrics)
131 struct d3dx_font *This = impl_from_ID3DXFont(iface);
132 TRACE("iface %p, metrics %p\n", iface, metrics);
133 return GetTextMetricsW(This->hdc, metrics);
136 static HDC WINAPI ID3DXFontImpl_GetDC(ID3DXFont *iface)
138 struct d3dx_font *This = impl_from_ID3DXFont(iface);
139 TRACE("iface %p\n", iface);
140 return This->hdc;
143 static HRESULT WINAPI ID3DXFontImpl_GetGlyphData(ID3DXFont *iface, UINT glyph,
144 IDirect3DTexture9 **texture, RECT *blackbox, POINT *cellinc)
146 FIXME("iface %p, glyph %#x, texture %p, blackbox %p, cellinc %p stub!\n",
147 iface, glyph, texture, blackbox, cellinc);
148 return E_NOTIMPL;
151 static HRESULT WINAPI ID3DXFontImpl_PreloadCharacters(ID3DXFont *iface, UINT first, UINT last)
153 FIXME("iface %p, first %u, last %u stub!\n", iface, first, last);
154 return S_OK;
157 static HRESULT WINAPI ID3DXFontImpl_PreloadGlyphs(ID3DXFont *iface, UINT first, UINT last)
159 FIXME("iface %p, first %u, last %u stub!\n", iface, first, last);
160 return E_NOTIMPL;
163 static HRESULT WINAPI ID3DXFontImpl_PreloadTextA(ID3DXFont *iface, const char *string, INT count)
165 FIXME("iface %p, string %s, count %d stub!\n", iface, debugstr_a(string), count);
166 return E_NOTIMPL;
169 static HRESULT WINAPI ID3DXFontImpl_PreloadTextW(ID3DXFont *iface, const WCHAR *string, INT count)
171 FIXME("iface %p, string %s, count %d stub!\n", iface, debugstr_w(string), count);
172 return E_NOTIMPL;
175 static INT WINAPI ID3DXFontImpl_DrawTextA(ID3DXFont *iface, ID3DXSprite *sprite,
176 const char *string, INT count, RECT *rect, DWORD format, D3DCOLOR color)
178 FIXME("iface %p, sprite %p, string %s, count %d, rect %s, format %#x, color 0x%08x stub!\n",
179 iface, sprite, debugstr_a(string), count, wine_dbgstr_rect(rect), format, color);
180 return 1;
183 static INT WINAPI ID3DXFontImpl_DrawTextW(ID3DXFont *iface, ID3DXSprite *sprite,
184 const WCHAR *string, INT count, RECT *rect, DWORD format, D3DCOLOR color)
186 FIXME("iface %p, sprite %p, string %s, count %d, rect %s, format %#x, color 0x%08x stub!\n",
187 iface, sprite, debugstr_w(string), count, wine_dbgstr_rect(rect), format, color);
188 return 1;
191 static HRESULT WINAPI ID3DXFontImpl_OnLostDevice(ID3DXFont *iface)
193 FIXME("iface %p stub!\n", iface);
194 return D3D_OK;
197 static HRESULT WINAPI ID3DXFontImpl_OnResetDevice(ID3DXFont *iface)
199 FIXME("iface %p stub\n", iface);
200 return D3D_OK;
203 static const ID3DXFontVtbl D3DXFont_Vtbl =
205 /*** IUnknown methods ***/
206 ID3DXFontImpl_QueryInterface,
207 ID3DXFontImpl_AddRef,
208 ID3DXFontImpl_Release,
209 /*** ID3DXFont methods ***/
210 ID3DXFontImpl_GetDevice,
211 ID3DXFontImpl_GetDescA,
212 ID3DXFontImpl_GetDescW,
213 ID3DXFontImpl_GetTextMetricsA,
214 ID3DXFontImpl_GetTextMetricsW,
215 ID3DXFontImpl_GetDC,
216 ID3DXFontImpl_GetGlyphData,
217 ID3DXFontImpl_PreloadCharacters,
218 ID3DXFontImpl_PreloadGlyphs,
219 ID3DXFontImpl_PreloadTextA,
220 ID3DXFontImpl_PreloadTextW,
221 ID3DXFontImpl_DrawTextA,
222 ID3DXFontImpl_DrawTextW,
223 ID3DXFontImpl_OnLostDevice,
224 ID3DXFontImpl_OnResetDevice
227 HRESULT WINAPI D3DXCreateFontA(struct IDirect3DDevice9 *device, INT height, UINT width,
228 UINT weight, UINT miplevels, BOOL italic, DWORD charset, DWORD precision, DWORD quality,
229 DWORD pitchandfamily, const char *facename, struct ID3DXFont **font)
231 D3DXFONT_DESCA desc;
233 if( !device || !font ) return D3DERR_INVALIDCALL;
235 desc.Height=height;
236 desc.Width=width;
237 desc.Weight=weight;
238 desc.MipLevels=miplevels;
239 desc.Italic=italic;
240 desc.CharSet=charset;
241 desc.OutputPrecision=precision;
242 desc.Quality=quality;
243 desc.PitchAndFamily=pitchandfamily;
244 if(facename != NULL) lstrcpyA(desc.FaceName, facename);
245 else desc.FaceName[0] = '\0';
247 return D3DXCreateFontIndirectA(device, &desc, font);
250 HRESULT WINAPI D3DXCreateFontW(IDirect3DDevice9 *device, INT height, UINT width, UINT weight, UINT miplevels, BOOL italic, DWORD charset,
251 DWORD precision, DWORD quality, DWORD pitchandfamily, const WCHAR *facename, ID3DXFont **font)
253 D3DXFONT_DESCW desc;
255 if( !device || !font ) return D3DERR_INVALIDCALL;
257 desc.Height=height;
258 desc.Width=width;
259 desc.Weight=weight;
260 desc.MipLevels=miplevels;
261 desc.Italic=italic;
262 desc.CharSet=charset;
263 desc.OutputPrecision=precision;
264 desc.Quality=quality;
265 desc.PitchAndFamily=pitchandfamily;
266 if(facename != NULL) lstrcpyW(desc.FaceName, facename);
267 else desc.FaceName[0] = '\0';
269 return D3DXCreateFontIndirectW(device, &desc, font);
272 /***********************************************************************
273 * D3DXCreateFontIndirectA (D3DX9_36.@)
275 HRESULT WINAPI D3DXCreateFontIndirectA(IDirect3DDevice9 *device, const D3DXFONT_DESCA *desc, ID3DXFont **font)
277 D3DXFONT_DESCW widedesc;
279 if( !device || !desc || !font ) return D3DERR_INVALIDCALL;
281 /* Copy everything but the last structure member. This requires the
282 two D3DXFONT_DESC structures to be equal until the FaceName member */
283 memcpy(&widedesc, desc, FIELD_OFFSET(D3DXFONT_DESCA, FaceName));
284 MultiByteToWideChar(CP_ACP, 0, desc->FaceName, -1, widedesc.FaceName, ARRAY_SIZE(widedesc.FaceName));
285 return D3DXCreateFontIndirectW(device, &widedesc, font);
288 /***********************************************************************
289 * D3DXCreateFontIndirectW (D3DX9_36.@)
291 HRESULT WINAPI D3DXCreateFontIndirectW(IDirect3DDevice9 *device, const D3DXFONT_DESCW *desc, ID3DXFont **font)
293 D3DDEVICE_CREATION_PARAMETERS cpars;
294 D3DDISPLAYMODE mode;
295 struct d3dx_font *object;
296 IDirect3D9 *d3d;
297 HRESULT hr;
299 TRACE("(%p, %p, %p)\n", device, desc, font);
301 if( !device || !desc || !font ) return D3DERR_INVALIDCALL;
303 /* the device MUST support D3DFMT_A8R8G8B8 */
304 IDirect3DDevice9_GetDirect3D(device, &d3d);
305 IDirect3DDevice9_GetCreationParameters(device, &cpars);
306 IDirect3DDevice9_GetDisplayMode(device, 0, &mode);
307 hr = IDirect3D9_CheckDeviceFormat(d3d, cpars.AdapterOrdinal, cpars.DeviceType, mode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_A8R8G8B8);
308 if(FAILED(hr)) {
309 IDirect3D9_Release(d3d);
310 return D3DXERR_INVALIDDATA;
312 IDirect3D9_Release(d3d);
314 object = HeapAlloc(GetProcessHeap(), 0, sizeof(struct d3dx_font));
315 if(object==NULL) {
316 *font=NULL;
317 return E_OUTOFMEMORY;
319 object->ID3DXFont_iface.lpVtbl = &D3DXFont_Vtbl;
320 object->ref=1;
321 object->device=device;
322 object->desc=*desc;
324 object->hdc = CreateCompatibleDC(NULL);
325 if( !object->hdc ) {
326 HeapFree(GetProcessHeap(), 0, object);
327 return D3DXERR_INVALIDDATA;
330 object->hfont = CreateFontW(desc->Height, desc->Width, 0, 0, desc->Weight, desc->Italic, FALSE, FALSE, desc->CharSet,
331 desc->OutputPrecision, CLIP_DEFAULT_PRECIS, desc->Quality, desc->PitchAndFamily, desc->FaceName);
332 if( !object->hfont ) {
333 DeleteDC(object->hdc);
334 HeapFree(GetProcessHeap(), 0, object);
335 return D3DXERR_INVALIDDATA;
337 SelectObject(object->hdc, object->hfont);
339 IDirect3DDevice9_AddRef(device);
340 *font=&object->ID3DXFont_iface;
342 return D3D_OK;