From 1cc58fdf174656a52603af00cb40478066c5abd4 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Wed, 1 Jun 2011 09:45:55 +0200 Subject: Make QSGTextNode back-end for QML's TextInput and TextEdit Use the general QSGTextNode class as back-end for all text elements in QML to make all text elements look the same and use the same text rasterization back-end. This requires a few rewrites in the text node to support e.g. selections. Crashes seen with threaded renderer in TextEdit and TextInput on Mac are also fixed by this. Reviewed-by: Jiang Jiang Task-number: QTBUG-18019, QTBUG-20017 Change-Id: I4207faf180c83422e5f8b726741321af395bd724 Reviewed-on: http://codereview.qt.nokia.com/2865 Reviewed-by: Eskil Abrahamsen Blomfeldt --- src/declarative/items/qsgtext.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'src/declarative/items/qsgtext.cpp') diff --git a/src/declarative/items/qsgtext.cpp b/src/declarative/items/qsgtext.cpp index d323e3bd54..7e8cf2d099 100644 --- a/src/declarative/items/qsgtext.cpp +++ b/src/declarative/items/qsgtext.cpp @@ -107,7 +107,12 @@ QSGTextPrivate::QSGTextPrivate() richText(false), singleline(false), cacheAllTextAsImage(true), internalWidthUpdate(false), requireImplicitWidth(false), truncated(false), hAlignImplicit(true), rightToLeftText(false), layoutTextElided(false), richTextAsImage(false), textureImageCacheDirty(false), naturalWidth(0), - doc(0), layoutThread(0), nodeType(NodeIsNull) + doc(0), nodeType(NodeIsNull) + +#if defined(Q_OS_MAC) + , layoutThread(0) +#endif + { cacheAllTextAsImage = enableImageCache(); } @@ -291,7 +296,9 @@ void QSGTextPrivate::updateSize() int dy = q->height(); QSize size(0, 0); +#if defined(Q_OS_MAC) layoutThread = QThread::currentThread(); +#endif //setup instance of QTextLayout for all cases other than richtext if (!richText) { @@ -313,6 +320,8 @@ void QSGTextPrivate::updateSize() QTextOption option; option.setAlignment((Qt::Alignment)int(horizontalAlignment | vAlign)); option.setWrapMode(QTextOption::WrapMode(wrapMode)); + if (!cacheAllTextAsImage && !richTextAsImage && !qmlDisableDistanceField()) + option.setUseDesignMetrics(true); doc->setDefaultTextOption(option); if (requireImplicitWidth && q->widthValid()) { doc->setTextWidth(-1); @@ -376,6 +385,8 @@ QRect QSGTextPrivate::setupTextLayout() QTextOption textOption = layout.textOption(); textOption.setAlignment(Qt::Alignment(q->effectiveHAlign())); textOption.setWrapMode(QTextOption::WrapMode(wrapMode)); + if (!cacheAllTextAsImage && !richTextAsImage && !qmlDisableDistanceField()) + textOption.setUseDesignMetrics(true); layout.setTextOption(textOption); bool elideText = false; @@ -907,8 +918,6 @@ void QSGText::setFont(const QFont &font) d->sourceFont = font; QFont oldFont = d->font; d->font = font; - if (!qmlDisableDistanceField()) - d->font.setHintingPreference(QFont::PreferNoHinting); if (d->font.pointSizeF() != -1) { // 0.5pt resolution @@ -1480,8 +1489,10 @@ QSGNode *QSGText::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *data) QRectF bounds = boundingRect(); // We need to make sure the layout is done in the current thread +#if defined(Q_OS_MAC) if (d->layoutThread != QThread::currentThread()) d->updateLayout(); +#endif // XXX todo - some styled text can be done by the QSGTextNode if (d->richTextAsImage || d->cacheAllTextAsImage || (qmlDisableDistanceField() && d->style != Normal)) { -- cgit v1.2.3