]> git.lyx.org Git - lyx.git/blobdiff - src/support/os_win32.cpp
remove lyxrc dependence from support/*
[lyx.git] / src / support / os_win32.cpp
index 80e60e6811b451d664c0e1c37bf37a653b934f63..463e341d62f4d69cff9483dcce291757d653a803 100644 (file)
@@ -53,7 +53,7 @@
 #include <direct.h> // _getdrive
 #include <shlobj.h>  // SHGetFolderPath
 #include <windef.h>
-#include <shellapi.h>  
+#include <shellapi.h>
 #include <shlwapi.h>
 
 // Must define SHGFP_TYPE_CURRENT for older versions of MinGW.
@@ -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);
@@ -144,7 +149,7 @@ void init(int /* argc */, char * argv[])
         * shell scripts failed, for mysterious reasons...
         *
         * I've chosen for now, therefore, to simply add Ruurd's original
-        * code as-is. A wrapper program hidecmd.c has been added to 
+        * code as-is. A wrapper program hidecmd.c has been added to
         * development/Win32 which hides the console window of lyx when
         * lyx is invoked as a parameter of hidecmd.exe.
         */
@@ -407,12 +412,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 =
                        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);
 }
 
 
@@ -420,12 +436,23 @@ 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