aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/declarative/qsgtext
diff options
context:
space:
mode:
authorEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>2011-06-01 09:45:55 +0200
committerQt by Nokia <qt-info@nokia.com>2011-08-19 15:15:56 +0200
commit1cc58fdf174656a52603af00cb40478066c5abd4 (patch)
tree432054d60316a981b17655dc888805e4e5434966 /tests/auto/declarative/qsgtext
parent7059861a8b8d48b5187eb46a2678f306ba288320 (diff)
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 <eskil.abrahamsen-blomfeldt@nokia.com>
Diffstat (limited to 'tests/auto/declarative/qsgtext')
-rw-r--r--tests/auto/declarative/qsgtext/tst_qsgtext.cpp37
1 files changed, 34 insertions, 3 deletions
diff --git a/tests/auto/declarative/qsgtext/tst_qsgtext.cpp b/tests/auto/declarative/qsgtext/tst_qsgtext.cpp
index 48d679bfa7..747ea51f41 100644
--- a/tests/auto/declarative/qsgtext/tst_qsgtext.cpp
+++ b/tests/auto/declarative/qsgtext/tst_qsgtext.cpp
@@ -45,6 +45,7 @@
#include <private/qsgtext_p.h>
#include <private/qsgtext_p_p.h>
#include <private/qdeclarativevaluetype_p.h>
+#include <private/qsgdistancefieldglyphcache_p.h>
#include <QFontMetrics>
#include <QGraphicsSceneMouseEvent>
#include <qmath.h>
@@ -61,6 +62,8 @@
#define SRCDIR "."
#endif
+DEFINE_BOOL_CONFIG_OPTION(qmlDisableDistanceField, QML_DISABLE_DISTANCEFIELD)
+
class tst_qsgtext : public QObject
{
@@ -261,14 +264,42 @@ void tst_qsgtext::width()
delete textObject;
}
+ bool requiresUnhintedMetrics = !qmlDisableDistanceField();
+
for (int i = 0; i < standard.size(); i++)
{
QVERIFY(!Qt::mightBeRichText(standard.at(i))); // self-test
QFont f;
- QFontMetricsF fm(f);
- qreal metricWidth = fm.size(Qt::TextExpandTabs && Qt::TextShowMnemonic, standard.at(i)).width();
- metricWidth = qCeil(metricWidth);
+ qreal metricWidth = 0.0;
+
+ if (requiresUnhintedMetrics) {
+ QString s = standard.at(i);
+ s.replace(QLatin1Char('\n'), QChar::LineSeparator);
+
+ QTextLayout layout(s);
+ layout.setFlags(Qt::TextExpandTabs | Qt::TextShowMnemonic);
+ {
+ QTextOption option;
+ option.setUseDesignMetrics(true);
+ layout.setTextOption(option);
+ }
+
+ layout.beginLayout();
+ forever {
+ QTextLine line = layout.createLine();
+ if (!line.isValid())
+ break;
+ }
+
+ layout.endLayout();
+
+ metricWidth = qCeil(layout.boundingRect().width());
+ } else {
+ QFontMetricsF fm(f);
+ qreal metricWidth = fm.size(Qt::TextExpandTabs && Qt::TextShowMnemonic, standard.at(i)).width();
+ metricWidth = qCeil(metricWidth);
+ }
QString componentStr = "import QtQuick 2.0\nText { text: \"" + standard.at(i) + "\" }";
QDeclarativeComponent textComponent(&engine);