diff options
author | Sebastian Geerken <devnull@localhost> | 2013-10-15 15:36:41 +0200 |
---|---|---|
committer | Sebastian Geerken <devnull@localhost> | 2013-10-15 15:36:41 +0200 |
commit | 78172bb4bd05f70d089a8025cd63fd72c7cccadc (patch) | |
tree | 568bee50a94553ad19afe38bd86d80594fb6280e /dw/textblock_linebreaking.cc | |
parent | 8de011d8d7357509c487b3de5e052dfc52730b2b (diff) |
Constant strechability when line is not justified.
Diffstat (limited to 'dw/textblock_linebreaking.cc')
-rw-r--r-- | dw/textblock_linebreaking.cc | 66 |
1 files changed, 44 insertions, 22 deletions
diff --git a/dw/textblock_linebreaking.cc b/dw/textblock_linebreaking.cc index d1b0df85..33195ab1 100644 --- a/dw/textblock_linebreaking.cc +++ b/dw/textblock_linebreaking.cc @@ -274,9 +274,9 @@ void Textblock::printWord (Word *word) printWordWithFlags (word); printf (" [%d / %d + %d - %d => %d + %d - %d] => ", - word->size.width, word->origSpace, getStretchability(word), - getShrinkability(word), word->totalWidth, word->totalStretchability, - word->totalShrinkability); + word->size.width, word->origSpace, getSpaceStretchability(word), + getSpaceShrinkability(word), word->totalWidth, + word->totalStretchability, word->totalShrinkability); word->badnessAndPenalty.print (); } @@ -291,18 +291,19 @@ void Textblock::justifyLine (Line *line, int diff) * values. */ if (diff > 0) { - int stretchabilitySum = 0; + int spaceStretchabilitySum = 0; for (int i = line->firstWord; i < line->lastWord; i++) - stretchabilitySum += getStretchability(words->getRef(i)); + spaceStretchabilitySum += getSpaceStretchability(words->getRef(i)); - if (stretchabilitySum > 0) { - int stretchabilityCum = 0; + if (spaceStretchabilitySum > 0) { + int spaceStretchabilityCum = 0; int spaceDiffCum = 0; for (int i = line->firstWord; i < line->lastWord; i++) { Word *word = words->getRef (i); - stretchabilityCum += getStretchability(word); + spaceStretchabilityCum += getSpaceStretchability(word); int spaceDiff = - stretchabilityCum * diff / stretchabilitySum - spaceDiffCum; + spaceStretchabilityCum * diff / spaceStretchabilitySum + - spaceDiffCum; spaceDiffCum += spaceDiff; PRINTF (" %d (of %d): diff = %d\n", i, words->size (), @@ -312,18 +313,19 @@ void Textblock::justifyLine (Line *line, int diff) } } } else if (diff < 0) { - int shrinkabilitySum = 0; + int spaceShrinkabilitySum = 0; for (int i = line->firstWord; i < line->lastWord; i++) - shrinkabilitySum += getShrinkability(words->getRef(i)); + spaceShrinkabilitySum += getSpaceShrinkability(words->getRef(i)); - if (shrinkabilitySum > 0) { - int shrinkabilityCum = 0; + if (spaceShrinkabilitySum > 0) { + int spaceShrinkabilityCum = 0; int spaceDiffCum = 0; for (int i = line->firstWord; i < line->lastWord; i++) { Word *word = words->getRef (i); - shrinkabilityCum += getShrinkability(word); + spaceShrinkabilityCum += getSpaceShrinkability(word); int spaceDiff = - shrinkabilityCum * diff / shrinkabilitySum - spaceDiffCum; + spaceShrinkabilityCum * diff / spaceShrinkabilitySum + - spaceDiffCum; spaceDiffCum += spaceDiff; word->effSpace = word->origSpace + spaceDiff; @@ -1034,8 +1036,8 @@ void Textblock::accumulateWordData (int wordIndex) 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; + word->totalStretchability = getLineStretchability (word); + word->totalShrinkability = getLineShrinkability (word); } else { Word *prevWord = words->getRef (wordIndex - 1); @@ -1043,9 +1045,9 @@ void Textblock::accumulateWordData (int wordIndex) + prevWord->origSpace - prevWord->hyphenWidth + word->size.width + word->hyphenWidth; word->totalStretchability = - prevWord->totalStretchability + getStretchability(prevWord); + prevWord->totalStretchability + getSpaceStretchability(prevWord); word->totalShrinkability = - prevWord->totalShrinkability + getShrinkability(prevWord); + prevWord->totalShrinkability + getSpaceShrinkability(prevWord); } word->badnessAndPenalty.calcBadness (word->totalWidth, availWidth, @@ -1261,7 +1263,7 @@ void Textblock::removeTemporaryLines () lines->setSize (nonTemporaryLines); } -int Textblock::getShrinkability(struct Word *word) +int Textblock::getSpaceShrinkability(struct Word *word) { if (word->spaceStyle->textAlign == core::style::TEXT_ALIGN_JUSTIFY) return word->origSpace / 3; @@ -1269,9 +1271,29 @@ int Textblock::getShrinkability(struct Word *word) return 0; } -int Textblock::getStretchability(struct Word *word) +int Textblock::getSpaceStretchability(struct Word *word) { - return word->origSpace / 2; + if (word->spaceStyle->textAlign == core::style::TEXT_ALIGN_JUSTIFY) + return word->origSpace / 2; + else + return 0; + + // Alternative: return word->origSpace / 2; +} + +int Textblock::getLineShrinkability(struct Word *someWord) +{ + return 0; +} + +int Textblock::getLineStretchability(struct Word *someWord) +{ + if (someWord->spaceStyle->textAlign == core::style::TEXT_ALIGN_JUSTIFY) + return 0; + else + return 3 * someWord->origSpace; + + // Alternative: return 0; } } // namespace dw |