/* * Copyright (c) 2022, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include #include #include #include namespace Web::Platform { enum class GenericFont { Cursive, Fantasy, Monospace, SansSerif, Serif, UiMonospace, UiRounded, UiSansSerif, UiSerif, __Count, }; struct GenericFontKey { GenericFont generic_font; int weight; int slope; bool operator==(GenericFontKey const&) const = default; }; class WEB_API FontPlugin { public: FontPlugin(bool is_layout_test_mode, Gfx::SystemFontProvider* = nullptr); ~FontPlugin(); static FontPlugin& the(); static void install(FontPlugin&); RefPtr default_font(float point_size, Optional const& font_variation_settings = {}, Optional const& shape_features = {}); Gfx::Font& default_fixed_width_font(); FlyString generic_font_name(GenericFont, int weight, int slope); Vector symbol_font_names(); bool is_layout_test_mode() const { return m_is_layout_test_mode; } void update_generic_fonts(); private: FlyString compute_generic_font_name(GenericFont, int weight, int slope); Vector> m_generic_font_fallbacks; HashMap m_generic_font_cache; Vector m_symbol_font_names; RefPtr m_default_fixed_width_font; bool m_is_layout_test_mode { false }; }; } template<> struct AK::Traits : public AK::DefaultTraits { static unsigned hash(Web::Platform::GenericFontKey const& key) { return pair_int_hash(pair_int_hash(to_underlying(key.generic_font), key.weight), key.slope); } };