enough with umpteen "i18n.h" files. Consolidate on pbd/i18n.h
[ardour.git] / gtk2_ardour / bundle_env_mingw.cc
1 /*
2     Copyright (C) 2001-2012 Paul Davis
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include <stdlib.h>
21 #include <string>
22 #include "bundle_env.h"
23 #include "pbd/i18n.h"
24
25 #include <glibmm.h>
26 #include <fontconfig/fontconfig.h>
27 #include <pango/pangoft2.h>
28 #include <pango/pangocairo.h>
29
30 #include <windows.h>
31 #include <wingdi.h>
32
33 #include "ardour/ardour.h"
34 #include "ardour/search_paths.h"
35 #include "ardour/filesystem_paths.h"
36
37 #include "pbd/file_utils.h"
38 #include "pbd/epa.h"
39
40 using namespace std;
41 using namespace PBD;
42 using namespace ARDOUR;
43
44 void
45 fixup_bundle_environment (int, char* [], string & localedir)
46 {
47         EnvironmentalProtectionAgency::set_global_epa (new EnvironmentalProtectionAgency (true));
48         /* what to do ? */
49         // we should at least set ARDOUR_DATA_PATH to prevent the warning message.
50         // setting a FONTCONFIG_FILE won't hurt either see bundle_env_msvc.cc
51         // (pangocairo prefers the windows gdi backend unless PANGOCAIRO_BACKEND=fc is set)
52
53         // Unset GTK2_RC_FILES so that only ardour specific files are loaded
54         Glib::unsetenv ("GTK2_RC_FILES");
55
56         std::string path;
57
58         if (ARDOUR::translations_are_enabled ()) {
59                 path = windows_search_path().to_string();
60                 path += "\\locale";
61                 Glib::setenv ("GTK_LOCALEDIR", path, true);
62
63                 // and return the same path to our caller
64                 localedir = path;
65         }
66
67         const char *cstr;
68         cstr = getenv ("VAMP_PATH");
69         if (cstr) {
70                 path = cstr;
71                 path += G_SEARCHPATH_SEPARATOR;
72         } else {
73                 path = "";
74         }
75         path += Glib::build_filename(ardour_dll_directory(), "vamp");
76         path += G_SEARCHPATH_SEPARATOR;
77         path += "%ProgramFiles%\\Vamp Plugins"; // default vamp path
78         path += G_SEARCHPATH_SEPARATOR;
79         path += "%COMMONPROGRAMFILES%\\Vamp Plugins";
80         Glib::setenv ("VAMP_PATH", path, true);
81
82         Glib::setenv ("SUIL_MODULE_DIR", Glib::build_filename(ardour_dll_directory(), "suil"), true);
83
84         /* XXX this should really be PRODUCT_EXE see tools/x-win/package.sh
85          * ardour on windows does not have a startup wrapper script.
86          *
87          * then again, there's probably nobody using NSM on windows.
88          * because neither nsmd nor the GUI is currently available for windows.
89          * furthermore it'll be even less common for derived products.
90          */
91         Glib::setenv ("ARDOUR_SELF", Glib::build_filename(ardour_dll_directory(), "ardour.exe"), true);
92 }
93
94 static __cdecl void
95 unload_custom_fonts()
96 {
97         std::string ardour_mono_file;
98         if (!find_file (ardour_data_search_path(), "ArdourMono.ttf", ardour_mono_file)) {
99                 return;
100         }
101         RemoveFontResource(ardour_mono_file.c_str());
102 }
103
104 void
105 load_custom_fonts()
106 {
107         std::string ardour_mono_file;
108
109         if (!find_file (ardour_data_search_path(), "ArdourMono.ttf", ardour_mono_file)) {
110                 cerr << _("Cannot find ArdourMono TrueType font") << endl;
111                 return;
112         }
113
114         if (pango_font_map_get_type() == PANGO_TYPE_FT2_FONT_MAP) {
115                 FcConfig *config = FcInitLoadConfigAndFonts();
116                 FcBool ret = FcConfigAppFontAddFile(config, reinterpret_cast<const FcChar8*>(ardour_mono_file.c_str()));
117
118                 if (ret == FcFalse) {
119                         cerr << _("Cannot load ArdourMono TrueType font.") << endl;
120                 }
121
122                 ret = FcConfigSetCurrent(config);
123
124                 if (ret == FcFalse) {
125                         cerr << _("Failed to set fontconfig configuration.") << endl;
126                 }
127         } else {
128                 // pango with win32 backend
129                 if (0 == AddFontResource(ardour_mono_file.c_str())) {
130                         cerr << _("Cannot register ArdourMono TrueType font with windows gdi.") << endl;
131                 } else {
132                         atexit (&unload_custom_fonts);
133                 }
134         }
135 }