From a4a3703fb41300b24fafc23f31955dd882668f55 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 4 Jun 2024 17:09:58 +0200 Subject: [PATCH] LibGfx: Remove unused GlyphBitmap class --- Userland/Libraries/LibGfx/Font/Font.h | 48 +------------------ Userland/Libraries/LibGfx/Font/ScaledFont.cpp | 2 +- Userland/Libraries/LibGfx/Forward.h | 1 - Userland/Libraries/LibGfx/Painter.cpp | 44 +---------------- Userland/Libraries/LibGfx/Painter.h | 1 - 5 files changed, 4 insertions(+), 92 deletions(-) diff --git a/Userland/Libraries/LibGfx/Font/Font.h b/Userland/Libraries/LibGfx/Font/Font.h index 24bd844b492..b562d21b864 100644 --- a/Userland/Libraries/LibGfx/Font/Font.h +++ b/Userland/Libraries/LibGfx/Font/Font.h @@ -19,50 +19,9 @@ namespace Gfx { -// FIXME: Make a MutableGlyphBitmap buddy class for FontEditor instead? -class GlyphBitmap { -public: - GlyphBitmap() = default; - GlyphBitmap(Bytes rows, IntSize size) - : m_rows(rows) - , m_size(size) - { - } - - unsigned row(unsigned index) const { return ByteReader::load32(bitmap(index).data()); } - - bool bit_at(int x, int y) const { return bitmap(y).get(x); } - void set_bit_at(int x, int y, bool b) { bitmap(y).set(x, b); } - - IntSize size() const { return m_size; } - int width() const { return m_size.width(); } - int height() const { return m_size.height(); } - - static constexpr size_t bytes_per_row() { return sizeof(u32); } - static constexpr int max_width() { return bytes_per_row() * 8; } - static constexpr int max_height() { return max_width() + bytes_per_row(); } - -private: - AK::Bitmap bitmap(size_t y) const - { - return { const_cast(m_rows.offset_pointer(bytes_per_row() * y)), bytes_per_row() * 8 }; - } - - Bytes m_rows; - IntSize m_size { 0, 0 }; -}; - class Glyph { public: - Glyph(GlyphBitmap const& glyph_bitmap, float left_bearing, float advance, float ascent) - : m_glyph_bitmap(glyph_bitmap) - , m_left_bearing(left_bearing) - , m_advance(advance) - , m_ascent(ascent) - { - } - - Glyph(RefPtr bitmap, float left_bearing, float advance, float ascent, bool is_color_bitmap) + Glyph(NonnullRefPtr bitmap, float left_bearing, float advance, float ascent, bool is_color_bitmap) : m_bitmap(bitmap) , m_left_bearing(left_bearing) , m_advance(advance) @@ -73,16 +32,13 @@ public: bool is_color_bitmap() const { return m_color_bitmap; } - bool is_glyph_bitmap() const { return !m_bitmap; } - GlyphBitmap glyph_bitmap() const { return m_glyph_bitmap; } RefPtr bitmap() const { return m_bitmap; } float left_bearing() const { return m_left_bearing; } float advance() const { return m_advance; } float ascent() const { return m_ascent; } private: - GlyphBitmap m_glyph_bitmap; - RefPtr m_bitmap; + NonnullRefPtr m_bitmap; float m_left_bearing; float m_advance; float m_ascent; diff --git a/Userland/Libraries/LibGfx/Font/ScaledFont.cpp b/Userland/Libraries/LibGfx/Font/ScaledFont.cpp index 855f3edf957..34941783916 100644 --- a/Userland/Libraries/LibGfx/Font/ScaledFont.cpp +++ b/Userland/Libraries/LibGfx/Font/ScaledFont.cpp @@ -90,7 +90,7 @@ Gfx::Glyph ScaledFont::glyph(u32 code_point, GlyphSubpixelOffset subpixel_offset auto id = glyph_id_for_code_point(code_point); auto bitmap = rasterize_glyph(id, subpixel_offset); auto metrics = glyph_metrics(id); - return Gfx::Glyph(bitmap, metrics.left_side_bearing, metrics.advance_width, metrics.ascender, m_font->has_color_bitmaps()); + return Gfx::Glyph(*bitmap, metrics.left_side_bearing, metrics.advance_width, metrics.ascender, m_font->has_color_bitmaps()); } float ScaledFont::glyph_left_bearing(u32 code_point) const diff --git a/Userland/Libraries/LibGfx/Forward.h b/Userland/Libraries/LibGfx/Forward.h index 56735ae73f8..fe2e448a810 100644 --- a/Userland/Libraries/LibGfx/Forward.h +++ b/Userland/Libraries/LibGfx/Forward.h @@ -19,7 +19,6 @@ class DisjointRectSet; class Emoji; class Font; -class GlyphBitmap; class ImageDecoder; struct FontPixelMetrics; class ScaledFont; diff --git a/Userland/Libraries/LibGfx/Painter.cpp b/Userland/Libraries/LibGfx/Painter.cpp index 9e2065f6ea9..f7a0bdcdd36 100644 --- a/Userland/Libraries/LibGfx/Painter.cpp +++ b/Userland/Libraries/LibGfx/Painter.cpp @@ -433,46 +433,6 @@ void Painter::draw_rect(IntRect const& a_rect, Color color, bool rough) } } -void Painter::draw_bitmap(IntPoint p, GlyphBitmap const& bitmap, Color color) -{ - auto dst_rect = IntRect(p, bitmap.size()).translated(translation()); - auto clipped_rect = dst_rect.intersected(clip_rect()); - if (clipped_rect.is_empty()) - return; - int const first_row = clipped_rect.top() - dst_rect.top(); - int const last_row = clipped_rect.bottom() - dst_rect.top(); - int const first_column = clipped_rect.left() - dst_rect.left(); - int const last_column = clipped_rect.right() - dst_rect.left(); - - int scale = this->scale(); - ARGB32* dst = m_target->scanline(clipped_rect.y() * scale) + clipped_rect.x() * scale; - auto dst_format = target()->format(); - size_t const dst_skip = m_target->pitch() / sizeof(ARGB32); - - if (scale == 1) { - for (int row = first_row; row < last_row; ++row) { - for (int j = 0; j < (last_column - first_column); ++j) { - if (bitmap.bit_at(j + first_column, row)) - dst[j] = color_for_format(dst_format, dst[j]).blend(color).value(); - } - dst += dst_skip; - } - } else { - for (int row = first_row; row < last_row; ++row) { - for (int j = 0; j < (last_column - first_column); ++j) { - if (bitmap.bit_at((j + first_column), row)) { - for (int iy = 0; iy < scale; ++iy) - for (int ix = 0; ix < scale; ++ix) { - auto pixel_index = j * scale + ix + iy * dst_skip; - dst[pixel_index] = color_for_format(dst_format, dst[pixel_index]).blend(color).value(); - } - } - } - dst += dst_skip * scale; - } - } -} - struct BlitState { enum AlphaState { NoAlpha = 0, @@ -955,9 +915,7 @@ FLATTEN void Painter::draw_glyph(FloatPoint point, u32 code_point, Font const& f auto glyph_position = Gfx::GlyphRasterPosition::get_nearest_fit_for(top_left); auto glyph = font.glyph(code_point, glyph_position.subpixel_offset); - if (glyph.is_glyph_bitmap()) { - draw_bitmap(top_left.to_type(), glyph.glyph_bitmap(), color); - } else if (glyph.is_color_bitmap()) { + if (glyph.is_color_bitmap()) { float scaled_width = glyph.advance(); float ratio = static_cast(glyph.bitmap()->height()) / static_cast(glyph.bitmap()->width()); float scaled_height = scaled_width * ratio; diff --git a/Userland/Libraries/LibGfx/Painter.h b/Userland/Libraries/LibGfx/Painter.h index da1a47ccce8..0a4818caa0c 100644 --- a/Userland/Libraries/LibGfx/Painter.h +++ b/Userland/Libraries/LibGfx/Painter.h @@ -73,7 +73,6 @@ public: void fill_rect_with_rounded_corners(IntRect const&, Color, int top_left_radius, int top_right_radius, int bottom_right_radius, int bottom_left_radius); void fill_ellipse(IntRect const&, Color); void draw_rect(IntRect const&, Color, bool rough = false); - void draw_bitmap(IntPoint, GlyphBitmap const&, Color = Color()); void draw_scaled_bitmap(IntRect const& dst_rect, Gfx::Bitmap const&, IntRect const& src_rect, float opacity = 1.0f, ScalingMode = ScalingMode::NearestNeighbor); void draw_scaled_bitmap(IntRect const& dst_rect, Gfx::Bitmap const&, FloatRect const& src_rect, float opacity = 1.0f, ScalingMode = ScalingMode::NearestNeighbor); void draw_scaled_bitmap_with_transform(IntRect const& dst_rect, Gfx::Bitmap const&, FloatRect const& src_rect, Gfx::AffineTransform const&, float opacity = 1.0f, ScalingMode = ScalingMode::NearestNeighbor);