1
0
mirror of https://github.com/SerenityOS/serenity synced 2024-07-09 12:54:23 +00:00

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))
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
{
return header().ascender;
return m_data.ascender;
}
i16 Hhea::descender() const
{
return header().descender;
return m_data.descender;
}
i16 Hhea::line_gap() const
{
return header().line_gap;
return m_data.line_gap;
}
u16 Hhea::advance_width_max() const
{
return header().advance_width_max;
return m_data.advance_width_max;
}
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)

View File

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