diff options
-rw-r--r-- | dw/textblock.cc | 8 | ||||
-rw-r--r-- | dw/textblock.hh | 4 | ||||
-rw-r--r-- | dw/textblock_linebreaking.cc | 29 |
3 files changed, 24 insertions, 17 deletions
diff --git a/dw/textblock.cc b/dw/textblock.cc index 8d0e0bcb..068a7c0d 100644 --- a/dw/textblock.cc +++ b/dw/textblock.cc @@ -1325,8 +1325,7 @@ void Textblock::fillWord (Word *word, int width, int ascent, int descent, word->size.width = width; word->size.ascent = ascent; word->size.descent = descent; - word->origSpace = word->effSpace = word->stretchability = - word->shrinkability = 0; + word->origSpace = word->effSpace = 0; word->hyphenWidth = 0; word->badnessAndPenalty.setPenalty (PENALTY_PROHIBIT_BREAK); word->content.space = false; @@ -1817,11 +1816,6 @@ void Textblock::fillSpace (Word *word, core::style::Style *style) word->content.space = true; word->effSpace = word->origSpace = style->font->spaceWidth + style->wordSpacing; - word->stretchability = word->origSpace / 2; - if(style->textAlign == core::style::TEXT_ALIGN_JUSTIFY) - word->shrinkability = word->origSpace / 3; - else - word->shrinkability = 0; //DBG_OBJ_ARRSET_NUM (this, "words.%d.origSpace", wordIndex, // word->origSpace); diff --git a/dw/textblock.hh b/dw/textblock.hh index 39088da6..d5b64e42 100644 --- a/dw/textblock.hh +++ b/dw/textblock.hh @@ -315,7 +315,6 @@ protected: core::Requisition size; /* Space after the word, only if it's not a break: */ short origSpace; /* from font, set by addSpace */ - short stretchability, shrinkability; short effSpace; /* effective space, set by wordWrap, * used for drawing etc. */ short hyphenWidth; /* Additional width, when a word is part @@ -325,7 +324,6 @@ protected: * "hyphenWidth > 0" is also used to decide * whether to draw a hyphen. */ short flags; - short penaltyIndex; core::Content content; // accumulated values, relative to the beginning of the line @@ -561,6 +559,8 @@ protected: void handleWordExtremes (int wordIndex); void correctLastWordExtremes (); + static int getShrinkability(struct Word *word); + static int getStretchability(struct Word *word); int hyphenateWord (int wordIndex); void accumulateWordForLine (int lineIndex, int wordIndex); void accumulateWordData (int wordIndex); diff --git a/dw/textblock_linebreaking.cc b/dw/textblock_linebreaking.cc index 47c7fa00..35273565 100644 --- a/dw/textblock_linebreaking.cc +++ b/dw/textblock_linebreaking.cc @@ -250,8 +250,8 @@ void Textblock::printWord (Word *word) printWordWithFlags (word); printf (" [%d / %d + %d - %d => %d + %d - %d] => ", - word->size.width, word->origSpace, word->stretchability, - word->shrinkability, word->totalWidth, word->totalStretchability, + word->size.width, word->origSpace, getStretchability(word), + getShrinkability(word), word->totalWidth, word->totalStretchability, word->totalShrinkability); word->badnessAndPenalty.print (); } @@ -269,14 +269,14 @@ void Textblock::justifyLine (Line *line, int diff) if (diff > 0) { int stretchabilitySum = 0; for (int i = line->firstWord; i < line->lastWord; i++) - stretchabilitySum += words->getRef(i)->stretchability; + stretchabilitySum += getStretchability(words->getRef(i)); if (stretchabilitySum > 0) { int stretchabilityCum = 0; int spaceDiffCum = 0; for (int i = line->firstWord; i < line->lastWord; i++) { Word *word = words->getRef (i); - stretchabilityCum += word->stretchability; + stretchabilityCum += getStretchability(word); int spaceDiff = stretchabilityCum * diff / stretchabilitySum - spaceDiffCum; spaceDiffCum += spaceDiff; @@ -290,14 +290,14 @@ void Textblock::justifyLine (Line *line, int diff) } else if (diff < 0) { int shrinkabilitySum = 0; for (int i = line->firstWord; i < line->lastWord; i++) - shrinkabilitySum += words->getRef(i)->shrinkability; + shrinkabilitySum += getShrinkability(words->getRef(i)); if (shrinkabilitySum > 0) { int shrinkabilityCum = 0; int spaceDiffCum = 0; for (int i = line->firstWord; i < line->lastWord; i++) { Word *word = words->getRef (i); - shrinkabilityCum += word->shrinkability; + shrinkabilityCum += getShrinkability(word); int spaceDiff = shrinkabilityCum * diff / shrinkabilitySum - spaceDiffCum; spaceDiffCum += spaceDiff; @@ -929,9 +929,9 @@ void Textblock::accumulateWordData (int wordIndex) + prevWord->origSpace - prevWord->hyphenWidth + word->size.width + word->hyphenWidth; word->totalStretchability = - prevWord->totalStretchability + prevWord->stretchability; + prevWord->totalStretchability + getStretchability(prevWord); word->totalShrinkability = - prevWord->totalShrinkability + prevWord->shrinkability; + prevWord->totalShrinkability + getShrinkability(prevWord); } word->badnessAndPenalty.calcBadness (word->totalWidth, availWidth, @@ -1147,4 +1147,17 @@ void Textblock::removeTemporaryLines () lines->setSize (nonTemporaryLines); } +int Textblock::getShrinkability(struct Word *word) +{ + if (word->spaceStyle->textAlign == core::style::TEXT_ALIGN_JUSTIFY) + return word->origSpace / 3; + else + return 0; +} + +int Textblock::getStretchability(struct Word *word) +{ + return word->origSpace / 2; +} + } // namespace dw |