Skip to content

Commit 804b8de

Browse files
feat: Use fontconfig on Linux to find the font (#1559)
1 parent 1404313 commit 804b8de

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/core/diagnostics/osd_graph.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,15 @@
3939
#include <GL/glew.h>
4040

4141
#include <atomic>
42+
#include <cstdio>
43+
#include <filesystem>
4244
#include <list>
4345
#include <memory>
4446
#include <mutex>
4547
#include <optional>
4648
#include <thread>
47-
#include <tuple>
49+
50+
namespace fs = std::filesystem;
4851

4952
namespace caspar { namespace core { namespace diagnostics { namespace osd {
5053

@@ -62,11 +65,22 @@ sf::Color get_sfml_color(int color)
6265
static_cast<sf::Uint8>(color >> 0 & 255)};
6366
}
6467

65-
sf::Font& get_default_font()
68+
auto& get_default_font()
6669
{
6770
static sf::Font DEFAULT_FONT = []() {
71+
fs::path path{DIAG_FONT_PATH};
72+
#ifdef __linux__
73+
if (!fs::exists(path)) {
74+
auto cmd = "fc-match --format=%{file} " + path.string();
75+
if (auto pipe = popen(cmd.data(), "r")) {
76+
char buf[128];
77+
path.clear();
78+
while (fgets(buf, sizeof(buf), pipe)) path += buf;
79+
}
80+
}
81+
#endif
6882
sf::Font font;
69-
if (!font.loadFromFile(DIAG_FONT_PATH))
83+
if (!font.loadFromFile(path.string()))
7084
CASPAR_THROW_EXCEPTION(file_not_found() << msg_info(DIAG_FONT_PATH " not found"));
7185
return font;
7286
}();

0 commit comments

Comments
 (0)