2020-01-18 09:38:21 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 09:38:21 +01:00
|
|
|
*/
|
|
|
|
|
2019-10-18 23:02:10 +02:00
|
|
|
#pragma once
|
|
|
|
|
2020-05-26 23:45:48 +02:00
|
|
|
#include <AK/FlyString.h>
|
2019-10-18 23:02:10 +02:00
|
|
|
#include <AK/HashMap.h>
|
|
|
|
#include <AK/String.h>
|
2022-04-09 09:28:38 +02:00
|
|
|
#include <LibGfx/Font/Font.h>
|
2020-02-15 00:10:34 +01:00
|
|
|
#include <LibGfx/Forward.h>
|
2019-10-18 23:02:10 +02:00
|
|
|
|
|
|
|
struct FontSelector {
|
2020-05-26 23:45:48 +02:00
|
|
|
FlyString family;
|
2022-03-26 23:55:11 +01:00
|
|
|
float point_size { 0 };
|
2020-12-14 15:56:01 +01:00
|
|
|
int weight { 0 };
|
2022-01-31 20:18:15 -05:00
|
|
|
int slope { 0 };
|
2019-10-18 23:02:10 +02:00
|
|
|
|
2022-04-01 20:58:27 +03:00
|
|
|
bool operator==(FontSelector const& other) const
|
2019-10-18 23:02:10 +02:00
|
|
|
{
|
2022-03-26 23:55:11 +01:00
|
|
|
return family == other.family && point_size == other.point_size && weight == other.weight && slope == other.slope;
|
2019-10-18 23:02:10 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
namespace AK {
|
|
|
|
template<>
|
|
|
|
struct Traits<FontSelector> : public GenericTraits<FontSelector> {
|
2022-04-01 20:58:27 +03:00
|
|
|
static unsigned hash(FontSelector const& key) { return pair_int_hash(pair_int_hash(key.family.hash(), key.weight), key.point_size); }
|
2019-10-18 23:02:10 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
class FontCache {
|
|
|
|
public:
|
|
|
|
static FontCache& the();
|
2022-04-01 20:58:27 +03:00
|
|
|
RefPtr<Gfx::Font> get(FontSelector const&) const;
|
|
|
|
void set(FontSelector const&, NonnullRefPtr<Gfx::Font>);
|
2019-10-18 23:02:10 +02:00
|
|
|
|
|
|
|
private:
|
2022-03-14 13:21:51 -06:00
|
|
|
FontCache() = default;
|
2020-02-06 11:56:38 +01:00
|
|
|
mutable HashMap<FontSelector, NonnullRefPtr<Gfx::Font>> m_fonts;
|
2019-10-18 23:02:10 +02:00
|
|
|
};
|