mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:27:45 +00:00
LibGfx/OpenType: Read "hhea" table using a C++ struct
This commit is contained in:
parent
61be11960b
commit
d201acf102
2 changed files with 27 additions and 15 deletions
|
@ -107,7 +107,7 @@ IndexToLocFormat Head::index_to_loc_format() const
|
||||||
|
|
||||||
Optional<Hhea> Hhea::from_slice(ReadonlyBytes slice)
|
Optional<Hhea> Hhea::from_slice(ReadonlyBytes slice)
|
||||||
{
|
{
|
||||||
if (slice.size() < (size_t)Sizes::Table) {
|
if (slice.size() < sizeof(HorizontalHeaderTable)) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
return Hhea(slice);
|
return Hhea(slice);
|
||||||
|
@ -115,27 +115,27 @@ Optional<Hhea> Hhea::from_slice(ReadonlyBytes slice)
|
||||||
|
|
||||||
i16 Hhea::ascender() const
|
i16 Hhea::ascender() const
|
||||||
{
|
{
|
||||||
return be_i16(m_slice.offset_pointer((u32)Offsets::Ascender));
|
return header().ascender;
|
||||||
}
|
}
|
||||||
|
|
||||||
i16 Hhea::descender() const
|
i16 Hhea::descender() const
|
||||||
{
|
{
|
||||||
return be_i16(m_slice.offset_pointer((u32)Offsets::Descender));
|
return header().descender;
|
||||||
}
|
}
|
||||||
|
|
||||||
i16 Hhea::line_gap() const
|
i16 Hhea::line_gap() const
|
||||||
{
|
{
|
||||||
return be_i16(m_slice.offset_pointer((u32)Offsets::LineGap));
|
return header().line_gap;
|
||||||
}
|
}
|
||||||
|
|
||||||
u16 Hhea::advance_width_max() const
|
u16 Hhea::advance_width_max() const
|
||||||
{
|
{
|
||||||
return be_u16(m_slice.offset_pointer((u32)Offsets::AdvanceWidthMax));
|
return header().advance_width_max;
|
||||||
}
|
}
|
||||||
|
|
||||||
u16 Hhea::number_of_h_metrics() const
|
u16 Hhea::number_of_h_metrics() const
|
||||||
{
|
{
|
||||||
return be_u16(m_slice.offset_pointer((u32)Offsets::NumberOfHMetrics));
|
return header().number_of_h_metrics;
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<Maxp> Maxp::from_slice(ReadonlyBytes slice)
|
Optional<Maxp> Maxp::from_slice(ReadonlyBytes slice)
|
||||||
|
|
|
@ -28,6 +28,9 @@ struct LongDateTime {
|
||||||
BigEndian<u64> value;
|
BigEndian<u64> value;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
using FWord = BigEndian<i16>;
|
||||||
|
using UFWord = BigEndian<u16>;
|
||||||
|
|
||||||
// https://learn.microsoft.com/en-us/typography/opentype/spec/head
|
// https://learn.microsoft.com/en-us/typography/opentype/spec/head
|
||||||
// head: Font Header Table
|
// head: Font Header Table
|
||||||
class Head {
|
class Head {
|
||||||
|
@ -86,17 +89,26 @@ public:
|
||||||
u16 number_of_h_metrics() const;
|
u16 number_of_h_metrics() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum class Offsets {
|
struct HorizontalHeaderTable {
|
||||||
Ascender = 4,
|
BigEndian<u16> major_version;
|
||||||
Descender = 6,
|
BigEndian<u16> minor_version;
|
||||||
LineGap = 8,
|
FWord ascender;
|
||||||
AdvanceWidthMax = 10,
|
FWord descender;
|
||||||
NumberOfHMetrics = 34,
|
FWord line_gap;
|
||||||
};
|
UFWord advance_width_max;
|
||||||
enum class Sizes {
|
FWord min_left_side_bearing;
|
||||||
Table = 36,
|
FWord min_right_side_bearing;
|
||||||
|
FWord x_max_extent;
|
||||||
|
BigEndian<i16> caret_slope_rise;
|
||||||
|
BigEndian<i16> caret_slope_run;
|
||||||
|
BigEndian<i16> caret_offset;
|
||||||
|
BigEndian<i16> reserved[4];
|
||||||
|
BigEndian<i16> metric_data_format;
|
||||||
|
BigEndian<u16> number_of_h_metrics;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
HorizontalHeaderTable const& header() const { return *bit_cast<HorizontalHeaderTable const*>(m_slice.data()); }
|
||||||
|
|
||||||
Hhea(ReadonlyBytes slice)
|
Hhea(ReadonlyBytes slice)
|
||||||
: m_slice(slice)
|
: m_slice(slice)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue