diff options
| author | Ted Gould <ted@gould.cx> | 2006-02-06 05:38:08 +0000 |
|---|---|---|
| committer | gouldtj <gouldtj@users.sourceforge.net> | 2006-02-06 05:38:08 +0000 |
| commit | 1d97567299259f4ceaea8ff51de359dc74b49578 (patch) | |
| tree | 5d4da9bec137ed8edc1e1e25faa068645a3c67a5 /src/text-editing.cpp | |
| parent | DBL_MIN replaced by -DBL_MAX which is what I meant all along. (diff) | |
| download | inkscape-1d97567299259f4ceaea8ff51de359dc74b49578.tar.gz inkscape-1d97567299259f4ceaea8ff51de359dc74b49578.zip | |
(bzr r90)
Diffstat (limited to 'src/text-editing.cpp')
| -rw-r--r-- | src/text-editing.cpp | 29 |
1 files changed, 8 insertions, 21 deletions
diff --git a/src/text-editing.cpp b/src/text-editing.cpp index f0cb4bd9d..d5a53fc49 100644 --- a/src/text-editing.cpp +++ b/src/text-editing.cpp @@ -183,36 +183,23 @@ unsigned sp_text_get_length(SPObject const *item) } /** Recursively gets the length of all the SPStrings at or below the given -\a item, before and not including \a upto. Also adds 1 for each line break encountered. */ +\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) && !SP_IS_TEXT(item)) { - if (item != SP_OBJECT_PARENT(item)->firstChild()) { - // add 1 for each newline - length++; - } - } + 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 (upto && child == upto) { - // hit upto, return immediately + if (child == upto) return length; - } - if (SP_IS_STRING(child)) { - length += SP_STRING(child)->string.length(); - } + if (SP_IS_STRING(child)) length += SP_STRING(child)->string.length(); else { - if (upto && child->isAncestorOf(upto)) { - // upto is below us, recurse and break loop - length += sp_text_get_length_upto(child, upto); + if (child->isAncestorOf(upto)) { + length += sp_text_get_length(child); return length; } else { - // recurse and go to the next sibling - length += sp_text_get_length_upto(child, upto); + length += sp_text_get_length(child); } } } |
