diff options
author | sgeerken <devnull@localhost> | 2012-07-28 21:12:12 +0200 |
---|---|---|
committer | sgeerken <devnull@localhost> | 2012-07-28 21:12:12 +0200 |
commit | 3bc88f6f7c19c122eec571358d94d79b8801d89e (patch) | |
tree | 643ccdbeab4a38a8d90d05a1e1ea7c5c87f48c0f | |
parent | 196933111c2d20973cbce20c6f51e32e977b9dcf (diff) |
Removed lineIndex parameter from accumulateWordData(); accumulateWordData() now calculates the line index from the word index. Aside from the simplification, this fixes some bugs caused by wrong arguments for lineIndex.
-rw-r--r-- | doc/dw-line-breaking.doc | 2 | ||||
-rw-r--r-- | dw/textblock.cc | 4 | ||||
-rw-r--r-- | dw/textblock.hh | 2 | ||||
-rw-r--r-- | dw/textblock_linebreaking.cc | 48 |
4 files changed, 28 insertions, 28 deletions
diff --git a/doc/dw-line-breaking.doc b/doc/dw-line-breaking.doc index bd6f8856..50eac84f 100644 --- a/doc/dw-line-breaking.doc +++ b/doc/dw-line-breaking.doc @@ -205,7 +205,7 @@ usw. detail.)</li> <li>It should be simple to assign a larger penalty for hyphens, when the line before is already hyphenated. This way, hyphens in - adjacent are pelalized furher./li> + adjacent are pelalized further.</li> </ul> */ diff --git a/dw/textblock.cc b/dw/textblock.cc index 03f6dbb9..c8aaebe1 100644 --- a/dw/textblock.cc +++ b/dw/textblock.cc @@ -1579,7 +1579,7 @@ void Textblock::addSpace (core::style::Style *style) int wordIndex = words->size () - 1; if (wordIndex >= 0) { fillSpace (words->getRef(wordIndex), style); - accumulateWordData (wordIndex, lines->size ()); + accumulateWordData (wordIndex); } } @@ -1638,7 +1638,7 @@ void Textblock::addHyphen () // TODO Optimize? Like spaces? word->hyphenWidth = layout->textWidth (word->style->font, "\xc2\xad", 2); - accumulateWordData (wordIndex, lines->size ()); + accumulateWordData (wordIndex); } } diff --git a/dw/textblock.hh b/dw/textblock.hh index 9f1cbb63..2327ff15 100644 --- a/dw/textblock.hh +++ b/dw/textblock.hh @@ -441,7 +441,7 @@ protected: virtual void wordWrap (int wordIndex, bool wrapAll); int hyphenateWord (int wordIndex); void accumulateWordForLine (int lineIndex, int wordIndex); - void accumulateWordData(int wordIndex, int lineIndex); + void accumulateWordData(int wordIndex); int calcAvailWidth (int lineIndex); void initLine1Offset (int wordIndex); void alignLine (int lineIndex); diff --git a/dw/textblock_linebreaking.cc b/dw/textblock_linebreaking.cc index b8d94813..0d259a47 100644 --- a/dw/textblock_linebreaking.cc +++ b/dw/textblock_linebreaking.cc @@ -290,7 +290,8 @@ void Textblock::justifyLine (Line *line, int diff) Textblock::Line *Textblock::addLine (int firstWord, int lastWord, bool temporary) { - PRINTF ("[%p] ADD_LINE (%d, %d)\n", this, firstWord, lastWord); + PRINTF ("[%p] ADD_LINE (%d, %d) => %d\n", + this, firstWord, lastWord, lines->size ()); Word *lastWordOfLine = words->getRef(lastWord); // Word::totalWidth includes the hyphen (which is what we want here). @@ -416,7 +417,7 @@ void Textblock::wordWrap (int wordIndex, bool wrapAll) word = words->getRef (wordIndex); word->effSpace = word->origSpace; - accumulateWordData (wordIndex, lines->size ()); + accumulateWordData (wordIndex); bool newLine; do { @@ -457,7 +458,7 @@ void Textblock::wordWrap (int wordIndex, bool wrapAll) mustQueueResize = true; if(newLine) { - accumulateWordData (wordIndex, lines->size() - 1); + accumulateWordData (wordIndex); int wordIndexEnd = wordIndex; bool lineAdded; @@ -552,7 +553,7 @@ void Textblock::wordWrap (int wordIndex, bool wrapAll) PRINTF ("[%p] accumulating again from %d to %d\n", this, breakPos + 1, wordIndexEnd); for(int i = breakPos + 1; i <= wordIndexEnd; i++) - accumulateWordData (i, lines->size() - 1); + accumulateWordData (i); } while(!lineAdded); } @@ -623,7 +624,7 @@ int Textblock::hyphenateWord (int wordIndex) } } - accumulateWordData (wordIndex + i, lines->size() - 1); + accumulateWordData (wordIndex + i); } PRINTF (" finished\n"); @@ -698,35 +699,34 @@ void Textblock::accumulateWordForLine (int lineIndex, int wordIndex) } } -void Textblock::accumulateWordData (int wordIndex, int lineIndex) +void Textblock::accumulateWordData (int wordIndex) { + int lineIndex = lines->size (); + while (lineIndex > 0 && wordIndex <= lines->getRef(lineIndex - 1)->lastWord) + lineIndex--; + + int firstWordOfLine; + if (lineIndex == 0) + firstWordOfLine = 0; + else + firstWordOfLine = lines->getRef(lineIndex - 1)->lastWord + 1; + Word *word = words->getRef (wordIndex); - PRINTF ("[%p] ACCUMULATE_WORD_DATA (%d): ...\n", this, wordIndex); + PRINTF ("[%p] ACCUMULATE_WORD_DATA (%d); lineIndex = %d: ...\n", + this, wordIndex, lineIndex); int availWidth = calcAvailWidth (lineIndex); - if (wordIndex == 0 || - (lines->size () > 0 && - wordIndex == lines->getRef(lines->size () - 1)->lastWord + 1)) { + PRINTF (" (%s existing line %d starts with word %d)\n", + lineIndex < lines->size () ? "already" : "not yet", + lineIndex, firstWordOfLine); + + if (wordIndex == firstWordOfLine) { // first word of the (not neccessarily yet existing) line word->totalWidth = word->size.width + word->hyphenWidth; word->totalStretchability = 0; word->totalShrinkability = 0; - //printf (" (first word of line)\n"); } else { - // if (lines->size () == 0) - // printf (" (word %d word of not-yet-existing line %d)\n", - // wordIndex, 0); - // else if (wordIndex > lines->getLastRef()->lastWord) - // printf (" (word %d word of not-yet-existing line %d)\n", - // wordIndex - (lines->getLastRef()->lastWord + 1), - // lines->size()); - // else { - // int line = findLineOfWord (wordIndex); - // printf (" (word %d word of line %d)\n", - // wordIndex - lines->getRef(line)->firstWord, line); - // } - Word *prevWord = words->getRef (wordIndex - 1); word->totalWidth = prevWord->totalWidth |