diff options
author | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2013-01-12 19:14:49 +0100 |
---|---|---|
committer | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2013-01-12 19:14:49 +0100 |
commit | 69666a2dafc8a00e5029f4b671ed94d5be38e109 (patch) | |
tree | b4a11a8877c9743db004c9e2b740c9ffd5cf0c36 /dw/textblock_linebreaking.cc | |
parent | e0d4ebb62c7fba10aeb4490ead349c71aa1cee14 (diff) |
compute stretchability and shrinkability dynamically
Together with the removal of another unused field
this reduces the size of struct Word by 8 bytes.
Diffstat (limited to 'dw/textblock_linebreaking.cc')
-rw-r--r-- | dw/textblock_linebreaking.cc | 29 |
1 files changed, 21 insertions, 8 deletions
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 |