From 5a70ccecb3bc7a03155f93dff1af59abdee87bbc Mon Sep 17 00:00:00 2001 From: Stephan Unverwerth Date: Sat, 2 Jan 2021 18:20:10 +0100 Subject: LibGfx: Add more query methods to FontDatabase and Typeface --- Userland/Libraries/LibGfx/FontDatabase.cpp | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'Userland/Libraries/LibGfx/FontDatabase.cpp') diff --git a/Userland/Libraries/LibGfx/FontDatabase.cpp b/Userland/Libraries/LibGfx/FontDatabase.cpp index dc3fbd41e9..0410b0dd9d 100644 --- a/Userland/Libraries/LibGfx/FontDatabase.cpp +++ b/Userland/Libraries/LibGfx/FontDatabase.cpp @@ -159,10 +159,19 @@ RefPtr FontDatabase::get_by_name(const StringView& name) RefPtr FontDatabase::get(const String& family, unsigned size, unsigned weight) { - for (auto& it : m_private->full_name_to_font_map) { - auto& font = *it.value; - if (font.family() == family && font.presentation_size() == size && font.weight() == weight) - return font; + for (auto typeface : m_private->typefaces) { + if (typeface->family() == family && typeface->weight() == weight) + return typeface->get_font(size); + } + return nullptr; +} + +RefPtr FontDatabase::get(const String& family, const String& variant, unsigned size) +{ + dbgln("FontDatabase: Request font {} {} {}", family, variant, size); + for (auto typeface : m_private->typefaces) { + if (typeface->family() == family && typeface->variant() == variant) + return typeface->get_font(size); } return nullptr; } @@ -178,4 +187,11 @@ RefPtr FontDatabase::get_or_create_typeface(const String& family, cons return typeface; } +void FontDatabase::for_each_typeface(Function callback) +{ + for (auto typeface : m_private->typefaces) { + callback(*typeface); + } +} + } -- cgit v1.2.3