gdi32[3/3]: if freetype fails try to load manually fonts wrapped as PE resources (fixed)

Mikolaj Zalewski mikolajz at google.com
Fri Sep 7 12:33:46 CDT 2007


As Huw thinks this patch could go in I resend it with fixed calling convention
-------------- next part --------------
From e12a0ee0d2bd383f0e9f1e519cd720210652f692 Mon Sep 17 00:00:00 2001
From: Mikolaj Zalewski <mikolaj at zalewski.pl>
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 efc044b..8321598 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


More information about the wine-patches mailing list