Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenfont.c
Go to the documentation of this file.
00001 /* 00002 * Copyright (C) 2008 Tony Wasserka 00003 * 00004 * This library is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU Lesser General Public 00006 * License as published by the Free Software Foundation; either 00007 * version 2.1 of the License, or (at your option) any later version. 00008 * 00009 * This library is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 * Lesser General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU Lesser General Public 00015 * License along with this library; if not, write to the Free Software 00016 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 00017 * 00018 */ 00019 00020 #include "config.h" 00021 #include "wine/port.h" 00022 00023 #include "wine/debug.h" 00024 #include "wine/unicode.h" 00025 #include "d3dx9_36_private.h" 00026 00027 WINE_DEFAULT_DEBUG_CHANNEL(d3dx); 00028 00029 static HRESULT WINAPI ID3DXFontImpl_QueryInterface(LPD3DXFONT iface, REFIID riid, LPVOID *object) 00030 { 00031 ID3DXFontImpl *This=(ID3DXFontImpl*)iface; 00032 00033 TRACE("(%p): QueryInterface from %s\n", This, debugstr_guid(riid)); 00034 if(IsEqualGUID(riid, &IID_IUnknown) || IsEqualGUID(riid, &IID_ID3DXFont)) { 00035 IUnknown_AddRef(iface); 00036 *object=This; 00037 return S_OK; 00038 } 00039 WARN("(%p)->(%s, %p): not found\n", iface, debugstr_guid(riid), *object); 00040 return E_NOINTERFACE; 00041 } 00042 00043 static ULONG WINAPI ID3DXFontImpl_AddRef(LPD3DXFONT iface) 00044 { 00045 ID3DXFontImpl *This=(ID3DXFontImpl*)iface; 00046 ULONG ref=InterlockedIncrement(&This->ref); 00047 TRACE("(%p): AddRef from %d\n", This, ref-1); 00048 return ref; 00049 } 00050 00051 static ULONG WINAPI ID3DXFontImpl_Release(LPD3DXFONT iface) 00052 { 00053 ID3DXFontImpl *This=(ID3DXFontImpl*)iface; 00054 ULONG ref=InterlockedDecrement(&This->ref); 00055 TRACE("(%p): ReleaseRef to %d\n", This, ref); 00056 00057 if(ref==0) { 00058 DeleteObject(This->hfont); 00059 DeleteDC(This->hdc); 00060 IDirect3DDevice9_Release(This->device); 00061 HeapFree(GetProcessHeap(), 0, This); 00062 } 00063 return ref; 00064 } 00065 00066 static HRESULT WINAPI ID3DXFontImpl_GetDevice(LPD3DXFONT iface, LPDIRECT3DDEVICE9 *device) 00067 { 00068 ID3DXFontImpl *This=(ID3DXFontImpl*)iface; 00069 TRACE("(%p)\n", This); 00070 00071 if( !device ) return D3DERR_INVALIDCALL; 00072 *device = This->device; 00073 IDirect3DDevice9_AddRef(This->device); 00074 00075 return D3D_OK; 00076 } 00077 00078 static HRESULT WINAPI ID3DXFontImpl_GetDescA(LPD3DXFONT iface, D3DXFONT_DESCA *desc) 00079 { 00080 ID3DXFontImpl *This=(ID3DXFontImpl*)iface; 00081 TRACE("(%p)\n", This); 00082 00083 if( !desc ) return D3DERR_INVALIDCALL; 00084 memcpy(desc, &This->desc, FIELD_OFFSET(D3DXFONT_DESCA, FaceName)); 00085 WideCharToMultiByte(CP_ACP, 0, This->desc.FaceName, -1, desc->FaceName, sizeof(desc->FaceName) / sizeof(CHAR), NULL, NULL); 00086 00087 return D3D_OK; 00088 } 00089 00090 static HRESULT WINAPI ID3DXFontImpl_GetDescW(LPD3DXFONT iface, D3DXFONT_DESCW *desc) 00091 { 00092 ID3DXFontImpl *This=(ID3DXFontImpl*)iface; 00093 TRACE("(%p)\n", This); 00094 00095 if( !desc ) return D3DERR_INVALIDCALL; 00096 *desc = This->desc; 00097 00098 return D3D_OK; 00099 } 00100 00101 static BOOL WINAPI ID3DXFontImpl_GetTextMetricsA(LPD3DXFONT iface, TEXTMETRICA *metrics) 00102 { 00103 ID3DXFontImpl *This=(ID3DXFontImpl*)iface; 00104 TRACE("(%p)\n", This); 00105 return GetTextMetricsA(This->hdc, metrics); 00106 } 00107 00108 static BOOL WINAPI ID3DXFontImpl_GetTextMetricsW(LPD3DXFONT iface, TEXTMETRICW *metrics) 00109 { 00110 ID3DXFontImpl *This=(ID3DXFontImpl*)iface; 00111 TRACE("(%p)\n", This); 00112 return GetTextMetricsW(This->hdc, metrics); 00113 } 00114 00115 static HDC WINAPI ID3DXFontImpl_GetDC(LPD3DXFONT iface) 00116 { 00117 ID3DXFontImpl *This=(ID3DXFontImpl*)iface; 00118 TRACE("(%p)\n", This); 00119 return This->hdc; 00120 } 00121 00122 static HRESULT WINAPI ID3DXFontImpl_GetGlyphData(LPD3DXFONT iface, UINT glyph, LPDIRECT3DTEXTURE9 *texture, RECT *blackbox, POINT *cellinc) 00123 { 00124 ID3DXFontImpl *This=(ID3DXFontImpl*)iface; 00125 FIXME("(%p): stub\n", This); 00126 return D3D_OK; 00127 } 00128 00129 static HRESULT WINAPI ID3DXFontImpl_PreloadCharacters(LPD3DXFONT iface, UINT first, UINT last) 00130 { 00131 ID3DXFontImpl *This=(ID3DXFontImpl*)iface; 00132 FIXME("(%p): stub\n", This); 00133 return D3D_OK; 00134 } 00135 00136 static HRESULT WINAPI ID3DXFontImpl_PreloadGlyphs(LPD3DXFONT iface, UINT first, UINT last) 00137 { 00138 ID3DXFontImpl *This=(ID3DXFontImpl*)iface; 00139 FIXME("(%p): stub\n", This); 00140 return D3D_OK; 00141 } 00142 00143 static HRESULT WINAPI ID3DXFontImpl_PreloadTextA(LPD3DXFONT iface, LPCSTR string, INT count) 00144 { 00145 ID3DXFontImpl *This=(ID3DXFontImpl*)iface; 00146 FIXME("(%p): stub\n", This); 00147 return D3D_OK; 00148 } 00149 00150 static HRESULT WINAPI ID3DXFontImpl_PreloadTextW(LPD3DXFONT iface, LPCWSTR string, INT count) 00151 { 00152 ID3DXFontImpl *This=(ID3DXFontImpl*)iface; 00153 FIXME("(%p): stub\n", This); 00154 return D3D_OK; 00155 } 00156 00157 static INT WINAPI ID3DXFontImpl_DrawTextA(LPD3DXFONT iface, LPD3DXSPRITE sprite, LPCSTR string, INT count, LPRECT rect, DWORD format, D3DCOLOR color) 00158 { 00159 ID3DXFontImpl *This=(ID3DXFontImpl*)iface; 00160 FIXME("(%p): stub\n", This); 00161 return 1; 00162 } 00163 00164 static INT WINAPI ID3DXFontImpl_DrawTextW(LPD3DXFONT iface, LPD3DXSPRITE sprite, LPCWSTR string, INT count, LPRECT rect, DWORD format, D3DCOLOR color) 00165 { 00166 ID3DXFontImpl *This=(ID3DXFontImpl*)iface; 00167 FIXME("(%p): stub\n", This); 00168 return 1; 00169 } 00170 00171 static HRESULT WINAPI ID3DXFontImpl_OnLostDevice(LPD3DXFONT iface) 00172 { 00173 ID3DXFontImpl *This=(ID3DXFontImpl*)iface; 00174 FIXME("(%p): stub\n", This); 00175 return D3D_OK; 00176 } 00177 00178 static HRESULT WINAPI ID3DXFontImpl_OnResetDevice(LPD3DXFONT iface) 00179 { 00180 ID3DXFontImpl *This=(ID3DXFontImpl*)iface; 00181 FIXME("(%p): stub\n", This); 00182 return D3D_OK; 00183 } 00184 00185 static const ID3DXFontVtbl D3DXFont_Vtbl = 00186 { 00187 /*** IUnknown methods ***/ 00188 ID3DXFontImpl_QueryInterface, 00189 ID3DXFontImpl_AddRef, 00190 ID3DXFontImpl_Release, 00191 /*** ID3DXFont methods ***/ 00192 ID3DXFontImpl_GetDevice, 00193 ID3DXFontImpl_GetDescA, 00194 ID3DXFontImpl_GetDescW, 00195 ID3DXFontImpl_GetTextMetricsA, 00196 ID3DXFontImpl_GetTextMetricsW, 00197 ID3DXFontImpl_GetDC, 00198 ID3DXFontImpl_GetGlyphData, 00199 ID3DXFontImpl_PreloadCharacters, 00200 ID3DXFontImpl_PreloadGlyphs, 00201 ID3DXFontImpl_PreloadTextA, 00202 ID3DXFontImpl_PreloadTextW, 00203 ID3DXFontImpl_DrawTextA, 00204 ID3DXFontImpl_DrawTextW, 00205 ID3DXFontImpl_OnLostDevice, 00206 ID3DXFontImpl_OnResetDevice 00207 }; 00208 00209 HRESULT WINAPI D3DXCreateFontA(LPDIRECT3DDEVICE9 device, INT height, UINT width, UINT weight, UINT miplevels, BOOL italic, DWORD charset, 00210 DWORD precision, DWORD quality, DWORD pitchandfamily, LPCSTR facename, LPD3DXFONT *font) 00211 { 00212 D3DXFONT_DESCA desc; 00213 00214 if( !device || !font ) return D3DERR_INVALIDCALL; 00215 00216 desc.Height=height; 00217 desc.Width=width; 00218 desc.Weight=weight; 00219 desc.MipLevels=miplevels; 00220 desc.Italic=italic; 00221 desc.CharSet=charset; 00222 desc.OutputPrecision=precision; 00223 desc.Quality=quality; 00224 desc.PitchAndFamily=pitchandfamily; 00225 if(facename != NULL) lstrcpyA(desc.FaceName, facename); 00226 else desc.FaceName[0] = '\0'; 00227 00228 return D3DXCreateFontIndirectA(device, &desc, font); 00229 } 00230 00231 HRESULT WINAPI D3DXCreateFontW(LPDIRECT3DDEVICE9 device, INT height, UINT width, UINT weight, UINT miplevels, BOOL italic, DWORD charset, 00232 DWORD precision, DWORD quality, DWORD pitchandfamily, LPCWSTR facename, LPD3DXFONT *font) 00233 { 00234 D3DXFONT_DESCW desc; 00235 00236 if( !device || !font ) return D3DERR_INVALIDCALL; 00237 00238 desc.Height=height; 00239 desc.Width=width; 00240 desc.Weight=weight; 00241 desc.MipLevels=miplevels; 00242 desc.Italic=italic; 00243 desc.CharSet=charset; 00244 desc.OutputPrecision=precision; 00245 desc.Quality=quality; 00246 desc.PitchAndFamily=pitchandfamily; 00247 if(facename != NULL) strcpyW(desc.FaceName, facename); 00248 else desc.FaceName[0] = '\0'; 00249 00250 return D3DXCreateFontIndirectW(device, &desc, font); 00251 } 00252 00253 /*********************************************************************** 00254 * D3DXCreateFontIndirectA (D3DX9_36.@) 00255 */ 00256 HRESULT WINAPI D3DXCreateFontIndirectA(LPDIRECT3DDEVICE9 device, CONST D3DXFONT_DESCA *desc, LPD3DXFONT *font) 00257 { 00258 D3DXFONT_DESCW widedesc; 00259 00260 if( !device || !desc || !font ) return D3DERR_INVALIDCALL; 00261 00262 /* Copy everything but the last structure member. This requires the 00263 two D3DXFONT_DESC structures to be equal until the FaceName member */ 00264 memcpy(&widedesc, desc, FIELD_OFFSET(D3DXFONT_DESCA, FaceName)); 00265 MultiByteToWideChar(CP_ACP, 0, desc->FaceName, -1, 00266 widedesc.FaceName, sizeof(widedesc.FaceName)/sizeof(WCHAR)); 00267 return D3DXCreateFontIndirectW(device, &widedesc, font); 00268 } 00269 00270 /*********************************************************************** 00271 * D3DXCreateFontIndirectW (D3DX9_36.@) 00272 */ 00273 HRESULT WINAPI D3DXCreateFontIndirectW(LPDIRECT3DDEVICE9 device, CONST D3DXFONT_DESCW *desc, LPD3DXFONT *font) 00274 { 00275 D3DDEVICE_CREATION_PARAMETERS cpars; 00276 D3DDISPLAYMODE mode; 00277 ID3DXFontImpl *object; 00278 IDirect3D9 *d3d; 00279 HRESULT hr; 00280 FIXME("stub\n"); 00281 00282 if( !device || !desc || !font ) return D3DERR_INVALIDCALL; 00283 00284 /* the device MUST support D3DFMT_A8R8G8B8 */ 00285 IDirect3DDevice9_GetDirect3D(device, &d3d); 00286 IDirect3DDevice9_GetCreationParameters(device, &cpars); 00287 IDirect3DDevice9_GetDisplayMode(device, 0, &mode); 00288 hr = IDirect3D9_CheckDeviceFormat(d3d, cpars.AdapterOrdinal, cpars.DeviceType, mode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_A8R8G8B8); 00289 if(FAILED(hr)) { 00290 IDirect3D9_Release(d3d); 00291 return D3DXERR_INVALIDDATA; 00292 } 00293 IDirect3D9_Release(d3d); 00294 00295 object=HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(ID3DXFontImpl)); 00296 if(object==NULL) { 00297 *font=NULL; 00298 return E_OUTOFMEMORY; 00299 } 00300 object->lpVtbl=&D3DXFont_Vtbl; 00301 object->ref=1; 00302 object->device=device; 00303 object->desc=*desc; 00304 00305 object->hdc = CreateCompatibleDC(NULL); 00306 if( !object->hdc ) { 00307 HeapFree(GetProcessHeap(), 0, object); 00308 return D3DXERR_INVALIDDATA; 00309 } 00310 00311 object->hfont = CreateFontW(desc->Height, desc->Width, 0, 0, desc->Weight, desc->Italic, FALSE, FALSE, desc->CharSet, 00312 desc->OutputPrecision, CLIP_DEFAULT_PRECIS, desc->Quality, desc->PitchAndFamily, desc->FaceName); 00313 if( !object->hfont ) { 00314 DeleteDC(object->hdc); 00315 HeapFree(GetProcessHeap(), 0, object); 00316 return D3DXERR_INVALIDDATA; 00317 } 00318 SelectObject(object->hdc, object->hfont); 00319 00320 IDirect3DDevice9_AddRef(device); 00321 *font=(LPD3DXFONT)object; 00322 00323 return D3D_OK; 00324 } Generated on Sat May 26 2012 04:19:40 for ReactOS by
1.7.6.1
|