changeset 2770:b73d5f7cf8a3

compute stretchability and shrinkability dynamically Together with the removal of another unused field this reduces the size of struct Word by 8 bytes.
author Johannes Hofmann <Johannes.Hofmann@gmx.de>
date Sat, 12 Jan 2013 19:14:49 +0100
parents 583a9090e365
children fb399dcc5866
files dw/textblock.cc dw/textblock.hh dw/textblock_linebreaking.cc
diffstat 3 files changed, 24 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/dw/textblock.cc	Fri Jan 11 17:08:01 2013 -0300
+++ b/dw/textblock.cc	Sat Jan 12 19:14:49 2013 +0100
@@ -1325,8 +1325,7 @@
    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 @@
       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);
--- a/dw/textblock.hh	Fri Jan 11 17:08:01 2013 -0300
+++ b/dw/textblock.hh	Sat Jan 12 19:14:49 2013 +0100
@@ -315,7 +315,6 @@
       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 @@
                           * "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 @@
    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);
--- a/dw/textblock_linebreaking.cc	Fri Jan 11 17:08:01 2013 -0300
+++ b/dw/textblock_linebreaking.cc	Sat Jan 12 19:14:49 2013 +0100
@@ -250,8 +250,8 @@
    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 @@
    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 @@
    } 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 @@
          + 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 @@
    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