From dcbe302f8376c8e16f16cfc63a94fa22660797f7 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Thu, 26 Oct 2023 16:01:29 +0100 Subject: [PATCH] LibGfx: Remove bit casting in OpenType Head table after construction --- .../Libraries/LibGfx/Font/OpenType/Tables.cpp | 19 ++++++++++--------- .../Libraries/LibGfx/Font/OpenType/Tables.h | 8 +++----- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/Userland/Libraries/LibGfx/Font/OpenType/Tables.cpp b/Userland/Libraries/LibGfx/Font/OpenType/Tables.cpp index 8547072686..89e2351bc2 100644 --- a/Userland/Libraries/LibGfx/Font/OpenType/Tables.cpp +++ b/Userland/Libraries/LibGfx/Font/OpenType/Tables.cpp @@ -31,47 +31,48 @@ ErrorOr 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(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: diff --git a/Userland/Libraries/LibGfx/Font/OpenType/Tables.h b/Userland/Libraries/LibGfx/Font/OpenType/Tables.h index c49108db95..bf5073b4a2 100644 --- a/Userland/Libraries/LibGfx/Font/OpenType/Tables.h +++ b/Userland/Libraries/LibGfx/Font/OpenType/Tables.h @@ -120,14 +120,12 @@ private: }; static_assert(AssertSize()); - FontHeaderTable const& header() const { return *bit_cast(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