diff options
-rw-r--r-- | dw/textblock.cc | 36 | ||||
-rw-r--r-- | dw/textblock.hh | 6 | ||||
-rw-r--r-- | dw/textblock_linebreaking.cc | 43 |
3 files changed, 44 insertions, 41 deletions
diff --git a/dw/textblock.cc b/dw/textblock.cc index c1308b0a..7a379a08 100644 --- a/dw/textblock.cc +++ b/dw/textblock.cc @@ -267,7 +267,7 @@ Textblock::Textblock (bool limitTextWidth) // random value lineBreakWidth = 100; - DBG_OBJ_SET_NUM ("lineBreakWidth", availWidth); + DBG_OBJ_SET_NUM ("lineBreakWidth", lineBreakWidth); verticalOffset = 0; DBG_OBJ_SET_NUM ("verticalOffset", verticalOffset); @@ -388,13 +388,14 @@ void Textblock::sizeRequestImpl (core::Requisition *requisition) } DBG_OBJ_MSGF ("resize", 1, - "before considering availWidth (= %d): %d * (%d + %d)", - availWidth, requisition->width, requisition->ascent, + "before considering lineBreakWidth (= %d): %d * (%d + %d)", + lineBreakWidth, requisition->width, requisition->ascent, requisition->descent); + // TODO The following will not be necessary anymore: if (requisition->width < lineBreakWidth) { requisition->width = lineBreakWidth; - DBG_OBJ_MSGF ("resize", 1, "adjusting to availWidth => %d", + DBG_OBJ_MSGF ("resize", 1, "adjusting to lineBreakWidth => %d", requisition->width); } @@ -777,7 +778,7 @@ void Textblock::setWidth (int width) DBG_OBJ_MSG_START (); lineBreakWidth = width; - DBG_OBJ_SET_NUM ("lineBreakWidth", availWidth); + DBG_OBJ_SET_NUM ("lineBreakWidth", lineBreakWidth); queueResize (OutOfFlowMgr::createRefNormalFlow (0), false); mustQueueResize = false; redrawY = 0; @@ -1050,32 +1051,33 @@ void Textblock::calcWidgetSize (core::Widget *widget, core::Requisition *size) DBG_OBJ_MSGF ("resize", 0, "<b>calcWidgetSize</b> (%p, ...)", widget); core::Requisition requisition; - int availWidth; + int lineBreakWidth; core::style::Style *wstyle = widget->getStyle(); /* We ignore line1_offset[_eff]. */ - availWidth = + lineBreakWidth = this->lineBreakWidth - getStyle()->boxDiffWidth () - innerPadding; if (widget->usesHints ()) { - // This is a simplified version of calcAvailWidth (see there for - // more details). Until recently, the *attribute* availWidth was + // This is a simplified version of calcLineBreakWidth (see there for + // more details). Until recently, the *attribute* lineBreakWidth was // used, widthout any corrections. To limit the damage, only // includde left and right border (by floats), until the Great // Redesign Of Widget Sizes (GROWS). - int corrAvailWidth; + int corrLineBreakWidth; // Textblocks keep track of borders themselves, so they get the - // total available width. (Should once replaced by something + // total line break width. (Should once replaced by something // like OOFAware.) if (widget->instanceOf (Textblock::CLASS_ID)) - corrAvailWidth = availWidth; + corrLineBreakWidth = lineBreakWidth; else - corrAvailWidth = - misc::max (availWidth - (newLineLeftBorder + newLineRightBorder), + corrLineBreakWidth = + misc::max (lineBreakWidth + - (newLineLeftBorder + newLineRightBorder), 0); - DBG_OBJ_MSGF ("resize", 1, "setting hint: %d", corrAvailWidth); - widget->setWidth (corrAvailWidth); + DBG_OBJ_MSGF ("resize", 1, "setting hint: %d", corrLineBreakWidth); + widget->setWidth (corrLineBreakWidth); widget->sizeRequest (size); DBG_OBJ_MSGF ("resize", 1, "sizeRequest => %d * (%d + %d)", size->width, size->ascent, size->descent); @@ -1097,7 +1099,7 @@ void Textblock::calcWidgetSize (core::Widget *widget, core::Requisition *size) + wstyle->boxDiffWidth (); else size->width = - core::style::multiplyWithPerLength (availWidth, wstyle->width); + core::style::multiplyWithPerLength (lineBreakWidth, wstyle->width); if (wstyle->height == core::style::LENGTH_AUTO) { size->ascent = requisition.ascent; diff --git a/dw/textblock.hh b/dw/textblock.hh index 37786a1e..80590c96 100644 --- a/dw/textblock.hh +++ b/dw/textblock.hh @@ -130,7 +130,7 @@ namespace dw { * widget: * * <ul> - * <li> The available size of the widget has changed, e.g., because the + * <li> The line break size of the widget has changed, e.g., because the * user has changed the size of the browser window. In this case, * it is necessary to rewrap all the lines. * @@ -489,7 +489,7 @@ protected: * (which is used by DwTable!), and * (ii) line1_offset is ignored (line1_offset_eff is set to 0), * when line1_offset plus the width of the first word is - * greater than the the available witdh. + * greater than the the line break witdh. * * \todo Eliminate all these ad-hoc features by a new, simpler and * more elegant design. ;-) @@ -737,7 +737,7 @@ protected: void moveWordIndices (int wordIndex, int num, int *addIndex1 = NULL); void accumulateWordForLine (int lineIndex, int wordIndex); void accumulateWordData (int wordIndex); - int calcAvailWidth (int lineIndex); + int calcLineBreakWidth (int lineIndex); void initLine1Offset (int wordIndex); void alignLine (int lineIndex); diff --git a/dw/textblock_linebreaking.cc b/dw/textblock_linebreaking.cc index 7b9110ee..c7c30aee 100644 --- a/dw/textblock_linebreaking.cc +++ b/dw/textblock_linebreaking.cc @@ -92,7 +92,7 @@ void Textblock::BadnessAndPenalty::calcBadness (int totalWidth, int idealWidth, badness = ratio * ratio * ratio; } } - } else { // if (totalWidth > availWidth) + } else { // if (totalWidth > idealWidth) if (totalShrinkability == 0) badnessState = TOO_TIGHT; else { @@ -637,7 +637,7 @@ int Textblock::wrapWordInFlow (int wordIndex, bool wrapAll) // be left empty. // (In other cases, lines are never left empty, even if this means - // that the contents is wider than the available witdh. Leaving + // that the contents is wider than the line break width. Leaving // lines empty does not make sense without floats, since there will // be no possibility with more space anymore.) @@ -1526,12 +1526,13 @@ void Textblock::accumulateWordData (int wordIndex) Word *word = words->getRef (wordIndex); DBG_OBJ_MSGF ("construct.word.accum", 2, "lineIndex = %d", lineIndex); - int availWidth = calcAvailWidth (lineIndex); + int lineBreakWidth = calcLineBreakWidth (lineIndex); DBG_OBJ_MSGF ("construct.word.accum", 2, - "(%s existing line %d starts with word %d; availWidth = %d)", + "(%s existing line %d starts with word %d; " + "lineBreakWidth = %d)", lineIndex < lines->size () ? "already" : "not yet", - lineIndex, firstWordOfLine, availWidth); + lineIndex, firstWordOfLine, lineBreakWidth); if (wordIndex == firstWordOfLine) { // first word of the (not neccessarily yet existing) line @@ -1582,7 +1583,7 @@ void Textblock::accumulateWordData (int wordIndex) "totalShrinkability = %d + ... = %d", word->totalSpaceShrinkability, totalShrinkability); - word->badnessAndPenalty.calcBadness (word->totalWidth, availWidth, + word->badnessAndPenalty.calcBadness (word->totalWidth, lineBreakWidth, totalStretchability, totalShrinkability); @@ -1595,22 +1596,22 @@ void Textblock::accumulateWordData (int wordIndex) DBG_OBJ_MSG_END (); } -int Textblock::calcAvailWidth (int lineIndex) +int Textblock::calcLineBreakWidth (int lineIndex) { DBG_OBJ_MSGF ("construct.word.width", 1, - "<b>calcAvailWidth</b> (%d <i>of %d</i>)", + "<b>calcLineBreakWidth</b> (%d <i>of %d</i>)", lineIndex, lines->size()); DBG_OBJ_MSG_START (); - int availWidth = this->lineBreakWidth - innerPadding; + int lineBreakWidth = this->lineBreakWidth - innerPadding; if (limitTextWidth && layout->getUsesViewport () && // margin/border/padding will be subtracted later, via OOFM. - availWidth - getStyle()->boxDiffWidth() + lineBreakWidth - getStyle()->boxDiffWidth() > layout->getWidthViewport () - 10) - availWidth = layout->getWidthViewport () - 10; + lineBreakWidth = layout->getWidthViewport () - 10; if (lineIndex == 0) - availWidth -= line1OffsetEff; + lineBreakWidth -= line1OffsetEff; int leftBorder, rightBorder; if (mustBorderBeRegarded (lineIndex)) { @@ -1622,14 +1623,14 @@ int Textblock::calcAvailWidth (int lineIndex) leftBorder = misc::max (leftBorder, getStyle()->boxOffsetX()); rightBorder = misc::max (rightBorder, getStyle()->boxRestWidth()); - availWidth -= (leftBorder + rightBorder); + lineBreakWidth -= (leftBorder + rightBorder); DBG_OBJ_MSGF ("construct.word.width", 2, "=> %d - %d - (%d + %d) = %d\n", - this->availWidth, innerPadding, leftBorder, rightBorder, - availWidth); + this->lineBreakWidth, innerPadding, leftBorder, rightBorder, + lineBreakWidth); DBG_OBJ_MSG_END (); - return availWidth; + return lineBreakWidth; } void Textblock::initLine1Offset (int wordIndex) @@ -1671,7 +1672,7 @@ void Textblock::alignLine (int lineIndex) DBG_OBJ_MSG_START (); Line *line = lines->getRef (lineIndex); - int availWidth = calcAvailWidth (lineIndex); + int lineBreakWidth = calcLineBreakWidth (lineIndex); if (line->firstWord <= line->lastWord) { Word *firstWord = words->getRef (line->firstWord); Word *lastWord = words->getRef (line->lastWord); @@ -1704,18 +1705,18 @@ void Textblock::alignLine (int lineIndex) // when the line would be shrunken otherwise. (This solution is // far from perfect, but a better solution would make changes in // the line breaking algorithm necessary.) - availWidth < lastWord->totalWidth) - justifyLine (line, availWidth - lastWord->totalWidth); + lineBreakWidth < lastWord->totalWidth) + justifyLine (line, lineBreakWidth - lastWord->totalWidth); break; case core::style::TEXT_ALIGN_RIGHT: DBG_OBJ_MSG ("construct.line", 1, "first word has 'text-align: right'"); - line->leftOffset = availWidth - lastWord->totalWidth; + line->leftOffset = lineBreakWidth - lastWord->totalWidth; break; case core::style::TEXT_ALIGN_CENTER: DBG_OBJ_MSG ("construct.line", 1, "first word has 'text-align: center'"); - line->leftOffset = (availWidth - lastWord->totalWidth) / 2; + line->leftOffset = (lineBreakWidth - lastWord->totalWidth) / 2; break; default: /* compiler happiness */ |