mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-28 10:37:17 +02:00
Previously we would resolve font features (https://drafts.csswg.org/css-fonts-4/#feature-variation-precedence) per element, while this works for the current subset of the font feature resolution algorithm that we support, some as yet unimplemented parts require us to know whether we are resolving against a CSS @font-face rule, and if so which one (e.g. applying descriptors from the @font-face rule, deciding which @font-feature-values rules to apply, etc). To achieve this we store the data required to resolve font features in a struct and pass that to `FontComputer` which resolves the font features and stores them with the computed `Font`. We no longer need to invalidate the font shaping cache when features change since the features are defined per font (and therefore won't ever change).
39 lines
1.3 KiB
C++
39 lines
1.3 KiB
C++
/*
|
|
* Copyright (c) 2024, Andrew Kaster <andrew@ladybird.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/FlyString.h>
|
|
#include <AK/Function.h>
|
|
#include <AK/HashMap.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:
|
|
PathFontProvider();
|
|
virtual ~PathFontProvider() override;
|
|
|
|
void set_name_but_fixme_should_create_custom_system_font_provider(String name) { m_name = move(name); }
|
|
|
|
void load_all_fonts_from_uri(StringView);
|
|
|
|
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;
|
|
virtual StringView name() const LIFETIME_BOUND override { return m_name.bytes_as_string_view(); }
|
|
|
|
private:
|
|
HashMap<FlyString, Vector<NonnullRefPtr<Typeface>>, AK::ASCIICaseInsensitiveFlyStringTraits> m_typeface_by_family;
|
|
String m_name { "Path"_string };
|
|
};
|
|
|
|
}
|