1
0
mirror of https://github.com/SerenityOS/serenity synced 2024-07-09 14:50:45 +00:00

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))
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
{
return header().units_per_em;
return m_data.units_per_em;
}
i16 Head::xmin() const
{
return header().x_min;
return m_data.x_min;
}
i16 Head::ymin() const
{
return header().y_min;
return m_data.y_min;
}
i16 Head::xmax() const
{
return header().x_max;
return m_data.x_max;
}
i16 Head::ymax() const
{
return header().y_max;
return m_data.y_max;
}
u16 Head::style() const
{
return header().mac_style;
return m_data.mac_style;
}
u16 Head::lowest_recommended_ppem() const
{
return header().lowest_rec_ppem;
return m_data.lowest_rec_ppem;
}
IndexToLocFormat Head::index_to_loc_format() const
{
switch (header().index_to_loc_format) {
switch (m_data.index_to_loc_format) {
case 0:
return IndexToLocFormat::Offset16;
case 1:

View File

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