aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTor Arne Vestbø <[email protected]>2025-04-07 14:58:09 +0200
committerTor Arne Vestbø <[email protected]>2025-04-24 14:12:54 +0200
commit9a5e2a72a1b696dbd935c6dd656c1520dc14952a (patch)
treef553f11013b677ea87ad6fed1f24dea9be4085dd /src
parentafc47073617063daec9e961a8f582044c131fa6e (diff)
Respect target DPR when drawing text objects in QQuickTextNodeEngine
Instead of passing the DPR through as function arguments to each addFoo function we set the DPR on the QSGInternalTextNode and QQuickTextNodeEngine. We could have solved this by pulling the DPR from the QSGRootNode's renderer, but there might be more than one of them, and we're missing a setDevicePixelRatio in QSGAbstractRenderer (it's only exposed one level above, in QSGRenderer). Pick-to: 6.9 Fixes: QTBUG-127913 Change-Id: I48081d441259f0713cdc5f784eede6777b5fb601 Reviewed-by: Eskil Abrahamsen Blomfeldt <[email protected]>
Diffstat (limited to 'src')
-rw-r--r--src/quick/items/qquicktext.cpp2
-rw-r--r--src/quick/items/qquicktextedit.cpp12
-rw-r--r--src/quick/items/qquicktextnodeengine.cpp5
-rw-r--r--src/quick/items/qquicktextnodeengine_p.h7
-rw-r--r--src/quick/items/qsginternaltextnode.cpp2
-rw-r--r--src/quick/items/qsginternaltextnode_p.h6
6 files changed, 27 insertions, 7 deletions
diff --git a/src/quick/items/qquicktext.cpp b/src/quick/items/qquicktext.cpp
index 549420f72f..59ca657be6 100644
--- a/src/quick/items/qquicktext.cpp
+++ b/src/quick/items/qquicktext.cpp
@@ -2815,6 +2815,8 @@ QSGNode *QQuickText::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *data
node->setStyleColor(QColor::fromRgba(d->styleColor));
node->setLinkColor(QColor::fromRgba(d->linkColor));
+ node->setDevicePixelRatio(d->devicePixelRatio());
+
if (d->richText) {
node->setViewport(clipRect());
const qreal dx = QQuickTextUtil::alignedX(d->layedOutTextRect.width(), d->availableWidth(), effectiveHAlign()) + leftPadding();
diff --git a/src/quick/items/qquicktextedit.cpp b/src/quick/items/qquicktextedit.cpp
index cc843c144e..e6ca6be9cb 100644
--- a/src/quick/items/qquicktextedit.cpp
+++ b/src/quick/items/qquicktextedit.cpp
@@ -2458,12 +2458,13 @@ void QQuickTextEdit::setDocument(QTextDocument *doc)
q_textChanged();
}
-inline void resetEngine(QQuickTextNodeEngine *engine, const QColor& textColor, const QColor& selectedTextColor, const QColor& selectionColor)
+inline void resetEngine(QQuickTextNodeEngine *engine, const QColor& textColor, const QColor& selectedTextColor, const QColor& selectionColor, qreal dpr)
{
*engine = QQuickTextNodeEngine();
engine->setTextColor(textColor);
engine->setSelectedTextColor(selectedTextColor);
engine->setSelectionColor(selectionColor);
+ engine->setDevicePixelRatio(dpr);
}
QSGNode *QQuickTextEdit::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *updatePaintNodeData)
@@ -2500,8 +2501,11 @@ QSGNode *QQuickTextEdit::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *
while (nodeIterator != d->textNodeMap.end() && !nodeIterator->dirty())
++nodeIterator;
+ const auto dpr = window()->effectiveDevicePixelRatio();
QQuickTextNodeEngine engine;
+ engine.setDevicePixelRatio(dpr);
QQuickTextNodeEngine frameDecorationsEngine;
+ frameDecorationsEngine.setDevicePixelRatio(dpr);
if (!oldNode || nodeIterator < d->textNodeMap.end() || d->textNodeMap.isEmpty()) {
@@ -2537,7 +2541,7 @@ QSGNode *QQuickTextEdit::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *
// FIXME: the text decorations could probably be handled separately (only updated for affected textFrames)
rootNode->resetFrameDecorations(d->createTextNode());
- resetEngine(&frameDecorationsEngine, d->color, d->selectedTextColor, d->selectionColor);
+ resetEngine(&frameDecorationsEngine, d->color, d->selectedTextColor, d->selectionColor, dpr);
QSGInternalTextNode *node = nullptr;
@@ -2569,7 +2573,7 @@ QSGNode *QQuickTextEdit::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *
<< "to" << positionToRectangle(textFrame->lastPosition()).bottomRight();
frames.append(textFrame->childFrames());
frameDecorationsEngine.addFrameDecorations(d->document, textFrame);
- resetEngine(&engine, d->color, d->selectedTextColor, d->selectionColor);
+ resetEngine(&engine, d->color, d->selectedTextColor, d->selectionColor, dpr);
if (textFrame->firstPosition() > textFrame->lastPosition()
&& textFrame->frameFormat().position() != QTextFrameFormat::InFlow) {
@@ -2692,7 +2696,7 @@ QSGNode *QQuickTextEdit::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *
d->addCurrentTextNodeToRoot(&engine, rootNode, node, nodeIterator, nodeStart);
if (!createdNodeInView)
node = d->createTextNode();
- resetEngine(&engine, d->color, d->selectedTextColor, d->selectionColor);
+ resetEngine(&engine, d->color, d->selectedTextColor, d->selectionColor, dpr);
nodeStart = block.next().position();
}
++it;
diff --git a/src/quick/items/qquicktextnodeengine.cpp b/src/quick/items/qquicktextnodeengine.cpp
index 34b8ed938c..e1339c1e07 100644
--- a/src/quick/items/qquicktextnodeengine.cpp
+++ b/src/quick/items/qquicktextnodeengine.cpp
@@ -434,11 +434,12 @@ void QQuickTextNodeEngine::addTextObject(const QTextBlock &block, const QPointF
}
if (image.isNull()) {
- image = QImage(size.toSize(), QImage::Format_ARGB32_Premultiplied);
+ image = QImage((size * m_devicePixelRatio).toSize(), QImage::Format_ARGB32_Premultiplied);
+ image.setDevicePixelRatio(m_devicePixelRatio);
image.fill(Qt::transparent);
{
QPainter painter(&image);
- handler->drawObject(&painter, image.rect(), textDocument, pos, format);
+ handler->drawObject(&painter, QRectF({}, size), textDocument, pos, format);
}
}
diff --git a/src/quick/items/qquicktextnodeengine_p.h b/src/quick/items/qquicktextnodeengine_p.h
index f874320eb3..4ff3cdcd1b 100644
--- a/src/quick/items/qquicktextnodeengine_p.h
+++ b/src/quick/items/qquicktextnodeengine_p.h
@@ -189,7 +189,10 @@ public:
m_position = position;
}
-
+ void setDevicePixelRatio(qreal dpr)
+ {
+ m_devicePixelRatio = dpr;
+ }
private:
struct TextDecoration
@@ -231,6 +234,8 @@ private:
QList<TextDecoration> m_lines;
QVector<BinaryTreeNode> m_processedNodes;
+ qreal m_devicePixelRatio = 1.0;
+
bool m_hasSelection : 1;
bool m_hasContents : 1;
friend class QSGInternalTextNode;
diff --git a/src/quick/items/qsginternaltextnode.cpp b/src/quick/items/qsginternaltextnode.cpp
index d72e063187..11a83a6057 100644
--- a/src/quick/items/qsginternaltextnode.cpp
+++ b/src/quick/items/qsginternaltextnode.cpp
@@ -158,6 +158,7 @@ void QSGInternalTextNode::doAddTextDocument(QPointF position, QTextDocument *tex
engine.setSelectionColor(m_selectionColor);
engine.setAnchorColor(m_linkColor);
engine.setPosition(position);
+ engine.setDevicePixelRatio(m_devicePixelRatio);
QList<QTextFrame *> frames;
frames.append(textDocument->rootFrame());
@@ -206,6 +207,7 @@ void QSGInternalTextNode::doAddTextLayout(QPointF position, QTextLayout *textLay
engine.setSelectionColor(m_selectionColor);
engine.setAnchorColor(m_linkColor);
engine.setPosition(position);
+ engine.setDevicePixelRatio(m_devicePixelRatio);
#if QT_CONFIG(im)
int preeditLength = textLayout->preeditAreaText().size();
diff --git a/src/quick/items/qsginternaltextnode_p.h b/src/quick/items/qsginternaltextnode_p.h
index 986a5f8089..a7512021dd 100644
--- a/src/quick/items/qsginternaltextnode_p.h
+++ b/src/quick/items/qsginternaltextnode_p.h
@@ -151,6 +151,11 @@ public:
return m_viewport;
}
+ void setDevicePixelRatio(qreal dpr)
+ {
+ m_devicePixelRatio = dpr;
+ }
+
void setCursor(const QRectF &rect, const QColor &color);
void clearCursor();
@@ -195,6 +200,7 @@ private:
int m_firstLineInViewport = -1;
int m_firstLinePastViewport = -1;
bool m_containsUnscalableGlyphs = false;
+ qreal m_devicePixelRatio = 1.0;
friend class QQuickTextEdit;
friend class QQuickTextEditPrivate;