LibGfx: Remove unused GlyphBitmap class

This commit is contained in:
Andreas Kling 2024-06-04 17:09:58 +02:00
commit a4a3703fb4
Notes: sideshowbarker 2024-07-17 10:31:19 +09:00
5 changed files with 4 additions and 92 deletions

View file

@ -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<u8*>(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> bitmap, float left_bearing, float advance, float ascent, bool is_color_bitmap)
Glyph(NonnullRefPtr<Bitmap> 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> 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<Bitmap> m_bitmap;
NonnullRefPtr<Bitmap> m_bitmap;
float m_left_bearing;
float m_advance;
float m_ascent;

View file

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

View file

@ -19,7 +19,6 @@ class DisjointRectSet;
class Emoji;
class Font;
class GlyphBitmap;
class ImageDecoder;
struct FontPixelMetrics;
class ScaledFont;

View file

@ -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<int>(), glyph.glyph_bitmap(), color);
} else if (glyph.is_color_bitmap()) {
if (glyph.is_color_bitmap()) {
float scaled_width = glyph.advance();
float ratio = static_cast<float>(glyph.bitmap()->height()) / static_cast<float>(glyph.bitmap()->width());
float scaled_height = scaled_width * ratio;

View file

@ -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);