aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Geerken <devnull@localhost>2012-12-14 14:27:25 +0100
committerSebastian Geerken <devnull@localhost>2012-12-14 14:27:25 +0100
commit875355853f1c6cbdeb960133bf463a36072a0999 (patch)
tree37c457d9fb4752e32f5bf5f36b012dea2f251051
parent431606334a46191ed9d0bf8a823c6c61882046a4 (diff)
Textblock::findParagraphOfWord (not used yet)
-rw-r--r--dw/textblock.cc22
-rw-r--r--dw/textblock.hh1
2 files changed, 23 insertions, 0 deletions
diff --git a/dw/textblock.cc b/dw/textblock.cc
index 816b2680..4b9bbab0 100644
--- a/dw/textblock.cc
+++ b/dw/textblock.cc
@@ -1209,6 +1209,28 @@ int Textblock::findLineOfWord (int wordIndex)
}
/**
+ * \brief Find the paragraph of word \em wordIndex.
+ */
+int Textblock::findParagraphOfWord (int wordIndex)
+{
+ int high = paragraphs->size () - 1, index, low = 0;
+
+ if (wordIndex < 0 || wordIndex >= words->size ())
+ return -1;
+
+ while (true) {
+ index = (low + high) / 2;
+ if (wordIndex >= paragraphs->getRef(index)->firstWord) {
+ if (wordIndex <= paragraphs->getRef(index)->lastWord)
+ return index;
+ else
+ low = index + 1;
+ } else
+ high = index - 1;
+ }
+}
+
+/**
* \brief Find the index of the word, or -1.
*/
Textblock::Word *Textblock::findWord (int x, int y, bool *inSpace)
diff --git a/dw/textblock.hh b/dw/textblock.hh
index 5fea8ffc..8a246c47 100644
--- a/dw/textblock.hh
+++ b/dw/textblock.hh
@@ -466,6 +466,7 @@ protected:
void drawLine (Line *line, core::View *view, core::Rectangle *area);
int findLineIndex (int y);
int findLineOfWord (int wordIndex);
+ int findParagraphOfWord (int wordIndex);
Word *findWord (int x, int y, bool *inSpace);
Word *addWord (int width, int ascent, int descent, bool canBeHyphenated,