register ArdourMono font with windows
authorRobin Gareus <robin@gareus.org>
Thu, 2 Oct 2014 04:11:15 +0000 (06:11 +0200)
committerRobin Gareus <robin@gareus.org>
Thu, 2 Oct 2014 04:11:15 +0000 (06:11 +0200)
gtk2_ardour/bundle_env_mingw.cc

index 41a6aab5cc2b551e478ed6eb243109a738855824..723e3cee0c318a51dcbf6a19077820ae8eeff9b7 100644 (file)
 
 */
 
+#include <stdlib.h>
 #include "bundle_env.h"
 #include "i18n.h"
 
+#include <glibmm.h>
 #include <fontconfig/fontconfig.h>
+#include <windows.h>
+#include <wingdi.h>
 
 #include "ardour/ardour.h"
 #include "ardour/search_paths.h"
@@ -33,11 +37,25 @@ using namespace std;
 using namespace PBD;
 using namespace ARDOUR;
 
-
 void
 fixup_bundle_environment (int, char* [], const char** localedir)
 {
+       EnvironmentalProtectionAgency::set_global_epa (new EnvironmentalProtectionAgency (true));
        /* what to do ? */
+       // we should at least set ARDOUR_DATA_PATH to prevent the warning message.
+       // 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");
+}
+
+static __cdecl void unload_custom_fonts() {
+       std::string ardour_mono_file;
+       if (!find_file (ardour_data_search_path(), "ArdourMono.ttf", ardour_mono_file)) {
+               return;
+       }
+       RemoveFontResource(ardour_mono_file.c_str());
 }
 
 void load_custom_fonts() 
@@ -46,8 +64,10 @@ void load_custom_fonts()
 
        if (!find_file (ardour_data_search_path(), "ArdourMono.ttf", ardour_mono_file)) {
                cerr << _("Cannot find ArdourMono TrueType font") << endl;
+               return;
        }
 
+       // pango with fontconfig backend
        FcConfig *config = FcInitLoadConfigAndFonts();
        FcBool ret = FcConfigAppFontAddFile(config, reinterpret_cast<const FcChar8*>(ardour_mono_file.c_str()));
 
@@ -60,4 +80,11 @@ void load_custom_fonts()
        if (ret == FcFalse) {
                cerr << _("Failed to set fontconfig configuration.") << endl;
        }
+
+       // 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);
+       }
 }