aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Geerken <devnull@localhost>2013-07-02 13:25:04 +0200
committerSebastian Geerken <devnull@localhost>2013-07-02 13:25:04 +0200
commit8a4b80f989cabc0c83ed0a0c85189b5e84ad7fbe (patch)
treea32b28a44f8095374c7d9ab8385a1c078687eaab
parent7a1296f447abaf2787181eff5d41e35b9f20524c (diff)
Fixed a bug in the calculation of extremes, related to hyphenation.
-rw-r--r--dw/tablecell.cc6
-rw-r--r--dw/tablecell.hh2
-rw-r--r--dw/textblock.hh16
-rw-r--r--dw/textblock_linebreaking.cc32
4 files changed, 42 insertions, 14 deletions
diff --git a/dw/tablecell.cc b/dw/tablecell.cc
index 90dc310d..a3aaf07e 100644
--- a/dw/tablecell.cc
+++ b/dw/tablecell.cc
@@ -42,12 +42,12 @@ TableCell::~TableCell()
{
}
-void TableCell::wordWrap(int wordIndex, bool wrapAll)
+bool TableCell::wordWrap(int wordIndex, bool wrapAll)
{
Textblock::Word *word;
const char *p;
- Textblock::wordWrap (wordIndex, wrapAll);
+ bool ret = Textblock::wordWrap (wordIndex, wrapAll);
if (charWordIndex == -1) {
word = words->getRef (wordIndex);
@@ -66,6 +66,8 @@ void TableCell::wordWrap(int wordIndex, bool wrapAll)
if (wordIndex == charWordIndex)
updateValue ();
+
+ return ret;
}
int TableCell::getValue ()
diff --git a/dw/tablecell.hh b/dw/tablecell.hh
index 4bb8633c..f7c6042e 100644
--- a/dw/tablecell.hh
+++ b/dw/tablecell.hh
@@ -12,7 +12,7 @@ private:
int charWordIndex, charWordPos;
protected:
- void wordWrap (int wordIndex, bool wrapAll);
+ bool wordWrap (int wordIndex, bool wrapAll);
int getValue ();
void setMaxValue (int maxValue, int value);
diff --git a/dw/textblock.hh b/dw/textblock.hh
index fb9c8727..ab2061ac 100644
--- a/dw/textblock.hh
+++ b/dw/textblock.hh
@@ -242,9 +242,6 @@ protected:
int firstWord; /* first word's index in word vector */
int lastWord; /* last word's index in word vector */
- // TODO Adjust comments. Short note: maxParMin/maxParMax is
- // is never smaller than parMin/parMax.
-
/*
* General remark: all values include the last hyphen width, but
* not the last space; these values are, however corrected, when
@@ -256,15 +253,16 @@ protected:
*/
int parMin; /* The sum of all word minima (plus spaces,
- hyphen width etc.) of the last c */
+ hyphen width etc.) since the last possible
+ break within this paragraph. */
int parMax; /* The sum of all word maxima in this
* paragraph (plus spaces, hyphen width
* etc.). */
- int maxParMin; /* Maximum of all paragraph minima, including
- * this line. */
- int maxParMax; /* Maximum of all paragraph maxima (value of "parMax"),
- * including this one. */
+ int maxParMin; /* Maximum of all paragraph minima (value of
+ * "parMin), including this paragraph. */
+ int maxParMax; /* Maximum of all paragraph maxima (value of
+ * "parMax"), including this paragraph. */
};
struct Line
@@ -566,7 +564,7 @@ protected:
void accumulateWordExtremes (int firstWord, int lastWord,
int *maxOfMinWidth, int *sumOfMaxWidth);
void processWord (int wordIndex);
- virtual void wordWrap (int wordIndex, bool wrapAll);
+ virtual bool wordWrap (int wordIndex, bool wrapAll);
int searchMinBap (int firstWord, int lastWordm, int penaltyIndex,
bool correctAtEnd);
int considerHyphenation (int firstIndex, int breakPos);
diff --git a/dw/textblock_linebreaking.cc b/dw/textblock_linebreaking.cc
index df29c459..d1b0df85 100644
--- a/dw/textblock_linebreaking.cc
+++ b/dw/textblock_linebreaking.cc
@@ -462,7 +462,26 @@ void Textblock::accumulateWordExtremes (int firstWord, int lastWord,
void Textblock::processWord (int wordIndex)
{
- wordWrap (wordIndex, false);
+ bool wordListChanged = wordWrap (wordIndex, false);
+
+ if (wordListChanged) {
+ // If wordWrap has called hyphenateWord here, this has an effect
+ // on the call of handleWordExtremes. To avoid adding values
+ // more than one time (original un-hyphenated word, plus all
+ // parts of the hyphenated word, except the first one), the
+ // whole paragraph is recalculated again.
+
+ int firstWord;
+ if (paragraphs->size() > 0) {
+ firstWord = paragraphs->getLastRef()->firstWord;
+ paragraphs->setSize (paragraphs->size() - 1);
+ } else
+ firstWord = 0;
+
+ for (int i = firstWord; i <= wordIndex - 1; i++)
+ handleWordExtremes (i);
+ }
+
handleWordExtremes (wordIndex);
}
@@ -470,13 +489,17 @@ void Textblock::processWord (int wordIndex)
* This method is called in two cases: (i) when a word is added
* (ii) when a page has to be (partially) rewrapped. It does word wrap,
* and adds new lines if necessary.
+ *
+ * Returns whether the words list has changed at, or before, the word
+ * index.
*/
-void Textblock::wordWrap (int wordIndex, bool wrapAll)
+bool Textblock::wordWrap (int wordIndex, bool wrapAll)
{
PRINTF ("[%p] WORD_WRAP (%d, %s)\n",
this, wordIndex, wrapAll ? "true" : "false");
Word *word;
+ bool wordListChanged = false;
if (!wrapAll)
removeTemporaryLines ();
@@ -584,6 +607,9 @@ void Textblock::wordWrap (int wordIndex, bool wrapAll)
// update word pointer as hyphenateWord() can trigger a
// reorganization of the words structure
word = words->getRef (wordIndex);
+
+ if (n > 0 && hyphenatedWord <= wordIndex)
+ wordListChanged = true;
}
PRINTF ("[%p] accumulating again from %d to %d\n",
@@ -618,6 +644,8 @@ void Textblock::wordWrap (int wordIndex, bool wrapAll)
word->content.widget->parentRef);
}
}
+
+ return wordListChanged;
}
int Textblock::searchMinBap (int firstWord, int lastWord, int penaltyIndex,