-
Notifications
You must be signed in to change notification settings - Fork 269
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
Diag font: use path relative to executable. #1308
base: master
Are you sure you want to change the base?
Conversation
FWIW, c++17 has a "built-in" filesystem support in the standard library: https://en.cppreference.com/w/cpp/filesystem I don't remember if CCG has switched to c++17 yet, but it would be nice to see boost dependency reduced in favor of the standard library. |
Would that also contain a portable way to find the path relative to the executable? If so that would indeed be the preferred way. |
Something like this should do the trick: namespace fs = std::filesystem;
auto font_path = fs::path(argv[0]) / ".." / ".." / "LiberationMono-Regular.ttf"
if (!font.loadFromFile(font_path))
... If you don't like |
This wont work on windows, as the font is in the same folder as the executable there |
@Julusian would putting it in between ifdefs for linux/windows suffice? Together with the changes suggested by @dimitry-ishenko. |
@gizahNL you could do this to address @Julusian 's concern: namespace fs = std::filesystem;
...
auto pgm_dir = fs::path(argv[0]).parent_path();
auto font_name = "LiberationMono-Regular.ttf";
auto font_path = pgm_dir / font_name; // weendoze path
if(!fs::exists(font_path)) font_path = pgm_dir / ".." / font_name; // Linux path
if(!font.loadFromFile(font_path))
... But I've realized you probably don't have access to |
On linux we can also check where /proc/self/exe links to. I'm not sure if this issue is at all present on Windows, so for me it would be totally fine to #ifdef the logic under __linux |
Fixes diag window not loading when Caspar was not started from the caspar dir (i.e.: under systemd the working dir would be /, and caspar would look for the font in / instead of the installation directory).
9729563
to
9423041
Compare
2b0c540
to
8ec45a4
Compare
This may not be a solution for this, but I added a compile flag which resolves this issue for proper debian packaging. It expects the font to be installed through a package in the debian repositories, and allows for loading from that system path. I admit, doing it with a define isnt the best approach, but I wasn't sure how else to do it. |
@gizahNL in case it's still relevant, for systemd units you can set |
Fixes diag window not loading when Caspar was not started from the caspar dir (i.e.: under systemd the working dir would be /, and caspar would look for the font in / instead of the installation directory).