@@ -84,6 +84,8 @@ CONCRETE_NULL_CODE (qt_pixmap);
8484static hashmap<basic_character, qt_image> character_image;
8585// image cache
8686static hashmap<string, qt_pixmap> images;
87+ // emoji cache: glyphID -> (size -> picture)
88+ static hashmap<int , hashmap<int , picture>> emoji_cache;
8789
8890/*
8991** hash contents must be removed because
9496del_obj_qt_renderer (void ) {
9597 character_image= hashmap<basic_character, qt_image> ();
9698 images = hashmap<string, qt_pixmap> ();
99+ emoji_cache = hashmap<int , hashmap<int , picture>> ();
97100}
98101
99102/* *****************************************************************************
@@ -698,20 +701,35 @@ qt_renderer_rep::draw_emoji (int char_code, font_glyphs fn, SI x, SI y) {
698701 return ;
699702 }
700703
701- // Retrieve SVG data for the glyph
702- string svg_data= tt_font->face ->svg_table ->get_svg_from_glyphid (glyph_id);
703- if (N (svg_data) == 0 ) {
704- return ;
705- }
706-
707704 // Calculate emoji size
708705 SI xo, yo;
709706 glyph pre_gl= fn->get (char_code);
710707 glyph gl = shrink (pre_gl, std_shrinkf, std_shrinkf, xo, yo);
711708 int w= gl->width , h= gl->height ;
712709
713- // Create picture from SVG data
714- picture emoji_picture= svg_string_to_picture (svg_data, w, h);
710+ // check cache first
711+ picture emoji_picture;
712+ if (emoji_cache->contains (glyph_id)) {
713+ hashmap<int , picture> size_cache= emoji_cache[glyph_id];
714+ if (size_cache->contains (w)) {
715+ emoji_picture= size_cache[w];
716+ }
717+ }
718+
719+ // cache miss: get SVG data and create picture
720+ if (is_nil (emoji_picture)) {
721+ string svg_data= tt_font->face ->svg_table ->get_svg_from_glyphid (glyph_id);
722+ if (N (svg_data) == 0 ) {
723+ return ;
724+ }
725+ emoji_picture= svg_string_to_picture (svg_data, w, h);
726+ if (!is_nil (emoji_picture)) {
727+ if (!emoji_cache->contains (glyph_id)) {
728+ emoji_cache (glyph_id)= hashmap<int , picture> ();
729+ }
730+ emoji_cache[glyph_id](w)= emoji_picture;
731+ }
732+ }
715733 if (is_nil (emoji_picture)) {
716734 return ;
717735 }
0 commit comments