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

Mikolaj Zalewski mikolajz at google.com
Thu Sep 6 14:07:39 CDT 2007


This is some overlap with freetype as freetype 2.3.5 can load fonts
from PE resources. But the code is so small (we have all the tools
needed) and helps many programs (including working around the
Photoshop Z-order problem during startup as now the dialogs doesn't
show) that I thought it is useful.
-------------- next part --------------
From 7f1f1e8b693fc367d2b44ece3b1c3293e08496d7 Mon Sep 17 00:00:00 2001
From: Mikolaj Zalewski <mikolaj at zalewski.pl>
Date: Thu, 6 Sep 2007 11:43:02 -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..4ffaf5a 100644
--- a/dlls/gdi32/font.c
+++ b/dlls/gdi32/font.c
@@ -3185,12 +3185,48 @@ INT WINAPI AddFontResourceExA( LPCSTR st
     return ret;
 }
 
+static BOOL 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