diff --git a/rsvg-text.c b/rsvg-text.c
index 7066f24..10f0bbf 100644
--- a/rsvg-text.c
+++ b/rsvg-text.c
@@ -155,15 +155,18 @@ void
 
 static void
  _rsvg_node_text_type_tspan (RsvgNodeText * self, RsvgDrawingCtx * ctx,
-                             gdouble * x, gdouble * y, gboolean * lastwasspace);
+                             gdouble * x, gdouble * y, gboolean * lastwasspace,
+                             gboolean onlytext);
 
 static void
  _rsvg_node_text_type_tref (RsvgNodeTref * self, RsvgDrawingCtx * ctx,
-                            gdouble * x, gdouble * y, gboolean * lastwasspace);
+                            gdouble * x, gdouble * y, gboolean * lastwasspace,
+                            gboolean onlytext);
 
 static void
 _rsvg_node_text_type_children (RsvgNode * self, RsvgDrawingCtx * ctx,
-                               gdouble * x, gdouble * y, gboolean * lastwasspace)
+                               gdouble * x, gdouble * y, gboolean * lastwasspace,
+                               gboolean onlytext)
 {
     guint i;
 
@@ -175,14 +178,20 @@ _rsvg_node_text_type_children (RsvgNode * self, RsvgDrawingCtx * ctx,
             GString *str = _rsvg_text_chomp (rsvg_current_state (ctx), chars->contents, lastwasspace);
             rsvg_text_render_text (ctx, str->str, x, y);
             g_string_free (str, TRUE);
-        } else if (!strcmp (node->type->str, "tspan")) {
-            RsvgNodeText *tspan = (RsvgNodeText *) node;
-            rsvg_state_push (ctx);
-            _rsvg_node_text_type_tspan (tspan, ctx, x, y, lastwasspace);
-            rsvg_state_pop (ctx);
-        } else if (!strcmp (node->type->str, "tref")) {
-            RsvgNodeTref *tref = (RsvgNodeTref *) node;
-            _rsvg_node_text_type_tref (tref, ctx, x, y, lastwasspace);
+        } else {
+            if (onlytext) {
+               _rsvg_node_text_type_children(node, ctx, x, y, lastwasspace, onlytext);
+            } else {
+               if (!strcmp (node->type->str, "tspan")) {
+                  RsvgNodeText *tspan = (RsvgNodeText *) node;
+                  rsvg_state_push (ctx);
+                  _rsvg_node_text_type_tspan (tspan, ctx, x, y, lastwasspace, onlytext);
+                  rsvg_state_pop (ctx);
+               } else if (!strcmp (node->type->str, "tref")) {
+                  RsvgNodeTref *tref = (RsvgNodeTref *) node;
+                  _rsvg_node_text_type_tref (tref, ctx, x, y, lastwasspace, onlytext);
+               }
+            }
         }
     }
     rsvg_pop_discrete_layer (ctx);
@@ -190,17 +199,20 @@ _rsvg_node_text_type_children (RsvgNode * self, RsvgDrawingCtx * ctx,
 
 static int
  _rsvg_node_text_length_tref (RsvgNodeTref * self, RsvgDrawingCtx * ctx,
-                              gdouble * x, gboolean * lastwasspace);
+                              gdouble * x, gboolean * lastwasspace,
+                              gboolean onlytext);
 
 static int
  _rsvg_node_text_length_tspan (RsvgNodeText * self, RsvgDrawingCtx * ctx,
-                               gdouble * x, gboolean * lastwasspace);
+                               gdouble * x, gboolean * lastwasspace,
+                               gboolean onlytext);
 
 static gdouble rsvg_text_length_text_as_string (RsvgDrawingCtx * ctx, const char *text);
 
 static int
 _rsvg_node_text_length_children (RsvgNode * self, RsvgDrawingCtx * ctx,
-                                 gdouble * x, gboolean * lastwasspace)
+                                 gdouble * x, gboolean * lastwasspace,
+                                 gboolean onlytext)
 {
     guint i;
     int out = FALSE;
@@ -213,12 +225,18 @@ _rsvg_node_text_length_children (RsvgNode * self, RsvgDrawingCtx * ctx,
             GString *str = _rsvg_text_chomp (rsvg_current_state (ctx), chars->contents, lastwasspace);
             *x += rsvg_text_length_text_as_string (ctx, str->str);
             g_string_free (str, TRUE);
-        } else if (!strcmp (node->type->str, "tspan")) {
-            RsvgNodeText *tspan = (RsvgNodeText *) node;
-            out = _rsvg_node_text_length_tspan (tspan, ctx, x, lastwasspace);
-        } else if (!strcmp (node->type->str, "tref")) {
-            RsvgNodeTref *tref = (RsvgNodeTref *) node;
-            out = _rsvg_node_text_length_tref (tref, ctx, x, lastwasspace);
+        } else {
+            if (onlytext) {
+                out = _rsvg_node_text_length_children (node, ctx, x, lastwasspace, onlytext);
+            } else {
+                if (!strcmp (node->type->str, "tspan")) {
+                    RsvgNodeText *tspan = (RsvgNodeText *) node;
+                    out = _rsvg_node_text_length_tspan (tspan, ctx, x, lastwasspace, onlytext);
+                } else if (!strcmp (node->type->str, "tref")) {
+                    RsvgNodeTref *tref = (RsvgNodeTref *) node;
+                    out = _rsvg_node_text_length_tref (tref, ctx, x, lastwasspace, onlytext);
+                }
+            }
         }
         rsvg_state_pop (ctx);
         if (out)
@@ -243,7 +261,7 @@ _rsvg_node_text_draw (RsvgNode * self, RsvgDrawingCtx * ctx, int dominate)
 
     if (rsvg_current_state (ctx)->text_anchor != TEXT_ANCHOR_START) {
         double length = 0;
-        _rsvg_node_text_length_children (self, ctx, &length, &lastwasspace);
+        _rsvg_node_text_length_children (self, ctx, &length, &lastwasspace, FALSE);
         if (rsvg_current_state (ctx)->text_anchor == TEXT_ANCHOR_END)
             x -= length;
         if (rsvg_current_state (ctx)->text_anchor == TEXT_ANCHOR_MIDDLE)
@@ -251,7 +269,7 @@ _rsvg_node_text_draw (RsvgNode * self, RsvgDrawingCtx * ctx, int dominate)
     }
 
     lastwasspace = TRUE;
-    _rsvg_node_text_type_children (self, ctx, &x, &y, &lastwasspace);
+    _rsvg_node_text_type_children (self, ctx, &x, &y, &lastwasspace, FALSE);
 }
 
 RsvgNode *
