From a39810a9c51333bac6f71972b218c7d61fcbc91f Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 8 Jan 2016 11:25:50 +0800 Subject: [PATCH] text render fixed when having text blocks that contain only spaces --- Telegram/SourceFiles/gui/text.cpp | 47 +++++++++++++++---------------- Telegram/SourceFiles/history.cpp | 2 +- 2 files changed, 23 insertions(+), 26 deletions(-) diff --git a/Telegram/SourceFiles/gui/text.cpp b/Telegram/SourceFiles/gui/text.cpp index ac47b58e4d..328762ab26 100644 --- a/Telegram/SourceFiles/gui/text.cpp +++ b/Telegram/SourceFiles/gui/text.cpp @@ -1111,6 +1111,15 @@ public: if (_btype == TextBlockTText) { TextBlock *t = static_cast(b); + if (t->_words.isEmpty()) { // no words in this block, spaces only => layout this block in the same line + last_rPadding += lpadding; + + _lineHeight = qMax(_lineHeight, blockHeight); + + longWordLine = false; + continue; + } + QFixed f_wLeft = _wLeft; // vars for saving state of the last word start int32 f_lineHeight = _lineHeight; // f points to the last word-start element of t->_words for (TextBlock::TextWords::const_iterator j = t->_words.cbegin(), en = t->_words.cend(), f = j; j != en; ++j) { @@ -1166,28 +1175,6 @@ public: f_wLeft = _wLeft; f_lineHeight = _lineHeight; } - if (lpadding > 0) { // no words in this block, spaces only - int32 elidedLineHeight = qMax(_lineHeight, blockHeight); - bool elidedLine = _elideLast && (_y + elidedLineHeight >= _yToElide); - if (elidedLine) { - _lineHeight = elidedLineHeight; - } - ushort nextStart = _blockEnd(_t, i, e); - if (!drawLine(nextStart, i + 1, e)) return; - _y += _lineHeight; - _lineHeight = qMax(0, blockHeight); - _lineStart = nextStart; - _lineStartBlock = blockIndex + 1; - - last_rBearing = _rb; - last_rPadding = b->rpadding(); - _wLeft = _w; - if (_elideLast && _elideRemoveFromEnd > 0 && (_y + blockHeight >= _yToElide)) { - _wLeft -= _elideRemoveFromEnd; - } - - longWordLine = true; - } continue; } @@ -2762,8 +2749,8 @@ int32 Text::countHeight(int32 w) const { longWordLine = true; continue; } - widthLeft -= b->f_lpadding(); - QFixed newWidthLeft = widthLeft - last_rBearing - (last_rPadding + b->f_width() - _rb); + QFixed lpadding = b->f_lpadding(); + QFixed newWidthLeft = widthLeft - lpadding - last_rBearing - (last_rPadding + b->f_width() - _rb); if (newWidthLeft >= 0) { last_rBearing = _rb; last_rPadding = b->f_rpadding(); @@ -2777,13 +2764,23 @@ int32 Text::countHeight(int32 w) const { if (_btype == TextBlockTText) { TextBlock *t = static_cast(b); + if (t->_words.isEmpty()) { // no words in this block, spaces only => layout this block in the same line + last_rPadding += lpadding; + + lineHeight = qMax(lineHeight, blockHeight); + + longWordLine = false; + continue; + } + QFixed f_wLeft = widthLeft; int32 f_lineHeight = lineHeight; for (TextBlock::TextWords::const_iterator j = t->_words.cbegin(), e = t->_words.cend(), f = j; j != e; ++j) { bool wordEndsHere = (j->width >= 0); QFixed j_width = wordEndsHere ? j->width : -j->width; - QFixed newWidthLeft = widthLeft - last_rBearing - (last_rPadding + j_width - j->f_rbearing()); + QFixed newWidthLeft = widthLeft - lpadding - last_rBearing - (last_rPadding + j_width - j->f_rbearing()); + lpadding = 0; if (newWidthLeft >= 0) { last_rBearing = j->f_rbearing(); last_rPadding = j->rpadding; diff --git a/Telegram/SourceFiles/history.cpp b/Telegram/SourceFiles/history.cpp index 2cc47fda1c..333ca80b0d 100644 --- a/Telegram/SourceFiles/history.cpp +++ b/Telegram/SourceFiles/history.cpp @@ -6542,7 +6542,7 @@ void HistoryMessage::drawMessageText(Painter &p, QRect trect, uint32 selection) p.setFont(st::msgFont); uint16 selectedFrom = (selection == FullSelection) ? 0 : (selection >> 16) & 0xFFFF; uint16 selectedTo = (selection == FullSelection) ? 0 : selection & 0xFFFF; - _text.draw(p, trect.x(), trect.y(), trect.width(), Qt::AlignLeft, 0, -1, selectedFrom, selectedTo); + _text.draw(p, trect.x(), trect.y(), trect.width(), style::al_left, 0, -1, selectedFrom, selectedTo); } void HistoryMessage::destroy() {