On Wed, Jul 11, 2007 at 09:14:27AM +0200, Joost Verburg wrote:
> Peter Kümmel wrote:
> > What about using my patch and to replace the QLibrary code with your
> > native calls?
> 
> I think using native calls is safer. This is the standard method that is 
> known to work on all Windows versions. You should not use "#define 
> _WIN32_WINNT 0x0500" because it may cause other include files (like 
> boost) to think Windows 2000 functions can be used.

Please, find attached your patch complemented with the changes
for cygwin.

-- 
Enrico
Index: src/support/os_cygwin.cpp
===================================================================
--- src/support/os_cygwin.cpp   (revision 19033)
+++ src/support/os_cygwin.cpp   (working copy)
@@ -40,6 +40,11 @@ using lyx::support::addName;
 using lyx::support::addPath;
 using lyx::support::package;
 
+// API definition for manually calling font functions on Windows 2000 and later
+typedef int (WINAPI *FONTAPI)(LPCSTR, DWORD, PVOID);
+#define FR_PRIVATE     0x10
+
+// Names of TrueType fonts to load
 string const win_fonts_truetype[] = {"cmex10", "cmmi10", "cmr10", "cmsy10",
        "eufm10", "msam10", "msbm10", "wasy10", "esint10"};
 const int num_fonts_truetype = sizeof(win_fonts_truetype) / 
sizeof(*win_fonts_truetype);
@@ -330,12 +335,23 @@ void addFontResources()
        // Windows only: Add BaKoMa TrueType font resources
        string const fonts_dir = 
addPath(package().system_support().absFilename(), "fonts");
 
+       HMODULE hDLL = LoadLibrary("gdi32");
+       FONTAPI pAddFontResourceEx =
+               (FONTAPI) GetProcAddress(hDLL, "AddFontResourceExA");
+
        for (int i = 0 ; i < num_fonts_truetype ; ++i) {
                string const font_current = to_local8bit(from_utf8(convert_path(
                        addName(fonts_dir, win_fonts_truetype[i] + ".ttf"),
                        PathStyle(windows))));
-               AddFontResource(font_current.c_str());
+               if (pAddFontResourceEx) {
+                       // Windows 2000 and later: Use AddFontResourceEx
+                       pAddFontResourceEx(font_current.c_str(), FR_PRIVATE, 0);
+               } else {
+                       // Older Windows versions: Use AddFontResource
+                       AddFontResource(font_current.c_str());
+               }
        }
+       FreeLibrary(hDLL);
 #endif
 }
 
@@ -346,12 +362,22 @@ void restoreFontResources()
        // Windows only: Remove BaKoMa TrueType font resources
        string const fonts_dir = 
addPath(package().system_support().absFilename(), "fonts");
 
+       HMODULE hDLL = LoadLibrary("gdi32");
+       FONTAPI pRemoveFontResourceEx = (FONTAPI) GetProcAddress(hDLL, 
"RemoveFontResourceExA");
+
        for(int i = 0 ; i < num_fonts_truetype ; ++i) {
                string const font_current = to_local8bit(from_utf8(convert_path(
                        addName(fonts_dir, win_fonts_truetype[i] + ".ttf"),
                        PathStyle(windows))));
-               RemoveFontResource(font_current.c_str());
+               if (pRemoveFontResourceEx) {
+                       // Windows 2000 and later: Use RemoveFontResourceEx
+                       pRemoveFontResourceEx(font_current.c_str(), FR_PRIVATE, 
0);
+               } else {
+                       // Older Windows versions: Use RemoveFontResource
+                       RemoveFontResource(font_current.c_str());
+               }
        }
+       FreeLibrary(hDLL);
 #endif
 }
 
Index: src/support/os_win32.cpp
===================================================================
--- src/support/os_win32.cpp    (revision 19033)
+++ src/support/os_win32.cpp    (working copy)
@@ -74,6 +74,11 @@ using lyx::support::addName;
 using lyx::support::addPath;
 using lyx::support::package;
 
+// API definition for manually calling font functions on Windows 2000 and later
+typedef int (WINAPI *FONTAPI)(LPCSTR, DWORD, PVOID);
+#define FR_PRIVATE     0x10
+
+// Names of TrueType fonts to load
 string const win_fonts_truetype[] = {"cmex10", "cmmi10", "cmr10", "cmsy10",
        "eufm10", "msam10", "msbm10", "wasy10", "esint10"};
 const int num_fonts_truetype = sizeof(win_fonts_truetype) / 
sizeof(*win_fonts_truetype);
@@ -408,11 +413,22 @@ void addFontResources()
        // Windows only: Add BaKoMa TrueType font resources
        string const fonts_dir = 
addPath(package().system_support().absFilename(), "fonts");
 
+       HMODULE hDLL = LoadLibrary("gdi32");
+       FONTAPI pAddFontResourceEx = (FONTAPI) GetProcAddress(hDLL, 
"AddFontResourceExA");
+
        for (int i = 0 ; i < num_fonts_truetype ; ++i) {
                string const font_current =
                        addName(fonts_dir, win_fonts_truetype[i] + ".ttf");
-               
AddFontResource(to_local8bit(from_utf8(external_path(font_current))).c_str());
+               if (pAddFontResourceEx) {
+                       // Windows 2000 and later: Use AddFontResourceEx for 
private font
+                       
pAddFontResourceEx(to_local8bit(from_utf8(external_path(font_current))).c_str(),
 FR_PRIVATE, 0);
+               } else {
+                       // Older Windows versions: Use AddFontResource
+                       
AddFontResource(to_local8bit(from_utf8(external_path(font_current))).c_str());
+               }
        }
+
+       FreeLibrary(hDLL);
 }
 
 
@@ -421,11 +437,22 @@ void restoreFontResources()
        // Windows only: Remove BaKoMa TrueType font resources
        string const fonts_dir = 
addPath(package().system_support().absFilename(), "fonts");
 
+       HMODULE hDLL = LoadLibrary("gdi32");
+       FONTAPI pRemoveFontResourceEx = (FONTAPI) GetProcAddress(hDLL, 
"RemoveFontResourceExA");
+
        for(int i = 0 ; i < num_fonts_truetype ; ++i) {
                string const font_current =
                        addName(fonts_dir, win_fonts_truetype[i] + ".ttf");
-               
RemoveFontResource(to_local8bit(from_utf8(external_path(font_current))).c_str());
+               if (pRemoveFontResourceEx) {
+                       // Windows 2000 and later: Use RemoveFontResourceEx for 
private font
+                       
pRemoveFontResourceEx(to_local8bit(from_utf8(external_path(font_current))).c_str(),
 FR_PRIVATE, 0);
+               } else {
+                       // Older Windows versions: Use RemoveFontResource
+                       
RemoveFontResource(to_local8bit(from_utf8(external_path(font_current))).c_str());
+               }
        }
+
+       FreeLibrary(hDLL);
 }
 
 } // namespace os

Reply via email to