1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 20:27:45 +00:00

LibGfx: Add FontDatabase::get(family, size, weight)

This function allows you to look up a font by its exact parameters.
This commit is contained in:
Andreas Kling 2020-12-28 15:47:21 +01:00
parent cd9ad6a05e
commit 105eb8e1bc
2 changed files with 11 additions and 0 deletions

View file

@ -106,4 +106,14 @@ RefPtr<Gfx::Font> FontDatabase::get_by_name(const StringView& name)
return it->value;
}
RefPtr<Gfx::Font> 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;
}
return nullptr;
}
}

View file

@ -37,6 +37,7 @@ class FontDatabase {
public:
static FontDatabase& the();
RefPtr<Gfx::Font> get(const String& family, unsigned size, unsigned weight);
RefPtr<Gfx::Font> get_by_name(const StringView&);
void for_each_font(Function<void(const Gfx::Font&)>);
void for_each_fixed_width_font(Function<void(const Gfx::Font&)>);