mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:07:44 +00:00
LibTTF: Cache rasterized glyphs within TTF::ScaledFont
This commit is contained in:
parent
0f6cf9caa1
commit
1a072a61fb
2 changed files with 14 additions and 4 deletions
|
@ -444,4 +444,15 @@ int ScaledFont::width(const Utf32View& utf32) const
|
||||||
return width;
|
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>
|
#include <LibTTF/Tables.h>
|
||||||
|
|
||||||
#define POINTS_PER_INCH 72.0f
|
#define POINTS_PER_INCH 72.0f
|
||||||
#define DEFAULT_DPI 96
|
#define DEFAULT_DPI 96
|
||||||
|
|
||||||
namespace TTF {
|
namespace TTF {
|
||||||
|
|
||||||
class ScaledFont;
|
|
||||||
|
|
||||||
struct ScaledFontMetrics {
|
struct ScaledFontMetrics {
|
||||||
int ascender;
|
int ascender;
|
||||||
int descender;
|
int descender;
|
||||||
|
@ -124,7 +122,7 @@ public:
|
||||||
u32 glyph_id_for_codepoint(u32 codepoint) const { return m_font->glyph_id_for_codepoint(codepoint); }
|
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); }
|
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); }
|
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(); }
|
u32 glyph_count() const { return m_font->glyph_count(); }
|
||||||
int width(const StringView&) const;
|
int width(const StringView&) const;
|
||||||
int width(const Utf8View&) const;
|
int width(const Utf8View&) const;
|
||||||
|
@ -134,6 +132,7 @@ private:
|
||||||
RefPtr<Font> m_font;
|
RefPtr<Font> m_font;
|
||||||
float m_x_scale { 0.0 };
|
float m_x_scale { 0.0 };
|
||||||
float m_y_scale { 0.0 };
|
float m_y_scale { 0.0 };
|
||||||
|
mutable AK::HashMap<u32, RefPtr<Gfx::Bitmap>> m_cached_glyph_bitmaps;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue