From fb230a443e15b4e410ab4682dd83f549f90425a3 Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 28 Feb 2017 19:38:23 +0300 Subject: [PATCH] Fixed text with right bearings display. Sometimes Text::_maxWidth was not accumulated correctly because the intermediate text blocks had negative right bearing larger than the whole width of the next text block, so the final computed line width was less than some intermediate value. Now we accumulate the _maxWidth value after each block making this value correct. --- Telegram/SourceFiles/ui/text/text.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/Telegram/SourceFiles/ui/text/text.cpp b/Telegram/SourceFiles/ui/text/text.cpp index 42b9a8da1..bf56fc863 100644 --- a/Telegram/SourceFiles/ui/text/text.cpp +++ b/Telegram/SourceFiles/ui/text/text.cpp @@ -2498,15 +2498,23 @@ void Text::recountNaturalSize(bool initial, Qt::LayoutDirection optionsDir) { lineHeight = 0; last_rBearing = b->f_rbearing(); last_rPadding = b->f_rpadding(); - if (_maxWidth < _width) { - _maxWidth = _width; - } + + accumulate_max(_maxWidth, _width); _width = (b->f_width() - last_rBearing); continue; } auto b__f_rbearing = b->f_rbearing(); // cache + // We need to accumulate max width after each block, because + // some blocks have width less than -1 * previous right bearing. + // In that cases the _width gets _smaller_ after moving to the next block. + // + // But when we layout block and we're sure that _maxWidth is enough + // for all the blocks to fit on their line we check each block, even the + // intermediate one with a large negative right bearing. + accumulate_max(_maxWidth, _width); + _width += last_rBearing + (last_rPadding + b->f_width() - b__f_rbearing); lineHeight = qMax(lineHeight, blockHeight); @@ -2528,9 +2536,7 @@ void Text::recountNaturalSize(bool initial, Qt::LayoutDirection optionsDir) { if (_width > 0) { if (!lineHeight) lineHeight = countBlockHeight(_blocks.back(), _st); _minHeight += lineHeight; - if (_maxWidth < _width) { - _maxWidth = _width; - } + accumulate_max(_maxWidth, _width); } }