ladybird/Userland/Libraries/LibGfx/FontCascadeList.h
Aliaksandr Kalenik 2cb0039a13 LibGfx+LibWeb: Produce font cascade list in CSS font matching algorithm
According to the CSS font matching algorithm specification, it is
supposed to be executed for each glyph instead of each text run, as is
currently done. This change partially implements this by having the
font matching algorithm produce a list of fonts against which each
glyph will be tested to find its suitable font.

Now, it becomes possible to have per-glyph fallback fonts: if the
needed glyph is not present in a font, we can check the subsequent
fonts in the list.
2023-12-10 17:32:04 +01:00

44 lines
1.0 KiB
C++

/*
* Copyright (c) 2023, Aliaksandr Kalenik <kalenik.aliaksandr@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibGfx/Font/Font.h>
#include <LibGfx/Font/UnicodeRange.h>
namespace Gfx {
class FontCascadeList : public RefCounted<FontCascadeList> {
public:
static NonnullRefPtr<FontCascadeList> create()
{
return adopt_ref(*new FontCascadeList());
}
size_t size() const { return m_fonts.size(); }
bool is_empty() const { return m_fonts.is_empty(); }
Font const& first() const { return *m_fonts.first().font; }
void add(NonnullRefPtr<Font> font);
void add(NonnullRefPtr<Font> font, Vector<UnicodeRange> unicode_ranges);
void extend(FontCascadeList const& other);
Gfx::Font const& font_for_code_point(u32 code_point) const;
bool equals(FontCascadeList const& other) const;
struct Entry {
NonnullRefPtr<Font> font;
Optional<Vector<UnicodeRange>> unicode_ranges;
};
private:
Vector<Entry> m_fonts;
};
}