summaryrefslogtreecommitdiffstats
path: root/src/text-editing.cpp
diff options
context:
space:
mode:
authorbulia byak <buliabyak@gmail.com>2006-02-05 00:44:16 +0000
committerbuliabyak <buliabyak@users.sourceforge.net>2006-02-05 00:44:16 +0000
commitd28d568ea6afd2e08266922daf6f2c12f6eac720 (patch)
tree069a5c0fb116434f7da4b606b68b597b31957a4e /src/text-editing.cpp
parenthad 5 mins so I cleaned up a little more (diff)
downloadinkscape-d28d568ea6afd2e08266922daf6f2c12f6eac720.tar.gz
inkscape-d28d568ea6afd2e08266922daf6f2c12f6eac720.zip
sp_text_get_length_upto to count length recursively up to a given child
(bzr r76)
Diffstat (limited to 'src/text-editing.cpp')
-rw-r--r--src/text-editing.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/text-editing.cpp b/src/text-editing.cpp
index 44450f8fa..d5a53fc49 100644
--- a/src/text-editing.cpp
+++ b/src/text-editing.cpp
@@ -182,6 +182,30 @@ unsigned sp_text_get_length(SPObject const *item)
return length;
}
+/** Recursively gets the length of all the SPStrings at or below the given
+\a item. Also adds 1 for each line break encountered. */
+unsigned sp_text_get_length_upto(SPObject const *item, SPObject const *upto)
+{
+ unsigned length = 0;
+
+ if (SP_IS_STRING(item)) return SP_STRING(item)->string.length();
+ if (is_line_break_object(item)) length++;
+ for (SPObject const *child = item->firstChild() ; child ; child = SP_OBJECT_NEXT(child)) {
+ if (child == upto)
+ return length;
+ if (SP_IS_STRING(child)) length += SP_STRING(child)->string.length();
+ else {
+ if (child->isAncestorOf(upto)) {
+ length += sp_text_get_length(child);
+ return length;
+ } else {
+ length += sp_text_get_length(child);
+ }
+ }
+ }
+ return length;
+}
+
static Inkscape::XML::Node* duplicate_node_without_children(Inkscape::XML::Node const *old_node)
{
switch (old_node->type()) {