diff --git a/Libraries/LibTTF/Cmap.cpp b/Libraries/LibTTF/Cmap.cpp index 7fb6deda64..ce651e5385 100644 --- a/Libraries/LibTTF/Cmap.cpp +++ b/Libraries/LibTTF/Cmap.cpp @@ -90,7 +90,7 @@ Optional Cmap::subtable(u32 index) const u16 encoding_id = be_u16(m_slice.offset_pointer(record_offset + (u32)Offsets::EncodingRecord_EncodingID)); u32 subtable_offset = be_u32(m_slice.offset_pointer(record_offset + (u32)Offsets::EncodingRecord_Offset)); ASSERT(subtable_offset < m_slice.size()); - auto subtable_slice = ByteBuffer::copy(m_slice.offset_pointer(subtable_offset), m_slice.size() - subtable_offset); + auto subtable_slice = ReadonlyBytes(m_slice.offset_pointer(subtable_offset), m_slice.size() - subtable_offset); return Subtable(subtable_slice, platform_id, encoding_id); } @@ -163,7 +163,7 @@ u32 Cmap::glyph_id_for_codepoint(u32 codepoint) const return subtable.glyph_id_for_codepoint(codepoint); } -Optional Cmap::from_slice(const ByteBuffer& slice) +Optional Cmap::from_slice(const ReadonlyBytes& slice) { if (slice.size() < (size_t)Sizes::TableHeader) { return {}; diff --git a/Libraries/LibTTF/Cmap.h b/Libraries/LibTTF/Cmap.h index 4ba4a5c4b4..2133a72f91 100644 --- a/Libraries/LibTTF/Cmap.h +++ b/Libraries/LibTTF/Cmap.h @@ -26,7 +26,7 @@ #pragma once -#include +#include namespace TTF { @@ -56,7 +56,7 @@ public: UnicodeFullRepertoire = 10, }; - Subtable(const ByteBuffer& slice, u16 platform_id, u16 encoding_id) + Subtable(const ReadonlyBytes& slice, u16 platform_id, u16 encoding_id) : m_slice(slice) , m_raw_platform_id(platform_id) , m_encoding_id(encoding_id) @@ -95,12 +95,12 @@ public: u32 glyph_id_for_codepoint_table_4(u32 codepoint) const; u32 glyph_id_for_codepoint_table_12(u32 codepoint) const; - ByteBuffer m_slice; + ReadonlyBytes m_slice; u16 m_raw_platform_id { 0 }; u16 m_encoding_id { 0 }; }; - static Optional from_slice(const ByteBuffer&); + static Optional from_slice(const ReadonlyBytes&); u32 num_subtables() const; Optional subtable(u32 index) const; void set_active_index(u32 index) { m_active_index = index; } @@ -118,12 +118,12 @@ private: EncodingRecord = 8, }; - Cmap(const ByteBuffer& slice) + Cmap(const ReadonlyBytes& slice) : m_slice(slice) { } - ByteBuffer m_slice; + ReadonlyBytes m_slice; u32 m_active_index { UINT32_MAX }; }; diff --git a/Libraries/LibTTF/Font.cpp b/Libraries/LibTTF/Font.cpp index 5a1bde6145..9681e953b8 100644 --- a/Libraries/LibTTF/Font.cpp +++ b/Libraries/LibTTF/Font.cpp @@ -69,7 +69,7 @@ u32 tag_from_str(const char* str) return be_u32((const u8*)str); } -Optional Head::from_slice(const ByteBuffer& slice) +Optional Head::from_slice(const ReadonlyBytes& slice) { if (slice.size() < (size_t)Sizes::Table) { return {}; @@ -120,7 +120,7 @@ IndexToLocFormat Head::index_to_loc_format() const } } -Optional Hhea::from_slice(const ByteBuffer& slice) +Optional Hhea::from_slice(const ReadonlyBytes& slice) { if (slice.size() < (size_t)Sizes::Table) { return {}; @@ -153,7 +153,7 @@ u16 Hhea::number_of_h_metrics() const return be_u16(m_slice.offset_pointer((u32)Offsets::NumberOfHMetrics)); } -Optional Maxp::from_slice(const ByteBuffer& slice) +Optional Maxp::from_slice(const ReadonlyBytes& slice) { if (slice.size() < (size_t)Sizes::TableV0p5) { return {}; @@ -166,7 +166,7 @@ u16 Maxp::num_glyphs() const return be_u16(m_slice.offset_pointer((u32)Offsets::NumGlyphs)); } -Optional Hmtx::from_slice(const ByteBuffer& slice, u32 num_glyphs, u32 number_of_h_metrics) +Optional Hmtx::from_slice(const ReadonlyBytes& slice, u32 num_glyphs, u32 number_of_h_metrics) { if (slice.size() < number_of_h_metrics * (u32)Sizes::LongHorMetric + (num_glyphs - number_of_h_metrics) * (u32)Sizes::LeftSideBearing) { return {}; @@ -241,13 +241,13 @@ RefPtr Font::load_from_offset(ByteBuffer&& buffer, u32 offset) return nullptr; } - Optional opt_head_slice = {}; - Optional opt_hhea_slice = {}; - Optional opt_maxp_slice = {}; - Optional opt_hmtx_slice = {}; - Optional opt_cmap_slice = {}; - Optional opt_loca_slice = {}; - Optional opt_glyf_slice = {}; + Optional opt_head_slice = {}; + Optional opt_hhea_slice = {}; + Optional opt_maxp_slice = {}; + Optional opt_hmtx_slice = {}; + Optional opt_cmap_slice = {}; + Optional opt_loca_slice = {}; + Optional opt_glyf_slice = {}; Optional opt_head = {}; Optional opt_hhea = {}; @@ -271,7 +271,7 @@ RefPtr Font::load_from_offset(ByteBuffer&& buffer, u32 offset) dbg() << "Font file too small"; return nullptr; } - auto buffer_here = ByteBuffer::copy(buffer.offset_pointer(table_offset), table_length); + auto buffer_here = ReadonlyBytes(buffer.offset_pointer(table_offset), table_length); // Get the table offsets we need. if (tag == tag_from_str("head")) { diff --git a/Libraries/LibTTF/Glyf.cpp b/Libraries/LibTTF/Glyf.cpp index 381fbff152..f74502a69a 100644 --- a/Libraries/LibTTF/Glyf.cpp +++ b/Libraries/LibTTF/Glyf.cpp @@ -76,7 +76,7 @@ public: Gfx::FloatPoint point; }; - PointIterator(const ByteBuffer& slice, u16 num_points, u32 flags_offset, u32 x_offset, u32 y_offset, Gfx::AffineTransform affine) + PointIterator(const ReadonlyBytes& slice, u16 num_points, u32 flags_offset, u32 x_offset, u32 y_offset, Gfx::AffineTransform affine) : m_slice(slice) , m_points_remaining(num_points) , m_flags_offset(flags_offset) @@ -136,7 +136,7 @@ public: } private: - ByteBuffer m_slice; + ReadonlyBytes m_slice; u16 m_points_remaining; u8 m_flag { 0 }; Gfx::FloatPoint m_last_point = { 0.0f, 0.0f }; @@ -337,7 +337,7 @@ void Rasterizer::draw_line(Gfx::FloatPoint p0, Gfx::FloatPoint p1) } } -Optional Loca::from_slice(const ByteBuffer& slice, u32 num_glyphs, IndexToLocFormat index_to_loc_format) +Optional Loca::from_slice(const ReadonlyBytes& slice, u32 num_glyphs, IndexToLocFormat index_to_loc_format) { switch (index_to_loc_format) { case IndexToLocFormat::Offset16: @@ -367,7 +367,7 @@ u32 Loca::get_glyph_offset(u32 glyph_id) const } } -static void get_ttglyph_offsets(const ByteBuffer& slice, u32 num_points, u32 flags_offset, u32* x_offset, u32* y_offset) +static void get_ttglyph_offsets(const ReadonlyBytes& slice, u32 num_points, u32 flags_offset, u32* x_offset, u32* y_offset) { u32 flags_size = 0; u32 x_size = 0; @@ -512,7 +512,7 @@ Glyf::Glyph Glyf::glyph(u32 offset) const 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 = ByteBuffer::copy(m_slice.offset_pointer(offset + (u32)Sizes::GlyphHeader), m_slice.size() - offset - (u32)Sizes::GlyphHeader); + auto slice = ReadonlyBytes(m_slice.offset_pointer(offset + (u32)Sizes::GlyphHeader), m_slice.size() - offset - (u32)Sizes::GlyphHeader); return Glyph(slice, xmin, ymin, xmax, ymax, num_contours); } diff --git a/Libraries/LibTTF/Glyf.h b/Libraries/LibTTF/Glyf.h index d0246b6aec..c7beb43644 100644 --- a/Libraries/LibTTF/Glyf.h +++ b/Libraries/LibTTF/Glyf.h @@ -26,7 +26,7 @@ #pragma once -#include +#include #include #include #include @@ -50,18 +50,18 @@ private: class Loca { public: - static Optional from_slice(const ByteBuffer&, u32 num_glyphs, IndexToLocFormat); + static Optional from_slice(const ReadonlyBytes&, u32 num_glyphs, IndexToLocFormat); u32 get_glyph_offset(u32 glyph_id) const; private: - Loca(const ByteBuffer& slice, u32 num_glyphs, IndexToLocFormat index_to_loc_format) + Loca(const ReadonlyBytes& slice, u32 num_glyphs, IndexToLocFormat index_to_loc_format) : m_slice(slice) , m_num_glyphs(num_glyphs) , m_index_to_loc_format(index_to_loc_format) { } - ByteBuffer m_slice; + ReadonlyBytes m_slice; u32 m_num_glyphs { 0 }; IndexToLocFormat m_index_to_loc_format; }; @@ -70,7 +70,7 @@ class Glyf { public: class Glyph { public: - Glyph(const ByteBuffer& slice, i16 xmin, i16 ymin, i16 xmax, i16 ymax, i16 num_contours = -1) + Glyph(const ReadonlyBytes& slice, i16 xmin, i16 ymin, i16 xmax, i16 ymax, i16 num_contours = -1) : m_xmin(xmin) , m_ymin(ymin) , m_xmax(xmax) @@ -109,14 +109,14 @@ public: Gfx::AffineTransform affine; }; - ComponentIterator(const ByteBuffer& slice) + ComponentIterator(const ReadonlyBytes& slice) : m_slice(slice) { } Optional next(); private: - ByteBuffer m_slice; + ReadonlyBytes m_slice; bool m_has_more { true }; u32 m_offset { 0 }; }; @@ -150,10 +150,10 @@ public: i16 m_xmax { 0 }; i16 m_ymax { 0 }; i16 m_num_contours { -1 }; - ByteBuffer m_slice; + ReadonlyBytes m_slice; }; - Glyf(const ByteBuffer& slice) + Glyf(const ReadonlyBytes& slice) : m_slice(slice) { } @@ -170,7 +170,7 @@ private: GlyphHeader = 10, }; - ByteBuffer m_slice; + ReadonlyBytes m_slice; }; } diff --git a/Libraries/LibTTF/Tables.h b/Libraries/LibTTF/Tables.h index b792136bd2..5264911ad9 100644 --- a/Libraries/LibTTF/Tables.h +++ b/Libraries/LibTTF/Tables.h @@ -26,7 +26,7 @@ #pragma once -#include +#include namespace TTF { @@ -37,7 +37,7 @@ enum class IndexToLocFormat { class Head { public: - static Optional from_slice(const ByteBuffer&); + static Optional from_slice(const ReadonlyBytes&); u16 units_per_em() const; i16 xmin() const; i16 ymin() const; @@ -60,17 +60,17 @@ private: Table = 54, }; - Head(const ByteBuffer& slice) + Head(const ReadonlyBytes& slice) : m_slice(slice) { } - ByteBuffer m_slice; + ReadonlyBytes m_slice; }; class Hhea { public: - static Optional from_slice(const ByteBuffer&); + static Optional from_slice(const ReadonlyBytes&); i16 ascender() const; i16 descender() const; i16 line_gap() const; @@ -89,17 +89,17 @@ private: Table = 36, }; - Hhea(const ByteBuffer& slice) + Hhea(const ReadonlyBytes& slice) : m_slice(slice) { } - ByteBuffer m_slice; + ReadonlyBytes m_slice; }; class Maxp { public: - static Optional from_slice(const ByteBuffer&); + static Optional from_slice(const ReadonlyBytes&); u16 num_glyphs() const; private: @@ -110,12 +110,12 @@ private: TableV0p5 = 6, }; - Maxp(const ByteBuffer& slice) + Maxp(const ReadonlyBytes& slice) : m_slice(slice) { } - ByteBuffer m_slice; + ReadonlyBytes m_slice; }; struct GlyphHorizontalMetrics { @@ -125,7 +125,7 @@ struct GlyphHorizontalMetrics { class Hmtx { public: - static Optional from_slice(const ByteBuffer&, u32 num_glyphs, u32 number_of_h_metrics); + static Optional from_slice(const ReadonlyBytes&, u32 num_glyphs, u32 number_of_h_metrics); GlyphHorizontalMetrics get_glyph_horizontal_metrics(u32 glyph_id) const; private: @@ -134,14 +134,14 @@ private: LeftSideBearing = 2 }; - Hmtx(const ByteBuffer& slice, u32 num_glyphs, u32 number_of_h_metrics) + Hmtx(const ReadonlyBytes& slice, u32 num_glyphs, u32 number_of_h_metrics) : m_slice(slice) , m_num_glyphs(num_glyphs) , m_number_of_h_metrics(number_of_h_metrics) { } - ByteBuffer m_slice; + ReadonlyBytes m_slice; u32 m_num_glyphs { 0 }; u32 m_number_of_h_metrics { 0 }; };