From cdd91f4b481d11409afd1fc931b6c97c17224ffa Mon Sep 17 00:00:00 2001 From: Alex Studer Date: Wed, 3 Jul 2024 16:06:11 -0400 Subject: [PATCH] Ladybird+LibCore+Meta: Update font paths and names for Android We also disable fontconfig, because it doesn't have support for Android. --- Ladybird/FontPlugin.cpp | 11 ++++++----- Meta/CMake/fontconfig.cmake | 2 +- Userland/Libraries/LibCore/StandardPaths.cpp | 4 ++++ 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/Ladybird/FontPlugin.cpp b/Ladybird/FontPlugin.cpp index 47af0582fe7..fb17bb87368 100644 --- a/Ladybird/FontPlugin.cpp +++ b/Ladybird/FontPlugin.cpp @@ -173,11 +173,12 @@ void FontPlugin::update_generic_fonts() // Fallback fonts to look for if Gfx::Font can't load expected font // The lists are basically arbitrary, taken from https://www.w3.org/Style/Examples/007/fonts.en.html - Vector cursive_fallbacks { "Comic Sans MS"_fly_string, "Comic Sans"_fly_string, "Apple Chancery"_fly_string, "Bradley Hand"_fly_string, "Brush Script MT"_fly_string, "Snell Roundhand"_fly_string, "URW Chancery L"_fly_string }; - Vector fantasy_fallbacks { "Impact"_fly_string, "Luminari"_fly_string, "Chalkduster"_fly_string, "Jazz LET"_fly_string, "Blippo"_fly_string, "Stencil Std"_fly_string, "Marker Felt"_fly_string, "Trattatello"_fly_string }; - Vector monospace_fallbacks { "Andale Mono"_fly_string, "Courier New"_fly_string, "Courier"_fly_string, "FreeMono"_fly_string, "OCR A Std"_fly_string, "DejaVu Sans Mono"_fly_string, "Liberation Mono"_fly_string }; - Vector sans_serif_fallbacks { "Arial"_fly_string, "Helvetica"_fly_string, "Verdana"_fly_string, "Trebuchet MS"_fly_string, "Gill Sans"_fly_string, "Noto Sans"_fly_string, "Avantgarde"_fly_string, "Optima"_fly_string, "Arial Narrow"_fly_string, "Liberation Sans"_fly_string }; - Vector serif_fallbacks { "Times"_fly_string, "Times New Roman"_fly_string, "Didot"_fly_string, "Georgia"_fly_string, "Palatino"_fly_string, "Bookman"_fly_string, "New Century Schoolbook"_fly_string, "American Typewriter"_fly_string, "Liberation Serif"_fly_string, "Roman"_fly_string }; + // (We also add Android-specific font names to the list from W3 where required.) + Vector cursive_fallbacks { "Comic Sans MS"_fly_string, "Comic Sans"_fly_string, "Apple Chancery"_fly_string, "Bradley Hand"_fly_string, "Brush Script MT"_fly_string, "Snell Roundhand"_fly_string, "URW Chancery L"_fly_string, "Dancing Script"_fly_string }; + Vector fantasy_fallbacks { "Impact"_fly_string, "Luminari"_fly_string, "Chalkduster"_fly_string, "Jazz LET"_fly_string, "Blippo"_fly_string, "Stencil Std"_fly_string, "Marker Felt"_fly_string, "Trattatello"_fly_string, "Coming Soon"_fly_string }; + Vector monospace_fallbacks { "Andale Mono"_fly_string, "Courier New"_fly_string, "Courier"_fly_string, "FreeMono"_fly_string, "OCR A Std"_fly_string, "DejaVu Sans Mono"_fly_string, "Droid Sans Mono"_fly_string, "Liberation Mono"_fly_string }; + Vector sans_serif_fallbacks { "Arial"_fly_string, "Helvetica"_fly_string, "Verdana"_fly_string, "Trebuchet MS"_fly_string, "Gill Sans"_fly_string, "Noto Sans"_fly_string, "Avantgarde"_fly_string, "Optima"_fly_string, "Arial Narrow"_fly_string, "Liberation Sans"_fly_string, "Roboto"_fly_string }; + Vector serif_fallbacks { "Times"_fly_string, "Times New Roman"_fly_string, "Didot"_fly_string, "Georgia"_fly_string, "Palatino"_fly_string, "Bookman"_fly_string, "New Century Schoolbook"_fly_string, "American Typewriter"_fly_string, "Liberation Serif"_fly_string, "Roman"_fly_string, "Noto Serif"_fly_string }; update_mapping(Web::Platform::GenericFont::Cursive, cursive_fallbacks); update_mapping(Web::Platform::GenericFont::Fantasy, fantasy_fallbacks); diff --git a/Meta/CMake/fontconfig.cmake b/Meta/CMake/fontconfig.cmake index b1c533fc533..cd16431a3d0 100644 --- a/Meta/CMake/fontconfig.cmake +++ b/Meta/CMake/fontconfig.cmake @@ -1,4 +1,4 @@ -if (NOT APPLE) +if (NOT APPLE AND NOT ANDROID) find_package(Fontconfig REQUIRED) set(HAS_FONTCONFIG ON CACHE BOOL "" FORCE) add_compile_definitions(USE_FONTCONFIG=1) diff --git a/Userland/Libraries/LibCore/StandardPaths.cpp b/Userland/Libraries/LibCore/StandardPaths.cpp index 995c992e8f7..585b8a291de 100644 --- a/Userland/Libraries/LibCore/StandardPaths.cpp +++ b/Userland/Libraries/LibCore/StandardPaths.cpp @@ -206,6 +206,10 @@ ErrorOr> StandardPaths::font_directories() "/System/Library/Fonts"_string, "/Library/Fonts"_string, TRY(String::formatted("{}/Library/Fonts"sv, home_directory())), +# elif defined(AK_OS_ANDROID) + // FIXME: We should be using the ASystemFontIterator NDK API here. + // There is no guarantee that this will continue to exist on future versions of Android. + "/system/fonts"_string, # else TRY(String::formatted("{}/fonts"sv, data_directory())), TRY(String::formatted("{}/X11/fonts"sv, data_directory())),