]> git.lyx.org Git - lyx.git/commitdiff
Fix bug 3962 (by me, Peter, and Joost)
authorEnrico Forestieri <forenr@lyx.org>
Wed, 11 Jul 2007 11:57:58 +0000 (11:57 +0000)
committerEnrico Forestieri <forenr@lyx.org>
Wed, 11 Jul 2007 11:57:58 +0000 (11:57 +0000)
* src/support/os_cygwin.cpp
* src/support/os_win32.cpp
(addFontResources): use AddFontResourceEx on Windows version
supporting this API in order to mark our fonts as private.
(restoreFontResources): ditto with RemoveFontResourceEx.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@19038 a592a061-630c-0410-9148-cb99ea01b6c8

src/support/os_cygwin.cpp
src/support/os_win32.cpp

index 7f5c22d982ac2497813c80a7151f79b52e4bc9a2..5ec1d1e3d2591e3ffa0950c2e92cb80c73299603 100644 (file)
@@ -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 662693466a8d34bbc899ada43ec0dc605ea394a8..463e341d62f4d69cff9483dcce291757d653a803 100644 (file)
@@ -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