[gtk+] Avoid empty nodes another way



commit 59b12064686a2ee183ca6b686bd088f471383b95
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Sep 3 19:35:02 2017 -0400

    Avoid empty nodes another way
    
    Make gsk_text_node_new return NULL if the extents are empty.

 gsk/gskrendernodeimpl.c |    9 +++++++--
 gtk/gskpango.c          |   15 ++++++---------
 2 files changed, 13 insertions(+), 11 deletions(-)
---
diff --git a/gsk/gskrendernodeimpl.c b/gsk/gskrendernodeimpl.c
index 0b0981e..48fecc3 100644
--- a/gsk/gskrendernodeimpl.c
+++ b/gsk/gskrendernodeimpl.c
@@ -4041,6 +4041,13 @@ gsk_text_node_new (PangoFont        *font,
   GskTextNode *self;
   PangoRectangle ink_rect;
 
+  pango_glyph_string_extents (glyphs, font, &ink_rect, NULL);
+  pango_extents_to_pixels (&ink_rect, NULL);
+
+  /* Don't create nodes with empty bounds */
+  if (ink_rect.width == 0 || ink_rect.height == 0)
+    return NULL;
+
   self = (GskTextNode *) gsk_render_node_new (&GSK_TEXT_NODE_CLASS, 0);
 
   self->font = g_object_ref (font);
@@ -4053,8 +4060,6 @@ gsk_text_node_new (PangoFont        *font,
 
   self->has_color = font_has_color_glyphs (font);
 
-  pango_glyph_string_extents (glyphs, font, &ink_rect, NULL);
-  pango_extents_to_pixels (&ink_rect, NULL);
 
   graphene_rect_init (&self->render_node.bounds,
                       x_offset + base_x + ink_rect.x,
diff --git a/gtk/gskpango.c b/gtk/gskpango.c
index cb5fa76..c019539 100644
--- a/gtk/gskpango.c
+++ b/gtk/gskpango.c
@@ -119,25 +119,22 @@ gsk_pango_renderer_show_text_glyphs (PangoRenderer        *renderer,
   GdkRGBA color;
   PangoRectangle ink_rect;
 
-  /* FIXME: vulkan fallbacks don't deal with empty nodes gracefully */
-  pango_glyph_string_extents (glyphs, font, &ink_rect, NULL);
-  pango_extents_to_pixels (&ink_rect, NULL);
-  if (ink_rect.width == 0 || ink_rect.height == 0)
-    return;
-
   gtk_snapshot_get_offset (crenderer->snapshot, &x_offset, &y_offset);
-
-  gtk_snapshot_offset (crenderer->snapshot, base_x, base_y);
-
   get_color (crenderer, PANGO_RENDER_PART_FOREGROUND, &color);
 
   node = gsk_text_node_new (font, glyphs, &color, x_offset, y_offset, base_x, base_y);
+  if (node == NULL)
+    return;
+
   if (crenderer->snapshot->record_names)
     {
       char name[64];
       snprintf (name, sizeof (name), "Glyphs<%d>", glyphs->num_glyphs);
       gsk_render_node_set_name (node, name);
     }
+
+  gtk_snapshot_offset (crenderer->snapshot, base_x, base_y);
+
   gtk_snapshot_append_node (crenderer->snapshot, node);
   gsk_render_node_unref (node);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]