Here an updated patch which only calls the Ex functions
if they are available.

And what was the status? It doesn't work on Vista?
And also needs some chmod changes on cygwin?

Peter
Index: src/support/os_cygwin.cpp
===================================================================
--- src/support/os_cygwin.cpp   (revision 19031)
+++ src/support/os_cygwin.cpp   (working copy)
@@ -19,7 +19,12 @@
 
 #include "debug.h"
 
+// compile with Windows > Win98 API, but load those functions dynamically
+// only needed for AddFontResourceEx
+#define _WIN32_WINNT 0x0500
+#define WIN32_LEAN_AND_MEAN
 #include <windows.h>
+
 #include <io.h>
 #include <windef.h>
 #include <shellapi.h>
@@ -27,6 +32,8 @@
 
 #include <sys/cygwin.h>
 
+#include <QLibrary>
+
 using std::endl;
 using std::string;
 
@@ -324,6 +331,40 @@
 }
 
 
+// same as in os_win32.cpp
+static
+void fontResources(const std::string& name, LPCTSTR font_file_name)
+{
+       // first try to get the Ex version
+       typedef int (WINAPI* FontFunc)(LPCTSTR);
+       typedef int (WINAPI* FontExFunc)(LPCTSTR, DWORD, PVOID);
+       static FontFunc func = 0;
+       static FontExFunc func_ex = 0;
+       static std::string resolved_name;
+       if (resolved_name != name) {
+               QLibrary win_lib("gdi32");
+               win_lib.load();
+               std::string name_exa = name + "ExA";
+               func_ex = (FontExFunc) win_lib.resolve(name_exa.c_str());
+               if (!func_ex) {
+                       std::string name_a = name + "A";
+                       func = (FontFunc) win_lib.resolve(name_a.c_str());
+               }
+               resolved_name = name;
+       }
+       if (func_ex) {
+               func_ex(font_file_name, FR_PRIVATE, 0);
+               LYXERR(Debug::FONT) << "fontResources function: " << 
name.c_str() << "Ex" << endl;
+       } else if (func) {
+               func(font_file_name);
+               LYXERR(Debug::FONT) << "fontResources function: " << 
name.c_str() << endl;
+       } else {
+               // could never happen
+               LYXERR(Debug::FONT) << "fontResources - fatal error" << endl;
+       }
+}
+
+
 void addFontResources()
 {
 #ifdef X_DISPLAY_MISSING
@@ -334,7 +375,7 @@
                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());
+               fontResources("AddFontResource", font_current.c_str());
        }
 #endif
 }
@@ -350,7 +391,7 @@
                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());
+               fontResources("RemoveFontResource", font_current.c_str());
        }
 #endif
 }
Index: src/support/os_win32.h
===================================================================
--- src/support/os_win32.h      (revision 19031)
+++ src/support/os_win32.h      (working copy)
@@ -42,6 +42,10 @@
 # define _WIN32_IE 0x0500
 #endif
 
+// compile with Windows > Win98 API, but load those functions dynamically
+// only needed for AddFontResourceEx
+#define _WIN32_WINNT 0x0500
+#define WIN32_LEAN_AND_MEAN
 #include <windows.h>
 
 
Index: src/support/os_win32.cpp
===================================================================
--- src/support/os_win32.cpp    (revision 19031)
+++ src/support/os_win32.cpp    (working copy)
@@ -30,6 +30,8 @@
 #include <cstdlib>
 #include <vector>
 
+#include <QLibrary>
+
 /* The GetLongPathName macro may be defined on the compiling machine,
  * but we must use a bit of trickery if the resulting executable is
  * to run on a Win95 machine.
@@ -403,6 +405,39 @@
 }
 
 
+static
+void fontResources(const std::string& name, LPCTSTR font_file_name)
+{
+       // first try to get the Ex version
+       typedef int (WINAPI* FontFunc)(LPCTSTR);
+       typedef int (WINAPI* FontExFunc)(LPCTSTR, DWORD, PVOID);
+       static FontFunc func = 0;
+       static FontExFunc func_ex = 0;
+       static std::string resolved_name;
+       if (resolved_name != name) {
+               QLibrary win_lib("gdi32");
+               win_lib.load();
+               std::string name_exa = name + "ExA";
+               func_ex = (FontExFunc) win_lib.resolve(name_exa.c_str());
+               if (!func_ex) {
+                       std::string name_a = name + "A";
+                       func = (FontFunc) win_lib.resolve(name_a.c_str());
+               }
+               resolved_name = name;
+       }
+       if (func_ex) {
+               func_ex(font_file_name, FR_PRIVATE, 0);
+               LYXERR(Debug::FONT) << "fontResources function: " << 
name.c_str() << "Ex" << endl;
+       } else if (func) {
+               func(font_file_name);
+               LYXERR(Debug::FONT) << "fontResources function: " << 
name.c_str() << endl;
+       } else {
+               // could never happen
+               LYXERR(Debug::FONT) << "fontResources - fatal error" << endl;
+       }
+}
+
+
 void addFontResources()
 {
        // Windows only: Add BaKoMa TrueType font resources
@@ -411,7 +446,8 @@
        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());
+               fontResources("AddFontResource",
+                       
to_local8bit(from_utf8(external_path(font_current))).c_str());
        }
 }
 
@@ -424,7 +460,8 @@
        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());
+               fontResources("RemoveFontResource",
+                       
to_local8bit(from_utf8(external_path(font_current))).c_str());
        }
 }
 

Reply via email to