Serenity Operating System
at master 43 lines 1.1 kB view raw
1/* 2 * Copyright (c) 2018-2023, Andreas Kling <kling@serenityos.org> 3 * 4 * SPDX-License-Identifier: BSD-2-Clause 5 */ 6 7#pragma once 8 9#include <AK/FlyString.h> 10#include <AK/HashMap.h> 11#include <LibGfx/Font/Font.h> 12#include <LibGfx/Forward.h> 13 14struct FontSelector { 15 FlyString family; 16 float point_size { 0 }; 17 int weight { 0 }; 18 int width { 0 }; 19 int slope { 0 }; 20 21 bool operator==(FontSelector const& other) const 22 { 23 return family == other.family && point_size == other.point_size && weight == other.weight && width == other.width && slope == other.slope; 24 } 25}; 26 27namespace AK { 28template<> 29struct Traits<FontSelector> : public GenericTraits<FontSelector> { 30 static unsigned hash(FontSelector const& key) { return pair_int_hash(pair_int_hash(key.family.hash(), key.weight), key.point_size); } 31}; 32} 33 34class FontCache { 35public: 36 static FontCache& the(); 37 RefPtr<Gfx::Font const> get(FontSelector const&) const; 38 void set(FontSelector const&, NonnullRefPtr<Gfx::Font const>); 39 40private: 41 FontCache() = default; 42 mutable HashMap<FontSelector, NonnullRefPtr<Gfx::Font const>> m_fonts; 43};