diff options
-rw-r--r-- | Libraries/LibTTF/Font.cpp | 11 | ||||
-rw-r--r-- | Libraries/LibTTF/Font.h | 7 |
2 files changed, 14 insertions, 4 deletions
diff --git a/Libraries/LibTTF/Font.cpp b/Libraries/LibTTF/Font.cpp index 9681e953b8..2b53332bf1 100644 --- a/Libraries/LibTTF/Font.cpp +++ b/Libraries/LibTTF/Font.cpp @@ -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; +} + } diff --git a/Libraries/LibTTF/Font.h b/Libraries/LibTTF/Font.h index f430fdcc0d..3062cb1190 100644 --- a/Libraries/LibTTF/Font.h +++ b/Libraries/LibTTF/Font.h @@ -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; }; } |