summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2022-12-20 13:35:47 +0100
committerAndreas Kling <kling@serenityos.org>2022-12-21 08:44:22 +0100
commitabad1978848c425d51922d53697d1a737c4d1a03 (patch)
tree5fb3055ff23d1d1fc1e91f3d982588a4864d5ae4
parent2185a98b3669fa1c43f9da9c613e7f90cb5739e6 (diff)
downloadserenity-abad1978848c425d51922d53697d1a737c4d1a03.zip
LibGfx/OpenType: Read "glyf" table header using a C++ struct
-rw-r--r--Userland/Libraries/LibGfx/Font/OpenType/Glyf.cpp15
-rw-r--r--Userland/Libraries/LibGfx/Font/OpenType/Glyf.h15
2 files changed, 15 insertions, 15 deletions
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<Gfx::Bitmap> 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<GlyphHeader const*>(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<i16> number_of_contours;
+ BigEndian<i16> x_min;
+ BigEndian<i16> y_min;
+ BigEndian<i16> x_max;
+ BigEndian<i16> y_max;
};
ReadonlyBytes m_slice;