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