From 804b8deb339761856c3eceff5f908e148e35242d Mon Sep 17 00:00:00 2001 From: D-mo Date: Thu, 19 Sep 2024 09:15:59 -0400 Subject: [PATCH] feat: Use fontconfig on Linux to find the font (#1559) --- src/core/diagnostics/osd_graph.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/core/diagnostics/osd_graph.cpp b/src/core/diagnostics/osd_graph.cpp index aac1a46dbf..758dfcce71 100644 --- a/src/core/diagnostics/osd_graph.cpp +++ b/src/core/diagnostics/osd_graph.cpp @@ -39,12 +39,15 @@ #include #include +#include +#include #include #include #include #include #include -#include + +namespace fs = std::filesystem; namespace caspar { namespace core { namespace diagnostics { namespace osd { @@ -62,11 +65,22 @@ sf::Color get_sfml_color(int color) static_cast(color >> 0 & 255)}; } -sf::Font& get_default_font() +auto& get_default_font() { static sf::Font DEFAULT_FONT = []() { + fs::path path{DIAG_FONT_PATH}; +#ifdef __linux__ + if (!fs::exists(path)) { + auto cmd = "fc-match --format=%{file} " + path.string(); + if (auto pipe = popen(cmd.data(), "r")) { + char buf[128]; + path.clear(); + while (fgets(buf, sizeof(buf), pipe)) path += buf; + } + } +#endif sf::Font font; - if (!font.loadFromFile(DIAG_FONT_PATH)) + if (!font.loadFromFile(path.string())) CASPAR_THROW_EXCEPTION(file_not_found() << msg_info(DIAG_FONT_PATH " not found")); return font; }();