Truly independent web browser
/*
* Copyright (c) 2026-present, the Ladybird developers.
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/FlyString.h>
#include <AK/Span.h>
#include <AK/Vector.h>
#include <LibGfx/Font/FontVariationSettings.h>
struct hb_face_t;
namespace Gfx {
// The weight and the width use the scales of the OS/2 table. The slope is 0 for upright, 1 for italic and 2 for oblique.
struct FaceStyle {
u16 weight { 400 };
u16 width { 5 };
u8 slope { 0 };
bool operator==(FaceStyle const&) const = default;
};
// Vertical metrics in font units at the default coordinates, with y up.
struct FaceVerticalMetrics {
i32 ascender { 0 };
i32 descender { 0 };
i32 line_gap { 0 };
// The sxHeight of the OS/2 table, or 0 if the table does not give it.
i32 x_height { 0 };
};
// The family, the style and the vertical metrics of a face, read from its tables.
class FaceDescription {
public:
static FaceDescription read(hb_face_t*);
FlyString const& family() const { return m_family; }
FaceStyle style() const { return m_style; }
FaceVerticalMetrics const& vertical_metrics() const { return m_vertical_metrics; }
// Whether the face has a cmap subtable of the Windows symbol encoding, which marks a font of symbols rather than of
// text, even where its other subtables map letters (to ornaments, e.g.).
bool is_symbol_font() const { return m_is_symbol_font; }
// The style of the face with these variations applied.
FaceStyle style_for_variations(ReadonlySpan<FontVariationAxis>) const;
// Whether the face has a variation axis with this tag.
bool has_axis(u32 tag) const
{
return m_axes.contains([&](auto const& axis) { return axis.tag == tag; });
}
private:
struct VariationAxis {
u32 tag { 0 };
float minimum { 0 };
// The default value, or the value of the named instance that the face index selects.
float face_value { 0 };
float maximum { 0 };
};
FlyString m_family;
bool m_is_symbol_font { false };
// The style that the OS/2 and head tables give, which the axes of a variable face can change.
FaceStyle m_declared_style;
FaceStyle m_style;
FaceVerticalMetrics m_vertical_metrics;
Vector<VariationAxis> m_axes;
};
}