diff options
| author | Ted Gould <ted@gould.cx> | 2006-02-06 07:17:33 +0000 |
|---|---|---|
| committer | gouldtj <gouldtj@users.sourceforge.net> | 2006-02-06 07:17:33 +0000 |
| commit | 53e1c1a77a66d307715a796cb164d7f87ae9eba5 (patch) | |
| tree | 514aa9c110787f3c9abc480a223a254959199286 /src/text-editing.cpp | |
| parent | Had to include fstream for overloaded def of << (diff) | |
| download | inkscape-53e1c1a77a66d307715a796cb164d7f87ae9eba5.tar.gz inkscape-53e1c1a77a66d307715a796cb164d7f87ae9eba5.zip | |
r10887@tres: ted | 2006-02-05 23:16:41 -0800
Okay, I'm basically undoing the last commit that SVK screwed up. All
this work is not mine, it was done by other people. Sorry to mess
things up.
(bzr r92)
Diffstat (limited to 'src/text-editing.cpp')
| -rw-r--r-- | src/text-editing.cpp | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/src/text-editing.cpp b/src/text-editing.cpp index d5a53fc49..f0cb4bd9d 100644 --- a/src/text-editing.cpp +++ b/src/text-editing.cpp @@ -183,23 +183,36 @@ unsigned sp_text_get_length(SPObject const *item) } /** Recursively gets the length of all the SPStrings at or below the given -\a item. Also adds 1 for each line break encountered. */ +\a item, before and not including \a upto. 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++; + 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++; + } + } for (SPObject const *child = item->firstChild() ; child ; child = SP_OBJECT_NEXT(child)) { - if (child == upto) + if (upto && child == upto) { + // hit upto, return immediately 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 (child->isAncestorOf(upto)) { - length += sp_text_get_length(child); + if (upto && child->isAncestorOf(upto)) { + // upto is below us, recurse and break loop + length += sp_text_get_length_upto(child, upto); return length; } else { - length += sp_text_get_length(child); + // recurse and go to the next sibling + length += sp_text_get_length_upto(child, upto); } } } |
