Truly independent web browser
/*
* Copyright (c) 2018-2020, Andreas Kling <[email protected]>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/FlyString.h>
#include <AK/Function.h>
#include <AK/HashFunctions.h>
#include <AK/OwnPtr.h>
#include <AK/RefPtr.h>
#include <AK/kmalloc.h>
#include <LibGfx/Font/Typeface.h>
#include <LibGfx/Forward.h>
namespace Gfx {
class SystemFontProvider {
public:
virtual ~SystemFontProvider();
virtual RefPtr<Gfx::Font> get_font(FlyString const& family, float point_size, unsigned weight, unsigned width, unsigned slope, Optional<FontVariationSettings> const& font_variation_settings = {}, Optional<Gfx::ShapeFeatures> const& shape_features = {}) = 0;
virtual void for_each_typeface_with_family_name(FlyString const& family_name, Function<void(Typeface const&)>) = 0;
virtual RefPtr<Typeface> get_typeface_by_id(u64 generation, u64 face_id);
virtual RefPtr<Typeface> get_typeface_by_local_name(String const&);
virtual RefPtr<Gfx::Font> get_font_for_code_point(u32 code_point, float point_size, u16 weight, u16 width, u8 slope, bool prefer_color_emoji);
virtual Optional<FlyString> resolve_generic_family(StringView family_name, u16 weight, u8 slope);
};
class FontDatabase {
public:
AK_ALLOC_WITH_KMALLOC;
static FontDatabase& the();
SystemFontProvider& install_system_font_provider(NonnullOwnPtr<SystemFontProvider>);
RefPtr<Gfx::Font> get(FlyString const& family, float point_size, unsigned weight, unsigned width, unsigned slope, Optional<FontVariationSettings> const& font_variation_settings = {}, Optional<Gfx::ShapeFeatures> const& shape_features = {});
RefPtr<Gfx::Font> get_font_for_code_point(u32 code_point, float point_size, u16 weight, u16 width, u8 slope, bool prefer_color_emoji);
RefPtr<Typeface> get_typeface_by_id(u64 generation, u64 face_id);
RefPtr<Typeface> get_typeface_by_local_name(String const&);
Optional<FlyString> resolve_generic_family(StringView family_name, u16 weight, u8 slope);
void for_each_typeface_with_family_name(FlyString const& family_name, Function<void(Typeface const&)>);
[[nodiscard]] bool has_system_font_provider() const { return m_system_font_provider; }
static ErrorOr<Vector<String>> font_directories();
private:
FontDatabase();
~FontDatabase() = default;
OwnPtr<SystemFontProvider> m_system_font_provider;
};
}