1
0
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:
MacDue 2024-06-09 21:34:26 +01:00 committed by Nico Weber
parent d62d5079f4
commit dae6015431
2 changed files with 14 additions and 1 deletions

View File

@ -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

View File

@ -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;