From 2cd89531f9c0364a70c79c0a7e2f70e4e2a16fa2 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 24 Aug 2023 11:34:16 +0200 Subject: [PATCH] LibGfx: Add FontDatabase::for_each_typeface_with_family_name() Some clients (e.g LibWeb) want to look up typefaces by name. Since we already store typefaces in a HashMap keyed by family name, let's also have a nice & fast API that takes advantage of this. --- Userland/Libraries/LibGfx/Font/FontDatabase.cpp | 9 +++++++++ Userland/Libraries/LibGfx/Font/FontDatabase.h | 1 + 2 files changed, 10 insertions(+) diff --git a/Userland/Libraries/LibGfx/Font/FontDatabase.cpp b/Userland/Libraries/LibGfx/Font/FontDatabase.cpp index 01e672a7f3..2c33a96830 100644 --- a/Userland/Libraries/LibGfx/Font/FontDatabase.cpp +++ b/Userland/Libraries/LibGfx/Font/FontDatabase.cpp @@ -260,4 +260,13 @@ void FontDatabase::for_each_typeface(Function callback) } } +void FontDatabase::for_each_typeface_with_family_name(String const& family_name, Function callback) +{ + auto it = m_private->typefaces.find(family_name.bytes_as_string_view()); + if (it == m_private->typefaces.end()) + return; + for (auto const& typeface : it->value) + callback(*typeface); +} + } diff --git a/Userland/Libraries/LibGfx/Font/FontDatabase.h b/Userland/Libraries/LibGfx/Font/FontDatabase.h index 971b6a9e76..c76fe77bf1 100644 --- a/Userland/Libraries/LibGfx/Font/FontDatabase.h +++ b/Userland/Libraries/LibGfx/Font/FontDatabase.h @@ -55,6 +55,7 @@ public: void for_each_fixed_width_font(Function); void for_each_typeface(Function); + void for_each_typeface_with_family_name(String const& family_name, Function); void load_all_fonts_from_path(DeprecatedString const&);