ardour
bundle_env_cocoa.cc
Go to the documentation of this file.
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 <fstream>
21 #include <string>
22 #include <vector>
23 #include <cerrno>
24 #include <cstring>
25 
26 #include <glib.h>
27 #include <glibmm/fileutils.h>
28 #include <glibmm/miscutils.h>
29 
30 #include <fontconfig/fontconfig.h>
31 
32 #include "ardour/ardour.h"
34 
35 #include "pbd/epa.h"
36 #include "pbd/search_path.h"
37 #include "pbd/pathexpand.h"
38 #include "pbd/file_utils.h"
39 
40 #include "bundle_env.h"
41 
42 #include "i18n.h"
43 
44 #include <Carbon/Carbon.h>
45 #include <mach-o/dyld.h>
46 #include <sys/param.h>
47 
48 using namespace PBD;
49 using namespace ARDOUR;
50 using namespace std;
51 
52 extern void set_language_preference (); // cocoacarbon.mm
53 
54 void
55 fixup_bundle_environment (int, char* [], string & localedir)
56 {
57  if (!g_getenv ("ARDOUR_BUNDLED")) {
58  return;
59  }
60 
62 
64 
65  char execpath[MAXPATHLEN+1];
66  uint32_t pathsz = sizeof (execpath);
67 
68  _NSGetExecutablePath (execpath, &pathsz);
69 
70  std::string path;
71  std::string exec_dir = Glib::path_get_dirname (execpath);
72  std::string bundle_dir;
73  std::string userconfigdir = user_config_directory();
74 
75  bundle_dir = Glib::path_get_dirname (exec_dir);
76 
77 #ifdef ENABLE_NLS
79  localedir = "/this/cannot/exist";
80  } else {
81  /* force localedir into the bundle */
82 
83  vector<string> lpath;
84  lpath.push_back (bundle_dir);
85  lpath.push_back ("Resources");
86  lpath.push_back ("locale");
87  localedir = Glib::build_filename (lpath).c_str();
88  }
89 #endif
90 
91  export_search_path (bundle_dir, "ARDOUR_DLL_PATH", "/lib");
92 
93  /* inside an OS X .app bundle, there is no difference
94  between DATA and CONFIG locations, since OS X doesn't
95  attempt to do anything to expose the notion of
96  machine-independent shared data.
97  */
98 
99  export_search_path (bundle_dir, "ARDOUR_DATA_PATH", "/Resources");
100  export_search_path (bundle_dir, "ARDOUR_CONFIG_PATH", "/Resources");
101  export_search_path (bundle_dir, "ARDOUR_INSTANT_XML_PATH", "/Resources");
102  export_search_path (bundle_dir, "LADSPA_PATH", "/Plugins");
103  export_search_path (bundle_dir, "VAMP_PATH", "/lib");
104  export_search_path (bundle_dir, "GTK_PATH", "/lib/gtkengines");
105 
106  g_setenv ("SUIL_MODULE_DIR", (bundle_dir + "/lib").c_str(), 1);
107  g_setenv ("PATH", (bundle_dir + "/MacOS:" + std::string(g_getenv ("PATH"))).c_str(), 1);
108 
109  /* unset GTK_RC_FILES so that we only load the RC files that we define
110  */
111 
112  g_unsetenv ("GTK_RC_FILES");
113  g_setenv ("CHARSETALIASDIR", bundle_dir.c_str(), 1);
114  g_setenv ("FONTCONFIG_FILE", Glib::build_filename (bundle_dir, "Resources/fonts.conf").c_str(), 1);
115 }
116 
118 {
119  /* this code will only compile on OS X 10.6 and above, and we currently do not
120  * need it for earlier versions since we fall back on a non-monospace,
121  * non-custom font.
122  */
123 
124 #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
125  std::string ardour_mono_file;
126 
127  if (!find_file (ardour_data_search_path(), "ArdourMono.ttf", ardour_mono_file)) {
128  cerr << _("Cannot find ArdourMono TrueType font") << endl;
129  }
130 
131  CFStringRef ttf;
132  CFURLRef fontURL;
133  CFErrorRef error;
134  ttf = CFStringCreateWithBytes(
135  kCFAllocatorDefault, (UInt8*) ardour_mono_file.c_str(),
136  ardour_mono_file.length(),
137  kCFStringEncodingUTF8, FALSE);
138  fontURL = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, ttf, kCFURLPOSIXPathStyle, TRUE);
139  if (CTFontManagerRegisterFontsForURL(fontURL, kCTFontManagerScopeProcess, &error) != true) {
140  cerr << _("Cannot load ArdourMono TrueType font.") << endl;
141  }
142 #endif
143 }
void load_custom_fonts()
Definition: Beats.hpp:239
LIBPBD_API Transmitter error
LIBARDOUR_API bool translations_are_enabled()
Definition: globals.cc:636
static void set_global_epa(EnvironmentalProtectionAgency *epa)
Definition: epa.h:40
bool find_file(const Searchpath &search_path, const string &filename, std::string &result)
Definition: file_utils.cc:187
#define _(Text)
Definition: i18n.h:11
LIBPBD_API void export_search_path(const std::string &base_dir, const char *varname, const char *dir)
LIBARDOUR_API std::string user_config_directory(int version=-1)
static const char * localedir
Definition: load_session.cc:12
Definition: amp.h:29
void fixup_bundle_environment(int, char *[], string &localedir)
Definition: debug.h:30
void set_language_preference()
Definition: cocoacarbon.mm:77
LIBARDOUR_API PBD::Searchpath ardour_data_search_path()