LibGfx: Provide accessors to instruction data to OpenType::Font

These probably won't need to stick around forever, but will be helpful
for creating some debug utilities.
This commit is contained in:
MacDue 2023-01-10 20:59:58 +00:00 committed by Andreas Kling
parent 4e5dc169a6
commit 768dc4cda1
Notes: sideshowbarker 2024-07-18 00:41:35 +09:00
4 changed files with 34 additions and 0 deletions

View file

@ -703,4 +703,25 @@ bool OS2::use_typographic_metrics() const
return header().fs_selection & 0x80;
}
Optional<ReadonlyBytes> Font::font_program() const
{
if (m_fpgm.has_value())
return m_fpgm->program_data();
return {};
}
Optional<ReadonlyBytes> Font::control_value_program() const
{
if (m_prep.has_value())
return m_prep->program_data();
return {};
}
Optional<ReadonlyBytes> 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();
}
}

View file

@ -38,6 +38,10 @@ public:
virtual u8 slope() const override;
virtual bool is_fixed_width() const override;
Optional<ReadonlyBytes> font_program() const;
Optional<ReadonlyBytes> control_value_program() const;
Optional<ReadonlyBytes> glyph_program(u32 glyph_id) const;
private:
enum class Offsets {
NumTables = 4,

View file

@ -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.

View file

@ -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,