From f6c40abdb191f577911629f18147f0e9dbf2fe8d Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Mon, 2 Oct 2023 16:17:15 +0100 Subject: [PATCH] LibGfx: Give GlyphBitmap its rows data as Bytes Instead of giving it a raw pointer to the start of the font's rows data and an offset, give it the Bytes for its rows only. --- Userland/Libraries/LibGfx/Font/BitmapFont.cpp | 6 ++++-- Userland/Libraries/LibGfx/Font/Font.h | 8 +++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Userland/Libraries/LibGfx/Font/BitmapFont.cpp b/Userland/Libraries/LibGfx/Font/BitmapFont.cpp index d9befa1a67..3268556f9b 100644 --- a/Userland/Libraries/LibGfx/Font/BitmapFont.cpp +++ b/Userland/Libraries/LibGfx/Font/BitmapFont.cpp @@ -260,8 +260,9 @@ Glyph BitmapFont::glyph(u32 code_point) const // character, fall back to painting '?' if necessary. auto index = glyph_index(code_point).value_or('?'); auto width = m_glyph_widths[index]; + auto glyph_byte_count = m_glyph_height * GlyphBitmap::bytes_per_row(); return Glyph( - GlyphBitmap(m_rows.data(), index * m_glyph_height, { width, m_glyph_height }), + GlyphBitmap(m_rows.slice(index * glyph_byte_count, glyph_byte_count), { width, m_glyph_height }), 0, width, m_glyph_height); @@ -270,8 +271,9 @@ Glyph BitmapFont::glyph(u32 code_point) const Glyph BitmapFont::raw_glyph(u32 code_point) const { auto width = m_glyph_widths[code_point]; + auto glyph_byte_count = m_glyph_height * GlyphBitmap::bytes_per_row(); return Glyph( - GlyphBitmap(m_rows.data(), code_point * m_glyph_height, { width, m_glyph_height }), + GlyphBitmap(m_rows.slice(code_point * glyph_byte_count, glyph_byte_count), { width, m_glyph_height }), 0, width, m_glyph_height); diff --git a/Userland/Libraries/LibGfx/Font/Font.h b/Userland/Libraries/LibGfx/Font/Font.h index 19b940d3e7..21e3c37812 100644 --- a/Userland/Libraries/LibGfx/Font/Font.h +++ b/Userland/Libraries/LibGfx/Font/Font.h @@ -23,9 +23,8 @@ namespace Gfx { class GlyphBitmap { public: GlyphBitmap() = default; - GlyphBitmap(u8 const* rows, size_t start_index, IntSize size) + GlyphBitmap(Bytes rows, IntSize size) : m_rows(rows) - , m_start_index(start_index) , m_size(size) { } @@ -46,11 +45,10 @@ public: private: AK::Bitmap bitmap(size_t y) const { - return { const_cast(m_rows) + bytes_per_row() * (m_start_index + y), bytes_per_row() * 8 }; + return { const_cast(m_rows.offset_pointer(bytes_per_row() * y)), bytes_per_row() * 8 }; } - u8 const* m_rows { nullptr }; - size_t m_start_index { 0 }; + Bytes m_rows; IntSize m_size { 0, 0 }; };