@@ -268,7 +286,8 @@ rsvg_new_text (void)
 
 static void
 _rsvg_node_text_type_tspan (RsvgNodeText * self, RsvgDrawingCtx * ctx,
-                            gdouble * x, gdouble * y, gboolean * lastwasspace)
+                            gdouble * x, gdouble * y, gboolean * lastwasspace,
+                            gboolean onlytext)
 {
     rsvg_state_reinherit_top (ctx, self->super.state, 0);
 
@@ -277,7 +296,7 @@ _rsvg_node_text_type_tspan (RsvgNodeText * self, RsvgDrawingCtx * ctx,
         if (rsvg_current_state (ctx)->text_anchor != TEXT_ANCHOR_START) {
             double length = 0;
             gboolean lws = *lastwasspace;
-            _rsvg_node_text_length_children (&self->super, ctx, &length, &lws);
+            _rsvg_node_text_length_children (&self->super, ctx, &length, &lws, onlytext);
             if (rsvg_current_state (ctx)->text_anchor == TEXT_ANCHOR_END)
                 *x -= length;
             if (rsvg_current_state (ctx)->text_anchor == TEXT_ANCHOR_MIDDLE)
@@ -288,16 +307,16 @@ _rsvg_node_text_type_tspan (RsvgNodeText * self, RsvgDrawingCtx * ctx,
         *y = _rsvg_css_normalize_length (&self->y, ctx, 'v');
     *x += _rsvg_css_normalize_length (&self->dx, ctx, 'h');
     *y += _rsvg_css_normalize_length (&self->dy, ctx, 'v');
-    _rsvg_node_text_type_children (&self->super, ctx, x, y, lastwasspace);
+    _rsvg_node_text_type_children (&self->super, ctx, x, y, lastwasspace, onlytext);
 }
 
 static int
 _rsvg_node_text_length_tspan (RsvgNodeText * self, RsvgDrawingCtx * ctx, gdouble * x,
-                              gboolean * lastwasspace)
+                              gboolean * lastwasspace, gboolean onlytext)
 {
     if (self->x.factor != 'n' || self->y.factor != 'n')
         return TRUE;
-    return _rsvg_node_text_length_children (&self->super, ctx, x, lastwasspace);
+    return _rsvg_node_text_length_children (&self->super, ctx, x, lastwasspace, onlytext);
 }
 
 static void
@@ -340,18 +359,19 @@ rsvg_new_tspan (void)
 
 static void
 _rsvg_node_text_type_tref (RsvgNodeTref * self, RsvgDrawingCtx * ctx,
-                           gdouble * x, gdouble * y, gboolean * lastwasspace)
+                           gdouble * x, gdouble * y, gboolean * lastwasspace,
+                           gboolean onlytext)
 {
     if (self->link)
-        _rsvg_node_text_type_children (self->link, ctx, x, y, lastwasspace);
+        _rsvg_node_text_type_children (self->link, ctx, x, y, lastwasspace, TRUE);
 }
 
 static int
 _rsvg_node_text_length_tref (RsvgNodeTref * self, RsvgDrawingCtx * ctx, gdouble * x,
-                             gboolean * lastwasspace)
+                             gboolean * lastwasspace, gboolean onlytext)
 {
     if (self->link)
-        return _rsvg_node_text_length_children (self->link, ctx, x, lastwasspace);
+        return _rsvg_node_text_length_children (self->link, ctx, x, lastwasspace, TRUE);
     return FALSE;
 }
 
