[gtk+/gtk-3-22] emoji: Skip overly wide fallback rendering
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/gtk-3-22] emoji: Skip overly wide fallback rendering
- Date: Mon, 15 Jan 2018 13:22:08 +0000 (UTC)
commit 9e3b8145805d1bfd78a082c73c5e8a162f07db16
Author: Matthias Clasen <mclasen redhat com>
Date: Sun Dec 17 22:09:08 2017 -0500
emoji: Skip overly wide fallback rendering
Some emoji fonts (such as Emoji One), render Emoji sequences
such as some of the family variations using multiple individual
glyphs. This rendering is too wide and breaks our grid layout.
Therefore, we will just skip any sequence whose rendering is
more than twice as wide as a simple smiley.
gtk/gtkemojichooser.c | 20 +++++++++++++++++++-
1 files changed, 19 insertions(+), 1 deletions(-)
---
diff --git a/gtk/gtkemojichooser.c b/gtk/gtkemojichooser.c
index 232fc13..daa565b 100644
--- a/gtk/gtkemojichooser.c
+++ b/gtk/gtkemojichooser.c
@@ -361,6 +361,9 @@ add_emoji (GtkWidget *box,
char text[64];
char *p = text;
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++)
@@ -376,12 +379,27 @@ add_emoji (GtkWidget *box,
g_variant_unref (codes);
p[0] = 0;
- label = gtk_label_new (text);
+ label = gtk_label_new ("🙂");
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)
+ {
+ gtk_widget_destroy (label);
+ return;
+ }
+
child = gtk_flow_box_child_new ();
gtk_style_context_add_class (gtk_widget_get_style_context (child), "emoji");
g_object_set_data_full (G_OBJECT (child), "emoji-data",
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]