Module: wine Branch: master Commit: 0eb910352cc1413d48e8594a92547fc2a21ae168 URL: http://source.winehq.org/git/wine.git/?a=commit;h=0eb910352cc1413d48e8594a92...
Author: Mikolaj Zalewski mikolajz@google.com Date: Fri Sep 7 10:11:09 2007 -0700
gdi32: If freetype fails try to load manually fonts wrapped as PE resources.
---
dlls/gdi32/font.c | 38 +++++++++++++++++++++++++++++++++++++- 1 files changed, 37 insertions(+), 1 deletions(-)
diff --git a/dlls/gdi32/font.c b/dlls/gdi32/font.c index 01182fa..0cc7339 100644 --- a/dlls/gdi32/font.c +++ b/dlls/gdi32/font.c @@ -3185,12 +3185,48 @@ INT WINAPI AddFontResourceExA( LPCSTR str, DWORD fl, PVOID pdv ) return ret; }
+static BOOL CALLBACK load_enumed_resource(HMODULE hModule, LPCWSTR type, LPWSTR name, LONG_PTR lParam) +{ + HRSRC rsrc = FindResourceW(hModule, name, type); + HGLOBAL hMem = LoadResource(hModule, rsrc); + LPVOID *pMem = LockResource(hMem); + int *num_total = (int *)lParam; + DWORD num_in_res; + + TRACE("Found resource %s - trying to load\n", wine_dbgstr_w(type)); + if (!AddFontMemResourceEx(pMem, SizeofResource(hModule, rsrc), NULL, &num_in_res)) + { + ERR("Failed to load PE font resource mod=%p ptr=%p\n", hModule, hMem); + return FALSE; + } + + *num_total += num_in_res; + return TRUE; +} + /*********************************************************************** * AddFontResourceExW (GDI32.@) */ INT WINAPI AddFontResourceExW( LPCWSTR str, DWORD fl, PVOID pdv ) { - return WineEngAddFontResourceEx(str, fl, pdv); + int ret = WineEngAddFontResourceEx(str, fl, pdv); + if (ret == 0) + { + /* Freetype <2.3.5 have problems reading resources wrapped in PE files. */ + HMODULE hModule = LoadLibraryExW(str, NULL, LOAD_LIBRARY_AS_DATAFILE); + if (hModule != NULL) + { + int num_resources = 0; + LPWSTR rt_font = (LPWSTR)((ULONG_PTR)8); /* we don't want to include winuser.h */ + + TRACE("WineEndAddFontResourceEx failed on PE file %s - trying to load resources manualy\n", + wine_dbgstr_w(str)); + if (EnumResourceNamesW(hModule, rt_font, load_enumed_resource, (LONG_PTR)&num_resources)) + ret = num_resources; + FreeLibrary(hModule); + } + } + return ret; }
/***********************************************************************