LibGfx: Allow changing the default font path

This commit is contained in:
Filiph Sandström 2022-02-13 12:59:11 +01:00 committed by Linus Groh
parent 62102e3130
commit 8b7987be86
Notes: sideshowbarker 2024-07-17 18:53:53 +09:00
2 changed files with 16 additions and 1 deletions

View File

@ -25,6 +25,7 @@ static RefPtr<Font> s_default_font;
static String s_default_font_query;
static RefPtr<Font> s_fixed_width_font;
static String s_fixed_width_font_query;
static String s_default_fonts_lookup_path = "/res/fonts";
void FontDatabase::set_default_font_query(String query)
{
@ -39,6 +40,18 @@ String FontDatabase::default_font_query()
return s_default_font_query;
}
void FontDatabase::set_default_fonts_lookup_path(String path)
{
if (s_default_fonts_lookup_path == path)
return;
s_default_fonts_lookup_path = move(path);
}
String FontDatabase::default_fonts_lookup_path()
{
return s_default_fonts_lookup_path;
}
Font& FontDatabase::default_font()
{
if (!s_default_font) {
@ -80,7 +93,7 @@ struct FontDatabase::Private {
FontDatabase::FontDatabase()
: m_private(make<Private>())
{
Core::DirIterator dir_iterator("/res/fonts", Core::DirIterator::SkipDots);
Core::DirIterator dir_iterator(s_default_fonts_lookup_path, Core::DirIterator::SkipDots);
if (dir_iterator.has_error()) {
warnln("DirIterator: {}", dir_iterator.error_string());
exit(1);

View File

@ -39,8 +39,10 @@ public:
static String default_font_query();
static String fixed_width_font_query();
static String default_fonts_lookup_path();
static void set_default_font_query(String);
static void set_fixed_width_font_query(String);
static void set_default_fonts_lookup_path(String);
RefPtr<Gfx::Font> get(const String& family, unsigned size, unsigned weight, unsigned slope);
RefPtr<Gfx::Font> get(const String& family, const String& variant, unsigned size);