mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 20:15:17 +00:00
LibTTF: Cache rasterized glyphs within TTF::ScaledFont
This commit is contained in:
parent
0f6cf9caa1
commit
1a072a61fb
Notes:
sideshowbarker
2024-07-19 00:20:13 +09:00
Author: https://github.com/sunverwerth Commit: https://github.com/SerenityOS/serenity/commit/1a072a61fb8 Pull-request: https://github.com/SerenityOS/serenity/pull/4631 Issue: https://github.com/SerenityOS/serenity/issues/743 Reviewed-by: https://github.com/alimpfard
2 changed files with 14 additions and 4 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue