summaryrefslogtreecommitdiff
path: root/src/lib/util.cc
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2025-05-18 22:20:02 +0200
committerCarl Hetherington <cth@carlh.net>2025-05-19 21:25:35 +0200
commit8d18da108282203a90f4b5ae0123700b827e3eb7 (patch)
tree627bf6dad0c0cf0c7bff5ca4f147f0baa5c683a3 /src/lib/util.cc
parent0866fe0a549a489a140fd4670a5245ba231fc8ec (diff)
Tidy up finding required files during tests.
In particular, prefer not to use lots of fallback attempts. It seems that something funny is going on with how we find Liberation Sans on Linux, meaning that we were sometimes using the OS copy of the font when we didn't mean to.
Diffstat (limited to 'src/lib/util.cc')
-rw-r--r--src/lib/util.cc43
1 files changed, 16 insertions, 27 deletions
diff --git a/src/lib/util.cc b/src/lib/util.cc
index 81ae4c494..5ac75134d 100644
--- a/src/lib/util.cc
+++ b/src/lib/util.cc
@@ -136,6 +136,7 @@ using namespace dcpomatic;
*/
string program_name;
bool is_batch_converter = false;
+bool running_tests = false;
static boost::thread::id ui_thread;
static boost::filesystem::path backtrace_file;
@@ -458,18 +459,22 @@ LIBDCP_ENABLE_WARNINGS
#ifdef DCPOMATIC_WINDOWS
putenv("PANGOCAIRO_BACKEND=fontconfig");
- if (dcp::filesystem::exists(resources_path() / "fonts.conf")) {
- /* The actual application after installation */
- putenv(String::compose("FONTCONFIG_PATH=%1", resources_path().string()).c_str());
+ if (running_tests) {
+ putenv("FONTCONFIG_PATH=fonts");
} else {
- /* The place where fonts.conf is during tests */
- putenv("FONTCONFIG_PATH=build\\fonts");
+ putenv(String::compose("FONTCONFIG_PATH=%1", resources_path().string()).c_str());
}
#endif
#ifdef DCPOMATIC_OSX
setenv("PANGOCAIRO_BACKEND", "fontconfig", 1);
- setenv("FONTCONFIG_PATH", resources_path().string().c_str(), 1);
+ boost::filesystem::path fontconfig;
+ if (running_tests) {
+ fontconfig = directory_containing_executable().parent_path().parent_path() / "fonts";
+ } else {
+ fontconfig = resources_path();
+ }
+ setenv("FONTCONFIG_PATH", fontconfig.string().c_str(), 1);
#endif
Pango::init();
@@ -1042,29 +1047,13 @@ decrypt_kdm_with_helpful_error(dcp::EncryptedKDM kdm)
boost::filesystem::path
default_font_file()
{
- boost::filesystem::path liberation_normal;
- try {
- liberation_normal = resources_path() / "LiberationSans-Regular.ttf";
- if (!dcp::filesystem::exists(liberation_normal)) {
- /* Hack for unit tests */
- liberation_normal = resources_path() / "fonts" / "LiberationSans-Regular.ttf";
- }
- } catch (boost::filesystem::filesystem_error& e) {
-
- }
-
- if (!dcp::filesystem::exists(liberation_normal)) {
- liberation_normal = "/usr/share/fonts/truetype/liberation/LiberationSans-Regular.ttf";
- }
- if (!dcp::filesystem::exists(liberation_normal)) {
- liberation_normal = "/usr/share/fonts/liberation-sans/LiberationSans-Regular.ttf";
- }
- if (!dcp::filesystem::exists(liberation_normal)) {
- /* Fedora 41 puts it here */
- liberation_normal = "/usr/share/fonts/liberation-sans-fonts/LiberationSans-Regular.ttf";
+ if (running_tests) {
+ auto const liberation = directory_containing_executable().parent_path().parent_path() / "fonts" / "LiberationSans-Regular.ttf";
+ DCPOMATIC_ASSERT(dcp::filesystem::exists(liberation));
+ return liberation;
}
- return liberation_normal;
+ return resources_path() / "LiberationSans-Regular.ttf";
}