mirror of
https://github.com/SerenityOS/serenity
synced 2024-07-03 10:33:40 +00:00
LibGfx: Add cache for glyph paths
These are only cached via the `append_glyph_path_to()` API, so uses of fonts that only care about bitmaps do not pay for this cache.
This commit is contained in:
parent
d62d5079f4
commit
dae6015431
|
@ -85,7 +85,18 @@ RefPtr<Gfx::Bitmap> ScaledFont::rasterize_glyph(u32 glyph_id, GlyphSubpixelOffse
|
|||
|
||||
bool ScaledFont::append_glyph_path_to(Gfx::Path& path, u32 glyph_id) const
|
||||
{
|
||||
return m_font->append_glyph_path_to(path, glyph_id, m_x_scale, m_y_scale);
|
||||
auto glyph_iterator = m_glyph_cache.find(glyph_id);
|
||||
if (glyph_iterator != m_glyph_cache.end()) {
|
||||
path.append_path(glyph_iterator->value, Path::AppendRelativeToLastPoint::Yes);
|
||||
return true;
|
||||
}
|
||||
Gfx::Path glyph_path;
|
||||
bool success = m_font->append_glyph_path_to(glyph_path, glyph_id, m_x_scale, m_y_scale);
|
||||
if (success) {
|
||||
path.append_path(glyph_path, Path::AppendRelativeToLastPoint::Yes);
|
||||
m_glyph_cache.set(glyph_id, move(glyph_path));
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
Gfx::Glyph ScaledFont::glyph(u32 code_point) const
|
||||
|
|
|
@ -80,6 +80,8 @@ private:
|
|||
float m_y_scale { 0.0f };
|
||||
float m_point_width { 0.0f };
|
||||
float m_point_height { 0.0f };
|
||||
|
||||
mutable HashMap<u32, Gfx::Path> m_glyph_cache;
|
||||
mutable HashMap<GlyphIndexWithSubpixelOffset, RefPtr<Gfx::Bitmap>> m_cached_glyph_bitmaps;
|
||||
Gfx::FontPixelMetrics m_pixel_metrics;
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user