shell32: Fixed potential buffer overwrite in execute_from_key (Coverity).
[wine/multimedia.git] / dlls / d3dx9_36 / font.c
blob46d0fde311920dd2eafb8396ac921035185e5dce
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
20 #include "config.h"
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);
36 *object=This;
37 return S_OK;
39 WARN("(%p)->(%s, %p): not found\n", iface, debugstr_guid(riid), *object);
40 return E_NOINTERFACE;
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);
48 return ref;
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);
57 if(ref==0) {
58 HeapFree(GetProcessHeap(), 0, This);
60 return ref;
63 static HRESULT WINAPI ID3DXFontImpl_GetDevice(LPD3DXFONT iface, LPDIRECT3DDEVICE9 *device)
65 ID3DXFontImpl *This=(ID3DXFontImpl*)iface;
66 FIXME("(%p): stub\n", This);
67 return D3D_OK;
70 static HRESULT WINAPI ID3DXFontImpl_GetDescA(LPD3DXFONT iface, D3DXFONT_DESCA *desc)
72 ID3DXFontImpl *This=(ID3DXFontImpl*)iface;
73 FIXME("(%p): stub\n", This);
74 return D3D_OK;
77 static HRESULT WINAPI ID3DXFontImpl_GetDescW(LPD3DXFONT iface, D3DXFONT_DESCW *desc)
79 ID3DXFontImpl *This=(ID3DXFontImpl*)iface;
80 FIXME("(%p): stub\n", This);
81 return D3D_OK;
84 static BOOL WINAPI ID3DXFontImpl_GetTextMetricsA(LPD3DXFONT iface, TEXTMETRICA *metrics)
86 ID3DXFontImpl *This=(ID3DXFontImpl*)iface;
87 FIXME("(%p): stub\n", This);
88 return FALSE;
91 static BOOL WINAPI ID3DXFontImpl_GetTextMetricsW(LPD3DXFONT iface, TEXTMETRICW *metrics)
93 ID3DXFontImpl *This=(ID3DXFontImpl*)iface;
94 FIXME("(%p): stub\n", This);
95 return FALSE;
98 static HDC WINAPI ID3DXFontImpl_GetDC(LPD3DXFONT iface)
100 ID3DXFontImpl *This=(ID3DXFontImpl*)iface;
101 FIXME("(%p): stub\n", This);
102 return NULL;
105 static HRESULT WINAPI ID3DXFontImpl_GetGlyphData(LPD3DXFONT iface, UINT glyph, LPDIRECT3DTEXTURE9 *texture, RECT *blackbox, POINT *cellinc)
107 ID3DXFontImpl *This=(ID3DXFontImpl*)iface;
108 FIXME("(%p): stub\n", This);
109 return D3D_OK;
112 static HRESULT WINAPI ID3DXFontImpl_PreloadCharacters(LPD3DXFONT iface, UINT first, UINT last)
114 ID3DXFontImpl *This=(ID3DXFontImpl*)iface;
115 FIXME("(%p): stub\n", This);
116 return D3D_OK;
119 static HRESULT WINAPI ID3DXFontImpl_PreloadGlyphs(LPD3DXFONT iface, UINT first, UINT last)
121 ID3DXFontImpl *This=(ID3DXFontImpl*)iface;
122 FIXME("(%p): stub\n", This);
123 return D3D_OK;
126 static HRESULT WINAPI ID3DXFontImpl_PreloadTextA(LPD3DXFONT iface, LPCSTR string, INT count)
128 ID3DXFontImpl *This=(ID3DXFontImpl*)iface;
129 FIXME("(%p): stub\n", This);
130 return D3D_OK;
133 static HRESULT WINAPI ID3DXFontImpl_PreloadTextW(LPD3DXFONT iface, LPCWSTR string, INT count)
135 ID3DXFontImpl *This=(ID3DXFontImpl*)iface;
136 FIXME("(%p): stub\n", This);
137 return D3D_OK;
140 static INT WINAPI ID3DXFontImpl_DrawTextA(LPD3DXFONT iface, LPD3DXSPRITE sprite, LPCSTR string, INT count, LPRECT rect, DWORD format, D3DCOLOR color)
142 ID3DXFontImpl *This=(ID3DXFontImpl*)iface;
143 FIXME("(%p): stub\n", This);
144 return 1;
147 static INT WINAPI ID3DXFontImpl_DrawTextW(LPD3DXFONT iface, LPD3DXSPRITE sprite, LPCWSTR string, INT count, LPRECT rect, DWORD format, D3DCOLOR color)
149 ID3DXFontImpl *This=(ID3DXFontImpl*)iface;
150 FIXME("(%p): stub\n", This);
151 return 1;
154 static HRESULT WINAPI ID3DXFontImpl_OnLostDevice(LPD3DXFONT iface)
156 ID3DXFontImpl *This=(ID3DXFontImpl*)iface;
157 FIXME("(%p): stub\n", This);
158 return D3D_OK;
161 static HRESULT WINAPI ID3DXFontImpl_OnResetDevice(LPD3DXFONT iface)
163 ID3DXFontImpl *This=(ID3DXFontImpl*)iface;
164 FIXME("(%p): stub\n", This);
165 return D3D_OK;
168 static const ID3DXFontVtbl D3DXFont_Vtbl =
170 /*** IUnknown methods ***/
171 ID3DXFontImpl_QueryInterface,
172 ID3DXFontImpl_AddRef,
173 ID3DXFontImpl_Release,
174 /*** ID3DXFont methods ***/
175 ID3DXFontImpl_GetDevice,
176 ID3DXFontImpl_GetDescA,
177 ID3DXFontImpl_GetDescW,
178 ID3DXFontImpl_GetTextMetricsA,
179 ID3DXFontImpl_GetTextMetricsW,
180 ID3DXFontImpl_GetDC,
181 ID3DXFontImpl_GetGlyphData,
182 ID3DXFontImpl_PreloadCharacters,
183 ID3DXFontImpl_PreloadGlyphs,
184 ID3DXFontImpl_PreloadTextA,
185 ID3DXFontImpl_PreloadTextW,
186 ID3DXFontImpl_DrawTextA,
187 ID3DXFontImpl_DrawTextW,
188 ID3DXFontImpl_OnLostDevice,
189 ID3DXFontImpl_OnResetDevice
192 HRESULT WINAPI D3DXCreateFontA(LPDIRECT3DDEVICE9 device, INT height, UINT width, UINT weight, UINT miplevels, BOOL italic, DWORD charset,
193 DWORD precision, DWORD quality, DWORD pitchandfamily, LPCSTR facename, LPD3DXFONT *font)
195 D3DXFONT_DESCA desc;
197 if(!facename) return D3DXERR_INVALIDDATA;
199 desc.Height=height;
200 desc.Width=width;
201 desc.Weight=weight;
202 desc.MipLevels=miplevels;
203 desc.Italic=italic;
204 desc.CharSet=charset;
205 desc.OutputPrecision=precision;
206 desc.Quality=quality;
207 desc.PitchAndFamily=pitchandfamily;
208 lstrcpyA(desc.FaceName, facename);
210 return D3DXCreateFontIndirectA(device, &desc, font);
213 HRESULT WINAPI D3DXCreateFontW(LPDIRECT3DDEVICE9 device, INT height, UINT width, UINT weight, UINT miplevels, BOOL italic, DWORD charset,
214 DWORD precision, DWORD quality, DWORD pitchandfamily, LPCWSTR facename, LPD3DXFONT *font)
216 D3DXFONT_DESCW desc;
218 if(!facename) return D3DXERR_INVALIDDATA;
220 desc.Height=height;
221 desc.Width=width;
222 desc.Weight=weight;
223 desc.MipLevels=miplevels;
224 desc.Italic=italic;
225 desc.CharSet=charset;
226 desc.OutputPrecision=precision;
227 desc.Quality=quality;
228 desc.PitchAndFamily=pitchandfamily;
229 strcpyW(desc.FaceName, facename);
231 return D3DXCreateFontIndirectW(device, &desc, font);
234 /***********************************************************************
235 * D3DXCreateFontIndirectA (D3DX9_36.@)
237 HRESULT WINAPI D3DXCreateFontIndirectA(LPDIRECT3DDEVICE9 device, CONST D3DXFONT_DESCA *desc, LPD3DXFONT *font)
239 D3DXFONT_DESCW widedesc;
241 if(!desc) return D3DERR_INVALIDCALL;
242 if(!desc->FaceName) return D3DERR_INVALIDCALL;
244 /* Copy everything but the last structure member. This requires the
245 two D3DXFONT_DESC structures to be equal until the FaceName member */
246 memcpy(&widedesc, desc, FIELD_OFFSET(D3DXFONT_DESCA, FaceName));
247 MultiByteToWideChar(CP_ACP, 0, desc->FaceName, -1,
248 widedesc.FaceName, sizeof(widedesc.FaceName)/sizeof(WCHAR));
249 return D3DXCreateFontIndirectW(device, &widedesc, font);
252 /***********************************************************************
253 * D3DXCreateFontIndirectW (D3DX9_36.@)
255 HRESULT WINAPI D3DXCreateFontIndirectW(LPDIRECT3DDEVICE9 device, CONST D3DXFONT_DESCW *desc, LPD3DXFONT *font)
257 ID3DXFontImpl *object;
259 FIXME("stub\n");
261 if(!desc) return D3DERR_INVALIDCALL;
263 object=HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(ID3DXFontImpl));
264 if(object==NULL) {
265 *font=NULL;
266 return E_OUTOFMEMORY;
268 object->lpVtbl=&D3DXFont_Vtbl;
269 object->ref=1;
271 *font=(LPD3DXFONT)object;
273 return D3D_OK;