summaryrefslogtreecommitdiffstats
path: root/src/libnrtype
diff options
context:
space:
mode:
authorbulia byak <buliabyak@gmail.com>2008-07-18 03:23:18 +0000
committerbuliabyak <buliabyak@users.sourceforge.net>2008-07-18 03:23:18 +0000
commitfa59f8140a9eb492e771c1183f34c02bac7f7bd9 (patch)
tree220e0f9b439861677bcef35bdb296ffedd1bbdc4 /src/libnrtype
parentadd utility function for average linespacing (diff)
downloadinkscape-fa59f8140a9eb492e771c1183f34c02bac7f7bd9.tar.gz
inkscape-fa59f8140a9eb492e771c1183f34c02bac7f7bd9.zip
add parameter for going n lines up/down
(bzr r6344)
Diffstat (limited to 'src/libnrtype')
-rw-r--r--src/libnrtype/Layout-TNG-OutIter.cpp38
-rw-r--r--src/libnrtype/Layout-TNG.h8
2 files changed, 26 insertions, 20 deletions
diff --git a/src/libnrtype/Layout-TNG-OutIter.cpp b/src/libnrtype/Layout-TNG-OutIter.cpp
index 41fd48c9a..7a45425c0 100644
--- a/src/libnrtype/Layout-TNG-OutIter.cpp
+++ b/src/libnrtype/Layout-TNG-OutIter.cpp
@@ -693,25 +693,28 @@ void Layout::iterator::beginCursorUpDown()
_cursor_moving_vertically = true;
}
-bool Layout::iterator::nextLineCursor()
+bool Layout::iterator::nextLineCursor(int n)
{
if (!_cursor_moving_vertically)
beginCursorUpDown();
if (_char_index == _parent_layout->_characters.size())
return false;
unsigned line_index = _parent_layout->_characters[_char_index].chunk(_parent_layout).in_line;
- if (line_index == _parent_layout->_lines.size() - 1) return false;
- if (_parent_layout->_lines[line_index + 1].in_shape != _parent_layout->_lines[line_index].in_shape) {
+ if (line_index == _parent_layout->_lines.size() - 1)
+ return false; // nowhere to go
+ else
+ n = MIN (n, _parent_layout->_lines.size() - 1 - line_index);
+ if (_parent_layout->_lines[line_index + n].in_shape != _parent_layout->_lines[line_index].in_shape) {
// switching between shapes: adjust the stored x to compensate
- _x_coordinate += _parent_layout->_chunks[_parent_layout->_spans[_parent_layout->_lineToSpan(line_index + 1)].in_chunk].left_x
+ _x_coordinate += _parent_layout->_chunks[_parent_layout->_spans[_parent_layout->_lineToSpan(line_index + n)].in_chunk].left_x
- _parent_layout->_chunks[_parent_layout->_spans[_parent_layout->_lineToSpan(line_index)].in_chunk].left_x;
}
- _char_index = _parent_layout->_cursorXOnLineToIterator(line_index + 1, _x_coordinate)._char_index;
+ _char_index = _parent_layout->_cursorXOnLineToIterator(line_index + n, _x_coordinate)._char_index;
_glyph_index = _parent_layout->_characters[_char_index].in_glyph;
return true;
}
-bool Layout::iterator::prevLineCursor()
+bool Layout::iterator::prevLineCursor(int n)
{
if (!_cursor_moving_vertically)
beginCursorUpDown();
@@ -720,13 +723,16 @@ bool Layout::iterator::prevLineCursor()
line_index = _parent_layout->_lines.size() - 1;
else
line_index = _parent_layout->_characters[_char_index].chunk(_parent_layout).in_line;
- if (line_index == 0) return false;
- if (_parent_layout->_lines[line_index - 1].in_shape != _parent_layout->_lines[line_index].in_shape) {
+ if (line_index == 0)
+ return false; // nowhere to go
+ else
+ n = MIN (n, line_index);
+ if (_parent_layout->_lines[line_index - n].in_shape != _parent_layout->_lines[line_index].in_shape) {
// switching between shapes: adjust the stored x to compensate
- _x_coordinate += _parent_layout->_chunks[_parent_layout->_spans[_parent_layout->_lineToSpan(line_index - 1)].in_chunk].left_x
+ _x_coordinate += _parent_layout->_chunks[_parent_layout->_spans[_parent_layout->_lineToSpan(line_index - n)].in_chunk].left_x
- _parent_layout->_chunks[_parent_layout->_spans[_parent_layout->_lineToSpan(line_index)].in_chunk].left_x;
}
- _char_index = _parent_layout->_cursorXOnLineToIterator(line_index - 1, _x_coordinate)._char_index;
+ _char_index = _parent_layout->_cursorXOnLineToIterator(line_index - n, _x_coordinate)._char_index;
_glyph_index = _parent_layout->_characters[_char_index].in_glyph;
return true;
}
@@ -903,24 +909,24 @@ bool Layout::iterator::_cursorLeftOrRightLocalXByWord(Direction direction)
return r;
}
-bool Layout::iterator::cursorUp()
+bool Layout::iterator::cursorUp(int n)
{
Direction block_progression = _parent_layout->_blockProgression();
if(block_progression == TOP_TO_BOTTOM)
- return prevLineCursor();
+ return prevLineCursor(n);
else if(block_progression == BOTTOM_TO_TOP)
- return nextLineCursor();
+ return nextLineCursor(n);
else
return _cursorLeftOrRightLocalX(RIGHT_TO_LEFT);
}
-bool Layout::iterator::cursorDown()
+bool Layout::iterator::cursorDown(int n)
{
Direction block_progression = _parent_layout->_blockProgression();
if(block_progression == TOP_TO_BOTTOM)
- return nextLineCursor();
+ return nextLineCursor(n);
else if(block_progression == BOTTOM_TO_TOP)
- return prevLineCursor();
+ return prevLineCursor(n);
else
return _cursorLeftOrRightLocalX(LEFT_TO_RIGHT);
}
diff --git a/src/libnrtype/Layout-TNG.h b/src/libnrtype/Layout-TNG.h
index ec12ddff5..36e7be0a5 100644
--- a/src/libnrtype/Layout-TNG.h
+++ b/src/libnrtype/Layout-TNG.h
@@ -852,8 +852,8 @@ public:
bool nextCursorPosition();
bool prevCursorPosition();
- bool nextLineCursor();
- bool prevLineCursor();
+ bool nextLineCursor(int n = 1);
+ bool prevLineCursor(int n = 1);
//words
bool nextStartOfWord();
@@ -879,8 +879,8 @@ public:
bool nextStartOfSource();
//logical cursor movement
- bool cursorUp();
- bool cursorDown();
+ bool cursorUp(int n = 1);
+ bool cursorDown(int n = 1);
bool cursorLeft();
bool cursorRight();