[gtk/gtk-3-22] emojichooser: Only measure reference emoji once
- From: Daniel Boles <dboles src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/gtk-3-22] emojichooser: Only measure reference emoji once
- Date: Mon, 12 Mar 2018 15:32:32 +0000 (UTC)
commit 04ff9b58f19e43697666dc5ccbe4faaa96fc29a0
Author: Timm Bäder <mail baedert org>
Date: Tue Feb 27 11:45:34 2018 +0100
emojichooser: Only measure reference emoji once
Doing that once for every emoji is pretty slow and unnecessary as the
width does not change.
gtk/gtkemojichooser.c | 32 ++++++++++++++++++++++++--------
1 file changed, 24 insertions(+), 8 deletions(-)
---
diff --git a/gtk/gtkemojichooser.c b/gtk/gtkemojichooser.c
index daa565bef7..0da57270b0 100644
--- a/gtk/gtkemojichooser.c
+++ b/gtk/gtkemojichooser.c
@@ -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);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]