enough with umpteen "i18n.h" files. Consolidate on pbd/i18n.h
[ardour.git] / gtk2_ardour / bundle_env_mingw.cc
index 723e3cee0c318a51dcbf6a19077820ae8eeff9b7..6ee1e0f7a24be27c66b9346e9fb51965ad761ded 100644 (file)
 */
 
 #include <stdlib.h>
+#include <string>
 #include "bundle_env.h"
-#include "i18n.h"
+#include "pbd/i18n.h"
 
 #include <glibmm.h>
 #include <fontconfig/fontconfig.h>
+#include <pango/pangoft2.h>
+#include <pango/pangocairo.h>
+
 #include <windows.h>
 #include <wingdi.h>
 
@@ -38,7 +42,7 @@ using namespace PBD;
 using namespace ARDOUR;
 
 void
-fixup_bundle_environment (int, char* [], const char** localedir)
+fixup_bundle_environment (int, char* [], string & localedir)
 {
        EnvironmentalProtectionAgency::set_global_epa (new EnvironmentalProtectionAgency (true));
        /* what to do ? */
@@ -46,11 +50,50 @@ fixup_bundle_environment (int, char* [], const char** localedir)
        // setting a FONTCONFIG_FILE won't hurt either see bundle_env_msvc.cc
        // (pangocairo prefers the windows gdi backend unless PANGOCAIRO_BACKEND=fc is set)
 
-       // Unset GTK_RC_FILES so that only ardour specific files are loaded
-       Glib::unsetenv ("GTK_RC_FILES");
+       // Unset GTK2_RC_FILES so that only ardour specific files are loaded
+       Glib::unsetenv ("GTK2_RC_FILES");
+
+       std::string path;
+
+       if (ARDOUR::translations_are_enabled ()) {
+               path = windows_search_path().to_string();
+               path += "\\locale";
+               Glib::setenv ("GTK_LOCALEDIR", path, true);
+
+               // and return the same path to our caller
+               localedir = path;
+       }
+
+       const char *cstr;
+       cstr = getenv ("VAMP_PATH");
+       if (cstr) {
+               path = cstr;
+               path += G_SEARCHPATH_SEPARATOR;
+       } else {
+               path = "";
+       }
+       path += Glib::build_filename(ardour_dll_directory(), "vamp");
+       path += G_SEARCHPATH_SEPARATOR;
+       path += "%ProgramFiles%\\Vamp Plugins"; // default vamp path
+       path += G_SEARCHPATH_SEPARATOR;
+       path += "%COMMONPROGRAMFILES%\\Vamp Plugins";
+       Glib::setenv ("VAMP_PATH", path, true);
+
+       Glib::setenv ("SUIL_MODULE_DIR", Glib::build_filename(ardour_dll_directory(), "suil"), true);
+
+       /* XXX this should really be PRODUCT_EXE see tools/x-win/package.sh
+        * ardour on windows does not have a startup wrapper script.
+        *
+        * then again, there's probably nobody using NSM on windows.
+        * because neither nsmd nor the GUI is currently available for windows.
+        * furthermore it'll be even less common for derived products.
+        */
+       Glib::setenv ("ARDOUR_SELF", Glib::build_filename(ardour_dll_directory(), "ardour.exe"), true);
 }
 
-static __cdecl void unload_custom_fonts() {
+static __cdecl void
+unload_custom_fonts()
+{
        std::string ardour_mono_file;
        if (!find_file (ardour_data_search_path(), "ArdourMono.ttf", ardour_mono_file)) {
                return;
@@ -58,7 +101,8 @@ static __cdecl void unload_custom_fonts() {
        RemoveFontResource(ardour_mono_file.c_str());
 }
 
-void load_custom_fonts() 
+void
+load_custom_fonts()
 {
        std::string ardour_mono_file;
 
@@ -67,24 +111,25 @@ void load_custom_fonts()
                return;
        }
 
-       // pango with fontconfig backend
-       FcConfig *config = FcInitLoadConfigAndFonts();
-       FcBool ret = FcConfigAppFontAddFile(config, reinterpret_cast<const FcChar8*>(ardour_mono_file.c_str()));
+       if (pango_font_map_get_type() == PANGO_TYPE_FT2_FONT_MAP) {
+               FcConfig *config = FcInitLoadConfigAndFonts();
+               FcBool ret = FcConfigAppFontAddFile(config, reinterpret_cast<const FcChar8*>(ardour_mono_file.c_str()));
 
-       if (ret == FcFalse) {
-               cerr << _("Cannot load ArdourMono TrueType font.") << endl;
-       }
-
-       ret = FcConfigSetCurrent(config);
+               if (ret == FcFalse) {
+                       cerr << _("Cannot load ArdourMono TrueType font.") << endl;
+               }
 
-       if (ret == FcFalse) {
-               cerr << _("Failed to set fontconfig configuration.") << endl;
-       }
+               ret = FcConfigSetCurrent(config);
 
-       // pango with win32 backend
-       if (0 == AddFontResource(ardour_mono_file.c_str())) {
-               cerr << _("Cannot register ArdourMono TrueType font with windows gdi.") << endl;
+               if (ret == FcFalse) {
+                       cerr << _("Failed to set fontconfig configuration.") << endl;
+               }
        } else {
-               atexit (&unload_custom_fonts);
+               // pango with win32 backend
+               if (0 == AddFontResource(ardour_mono_file.c_str())) {
+                       cerr << _("Cannot register ArdourMono TrueType font with windows gdi.") << endl;
+               } else {
+                       atexit (&unload_custom_fonts);
+               }
        }
 }