From 8475d7b7d70d5b98e7737f326653d80a9fd8e9cf Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Tue, 25 Aug 2020 21:58:48 +0200 Subject: [PATCH] Move the code to find Liberation into util.cc. --- src/lib/reel_writer.cc | 17 +---------------- src/lib/util.cc | 21 +++++++++++++++++++++ src/lib/util.h | 1 + 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/src/lib/reel_writer.cc b/src/lib/reel_writer.cc index 770130798..f5f21f2ea 100644 --- a/src/lib/reel_writer.cc +++ b/src/lib/reel_writer.cc @@ -439,24 +439,9 @@ maybe_add_text ( shared_ptr reel_asset; if (asset) { - boost::filesystem::path liberation_normal; - try { - liberation_normal = shared_path() / "LiberationSans-Regular.ttf"; - if (!boost::filesystem::exists (liberation_normal)) { - /* Hack for unit tests */ - liberation_normal = shared_path() / "fonts" / "LiberationSans-Regular.ttf"; - } - } catch (boost::filesystem::filesystem_error& e) { - - } - - if (!boost::filesystem::exists(liberation_normal)) { - liberation_normal = "/usr/share/fonts/truetype/liberation/LiberationSans-Regular.ttf"; - } - /* Add the font to the subtitle content */ BOOST_FOREACH (shared_ptr j, fonts) { - asset->add_font (j->id(), j->file().get_value_or(liberation_normal)); + asset->add_font (j->id(), j->file().get_value_or(default_font_file())); } if (dynamic_pointer_cast (asset)) { diff --git a/src/lib/util.cc b/src/lib/util.cc index 7ba9242fa..84138f4d9 100644 --- a/src/lib/util.cc +++ b/src/lib/util.cc @@ -1253,3 +1253,24 @@ decrypt_kdm_with_helpful_error (dcp::EncryptedKDM kdm) } } + +boost::filesystem::path +default_font_file () +{ + boost::filesystem::path liberation_normal; + try { + liberation_normal = shared_path() / "LiberationSans-Regular.ttf"; + if (!boost::filesystem::exists (liberation_normal)) { + /* Hack for unit tests */ + liberation_normal = shared_path() / "fonts" / "LiberationSans-Regular.ttf"; + } + } catch (boost::filesystem::filesystem_error& e) { + + } + + if (!boost::filesystem::exists(liberation_normal)) { + liberation_normal = "/usr/share/fonts/truetype/liberation/LiberationSans-Regular.ttf"; + } + + return liberation_normal; +} diff --git a/src/lib/util.h b/src/lib/util.h index 6cfe37beb..b4378040a 100644 --- a/src/lib/util.h +++ b/src/lib/util.h @@ -121,6 +121,7 @@ extern void write_swaroop_chain (boost::shared_ptr #endif extern dcp::Size scale_for_display (dcp::Size s, dcp::Size display_container, dcp::Size film_container); extern dcp::DecryptedKDM decrypt_kdm_with_helpful_error (dcp::EncryptedKDM kdm); +extern boost::filesystem::path default_font_file (); template std::list -- 2.30.2