LibGfx: Remove bit casting in OpenType Hhea table after construction

This commit is contained in:
Sam Atkins 2023-10-26 16:01:55 +01:00 committed by Andreas Kling
parent dcbe302f83
commit e4b3ee09e2
2 changed files with 10 additions and 11 deletions

View file

@ -87,32 +87,33 @@ ErrorOr<Hhea> Hhea::from_slice(ReadonlyBytes slice)
if (slice.size() < sizeof(HorizontalHeaderTable)) if (slice.size() < sizeof(HorizontalHeaderTable))
return Error::from_string_literal("Could not load Hhea: Not enough data"); return Error::from_string_literal("Could not load Hhea: Not enough data");
return Hhea(slice); auto const& horizontal_header_table = *bit_cast<HorizontalHeaderTable const*>(slice.data());
return Hhea(horizontal_header_table);
} }
i16 Hhea::ascender() const i16 Hhea::ascender() const
{ {
return header().ascender; return m_data.ascender;
} }
i16 Hhea::descender() const i16 Hhea::descender() const
{ {
return header().descender; return m_data.descender;
} }
i16 Hhea::line_gap() const i16 Hhea::line_gap() const
{ {
return header().line_gap; return m_data.line_gap;
} }
u16 Hhea::advance_width_max() const u16 Hhea::advance_width_max() const
{ {
return header().advance_width_max; return m_data.advance_width_max;
} }
u16 Hhea::number_of_h_metrics() const u16 Hhea::number_of_h_metrics() const
{ {
return header().number_of_h_metrics; return m_data.number_of_h_metrics;
} }
ErrorOr<Maxp> Maxp::from_slice(ReadonlyBytes slice) ErrorOr<Maxp> Maxp::from_slice(ReadonlyBytes slice)

View file

@ -159,14 +159,12 @@ private:
}; };
static_assert(AssertSize<HorizontalHeaderTable, 36>()); static_assert(AssertSize<HorizontalHeaderTable, 36>());
HorizontalHeaderTable const& header() const { return *bit_cast<HorizontalHeaderTable const*>(m_slice.data()); } Hhea(HorizontalHeaderTable const& horizontal_header_table)
: m_data(horizontal_header_table)
Hhea(ReadonlyBytes slice)
: m_slice(slice)
{ {
} }
ReadonlyBytes m_slice; HorizontalHeaderTable const& m_data;
}; };
// https://learn.microsoft.com/en-us/typography/opentype/spec/maxp // https://learn.microsoft.com/en-us/typography/opentype/spec/maxp