]> git.lyx.org Git - lyx.git/blobdiff - src/support/os_cygwin.C
* src/LaTeX.C (deplog): fix the regex to parse filenames in the log file
[lyx.git] / src / support / os_cygwin.C
index fafbaccf5cbe86fd1e5b56f4a41d884190c8b59a..6cb2f22590d845b525cf67b41f2df618db674006 100644 (file)
@@ -32,6 +32,19 @@ using std::string;
 
 using lyx::support::contains;
 
+#ifdef X_DISPLAY_MISSING
+#include "support/filetools.h"
+#include "support/package.h"
+#include "support/path.h"
+using lyx::support::addName;
+using lyx::support::addPath;
+using lyx::support::package;
+
+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);
+#endif
+
 
 namespace lyx {
 namespace support {
@@ -65,6 +78,9 @@ enum PathStyle {
 };
 
 
+/// Convert a path to or from posix style.
+/// \p p is encoded in local 8bit encoding or utf8.
+/// The result is returned in the same encoding as \p p.
 string convert_path(string const & p, PathStyle const & target)
 {
        char path_buf[PATH_MAX];
@@ -75,6 +91,8 @@ string convert_path(string const & p, PathStyle const & target)
 
        path_buf[0] = '\0';
 
+       // cygwin_conv_to_posix_path and cygwin_conv_to_win32_path do not
+       // care about the encoding.
        if (target == posix)
                cygwin_conv_to_posix_path(p.c_str(), path_buf);
        else
@@ -84,6 +102,9 @@ string convert_path(string const & p, PathStyle const & target)
 }
 
 
+/// Convert a path list to or from posix style.
+/// \p p is encoded in local 8bit encoding or utf8.
+/// The result is returned in the same encoding as \p p.
 string convert_path_list(string const & p, PathStyle const & target)
 {
        if (p.empty())
@@ -100,6 +121,7 @@ string convert_path_list(string const & p, PathStyle const & target)
                char * ptr = new char[target_size];
 
                if (ptr) {
+                       // FIXME: See comment in convert_path() above
                        if (target == posix)
                                cygwin_win32_to_posix_path_list(pc, ptr);
                        else
@@ -188,11 +210,7 @@ string::size_type common_path(string const & p1, string const & p2)
 
 string external_path(string const & p)
 {
-#ifdef X_DISPLAY_MISSING
-       return convert_path(p, PathStyle(windows));
-#else
        return convert_path(p, PathStyle(posix));
-#endif
 }
 
 
@@ -204,11 +222,7 @@ string internal_path(string const & p)
 
 string external_path_list(string const & p)
 {
-#ifdef X_DISPLAY_MISSING
-       return convert_path_list(p, PathStyle(windows));
-#else
        return convert_path_list(p, PathStyle(posix));
-#endif
 }
 
 
@@ -303,13 +317,44 @@ bool autoOpenFile(string const & filename, auto_open_mode const mode)
 {
        // reference: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc
        //                 /platform/shell/reference/functions/shellexecute.asp
-       string const win_path = convert_path(filename, PathStyle(windows));
+       string const win_path = to_local8bit(from_utf8(convert_path(filename, PathStyle(windows))));
        char const * action = (mode == VIEW) ? "open" : "edit";
        return reinterpret_cast<int>(ShellExecute(NULL, action,
                win_path.c_str(), NULL, NULL, 1)) > 32;
 }
 
 
+void addFontResources()
+{
+#ifdef X_DISPLAY_MISSING
+       // Windows only: Add BaKoMa TrueType font resources
+       string const fonts_dir = addPath(package().system_support(), "fonts");
+       
+       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());
+       }
+#endif
+}
+
+
+void restoreFontResources()
+{
+#ifdef X_DISPLAY_MISSING
+       // Windows only: Remove BaKoMa TrueType font resources
+       string const fonts_dir = addPath(package().system_support(), "fonts");
+       
+       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());
+       }
+#endif
+}
+
 } // namespace os
 } // namespace support
 } // namespace lyx