1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-29 04:07:34 +00:00

LibGfx/OpenType: Read "glyf" table header using a C++ struct

This commit is contained in:
Andreas Kling 2022-12-20 13:35:47 +01:00
parent 2185a98b36
commit abad197884
2 changed files with 15 additions and 15 deletions

View file

@ -358,13 +358,14 @@ RefPtr<Gfx::Bitmap> Glyf::Glyph::rasterize_simple(i16 font_ascender, i16 font_de
Glyf::Glyph Glyf::glyph(u32 offset) const Glyf::Glyph Glyf::glyph(u32 offset) const
{ {
VERIFY(m_slice.size() >= offset + (u32)Sizes::GlyphHeader); VERIFY(m_slice.size() >= offset + sizeof(GlyphHeader));
i16 num_contours = be_i16(m_slice.offset_pointer(offset)); auto const& glyph_header = *bit_cast<GlyphHeader const*>(m_slice.offset_pointer(offset));
i16 xmin = be_i16(m_slice.offset_pointer(offset + (u32)Offsets::XMin)); i16 num_contours = glyph_header.number_of_contours;
i16 ymin = be_i16(m_slice.offset_pointer(offset + (u32)Offsets::YMin)); i16 xmin = glyph_header.x_min;
i16 xmax = be_i16(m_slice.offset_pointer(offset + (u32)Offsets::XMax)); i16 ymin = glyph_header.y_min;
i16 ymax = be_i16(m_slice.offset_pointer(offset + (u32)Offsets::YMax)); i16 xmax = glyph_header.x_max;
auto slice = ReadonlyBytes(m_slice.offset_pointer(offset + (u32)Sizes::GlyphHeader), m_slice.size() - offset - (u32)Sizes::GlyphHeader); i16 ymax = glyph_header.y_max;
auto slice = m_slice.slice(offset + sizeof(GlyphHeader));
return Glyph(slice, xmin, ymin, xmax, ymax, num_contours); return Glyph(slice, xmin, ymin, xmax, ymax, num_contours);
} }

View file

@ -148,14 +148,13 @@ public:
Glyph glyph(u32 offset) const; Glyph glyph(u32 offset) const;
private: private:
enum class Offsets { // https://learn.microsoft.com/en-us/typography/opentype/spec/glyf#glyph-headers
XMin = 2, struct GlyphHeader {
YMin = 4, BigEndian<i16> number_of_contours;
XMax = 6, BigEndian<i16> x_min;
YMax = 8, BigEndian<i16> y_min;
}; BigEndian<i16> x_max;
enum class Sizes { BigEndian<i16> y_max;
GlyphHeader = 10,
}; };
ReadonlyBytes m_slice; ReadonlyBytes m_slice;