diff --git a/Userland/Libraries/LibGfx/Font/OpenType/Font.cpp b/Userland/Libraries/LibGfx/Font/OpenType/Font.cpp index 8da71fcc67..8095721ba3 100644 --- a/Userland/Libraries/LibGfx/Font/OpenType/Font.cpp +++ b/Userland/Libraries/LibGfx/Font/OpenType/Font.cpp @@ -703,4 +703,25 @@ bool OS2::use_typographic_metrics() const return header().fs_selection & 0x80; } +Optional Font::font_program() const +{ + if (m_fpgm.has_value()) + return m_fpgm->program_data(); + return {}; +} + +Optional Font::control_value_program() const +{ + if (m_prep.has_value()) + return m_prep->program_data(); + return {}; +} + +Optional Font::glyph_program(u32 glyph_id) const +{ + auto glyph_offset = m_loca.get_glyph_offset(glyph_id); + auto glyph = m_glyf.glyph(glyph_offset); + return glyph.program(); +} + } diff --git a/Userland/Libraries/LibGfx/Font/OpenType/Font.h b/Userland/Libraries/LibGfx/Font/OpenType/Font.h index d84c7ffac2..a1e27a7789 100644 --- a/Userland/Libraries/LibGfx/Font/OpenType/Font.h +++ b/Userland/Libraries/LibGfx/Font/OpenType/Font.h @@ -38,6 +38,10 @@ public: virtual u8 slope() const override; virtual bool is_fixed_width() const override; + Optional font_program() const; + Optional control_value_program() const; + Optional glyph_program(u32 glyph_id) const; + private: enum class Offsets { NumTables = 4, diff --git a/Userland/Libraries/LibGfx/Font/OpenType/Glyf.cpp b/Userland/Libraries/LibGfx/Font/OpenType/Glyf.cpp index fc4f256462..2758add798 100644 --- a/Userland/Libraries/LibGfx/Font/OpenType/Glyf.cpp +++ b/Userland/Libraries/LibGfx/Font/OpenType/Glyf.cpp @@ -250,6 +250,13 @@ static void get_ttglyph_offsets(ReadonlyBytes slice, u32 num_points, u32 flags_o *y_offset = *x_offset + x_size; } +ReadonlyBytes Glyf::Glyph::program() const +{ + auto instructions_start = m_num_contours * 2; + u16 num_instructions = be_u16(m_slice.offset_pointer(instructions_start)); + return m_slice.slice(instructions_start + 2, num_instructions); +} + void Glyf::Glyph::rasterize_impl(Gfx::PathRasterizer& rasterizer, Gfx::AffineTransform const& transform) const { // Get offset for flags, x, and y. diff --git a/Userland/Libraries/LibGfx/Font/OpenType/Glyf.h b/Userland/Libraries/LibGfx/Font/OpenType/Glyf.h index cfb6b130ce..8ac4b53d24 100644 --- a/Userland/Libraries/LibGfx/Font/OpenType/Glyf.h +++ b/Userland/Libraries/LibGfx/Font/OpenType/Glyf.h @@ -69,6 +69,8 @@ public: int ascender() const { return m_ymax; } int descender() const { return m_ymin; } + ReadonlyBytes program() const; + private: enum class Type { Simple,