From 988214ff0b2f90308a9f53b2f10803a2d713917e Mon Sep 17 00:00:00 2001 From: Mikolaj Zalewski Date: Fri, 7 Sep 2007 10:11:09 -0700 Subject: [PATCH] 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 st 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; } /*********************************************************************** -- 1.4.1