[librsvg] rsvg-base.c: Factor out node_is_text_or_tspan()



commit f85fb2749be295925752e0e8a58c9d1a6906f736
Author: Federico Mena Quintero <federico gnome org>
Date:   Wed Dec 6 07:29:58 2017 -0600

    rsvg-base.c: Factor out node_is_text_or_tspan()

 rsvg-base.c |   19 +++++++++++++++++--
 1 files changed, 17 insertions(+), 2 deletions(-)
---
diff --git a/rsvg-base.c b/rsvg-base.c
index 30cd72e..da5e514 100644
--- a/rsvg-base.c
+++ b/rsvg-base.c
@@ -889,6 +889,19 @@ extern RsvgNode *rsvg_node_chars_new(RsvgNode *parent);
 extern void rsvg_node_chars_append (RsvgNode *node, const char *text, gssize len);
 
 static gboolean
+node_is_text_or_tspan (RsvgNode *node)
+{
+    RsvgNodeType type;
+
+    if (!node) {
+        return FALSE;
+    }
+
+    type = rsvg_node_get_type (node);
+    return type == RSVG_NODE_TYPE_TEXT || type == RSVG_NODE_TYPE_TSPAN;
+}
+
+static gboolean
 find_last_chars_node_foreach (RsvgNode *node, gpointer data)
 {
     RsvgNode **dest;
@@ -919,10 +932,9 @@ find_last_chars_node_foreach (RsvgNode *node, gpointer data)
 static RsvgNode *
 find_last_chars_child_in_text_or_tspan (RsvgNode *node)
 {
-    RsvgNodeType type = rsvg_node_get_type (node);
     RsvgNode *child = NULL;
 
-    if (type == RSVG_NODE_TYPE_TSPAN || type == RSVG_NODE_TYPE_TEXT) {
+    if (node_is_text_or_tspan (node)) {
         /* find the last CHARS node in the text or tspan node, so that we can
          * coalesce the text, and thus avoid screwing up the Pango layouts.
          */
@@ -942,6 +954,9 @@ rsvg_characters_impl (RsvgHandle *ctx, const char *ch, gssize len)
     if (!ch || !len)
         return;
 
+    if (!node_is_text_or_tspan (ctx->priv->currentnode))
+        return;
+
     if (ctx->priv->currentnode) {
         node = find_last_chars_child_in_text_or_tspan (ctx->priv->currentnode);
     }


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