From f04a878e557642cde8f853e2e2d90ef45ab1a261 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 19 Dec 2022 13:54:16 +0100 Subject: [PATCH] LibGfx/OpenType: Read "maxp" table using a C++ struct --- .../Libraries/LibGfx/Font/OpenType/Font.cpp | 4 +-- .../Libraries/LibGfx/Font/OpenType/Tables.h | 32 ++++++++++++++++--- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/Userland/Libraries/LibGfx/Font/OpenType/Font.cpp b/Userland/Libraries/LibGfx/Font/OpenType/Font.cpp index 4a67a39ba2..807aae833f 100644 --- a/Userland/Libraries/LibGfx/Font/OpenType/Font.cpp +++ b/Userland/Libraries/LibGfx/Font/OpenType/Font.cpp @@ -140,7 +140,7 @@ u16 Hhea::number_of_h_metrics() const Optional Maxp::from_slice(ReadonlyBytes slice) { - if (slice.size() < (size_t)Sizes::TableV0p5) { + if (slice.size() < sizeof(MaximumProfileVersion0_5)) { return {}; } return Maxp(slice); @@ -148,7 +148,7 @@ Optional Maxp::from_slice(ReadonlyBytes slice) u16 Maxp::num_glyphs() const { - return be_u16(m_slice.offset_pointer((u32)Offsets::NumGlyphs)); + return header().num_glyphs; } Optional Hmtx::from_slice(ReadonlyBytes slice, u32 num_glyphs, u32 number_of_h_metrics) diff --git a/Userland/Libraries/LibGfx/Font/OpenType/Tables.h b/Userland/Libraries/LibGfx/Font/OpenType/Tables.h index 4f83da55c2..728d1856f5 100644 --- a/Userland/Libraries/LibGfx/Font/OpenType/Tables.h +++ b/Userland/Libraries/LibGfx/Font/OpenType/Tables.h @@ -28,6 +28,11 @@ struct LongDateTime { BigEndian value; }; +struct Version16Dot16 { + BigEndian major; + BigEndian minor; +}; + using FWord = BigEndian; using UFWord = BigEndian; @@ -122,16 +127,35 @@ private: class Maxp { public: static Optional from_slice(ReadonlyBytes); + u16 num_glyphs() const; private: - enum class Offsets { - NumGlyphs = 4 + struct MaximumProfileVersion0_5 { + Version16Dot16 version; + BigEndian num_glyphs; }; - enum class Sizes { - TableV0p5 = 6, + + struct MaximumProfileVersion1_0 { + Version16Dot16 version; + BigEndian num_glyphs; + BigEndian max_points; + BigEndian max_contours; + BigEndian max_composite_points; + BigEndian max_composite_contours; + BigEndian max_zones; + BigEndian max_twilight_points; + BigEndian max_storage; + BigEndian max_function_defs; + BigEndian max_instruction_defs; + BigEndian max_stack_elements; + BigEndian max_size_of_instructions; + BigEndian max_component_elements; + BigEndian max_component_depths; }; + MaximumProfileVersion0_5 const& header() const { return *bit_cast(m_slice.data()); } + Maxp(ReadonlyBytes slice) : m_slice(slice) {