-
Notifications
You must be signed in to change notification settings - Fork 272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow configuring diag font path at build time #1523
Conversation
This allows for better integration with distros that put the system font in a different directory.
9ee50d5
to
66816a6
Compare
@@ -12,6 +12,14 @@ set(CASPARCG_DOWNLOAD_CACHE ${CMAKE_CURRENT_BINARY_DIR}/external CACHE STRING "D | |||
|
|||
option(ENABLE_HTML "Enable HTML module, require CEF" ON) | |||
|
|||
set(DIAG_FONT_PATH "LiberationMono-Regular.ttf" CACHE STRING | |||
"Path to font that will be used to load diag font at runtime. By default | |||
this loads the font distribtued with the application from the working |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo - distribtued, should be distributed
I am a bit late to the scene, but what if the font path is not known at build-time? Or, what if it's not the same on the build machine compared to the target machine?... IMHO the options should be: (1) bundle the font in a specific location (eg, next to the main executable) and (2) use system facilities to locate the font (eg, fontconfig on Linux). |
The aim of this is to be friendly for distributing as a debian/arch/whatever package. In which case it can be reasonably assumed that the font will be found at a predictable path. Yeah I didn't think about using a system library to locate it. But I probably wouldn't have done it anyway, because it seems like quite an effort for what it is. |
I've looked at the fontconfig API and it's a bit of a mess... One lazy way of doing it would be something like this: std::string font_path;
auto pipe = popen("fc-match --format=%{file} LiberationMono-Regular.ttf", "r");
char buf[128];
while (fgets(buf, sizeof(buf), pipe)) font_path += buf; It's marginally less hacky than hard-coding the path, but if you are cool with it, I can spin off a PR shortly. |
One thing I saw that I didn't like was that the In this particular case it would be cheaper to create a class static variable (inside |
To elaborate on using static local variables, see this: https://godbolt.org/z/oEd7GMseT. Every time the function is called, it has to acquire and release the lock. |
@Julusian here are test results, which show that using global static variables gives ~15% speed improvement on Coliru. Single-threaded: https://coliru.stacked-crooked.com/a/ba4ab9ed90d28352
Multi-threaded: https://coliru.stacked-crooked.com/a/ac8424b20ed46f5a
On my local machine I get even more dramatic results: Single-threaded:
Multi-threaded:
|
This allows for better integration with distros that put the system font in a different directory.
As suggested in #1308 (comment).
The equivalent of the old
-DUSE_SYSTEM_DIAG_FONT=ON
option is now-DDIAG_FONT_PATH=/usr/share/fonts/truetype/liberation/LiberationMono-Regular.ttf