ardour/gtk2_ardour/bundle_env_mingw.cc

94 lines
2.8 KiB
C++
Raw Normal View History

/*
Copyright (C) 2001-2012 Paul Davis
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
2014-10-02 00:11:15 -04:00
#include <stdlib.h>
#include "bundle_env.h"
2014-09-30 21:59:48 -04:00
#include "i18n.h"
2014-10-02 00:11:15 -04:00
#include <glibmm.h>
2014-09-30 21:59:48 -04:00
#include <fontconfig/fontconfig.h>
2014-10-02 13:01:12 -04:00
#include <pango/pangoft2.h>
#include <pango/pangocairo.h>
2014-10-02 00:11:15 -04:00
#include <windows.h>
#include <wingdi.h>
2014-09-30 21:59:48 -04:00
#include "ardour/ardour.h"
#include "ardour/search_paths.h"
#include "ardour/filesystem_paths.h"
#include "pbd/file_utils.h"
#include "pbd/epa.h"
using namespace std;
using namespace PBD;
using namespace ARDOUR;
void
fixup_bundle_environment (int, char* [], const char** localedir)
{
2014-10-02 00:11:15 -04:00
EnvironmentalProtectionAgency::set_global_epa (new EnvironmentalProtectionAgency (true));
/* what to do ? */
2014-10-02 00:11:15 -04:00
// 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()
{
2014-09-30 21:59:48 -04:00
std::string ardour_mono_file;
if (!find_file (ardour_data_search_path(), "ArdourMono.ttf", ardour_mono_file)) {
cerr << _("Cannot find ArdourMono TrueType font") << endl;
2014-10-02 00:11:15 -04:00
return;
2014-09-30 21:59:48 -04:00
}
2014-10-02 13:01:12 -04:00
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()));
2014-09-30 21:59:48 -04:00
2014-10-02 13:01:12 -04:00
if (ret == FcFalse) {
cerr << _("Cannot load ArdourMono TrueType font.") << endl;
}
2014-09-30 21:59:48 -04:00
2014-10-02 13:01:12 -04:00
ret = FcConfigSetCurrent(config);
2014-10-02 00:11:15 -04:00
2014-10-02 13:01:12 -04:00
if (ret == FcFalse) {
cerr << _("Failed to set fontconfig configuration.") << endl;
}
2014-10-02 00:11:15 -04:00
} else {
2014-10-02 13:01:12 -04:00
// 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);
}
2014-10-02 00:11:15 -04:00
}
}