LibGfx: Rely on fontconfig(if enabled) for font directory resolution

this commit also introduces GlobalFontConfig class that is now
responsible for fontconfig initialization. it seems sane, even thought
FcInit's docs state that if the default configuration has already been
loaded, this routine does nothing.
This commit is contained in:
blukai 2025-05-21 02:55:15 +02:00 committed by Andrew Kaster
commit e356a4bd01
Notes: github-actions[bot] 2025-05-26 18:15:33 +00:00
5 changed files with 86 additions and 10 deletions

View file

@ -13,6 +13,10 @@
# include <FindDirectory.h>
#endif
#ifdef USE_FONTCONFIG
# include <LibGfx/Font/GlobalFontConfig.h>
#endif
namespace Gfx {
// Key function for SystemFontProvider to emit the vtable here
@ -51,7 +55,16 @@ void FontDatabase::for_each_typeface_with_family_name(FlyString const& family_na
ErrorOr<Vector<String>> FontDatabase::font_directories()
{
#if defined(AK_OS_HAIKU)
#if defined(USE_FONTCONFIG)
Vector<String> paths;
FcConfig* config = Gfx::GlobalFontConfig::the().get();
FcStrList* dirs = FcConfigGetFontDirs(config);
while (FcChar8* dir = FcStrListNext(dirs)) {
char const* dir_cstring = reinterpret_cast<char const*>(dir);
paths.append(TRY(String::from_utf8(StringView { dir_cstring, strlen(dir_cstring) })));
}
return paths;
#elif defined(AK_OS_HAIKU)
Vector<String> paths_vector;
char** paths;
size_t paths_count;