From 33238ea2c63b372ee8795eaafbfc5a859a778f8d Mon Sep 17 00:00:00 2001 From: Zhang Hao Date: Wed, 8 Sep 2021 17:14:46 +0800 Subject: Fix QTextEdit cursor rectangle vertical positioning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When there are characters with different pointsize in QScriptLine, the value of si.descent is less than sl.descent, which will cause the y value of the cursor rectangle to be too large. If si.descent is less than sl.descent, the height of the cursor rectangle is equal to base plus si.descent. Amends e99a883bd382ca950192bd66cafb2a1de6394ce7 Fixes: QTBUG-96288 Done-with: Tor Arne Vestbø Pick-to: 6.1 6.2 Change-Id: I4a8566b32cfa75d8ca1a584f5e8e577c5c9caf0d Reviewed-by: Volker Hilsheimer --- src/gui/text/qtextlayout.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/gui/text/qtextlayout.cpp b/src/gui/text/qtextlayout.cpp index 70e6043231..ad5e827bdd 100644 --- a/src/gui/text/qtextlayout.cpp +++ b/src/gui/text/qtextlayout.cpp @@ -1289,13 +1289,16 @@ void QTextLayout::drawCursor(QPainter *p, const QPointF &pos, int cursorPosition QFixed base = sl.base(); QFixed descent = sl.descent; + QFixed cursorDescent = descent; bool rightToLeft = d->isRightToLeft(); if (itm >= 0) { const QScriptItem &si = d->layoutData->items.at(itm); if (si.ascent >= 0) base = si.ascent; - if (si.descent >= 0) + if (si.descent == 0) descent = si.descent; + else if (si.descent > 0 && si.descent < descent) + cursorDescent = si.descent; rightToLeft = si.analysis.bidiLevel % 2; } qreal y = position.y() + (sl.y + sl.base() + sl.descent - base - descent).toReal(); @@ -1306,7 +1309,7 @@ void QTextLayout::drawCursor(QPainter *p, const QPointF &pos, int cursorPosition QPainter::CompositionMode origCompositionMode = p->compositionMode(); if (p->paintEngine()->hasFeature(QPaintEngine::RasterOpModes)) p->setCompositionMode(QPainter::RasterOp_NotDestination); - p->fillRect(QRectF(x, y, qreal(width), (base + descent).toReal()), p->pen().brush()); + p->fillRect(QRectF(x, y, qreal(width), (base + cursorDescent).toReal()), p->pen().brush()); p->setCompositionMode(origCompositionMode); if (toggleAntialiasing) p->setRenderHint(QPainter::Antialiasing, false); -- cgit v1.2.3