From c5cadca542feaae9687525e752c4c8e26258f404 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Wed, 11 Jan 2023 20:30:30 +0000 Subject: [PATCH] LibCore: Add StandardPaths::font_directories() This provides a list of well-known directories containing font files, e.g. for use with Gfx::FontDatabase::load_all_fonts_from_path(). --- Userland/Libraries/LibCore/StandardPaths.cpp | 19 +++++++++++++++++++ Userland/Libraries/LibCore/StandardPaths.h | 2 ++ 2 files changed, 21 insertions(+) diff --git a/Userland/Libraries/LibCore/StandardPaths.cpp b/Userland/Libraries/LibCore/StandardPaths.cpp index da3cdc1563..41755490e6 100644 --- a/Userland/Libraries/LibCore/StandardPaths.cpp +++ b/Userland/Libraries/LibCore/StandardPaths.cpp @@ -1,5 +1,6 @@ /* * Copyright (c) 2020, Andreas Kling + * Copyright (c) 2023, Linus Groh * * SPDX-License-Identifier: BSD-2-Clause */ @@ -7,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -110,4 +112,21 @@ DeprecatedString StandardPaths::tempfile_directory() return "/tmp"; } +ErrorOr> StandardPaths::font_directories() +{ + return Vector { { +#if defined(AK_OS_SERENITY) + TRY(String::from_utf8("/res/fonts"sv)), +#elif defined(AK_OS_MACOS) + TRY(String::from_utf8("/System/Library/Fonts"sv)), + TRY(String::from_utf8("/Library/Fonts"sv)), + TRY(String::formatted("{}/Library/Fonts"sv, home_directory())), +#else + TRY(String::from_utf8("/usr/share/fonts"sv)), + TRY(String::from_utf8("/usr/local/share/fonts"sv)), + TRY(String::formatted("{}/.local/share/fonts"sv, home_directory())), +#endif + } }; +} + } diff --git a/Userland/Libraries/LibCore/StandardPaths.h b/Userland/Libraries/LibCore/StandardPaths.h index ac6dd2b485..470438c62d 100644 --- a/Userland/Libraries/LibCore/StandardPaths.h +++ b/Userland/Libraries/LibCore/StandardPaths.h @@ -1,5 +1,6 @@ /* * Copyright (c) 2020, Andreas Kling + * Copyright (c) 2023, Linus Groh * * SPDX-License-Identifier: BSD-2-Clause */ @@ -21,6 +22,7 @@ public: static DeprecatedString config_directory(); static DeprecatedString data_directory(); static ErrorOr runtime_directory(); + static ErrorOr> font_directories(); }; }