diff options
author | corvid <corvid@lavabit.com> | 2009-09-25 23:37:25 +0000 |
---|---|---|
committer | corvid <corvid@lavabit.com> | 2009-09-25 23:37:25 +0000 |
commit | 04605a1431cd7baf40791902e12f075c94114bf6 (patch) | |
tree | a227f3ed96a9a22b624d7ab2a63ae171838d79c0 | |
parent | fb01366f82871c4dc669d8af6554297c2064be25 (diff) |
small cleanup in wordWrap
-rw-r--r-- | dw/textblock.cc | 55 |
1 files changed, 27 insertions, 28 deletions
diff --git a/dw/textblock.cc b/dw/textblock.cc index 49369571..0d76bc46 100644 --- a/dw/textblock.cc +++ b/dw/textblock.cc @@ -845,12 +845,12 @@ void Textblock::addLine (int wordInd, bool newPar) /* * This method is called in two cases: (i) when a word is added (by * Dw_page_add_word), and (ii) when a page has to be (partially) - * rewrapped. It does word wrap, and adds new lines, if necesary. + * rewrapped. It does word wrap, and adds new lines, if necessary. */ void Textblock::wordWrap(int wordIndex) { Line *lastLine; - Word *word, *prevWord; + Word *word; int availWidth, lastSpace, leftOffset; bool newLine = false, newPar = false; core::Extremes wordExtremes; @@ -874,34 +874,33 @@ void Textblock::wordWrap(int wordIndex) newPar = true; lastLine = NULL; } else { + Word *prevWord = words->getRef (wordIndex - 1); + lastLine = lines->getRef (lines->size () - 1); - if (lines->size () > 0) { - prevWord = words->getRef (wordIndex - 1); - if (prevWord->content.type == core::Content::BREAK) { - //DBG_MSG (page, "wrap", 0, "after a break"); - /* previous word is a break */ - newLine = true; - newPar = true; - } else if (word->style->whiteSpace - != core::style::WHITE_SPACE_NORMAL) { - //DBG_MSGF (page, "wrap", 0, "no wrap (white_space = %d)", - // word->style->white_space); - newLine = false; - newPar = false; - } else { - if (lastLine->firstWord != wordIndex) { - /* Does new word fit into the last line? */ - //DBG_MSGF (page, "wrap", 0, - // "word %d (%s) fits? (%d + %d + %d <= %d)...", - // word_ind, a_Dw_content_html (&word->content), - // page->lastLine_width, prevWord->orig_space, - // word->size.width, availWidth); - newLine = (lastLineWidth + prevWord->origSpace - + word->size.width > availWidth); - //DBG_MSGF (page, "wrap", 0, "... %s.", - // newLine ? "No" : "Yes"); - } + if (prevWord->content.type == core::Content::BREAK) { + //DBG_MSG (page, "wrap", 0, "after a break"); + /* previous word is a break */ + newLine = true; + newPar = true; + } else if (word->style->whiteSpace + != core::style::WHITE_SPACE_NORMAL) { + //DBG_MSGF (page, "wrap", 0, "no wrap (white_space = %d)", + // word->style->white_space); + newLine = false; + newPar = false; + } else { + if (lastLine->firstWord != wordIndex) { + /* Does new word fit into the last line? */ + //DBG_MSGF (page, "wrap", 0, + // "word %d (%s) fits? (%d + %d + %d <= %d)...", + // word_ind, a_Dw_content_html (&word->content), + // page->lastLine_width, prevWord->orig_space, + // word->size.width, availWidth); + newLine = (lastLineWidth + prevWord->origSpace + + word->size.width > availWidth); + //DBG_MSGF (page, "wrap", 0, "... %s.", + // newLine ? "No" : "Yes"); } } } |