LibGfx: Remove bit casting in OpenType Head table after construction

This commit is contained in:
Sam Atkins 2023-10-26 16:01:29 +01:00 committed by Andreas Kling
parent 72483673d2
commit dcbe302f83
2 changed files with 13 additions and 14 deletions

View file

@ -31,47 +31,48 @@ ErrorOr<Head> Head::from_slice(ReadonlyBytes slice)
if (slice.size() < sizeof(FontHeaderTable)) if (slice.size() < sizeof(FontHeaderTable))
return Error::from_string_literal("Could not load Head: Not enough data"); return Error::from_string_literal("Could not load Head: Not enough data");
return Head(slice); auto const& font_header_table = *bit_cast<FontHeaderTable const*>(slice.data());
return Head(font_header_table);
} }
u16 Head::units_per_em() const u16 Head::units_per_em() const
{ {
return header().units_per_em; return m_data.units_per_em;
} }
i16 Head::xmin() const i16 Head::xmin() const
{ {
return header().x_min; return m_data.x_min;
} }
i16 Head::ymin() const i16 Head::ymin() const
{ {
return header().y_min; return m_data.y_min;
} }
i16 Head::xmax() const i16 Head::xmax() const
{ {
return header().x_max; return m_data.x_max;
} }
i16 Head::ymax() const i16 Head::ymax() const
{ {
return header().y_max; return m_data.y_max;
} }
u16 Head::style() const u16 Head::style() const
{ {
return header().mac_style; return m_data.mac_style;
} }
u16 Head::lowest_recommended_ppem() const u16 Head::lowest_recommended_ppem() const
{ {
return header().lowest_rec_ppem; return m_data.lowest_rec_ppem;
} }
IndexToLocFormat Head::index_to_loc_format() const IndexToLocFormat Head::index_to_loc_format() const
{ {
switch (header().index_to_loc_format) { switch (m_data.index_to_loc_format) {
case 0: case 0:
return IndexToLocFormat::Offset16; return IndexToLocFormat::Offset16;
case 1: case 1:

View file

@ -120,14 +120,12 @@ private:
}; };
static_assert(AssertSize<FontHeaderTable, 54>()); static_assert(AssertSize<FontHeaderTable, 54>());
FontHeaderTable const& header() const { return *bit_cast<FontHeaderTable const*>(m_slice.data()); } Head(FontHeaderTable const& font_header_table)
: m_data(font_header_table)
Head(ReadonlyBytes slice)
: m_slice(slice)
{ {
} }
ReadonlyBytes m_slice; FontHeaderTable const& m_data;
}; };
// https://learn.microsoft.com/en-us/typography/opentype/spec/hhea // https://learn.microsoft.com/en-us/typography/opentype/spec/hhea