1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 08:27:45 +00:00

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

View file

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