LibTTF: Cache rasterized glyphs within TTF::ScaledFont

This commit is contained in:
Stephan Unverwerth 2020-12-29 17:56:13 +01:00 committed by Andreas Kling
parent 0f6cf9caa1
commit 1a072a61fb
Notes: sideshowbarker 2024-07-19 00:20:13 +09:00
2 changed files with 14 additions and 4 deletions

View file

@ -444,4 +444,15 @@ int ScaledFont::width(const Utf32View& utf32) const
return width;
}
RefPtr<Gfx::Bitmap> ScaledFont::raster_glyph(u32 glyph_id) const
{
auto glyph_iterator = m_cached_glyph_bitmaps.find(glyph_id);
if (glyph_iterator != m_cached_glyph_bitmaps.end())
return glyph_iterator->value;
auto glyph_bitmap = m_font->raster_glyph(glyph_id, m_x_scale, m_y_scale);
m_cached_glyph_bitmaps.set(glyph_id, glyph_bitmap);
return glyph_bitmap;
}
}

View file

@ -37,12 +37,10 @@
#include <LibTTF/Tables.h>
#define POINTS_PER_INCH 72.0f
#define DEFAULT_DPI 96
#define DEFAULT_DPI 96
namespace TTF {
class ScaledFont;
struct ScaledFontMetrics {
int ascender;
int descender;
@ -124,7 +122,7 @@ public:
u32 glyph_id_for_codepoint(u32 codepoint) const { return m_font->glyph_id_for_codepoint(codepoint); }
ScaledFontMetrics metrics() const { return m_font->metrics(m_x_scale, m_y_scale); }
ScaledGlyphMetrics glyph_metrics(u32 glyph_id) const { return m_font->glyph_metrics(glyph_id, m_x_scale, m_y_scale); }
RefPtr<Gfx::Bitmap> raster_glyph(u32 glyph_id) const { return m_font->raster_glyph(glyph_id, m_x_scale, m_y_scale); }
RefPtr<Gfx::Bitmap> raster_glyph(u32 glyph_id) const;
u32 glyph_count() const { return m_font->glyph_count(); }
int width(const StringView&) const;
int width(const Utf8View&) const;
@ -134,6 +132,7 @@ private:
RefPtr<Font> m_font;
float m_x_scale { 0.0 };
float m_y_scale { 0.0 };
mutable AK::HashMap<u32, RefPtr<Gfx::Bitmap>> m_cached_glyph_bitmaps;
};
}