Commit 04ff9b58 authored by Timm Bäder's avatar Timm Bäder 👎 Committed by Daniel Boles

emojichooser: Only measure reference emoji once

Doing that once for every emoji is pretty slow and unnecessary as the
width does not change.
parent 72ed0c95
......@@ -52,6 +52,8 @@ struct _GtkEmojiChooser
GtkWidget *stack;
GtkWidget *scrolled_window;
int emoji_max_width;
EmojiSection recent;
EmojiSection people;
EmojiSection body;
......@@ -363,7 +365,6 @@ add_emoji (GtkWidget *box,
int i;
PangoLayout *layout;
PangoRectangle rect;
int width;
codes = g_variant_get_child_value (item, 0);
for (i = 0; i < g_variant_n_children (codes); i++)
......@@ -379,22 +380,17 @@ add_emoji (GtkWidget *box,
g_variant_unref (codes);
p[0] = 0;
label = gtk_label_new ("🙂");
label = gtk_label_new (text);
attrs = pango_attr_list_new ();
pango_attr_list_insert (attrs, pango_attr_scale_new (PANGO_SCALE_X_LARGE));
gtk_label_set_attributes (GTK_LABEL (label), attrs);
pango_attr_list_unref (attrs);
layout = gtk_label_get_layout (GTK_LABEL (label));
pango_layout_get_extents (layout, &rect, NULL);
width = rect.width;
gtk_label_set_text (GTK_LABEL (label), text);
layout = gtk_label_get_layout (GTK_LABEL (label));
pango_layout_get_extents (layout, &rect, NULL);
/* Check for fallback rendering that generates too wide items */
if (rect.width >= 2 * width)
if (rect.width >= 2 * chooser->emoji_max_width)
{
gtk_widget_destroy (label);
return;
......@@ -641,6 +637,26 @@ gtk_emoji_chooser_init (GtkEmojiChooser *chooser)
gtk_widget_init_template (GTK_WIDGET (chooser));
/* Get a reasonable maximum width for an emoji. We do this to
* skip overly wide fallback rendering for certain emojis the
* font does not contain and therefore end up being rendered
* as multiply glyphs. */
{
PangoLayout *layout = gtk_widget_create_pango_layout (GTK_WIDGET (chooser), "🙂");
PangoAttrList *attrs;
PangoRectangle rect;
attrs = pango_attr_list_new ();
pango_attr_list_insert (attrs, pango_attr_scale_new (PANGO_SCALE_X_LARGE));
pango_layout_set_attributes (layout, attrs);
pango_attr_list_unref (attrs);
pango_layout_get_extents (layout, &rect, NULL);
chooser->emoji_max_width = rect.width;
g_object_unref (layout);
}
chooser->recent_long_press = gtk_gesture_long_press_new (chooser->recent.box);
g_signal_connect (chooser->recent_long_press, "pressed", G_CALLBACK (long_pressed_cb), chooser);
chooser->recent_multi_press = gtk_gesture_multi_press_new (chooser->recent.box);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment