diff --git a/Userland/Libraries/LibGfx/Font/OpenType/Glyf.cpp b/Userland/Libraries/LibGfx/Font/OpenType/Glyf.cpp index 85aba856f1..3e8e8e7197 100644 --- a/Userland/Libraries/LibGfx/Font/OpenType/Glyf.cpp +++ b/Userland/Libraries/LibGfx/Font/OpenType/Glyf.cpp @@ -358,13 +358,14 @@ RefPtr Glyf::Glyph::rasterize_simple(i16 font_ascender, i16 font_de Glyf::Glyph Glyf::glyph(u32 offset) const { - VERIFY(m_slice.size() >= offset + (u32)Sizes::GlyphHeader); - i16 num_contours = be_i16(m_slice.offset_pointer(offset)); - i16 xmin = be_i16(m_slice.offset_pointer(offset + (u32)Offsets::XMin)); - i16 ymin = be_i16(m_slice.offset_pointer(offset + (u32)Offsets::YMin)); - i16 xmax = be_i16(m_slice.offset_pointer(offset + (u32)Offsets::XMax)); - i16 ymax = be_i16(m_slice.offset_pointer(offset + (u32)Offsets::YMax)); - auto slice = ReadonlyBytes(m_slice.offset_pointer(offset + (u32)Sizes::GlyphHeader), m_slice.size() - offset - (u32)Sizes::GlyphHeader); + VERIFY(m_slice.size() >= offset + sizeof(GlyphHeader)); + auto const& glyph_header = *bit_cast(m_slice.offset_pointer(offset)); + i16 num_contours = glyph_header.number_of_contours; + i16 xmin = glyph_header.x_min; + i16 ymin = glyph_header.y_min; + i16 xmax = glyph_header.x_max; + i16 ymax = glyph_header.y_max; + auto slice = m_slice.slice(offset + sizeof(GlyphHeader)); return Glyph(slice, xmin, ymin, xmax, ymax, num_contours); } diff --git a/Userland/Libraries/LibGfx/Font/OpenType/Glyf.h b/Userland/Libraries/LibGfx/Font/OpenType/Glyf.h index 80dbebb805..b487534cc8 100644 --- a/Userland/Libraries/LibGfx/Font/OpenType/Glyf.h +++ b/Userland/Libraries/LibGfx/Font/OpenType/Glyf.h @@ -148,14 +148,13 @@ public: Glyph glyph(u32 offset) const; private: - enum class Offsets { - XMin = 2, - YMin = 4, - XMax = 6, - YMax = 8, - }; - enum class Sizes { - GlyphHeader = 10, + // https://learn.microsoft.com/en-us/typography/opentype/spec/glyf#glyph-headers + struct GlyphHeader { + BigEndian number_of_contours; + BigEndian x_min; + BigEndian y_min; + BigEndian x_max; + BigEndian y_max; }; ReadonlyBytes m_slice;