Truly independent web browser
/*
* Copyright (c) 2024, Andrew Kaster <[email protected]>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/FlyString.h>
#include <AK/Function.h>
#include <AK/HashMap.h>
#include <AK/HashTable.h>
#include <LibGfx/Font/FontCatalog.h>
#include <LibGfx/Font/FontDatabase.h>
#include <LibGfx/Font/Typeface.h>
namespace Gfx {
class PathFontProvider final : public SystemFontProvider {
AK_MAKE_NONCOPYABLE(PathFontProvider);
AK_MAKE_NONMOVABLE(PathFontProvider);
public:
AK_ALLOC_WITH_KMALLOC;
PathFontProvider();
virtual ~PathFontProvider() override;
void load_all_fonts_from_uri(StringView);
static void for_each_typeface_in_uri(StringView, HashTable<String>& loaded_paths, Function<void(String const& path, u32 ttc_index, FontFileFormat, NonnullRefPtr<Typeface>)>);
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 = {}) override;
virtual void for_each_typeface_with_family_name(FlyString const& family_name, Function<void(Typeface const&)>) override;
private:
HashMap<FlyString, Vector<NonnullRefPtr<Typeface>>, AK::ASCIICaseInsensitiveFlyStringTraits> m_typeface_by_family;
// Tracks files we've already loaded, to avoid mmap'ing the same .ttf/.otf/.ttc
// multiple times when overlapping font directories are walked (fontconfig commonly
// returns nested entries like /usr/share/fonts and /usr/share/fonts/truetype).
HashTable<String> m_loaded_paths;
};
}