1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
/*
* Copyright © Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 or 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "wallpaper_config.h"
#include <boost/filesystem.hpp>
#include <mutex>
#include <vector>
namespace
{
/// Font search logic should be kept in sync with src/server/shell/decoration/renderer.cpp
auto default_font() -> std::string
{
struct FontPath
{
char const* filename;
std::vector<char const*> prefixes;
};
FontPath const font_paths[]{
FontPath{"Ubuntu-B.ttf", {
"ubuntu-font-family", // Ubuntu < 18.04
"ubuntu", // Ubuntu >= 18.04/Arch
}},
FontPath{"FreeSansBold.ttf", {
"freefont", // Debian/Ubuntu
"gnu-free", // Fedora/Arch
}},
FontPath{"DejaVuSans-Bold.ttf", {
"dejavu", // Ubuntu (others?)
"", // Arch
}},
FontPath{"LiberationSans-Bold.ttf", {
"liberation-sans", // Fedora
"liberation-sans-fonts",// Fedora >= 42
"liberation", // Arch/Ubuntu
}},
FontPath{"OpenSans-Bold.ttf", {
"open-sans", // Fedora/Ubuntu
}},
};
char const* const font_path_search_paths[]{
"/usr/share/fonts/truetype", // Ubuntu/Debian
"/usr/share/fonts/TTF", // Arch
"/usr/share/fonts", // Fedora/Arch
};
std::vector<std::string> usable_search_paths;
for (auto const& path : font_path_search_paths)
{
if (boost::filesystem::exists(path))
usable_search_paths.push_back(path);
}
for (auto const& font : font_paths)
{
for (auto const& prefix : font.prefixes)
{
for (auto const& path : usable_search_paths)
{
auto const full_font_path = path + '/' + prefix + '/' + font.filename;
if (boost::filesystem::exists(full_font_path))
return full_font_path;
}
}
}
return "";
}
std::mutex mutex;
std::string font_file{default_font()};
}
void wallpaper::font_file(std::string const& font_file)
{
std::lock_guard lock{mutex};
::font_file = font_file;
}
auto wallpaper::font_file() -> std::string
{
std::lock_guard lock{mutex};
return ::font_file;
}
|