diff options
author | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com> | 2010-08-09 08:31:16 (GMT) |
---|---|---|
committer | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com> | 2010-08-09 08:35:56 (GMT) |
commit | c5fa9eb1cb02d979502e2c9918d752c6708fb406 (patch) | |
tree | 4b35490fde8398e9f1c4608f4e1f38adeb5e155a /src/gui | |
parent | cfe96b7c99cb12a666111c7861aba74d535adc89 (diff) | |
download | Qt-c5fa9eb1cb02d979502e2c9918d752c6708fb406.zip Qt-c5fa9eb1cb02d979502e2c9918d752c6708fb406.tar.gz Qt-c5fa9eb1cb02d979502e2c9918d752c6708fb406.tar.bz2 |
Fix scrollbar randomly popping up in QPlainTextEdit
When a line break was detected, we would retain the value of the
right bearing for the character after the break instead of resetting it
to the right bearing of the previous value. This could in some cases
cause the bounding rect of the text to be wrong, and could cause
unnecessary horizontal scrollbars to pop up. It was especially visible
when using WrapAnywhere. Visible e.g. in the compile output in Creator.
Done-by: mae
Reviewed-by: Eskil
Reviewed-by: Lars
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/text/qtextlayout.cpp | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/src/gui/text/qtextlayout.cpp b/src/gui/text/qtextlayout.cpp index 5a11c87..da43913 100644 --- a/src/gui/text/qtextlayout.cpp +++ b/src/gui/text/qtextlayout.cpp @@ -1709,14 +1709,18 @@ namespace { return glyphs.glyphs[logClusters[currentPosition - 1]]; } + inline void adjustRightBearing(glyph_t glyph) + { + qreal rb; + fontEngine->getGlyphBearings(glyph, 0, &rb); + rightBearing = qMin(QFixed(), QFixed::fromReal(rb)); + } + inline void adjustRightBearing() { if (currentPosition <= 0) return; - - qreal rb; - fontEngine->getGlyphBearings(currentGlyph(), 0, &rb); - rightBearing = qMin(QFixed(), QFixed::fromReal(rb)); + adjustRightBearing(currentGlyph()); } inline void resetRightBearing() @@ -1901,6 +1905,9 @@ void QTextLine::layout_helper(int maxGlyphs) } else { lbh.whiteSpaceOrObject = false; bool sb_or_ws = false; + glyph_t previousGlyph = 0; + if (lbh.currentPosition > 0 && lbh.logClusters[lbh.currentPosition - 1] <lbh.glyphs.numGlyphs) + previousGlyph = lbh.currentGlyph(); // needed to calculate right bearing later do { addNextCluster(lbh.currentPosition, end, lbh.tmpData, lbh.glyphCount, current, lbh.logClusters, lbh.glyphs); @@ -1944,9 +1951,15 @@ void QTextLine::layout_helper(int maxGlyphs) // We ignore the right bearing if the minimum negative bearing is too little to // expand the text beyond the edge. if (sb_or_ws|breakany) { + QFixed rightBearing = lbh.rightBearing; // store previous right bearing if (lbh.calculateNewWidth(line) - lbh.minimumRightBearing > line.width) lbh.adjustRightBearing(); if (lbh.checkFullOtherwiseExtend(line)) { + // we are too wide, fix right bearing + if (rightBearing <= 0) + lbh.rightBearing = rightBearing; // take from cache + else if (previousGlyph > 0) + lbh.adjustRightBearing(previousGlyph); if (!breakany) { line.textWidth += lbh.softHyphenWidth; } |