Fix QTextEdit cursor rectangle vertical positioning

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 e99a883bd3

Fixes: QTBUG-96288
Done-with: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Pick-to: 6.1 6.2
Change-Id: I4a8566b32cfa75d8ca1a584f5e8e577c5c9caf0d
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
Zhang Hao 2021-09-08 17:14:46 +08:00
parent 1c6d6b7c0d
commit 33238ea2c6

View File

@ -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);