summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui/text
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/gui/text')
-rw-r--r--tests/auto/gui/text/CMakeLists.txt4
-rw-r--r--tests/auto/gui/text/qabstracttextdocumentlayout/tst_qabstracttextdocumentlayout.cpp4
-rw-r--r--tests/auto/gui/text/qcssparser/tst_qcssparser.cpp55
-rw-r--r--tests/auto/gui/text/qfontdatabase/CMakeLists.txt2
-rw-r--r--tests/auto/gui/text/qfontdatabase/QtTestFallbackFont-Regular.ttfbin0 -> 5664 bytes
-rw-r--r--tests/auto/gui/text/qfontdatabase/QtTestLimitedFont-Regular.ttfbin0 -> 5280 bytes
-rw-r--r--tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp213
-rw-r--r--tests/auto/gui/text/qfontmetrics/CMakeLists.txt4
-rw-r--r--tests/auto/gui/text/qfontmetrics/tst_qfontmetrics.cpp48
-rw-r--r--tests/auto/gui/text/qtextcursor/tst_qtextcursor.cpp4
-rw-r--r--tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp137
-rw-r--r--tests/auto/gui/text/qtextdocumentlayout/tst_qtextdocumentlayout.cpp12
-rw-r--r--tests/auto/gui/text/qtextformat/tst_qtextformat.cpp6
-rw-r--r--tests/auto/gui/text/qtextimagehandler/tst_qtextimagehandler.cpp70
-rw-r--r--tests/auto/gui/text/qtextlist/tst_qtextlist.cpp2
-rw-r--r--tests/auto/gui/text/qtextmarkdownwriter/data/example.md4
-rw-r--r--tests/auto/gui/text/qtexttable/tst_qtexttable.cpp74
17 files changed, 604 insertions, 35 deletions
diff --git a/tests/auto/gui/text/CMakeLists.txt b/tests/auto/gui/text/CMakeLists.txt
index bad13de7dc..30b35fb10a 100644
--- a/tests/auto/gui/text/CMakeLists.txt
+++ b/tests/auto/gui/text/CMakeLists.txt
@@ -11,7 +11,9 @@ add_subdirectory(qstatictext)
add_subdirectory(qsyntaxhighlighter)
add_subdirectory(qtextblock)
add_subdirectory(qtextcursor)
-add_subdirectory(qtextdocumentfragment)
+if(QT_FEATURE_texthtmlparser)
+ add_subdirectory(qtextdocumentfragment)
+endif()
add_subdirectory(qtextdocumentlayout)
add_subdirectory(qtextformat)
add_subdirectory(qtextimagehandler)
diff --git a/tests/auto/gui/text/qabstracttextdocumentlayout/tst_qabstracttextdocumentlayout.cpp b/tests/auto/gui/text/qabstracttextdocumentlayout/tst_qabstracttextdocumentlayout.cpp
index 2ae2ccda0a..3d0fab4603 100644
--- a/tests/auto/gui/text/qabstracttextdocumentlayout/tst_qabstracttextdocumentlayout.cpp
+++ b/tests/auto/gui/text/qabstracttextdocumentlayout/tst_qabstracttextdocumentlayout.cpp
@@ -22,9 +22,11 @@ public:
private slots:
void getSetCheck();
void maximumBlockCount();
+#ifndef QT_NO_TEXTHTMLPARSER
void anchorAt();
void imageAt();
void formatAt();
+#endif
};
tst_QAbstractTextDocumentLayout::tst_QAbstractTextDocumentLayout()
@@ -119,6 +121,7 @@ void tst_QAbstractTextDocumentLayout::maximumBlockCount()
QCOMPARE(layout.blockCount, 10);
}
+#ifndef QT_NO_TEXTHTMLPARSER
void tst_QAbstractTextDocumentLayout::anchorAt()
{
QTextDocument doc;
@@ -204,6 +207,7 @@ void tst_QAbstractTextDocumentLayout::formatAt()
QVERIFY(!format.toCharFormat().fontItalic());
QVERIFY(!format.isImageFormat());
}
+#endif
QTEST_MAIN(tst_QAbstractTextDocumentLayout)
#include "tst_qabstracttextdocumentlayout.moc"
diff --git a/tests/auto/gui/text/qcssparser/tst_qcssparser.cpp b/tests/auto/gui/text/qcssparser/tst_qcssparser.cpp
index a438d7ebc8..203fe003a0 100644
--- a/tests/auto/gui/text/qcssparser/tst_qcssparser.cpp
+++ b/tests/auto/gui/text/qcssparser/tst_qcssparser.cpp
@@ -56,6 +56,10 @@ private slots:
void quotedAndUnquotedIdentifiers();
void whitespaceValues_data();
void whitespaceValues();
+ void strokeLineCapValues_data();
+ void strokeLineCapValues();
+ void strokeLineJoinValues_data();
+ void strokeLineJoinValues();
};
void tst_QCssParser::scanner_data()
@@ -1759,6 +1763,57 @@ void tst_QCssParser::whitespaceValues()
QCOMPARE(rule.declarations.at(0).d->values.first().toString(), value);
}
+void tst_QCssParser::strokeLineCapValues_data()
+{
+ QTest::addColumn<QString>("value");
+
+ QTest::newRow("flatcap") << "flatcap";
+ QTest::newRow("roundcap") << "roundcap";
+ QTest::newRow("squarecap") << "squarecap";
+}
+
+void tst_QCssParser::strokeLineCapValues()
+{
+ QFETCH(QString, value);
+ QCss::Parser parser(QString("foo { -qt-stroke-linecap: %1 }").arg(value));
+ QCss::StyleSheet sheet;
+ QVERIFY(parser.parse(&sheet));
+
+ QCss::StyleRule rule = (!sheet.styleRules.isEmpty()) ?
+ sheet.styleRules.at(0) : *sheet.nameIndex.begin();
+ QCOMPARE(rule.declarations.size(), 1);
+
+ QCOMPARE(rule.declarations.at(0).d->property, QLatin1String("-qt-stroke-linecap"));
+ QCOMPARE(rule.declarations.at(0).d->values.first().type, QCss::Value::KnownIdentifier);
+ QCOMPARE(rule.declarations.at(0).d->values.first().toString(), value);
+}
+
+void tst_QCssParser::strokeLineJoinValues_data()
+{
+ QTest::addColumn<QString>("value");
+
+ QTest::newRow("beveljoin") << "beveljoin";
+ QTest::newRow("miterjoin") << "miterjoin";
+ QTest::newRow("roundjoin") << "roundjoin";
+ QTest::newRow("svgmiterjoin") << "svgmiterjoin";
+}
+
+void tst_QCssParser::strokeLineJoinValues()
+{
+ QFETCH(QString, value);
+ QCss::Parser parser(QString("foo { -qt-stroke-linejoin: %1 }").arg(value));
+ QCss::StyleSheet sheet;
+ QVERIFY(parser.parse(&sheet));
+
+ QCss::StyleRule rule = (!sheet.styleRules.isEmpty()) ?
+ sheet.styleRules.at(0) : *sheet.nameIndex.begin();
+ QCOMPARE(rule.declarations.size(), 1);
+
+ QCOMPARE(rule.declarations.at(0).d->property, QLatin1String("-qt-stroke-linejoin"));
+ QCOMPARE(rule.declarations.at(0).d->values.first().type, QCss::Value::KnownIdentifier);
+ QCOMPARE(rule.declarations.at(0).d->values.first().toString(), value);
+}
+
QTEST_MAIN(tst_QCssParser)
#include "tst_qcssparser.moc"
diff --git a/tests/auto/gui/text/qfontdatabase/CMakeLists.txt b/tests/auto/gui/text/qfontdatabase/CMakeLists.txt
index 18b96ded5d..0cb6e8d7c8 100644
--- a/tests/auto/gui/text/qfontdatabase/CMakeLists.txt
+++ b/tests/auto/gui/text/qfontdatabase/CMakeLists.txt
@@ -47,6 +47,8 @@ set(testdata_resource_files
"../../../shared/resources/testfont_open.otf"
"../../../shared/resources/testfont_variable.ttf"
"LED_REAL.TTF"
+ "QtTestLimitedFont-Regular.ttf"
+ "QtTestFallbackFont-Regular.ttf"
)
qt_internal_add_resource(tst_qfontdatabase "testdata"
diff --git a/tests/auto/gui/text/qfontdatabase/QtTestFallbackFont-Regular.ttf b/tests/auto/gui/text/qfontdatabase/QtTestFallbackFont-Regular.ttf
new file mode 100644
index 0000000000..ae21fec9a5
--- /dev/null
+++ b/tests/auto/gui/text/qfontdatabase/QtTestFallbackFont-Regular.ttf
Binary files differ
diff --git a/tests/auto/gui/text/qfontdatabase/QtTestLimitedFont-Regular.ttf b/tests/auto/gui/text/qfontdatabase/QtTestLimitedFont-Regular.ttf
new file mode 100644
index 0000000000..2891f8aeff
--- /dev/null
+++ b/tests/auto/gui/text/qfontdatabase/QtTestLimitedFont-Regular.ttf
Binary files differ
diff --git a/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp b/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp
index b2d00f6666..8733f64d97 100644
--- a/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp
+++ b/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp
@@ -70,12 +70,16 @@ private slots:
void findCourier();
#endif
+ void addApplicationFontFallback();
+
private:
QString m_ledFont;
QString m_testFont;
QString m_testFontCondensed;
QString m_testFontItalic;
QString m_testFontVariable;
+ QString m_limitedFont;
+ QString m_fallbackFont;
};
tst_QFontDatabase::tst_QFontDatabase()
@@ -89,11 +93,15 @@ void tst_QFontDatabase::initTestCase()
m_testFontCondensed = QFINDTESTDATA("testfont_condensed.ttf");
m_testFontItalic = QFINDTESTDATA("testfont_italic.ttf");
m_testFontVariable = QFINDTESTDATA("testfont_variable.ttf");
+ m_limitedFont = QFINDTESTDATA("QtTestLimitedFont-Regular.ttf");
+ m_fallbackFont = QFINDTESTDATA("QtTestFallbackFont-Regular.ttf");
QVERIFY(!m_ledFont.isEmpty());
QVERIFY(!m_testFont.isEmpty());
QVERIFY(!m_testFontCondensed.isEmpty());
QVERIFY(!m_testFontItalic.isEmpty());
QVERIFY(!m_testFontVariable.isEmpty());
+ QVERIFY(!m_limitedFont.isEmpty());
+ QVERIFY(!m_fallbackFont.isEmpty());
}
void tst_QFontDatabase::styles_data()
@@ -389,8 +397,14 @@ void tst_QFontDatabase::condensedFontWidthNoFontMerging()
void tst_QFontDatabase::condensedFontWidth()
{
- QFontDatabase::addApplicationFont(m_testFont);
- QFontDatabase::addApplicationFont(m_testFontCondensed);
+ int testFontId = QFontDatabase::addApplicationFont(m_testFont);
+ int testFontCondensedId = QFontDatabase::addApplicationFont(m_testFontCondensed);
+ auto cleanup = qScopeGuard([&testFontId, &testFontCondensedId] {
+ if (testFontId >= 0)
+ QFontDatabase::removeApplicationFont(testFontId);
+ if (testFontCondensedId >= 0)
+ QFontDatabase::removeApplicationFont(testFontCondensedId);
+ });
QVERIFY(QFontDatabase::hasFamily("QtBidiTestFont"));
if (!QFontDatabase::hasFamily("QtBidiTestFontCondensed"))
@@ -408,10 +422,16 @@ void tst_QFontDatabase::condensedFontWidth()
void tst_QFontDatabase::condensedFontMatching()
{
QFontDatabase::removeAllApplicationFonts();
- QFontDatabase::addApplicationFont(m_testFontCondensed);
+ int testFontCondensedId = QFontDatabase::addApplicationFont(m_testFontCondensed);
if (!QFontDatabase::hasFamily("QtBidiTestFont"))
QSKIP("This platform doesn't support preferred font family names (QTBUG-53478)");
- QFontDatabase::addApplicationFont(m_testFont);
+ int testFontId = QFontDatabase::addApplicationFont(m_testFont);
+ auto cleanup = qScopeGuard([&testFontId, &testFontCondensedId] {
+ if (testFontId >= 0)
+ QFontDatabase::removeApplicationFont(testFontId);
+ if (testFontCondensedId >= 0)
+ QFontDatabase::removeApplicationFont(testFontCondensedId);
+ });
// Test we correctly get the condensed font using different font matching methods:
QFont tfcByStretch("QtBidiTestFont");
@@ -555,5 +575,190 @@ void tst_QFontDatabase::variableFont()
QFontDatabase::removeApplicationFont(id);
}
+void tst_QFontDatabase::addApplicationFontFallback()
+{
+ int ledId = -1;
+ int id = -1;
+ int limitedId = -1;
+ int fallbackId = -1;
+ auto cleanup = qScopeGuard([&id, &ledId, &limitedId, &fallbackId] {
+ if (id >= 0)
+ QFontDatabase::removeApplicationFont(id);
+ if (ledId >= 0)
+ QFontDatabase::removeApplicationFont(ledId);
+ if (limitedId >= 0)
+ QFontDatabase::removeApplicationFont(limitedId);
+ if (fallbackId >= 0)
+ QFontDatabase::removeApplicationFont(fallbackId);
+ });
+
+ const QChar hebrewChar(0x05D0); // Hebrew 'aleph'
+
+ ledId = QFontDatabase::addApplicationFont(m_ledFont);
+ if (ledId < 0)
+ QSKIP("Skip the test since app fonts are not supported on this system");
+
+ auto getHebrewFont = [&]() {
+ QTextLayout layout;
+ layout.setText(hebrewChar);
+ layout.setFont(QFont(u"LED Real"_s));
+ layout.beginLayout();
+ layout.createLine();
+ layout.endLayout();
+
+ QList<QGlyphRun> glyphRuns = layout.glyphRuns();
+ if (glyphRuns.isEmpty())
+ return QString{};
+
+ return glyphRuns.first().rawFont().familyName();
+ };
+
+ QString defaultHebrewFont = getHebrewFont();
+ if (defaultHebrewFont.isEmpty())
+ QSKIP("Skip the test since Hebrew is not supported on this system");
+
+ QVERIFY(QFontDatabase::applicationFallbackFontFamilies(QChar::Script_Hebrew).isEmpty());
+ QFontDatabase::addApplicationFallbackFontFamily(QChar::Script_Hebrew, u"QtBidiTestFont"_s);
+
+ QCOMPARE(QFontDatabase::applicationFallbackFontFamilies(QChar::Script_Hebrew).size(), 1);
+ QCOMPARE(QFontDatabase::applicationFallbackFontFamilies(QChar::Script_Hebrew).first(), u"QtBidiTestFont"_s);
+
+ {
+ QString hebrewFontNow = getHebrewFont();
+ QCOMPARE(hebrewFontNow, defaultHebrewFont);
+ }
+
+ id = QFontDatabase::addApplicationFont(m_testFont);
+ QVERIFY(id >= 0);
+
+ {
+ QString hebrewFontNow = getHebrewFont();
+ QCOMPARE(hebrewFontNow, u"QtBidiTestFont"_s);
+ }
+
+ QFontDatabase::removeApplicationFallbackFontFamily(QChar::Script_Hebrew, u"QtBidiTestFont"_s);
+
+ {
+ QString hebrewFontNow = getHebrewFont();
+ QCOMPARE(hebrewFontNow, defaultHebrewFont);
+ }
+
+ QFontDatabase::setApplicationFallbackFontFamilies(QChar::Script_Hebrew, QStringList(u"QtBidiTestFont"_s));
+
+ {
+ QString hebrewFontNow = getHebrewFont();
+ QCOMPARE(hebrewFontNow, u"QtBidiTestFont"_s);
+ }
+
+ QFontDatabase::setApplicationFallbackFontFamilies(QChar::Script_Hebrew, QStringList{});
+
+ {
+ QString hebrewFontNow = getHebrewFont();
+ QCOMPARE(hebrewFontNow, defaultHebrewFont);
+ }
+
+ limitedId = QFontDatabase::addApplicationFont(m_limitedFont);
+ QVERIFY(limitedId >= 0);
+
+ fallbackId = QFontDatabase::addApplicationFont(m_fallbackFont);
+ QVERIFY(fallbackId >= 0);
+
+ QFontDatabase::addApplicationFallbackFontFamily(QChar::Script_Common, u"QtTestFallbackFont"_s);
+
+ // The fallback for Common will be used also for Latin, because Latin and Common are
+ // considered the same script by the font matching engine.
+ {
+ QTextLayout layout;
+ layout.setText(u"A'B,"_s);
+ layout.setFont(QFont(u"QtTestLimitedFont"_s));
+ layout.beginLayout();
+ layout.createLine();
+ layout.endLayout();
+
+ QList<QGlyphRun> glyphRuns = layout.glyphRuns();
+ QVERIFY(glyphRuns.size() > 1);
+ for (int i = 0; i < glyphRuns.size(); ++i) {
+ QVERIFY(glyphRuns.at(i).rawFont().familyName() == u"QtTestFallbackFont"_s
+ || glyphRuns.at(i).rawFont().familyName() == u"QtTestLimitedFont"_s);
+ }
+ }
+
+ // When the text only consists of common script characters, the fallback font will also be used.
+ {
+ QTextLayout layout;
+ layout.setText(u"',"_s);
+ layout.setFont(QFont(u"QtTestLimitedFont"_s));
+ layout.beginLayout();
+ layout.createLine();
+ layout.endLayout();
+
+ QList<QGlyphRun> glyphRuns = layout.glyphRuns();
+ QCOMPARE(glyphRuns.size(), 2);
+ for (int i = 0; i < glyphRuns.size(); ++i) {
+ QVERIFY(glyphRuns.at(i).rawFont().familyName() == u"QtTestFallbackFont"_s
+ || glyphRuns.at(i).rawFont().familyName() == u"QtTestLimitedFont"_s);
+ }
+ }
+
+ QVERIFY(QFontDatabase::removeApplicationFallbackFontFamily(QChar::Script_Common, u"QtTestFallbackFont"_s));
+ QFontDatabase::addApplicationFallbackFontFamily(QChar::Script_Latin, u"QtTestFallbackFont"_s);
+
+ // Latin fallback works just the same as Common fallback
+ {
+ QTextLayout layout;
+ layout.setText(u"A'B,"_s);
+ layout.setFont(QFont(u"QtTestLimitedFont"_s));
+ layout.beginLayout();
+ layout.createLine();
+ layout.endLayout();
+
+ QList<QGlyphRun> glyphRuns = layout.glyphRuns();
+ QCOMPARE(glyphRuns.size(), 2);
+ for (int i = 0; i < glyphRuns.size(); ++i) {
+ QVERIFY(glyphRuns.at(i).rawFont().familyName() == u"QtTestFallbackFont"_s
+ || glyphRuns.at(i).rawFont().familyName() == u"QtTestLimitedFont"_s);
+ }
+ }
+
+ // When the common character is placed next to a Cyrillic characters, it gets adapted to this,
+ // so the fallback font will not be selected, even if it supports the character in question
+ {
+ QTextLayout layout;
+ layout.setText(u"A'Б,"_s);
+ layout.setFont(QFont(u"QtTestLimitedFont"_s));
+ layout.beginLayout();
+ layout.createLine();
+ layout.endLayout();
+
+ QList<QGlyphRun> glyphRuns = layout.glyphRuns();
+ QCOMPARE(glyphRuns.size(), 2);
+ for (int i = 0; i < glyphRuns.size(); ++i) {
+ QVERIFY(glyphRuns.at(i).rawFont().familyName() != u"QtTestFallbackFont"_s);
+ }
+ }
+
+ QFontDatabase::addApplicationFallbackFontFamily(QChar::Script_Cyrillic, u"QtTestFallbackFont"_s);
+
+ // When we set the fallback font for Cyrillic as well, it gets selected
+ {
+ QTextLayout layout;
+ layout.setText(u"A'Б,"_s);
+ layout.setFont(QFont(u"QtTestLimitedFont"_s));
+ layout.beginLayout();
+ layout.createLine();
+ layout.endLayout();
+
+ QList<QGlyphRun> glyphRuns = layout.glyphRuns();
+ QCOMPARE(glyphRuns.size(), 2);
+ for (int i = 0; i < glyphRuns.size(); ++i) {
+ QVERIFY(glyphRuns.at(i).rawFont().familyName() == u"QtTestFallbackFont"_s
+ || glyphRuns.at(i).rawFont().familyName() == u"QtTestLimitedFont"_s);
+ }
+ }
+
+ QVERIFY(QFontDatabase::removeApplicationFallbackFontFamily(QChar::Script_Cyrillic, u"QtTestFallbackFont"_s));
+ QVERIFY(QFontDatabase::removeApplicationFallbackFontFamily(QChar::Script_Latin, u"QtTestFallbackFont"_s));
+}
+
QTEST_MAIN(tst_QFontDatabase)
#include "tst_qfontdatabase.moc"
diff --git a/tests/auto/gui/text/qfontmetrics/CMakeLists.txt b/tests/auto/gui/text/qfontmetrics/CMakeLists.txt
index d014d27d46..ee2f76ef76 100644
--- a/tests/auto/gui/text/qfontmetrics/CMakeLists.txt
+++ b/tests/auto/gui/text/qfontmetrics/CMakeLists.txt
@@ -24,8 +24,12 @@ qt_internal_add_test(tst_qfontmetrics
set_source_files_properties("../../../shared/resources/testfont.ttf"
PROPERTIES QT_RESOURCE_ALIAS "testfont.ttf"
)
+set_source_files_properties("../../../shared/resources/testfont_linemetrics.otf"
+ PROPERTIES QT_RESOURCE_ALIAS "testfont_linemetrics.otf"
+)
set(testfont_resource_files
"../../../shared/resources/testfont.ttf"
+ "../../../shared/resources/testfont_linemetrics.otf"
"ucs4font.ttf"
)
diff --git a/tests/auto/gui/text/qfontmetrics/tst_qfontmetrics.cpp b/tests/auto/gui/text/qfontmetrics/tst_qfontmetrics.cpp
index 678eb0393f..bad33ab0a4 100644
--- a/tests/auto/gui/text/qfontmetrics/tst_qfontmetrics.cpp
+++ b/tests/auto/gui/text/qfontmetrics/tst_qfontmetrics.cpp
@@ -36,6 +36,7 @@ private slots:
void verticalMetrics();
void largeText_data();
void largeText(); // QTBUG-123339
+ void typoLineMetrics();
};
void tst_QFontMetrics::same()
@@ -263,7 +264,7 @@ void tst_QFontMetrics::inFontUcs4()
glyphs.glyphs[0] = 0;
QVERIFY(engine->stringToCMap(string.constData(), string.size(),
&glyphs, &glyphs.numGlyphs,
- QFontEngine::GlyphIndicesOnly));
+ QFontEngine::GlyphIndicesOnly) > 0);
QCOMPARE(glyphs.numGlyphs, 1);
QCOMPARE(glyphs.glyphs[0], uint(1));
}
@@ -275,7 +276,7 @@ void tst_QFontMetrics::inFontUcs4()
glyphs.glyphs[0] = 0;
QVERIFY(engine->stringToCMap(string.constData(), string.size(),
&glyphs, &glyphs.numGlyphs,
- QFontEngine::GlyphIndicesOnly));
+ QFontEngine::GlyphIndicesOnly) >= 0);
QVERIFY(glyphs.glyphs[0] != 1);
}
}
@@ -410,5 +411,48 @@ void tst_QFontMetrics::largeText()
QVERIFY(boundingRect.isValid());
}
+void tst_QFontMetrics::typoLineMetrics()
+{
+ QString testFont = QFINDTESTDATA("fonts/testfont_linemetrics.otf");
+ QVERIFY(!testFont.isEmpty());
+
+ int id = QFontDatabase::addApplicationFont(testFont);
+ QVERIFY(id >= 0);
+
+ {
+ auto cleanup = qScopeGuard([&id] {
+ if (id >= 0)
+ QFontDatabase::removeApplicationFont(id);
+ });
+
+ QImage img(100, 100, QImage::Format_ARGB32);
+ img.setDevicePixelRatio(1.0);
+ QFont font(QFontDatabase::applicationFontFamilies(id).at(0), &img);
+ font.setPixelSize(18);
+
+ const qreal unitsPerEm = 1000.0;
+
+ QFontMetrics defaultFm(font);
+ const int defaultAscent = defaultFm.ascent();
+ const int defaultDescent = defaultFm.descent();
+ const int defaultLeading = defaultFm.leading();
+
+ QCOMPARE(defaultAscent, qRound(1234.0 / unitsPerEm * font.pixelSize()));
+ QCOMPARE(defaultDescent, qRound(5678.0 / unitsPerEm * font.pixelSize()));
+ QCOMPARE(defaultLeading, 0.0);
+
+ font.setStyleStrategy(QFont::PreferTypoLineMetrics);
+ const QFontMetrics typoFm(font);
+
+ const int typoAscent = typoFm.ascent();
+ const int typoDescent = typoFm.descent();
+ const int typoLeading = typoFm.leading();
+
+ QCOMPARE(typoAscent, qRound(2000.0 / unitsPerEm * font.pixelSize()));
+ QCOMPARE(typoDescent, qRound(3000.0 / unitsPerEm * font.pixelSize()));
+ QCOMPARE(typoLeading, qRound(1000.0 / unitsPerEm * font.pixelSize()));
+ }
+}
+
QTEST_MAIN(tst_QFontMetrics)
#include "tst_qfontmetrics.moc"
diff --git a/tests/auto/gui/text/qtextcursor/tst_qtextcursor.cpp b/tests/auto/gui/text/qtextcursor/tst_qtextcursor.cpp
index 6984cd1bd2..8f5cacae4a 100644
--- a/tests/auto/gui/text/qtextcursor/tst_qtextcursor.cpp
+++ b/tests/auto/gui/text/qtextcursor/tst_qtextcursor.cpp
@@ -39,7 +39,9 @@ private slots:
void navigation7();
void navigation8();
void navigation9();
+#ifndef QT_NO_TEXTHTMLPARSER
void navigation10();
+#endif
void movePositionEndOfLine();
void insertBlock();
void insertWithBlockSeparator1();
@@ -431,6 +433,7 @@ void tst_QTextCursor::navigation9()
QCOMPARE(cursor.position(), 15);
}
+#ifndef QT_NO_TEXTHTMLPARSER
void tst_QTextCursor::navigation10()
{
doc->setHtml("<html><p>just a simple paragraph.</p>"
@@ -542,6 +545,7 @@ void tst_QTextCursor::navigation10()
QVERIFY(ok);
QCOMPARE(cursor.position(), 1); // a
}
+#endif
void tst_QTextCursor::insertBlock()
{
diff --git a/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp b/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp
index 40f78ed778..600b45575f 100644
--- a/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp
+++ b/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp
@@ -1172,7 +1172,7 @@ void tst_QTextDocument::toHtml_data()
cursor.insertTable(2, 2);
QTest::newRow("simpletable") << QTextDocumentFragment(&doc)
- << QString("<table border=\"1\" cellspacing=\"2\">"
+ << QString("<table border=\"1\" style=\" border-collapse:collapse;\" cellpadding=\"4\">"
"\n<tr>\n<td></td>\n<td></td></tr>"
"\n<tr>\n<td></td>\n<td></td></tr>"
"</table>");
@@ -1186,7 +1186,7 @@ void tst_QTextDocument::toHtml_data()
table->mergeCells(0, 2, 1, 2);
QTest::newRow("tablespans") << QTextDocumentFragment(&doc)
- << QString("<table border=\"1\" cellspacing=\"2\">"
+ << QString("<table border=\"1\" style=\" border-collapse:collapse;\" cellpadding=\"4\">"
"\n<tr>\n<td colspan=\"2\"></td>\n<td colspan=\"2\"></td></tr>"
"</table>");
}
@@ -1205,7 +1205,7 @@ void tst_QTextDocument::toHtml_data()
cursor.insertTable(2, 2, fmt);
QTest::newRow("tableattrs") << QTextDocumentFragment(&doc)
- << QString("<table border=\"1\" style=\" float: right;\" align=\"center\" width=\"50%\" cellspacing=\"3\" cellpadding=\"3\" bgcolor=\"#ff00ff\">"
+ << QString("<table border=\"1\" style=\" float: right; border-collapse:collapse;\" align=\"center\" width=\"50%\" cellspacing=\"3\" cellpadding=\"3\" bgcolor=\"#ff00ff\">"
"\n<tr>\n<td></td>\n<td></td></tr>"
"\n<tr>\n<td></td>\n<td></td></tr>"
"</table>");
@@ -1227,7 +1227,7 @@ void tst_QTextDocument::toHtml_data()
cursor.insertTable(2, 2, fmt);
QTest::newRow("tableattrs2") << QTextDocumentFragment(&doc)
- << QString("<table border=\"1\" style=\" float: right; margin-top:0px; margin-bottom:35px; margin-left:25px; margin-right:0px;\" align=\"center\" width=\"50%\" cellspacing=\"3\" cellpadding=\"3\" bgcolor=\"#ff00ff\">"
+ << QString("<table border=\"1\" style=\" float: right; margin-top:0px; margin-bottom:35px; margin-left:25px; margin-right:0px; border-collapse:collapse;\" align=\"center\" width=\"50%\" cellspacing=\"3\" cellpadding=\"3\" bgcolor=\"#ff00ff\">"
"\n<tr>\n<td></td>\n<td></td></tr>"
"\n<tr>\n<td></td>\n<td></td></tr>"
"</table>");
@@ -1241,7 +1241,7 @@ void tst_QTextDocument::toHtml_data()
cursor.insertTable(4, 2, fmt);
QTest::newRow("tableheader") << QTextDocumentFragment(&doc)
- << QString("<table border=\"1\" cellspacing=\"2\">"
+ << QString("<table border=\"1\" style=\" border-collapse:collapse;\" cellpadding=\"4\">"
"<thead>\n<tr>\n<td></td>\n<td></td></tr>"
"\n<tr>\n<td></td>\n<td></td></tr></thead>"
"\n<tr>\n<td></td>\n<td></td></tr>"
@@ -1257,8 +1257,8 @@ void tst_QTextDocument::toHtml_data()
subTable->cellAt(0, 0).firstCursorPosition().insertText("Hey");
QTest::newRow("nestedtable") << QTextDocumentFragment(&doc)
- << QString("<table border=\"1\" cellspacing=\"2\">"
- "\n<tr>\n<td></td>\n<td>\n<table border=\"1\" cellspacing=\"2\">\n<tr>\n<td>\n<p DEFAULTBLOCKSTYLE>Hey</p></td></tr></table></td></tr>"
+ << QString("<table border=\"1\" style=\" border-collapse:collapse;\" cellpadding=\"4\">"
+ "\n<tr>\n<td></td>\n<td>\n<table border=\"1\" style=\" border-collapse:collapse;\" cellpadding=\"4\">\n<tr>\n<td>\n<p DEFAULTBLOCKSTYLE>Hey</p></td></tr></table></td></tr>"
"\n<tr>\n<td></td>\n<td></td></tr>"
"</table>");
}
@@ -1275,7 +1275,7 @@ void tst_QTextDocument::toHtml_data()
cursor.insertTable(1, 3, fmt);
QTest::newRow("colwidths") << QTextDocumentFragment(&doc)
- << QString("<table border=\"1\" cellspacing=\"2\">"
+ << QString("<table border=\"1\" style=\" border-collapse:collapse;\" cellpadding=\"4\">"
"\n<tr>\n<td></td>\n<td width=\"30%\"></td>\n<td width=\"40\"></td></tr>"
"</table>");
}
@@ -1292,7 +1292,7 @@ void tst_QTextDocument::toHtml_data()
cellCurs.mergeBlockCharFormat(fmt);
QTest::newRow("cellproperties") << QTextDocumentFragment(&doc)
- << QString("<table border=\"1\" cellspacing=\"2\">"
+ << QString("<table border=\"1\" style=\" border-collapse:collapse;\" cellpadding=\"4\">"
"\n<tr>\n<td bgcolor=\"#ffffff\"></td></tr>"
"</table>");
}
@@ -1559,7 +1559,7 @@ void tst_QTextDocument::toHtml_data()
table->setFormat(fmt);
QTest::newRow("mergedtablecolwidths") << QTextDocumentFragment(&doc)
- << QString("<table border=\"1\" cellspacing=\"2\">"
+ << QString("<table border=\"1\" style=\" border-collapse:collapse;\" cellpadding=\"4\">"
"\n<tr>\n<td colspan=\"2\"></td></tr>"
"\n<tr>\n<td width=\"20\"></td>\n<td width=\"40\"></td></tr>"
"</table>");
@@ -1622,7 +1622,7 @@ void tst_QTextDocument::toHtml_data()
table->cellAt(0, 0).firstCursorPosition().insertText("Blah");
QTest::newRow("table-vertical-alignment") << QTextDocumentFragment(&doc)
- << QString("<table border=\"1\" cellspacing=\"2\">"
+ << QString("<table border=\"1\" style=\" border-collapse:collapse;\" cellpadding=\"4\">"
"\n<tr>\n<td style=\" vertical-align:middle;\">\n"
"<p DEFAULTBLOCKSTYLE>Blah</p></td>"
"\n<td style=\" vertical-align:top;\"></td></tr>"
@@ -1651,7 +1651,7 @@ void tst_QTextDocument::toHtml_data()
table->cellAt(0, 0).firstCursorPosition().insertText("Blah");
QTest::newRow("table-cell-paddings") << QTextDocumentFragment(&doc)
- << QString("<table border=\"1\" cellspacing=\"2\">"
+ << QString("<table border=\"1\" style=\" border-collapse:collapse;\" cellpadding=\"4\">"
"\n<tr>\n<td style=\" padding-left:1;\">\n"
"<p DEFAULTBLOCKSTYLE>Blah</p></td>"
"\n<td style=\" padding-right:1;\"></td></tr>"
@@ -1669,7 +1669,7 @@ void tst_QTextDocument::toHtml_data()
cursor.insertTable(2, 2, fmt);
QTest::newRow("tableborder") << QTextDocumentFragment(&doc)
- << QString("<table border=\"1\" style=\" border-color:#0000ff; border-style:solid;\" cellspacing=\"2\">"
+ << QString("<table border=\"1\" style=\" border-color:#0000ff; border-style:solid; border-collapse:collapse;\" cellpadding=\"4\">"
"\n<tr>\n<td></td>\n<td></td></tr>"
"\n<tr>\n<td></td>\n<td></td></tr>"
"</table>");
@@ -1711,7 +1711,7 @@ void tst_QTextDocument::toHtml_data()
<< QString("EMPTYBLOCK") +
QString("<p OPENDEFAULTBLOCKSTYLE page-break-before:always;\">Foo</p>"
"\n<p OPENDEFAULTBLOCKSTYLE page-break-before:always; page-break-after:always;\">Bar</p>"
- "\n<table border=\"1\" style=\" page-break-after:always;\" cellspacing=\"2\">\n<tr>\n<td></td></tr></table>");
+ "\n<table border=\"1\" style=\" page-break-after:always; border-collapse:collapse;\" cellpadding=\"4\">\n<tr>\n<td></td></tr></table>");
}
{
@@ -4053,20 +4053,107 @@ void tst_QTextDocument::restoreStrokeFromHtml()
QTextDocument document;
QTextCursor textCursor(&document);
QTextCharFormat textOutline;
- textOutline.setTextOutline(QPen(Qt::red, 2.3));
- textCursor.insertText("Outlined text", textOutline);
+
+ // Set stroke color and width
+ {
+ QPen pen(Qt::red, 2.3, Qt::SolidLine);
+ textOutline.setTextOutline(pen);
+ textCursor.insertText("Outlined text", textOutline);
+ }
+
+ // Set Cap and Join styles
+ {
+ QPen pen;
+ pen.setCapStyle(Qt::FlatCap);
+ pen.setJoinStyle(Qt::RoundJoin);
+ textOutline.setTextOutline(pen);
+ textCursor.insertBlock();
+ textCursor.insertText("Cap and Join Style", textOutline);
+ }
+
+ // Set Miter limit
+ {
+ QPen pen;
+ pen.setJoinStyle(Qt::MiterJoin);
+ pen.setMiterLimit(4);
+ textOutline.setTextOutline(pen);
+ textCursor.insertBlock();
+ textCursor.insertText("Miter Limit", textOutline);
+ }
+
+ // Set Dash Array and Dash Offset
+ {
+ QPen pen;
+ QList<qreal> pattern;
+ const int dash = 2;
+ const int gap = 4;
+ pattern << dash << gap << dash << gap << dash << gap;
+ pen.setDashPattern(pattern);
+ pen.setDashOffset(3);
+ textOutline.setTextOutline(pen);
+ textCursor.insertBlock();
+ textCursor.insertText("Dash Pattern", textOutline);
+ }
+
{
QTextDocument otherDocument;
otherDocument.setHtml(document.toHtml());
- QCOMPARE(otherDocument.blockCount(), 1);
- QTextBlock block = otherDocument.firstBlock();
- QTextFragment fragment = block.begin().fragment();
- QCOMPARE(fragment.text(), QStringLiteral("Outlined text"));
- QTextCharFormat fmt = fragment.charFormat();
- QVERIFY(fmt.hasProperty(QTextCharFormat::TextOutline));
- QPen pen = fmt.textOutline();
- QCOMPARE(pen.color(), QColor(Qt::red));
- QCOMPARE(pen.widthF(), 2.3);
+ QCOMPARE(otherDocument.blockCount(), document.blockCount());
+
+ QTextBlock block;
+ QTextFragment fragment;
+ QTextCharFormat fmt;
+ QPen pen;
+
+ {
+ block = otherDocument.findBlockByNumber(0);
+ fragment = block.begin().fragment();
+ QCOMPARE(fragment.text(), QStringLiteral("Outlined text"));
+ fmt = fragment.charFormat();
+ QVERIFY(fmt.hasProperty(QTextCharFormat::TextOutline));
+ pen = fmt.textOutline();
+ QCOMPARE(pen.color(), QColor(Qt::red));
+ QCOMPARE(pen.widthF(), 2.3);
+ }
+
+ {
+ block = otherDocument.findBlockByNumber(1);
+ qDebug() << block.text();
+ fragment = block.begin().fragment();
+ QCOMPARE(fragment.text(), QStringLiteral("Cap and Join Style"));
+ fmt = fragment.charFormat();
+ QVERIFY(fmt.hasProperty(QTextCharFormat::TextOutline));
+ pen = fmt.textOutline();
+ QCOMPARE(pen.capStyle(), Qt::FlatCap);
+ QCOMPARE(pen.joinStyle(), Qt::RoundJoin);
+ }
+
+ {
+ block = otherDocument.findBlockByNumber(2);
+ fragment = block.begin().fragment();
+ QCOMPARE(fragment.text(), QStringLiteral("Miter Limit"));
+ fmt = fragment.charFormat();
+ QVERIFY(fmt.hasProperty(QTextCharFormat::TextOutline));
+ pen = fmt.textOutline();
+ QCOMPARE(pen.joinStyle(), Qt::MiterJoin);
+ QCOMPARE(pen.miterLimit(), 4);
+ }
+
+
+ {
+ block = otherDocument.findBlockByNumber(3);
+ fragment = block.begin().fragment();
+ QCOMPARE(fragment.text(), QStringLiteral("Dash Pattern"));
+ fmt = fragment.charFormat();
+ QVERIFY(fmt.hasProperty(QTextCharFormat::TextOutline));
+ pen = fmt.textOutline();
+ QCOMPARE(pen.dashOffset(), 3);
+ QList<qreal> pattern;
+ const int dash = 2;
+ const int gap = 4;
+ pattern << dash << gap << dash << gap << dash << gap;
+ QCOMPARE(pen.dashPattern(), pattern);
+ }
}
}
diff --git a/tests/auto/gui/text/qtextdocumentlayout/tst_qtextdocumentlayout.cpp b/tests/auto/gui/text/qtextdocumentlayout/tst_qtextdocumentlayout.cpp
index 2a279682ca..2ae31849bf 100644
--- a/tests/auto/gui/text/qtextdocumentlayout/tst_qtextdocumentlayout.cpp
+++ b/tests/auto/gui/text/qtextdocumentlayout/tst_qtextdocumentlayout.cpp
@@ -24,18 +24,24 @@ private slots:
void cleanupTestCase();
void defaultPageSizeHandling();
void idealWidth();
+#ifndef QT_NO_TEXTHTMLPARSER
void lineSeparatorFollowingTable();
+#endif
#ifndef QT_NO_WIDGETS
void wrapAtWordBoundaryOrAnywhere();
#endif
void inlineImage();
+#ifndef QT_NO_TEXTHTMLPARSER
void clippedTableCell();
+#endif
void floatingTablePageBreak();
void imageAtRightAlignedTab();
void blockVisibility();
+#ifndef QT_NO_TEXTHTMLPARSER
void testHitTest();
void largeImage();
+#endif
private:
QTextDocument *doc;
@@ -99,6 +105,7 @@ void tst_QTextDocumentLayout::idealWidth()
QVERIFY(doc->idealWidth() > 0);
}
+#ifndef QT_NO_TEXTHTMLPARSER
// none of the QTextLine items in the document should intersect with the margin rect
void tst_QTextDocumentLayout::lineSeparatorFollowingTable()
{
@@ -145,6 +152,7 @@ void tst_QTextDocumentLayout::lineSeparatorFollowingTable()
}
}
}
+#endif
#ifndef QT_NO_WIDGETS
void tst_QTextDocumentLayout::wrapAtWordBoundaryOrAnywhere()
@@ -184,6 +192,7 @@ void tst_QTextDocumentLayout::inlineImage()
QCOMPARE(doc->pageCount(), 1);
}
+#ifndef QT_NO_TEXTHTMLPARSER
void tst_QTextDocumentLayout::clippedTableCell()
{
const char *html =
@@ -224,6 +233,7 @@ void tst_QTextDocumentLayout::clippedTableCell()
expected.save("expected.png");
QCOMPARE(img, expected);
}
+#endif
void tst_QTextDocumentLayout::floatingTablePageBreak()
{
@@ -323,6 +333,7 @@ void tst_QTextDocumentLayout::blockVisibility()
QCOMPARE(doc->size(), halfSize);
}
+#ifndef QT_NO_TEXTHTMLPARSER
void tst_QTextDocumentLayout::largeImage()
{
auto img = QImage(400, 500, QImage::Format_ARGB32_Premultiplied);
@@ -416,6 +427,7 @@ void tst_QTextDocumentLayout::testHitTest()
QVERIFY(positionY - topMargin <= y);
}
}
+#endif
QTEST_MAIN(tst_QTextDocumentLayout)
#include "tst_qtextdocumentlayout.moc"
diff --git a/tests/auto/gui/text/qtextformat/tst_qtextformat.cpp b/tests/auto/gui/text/qtextformat/tst_qtextformat.cpp
index d20a2f1ea5..6c6145561d 100644
--- a/tests/auto/gui/text/qtextformat/tst_qtextformat.cpp
+++ b/tests/auto/gui/text/qtextformat/tst_qtextformat.cpp
@@ -7,7 +7,9 @@
#include <qcoreapplication.h>
#include <qdebug.h>
+#if QT_CONFIG(settings)
#include <qsettings.h>
+#endif
#include <qtextformat.h>
#include <private/qtextformat_p.h>
#include <qtextdocument.h>
@@ -27,7 +29,9 @@ Q_OBJECT
private slots:
void getSetCheck();
void defaultAlignment();
+#if QT_CONFIG(settings)
void testQTextCharFormat() const;
+#endif
void testUnderlinePropertyPrecedence();
void toFormat();
void resolveFont();
@@ -47,6 +51,7 @@ private slots:
#endif
};
+#if QT_CONFIG(settings)
/*! \internal
This (used to) trigger a crash in:
@@ -61,6 +66,7 @@ void tst_QTextFormat::testQTextCharFormat() const
settings.value("test", test);
}
+#endif
// Testing get/set functions
void tst_QTextFormat::getSetCheck()
diff --git a/tests/auto/gui/text/qtextimagehandler/tst_qtextimagehandler.cpp b/tests/auto/gui/text/qtextimagehandler/tst_qtextimagehandler.cpp
index 5311aa6f2b..0048623d0e 100644
--- a/tests/auto/gui/text/qtextimagehandler/tst_qtextimagehandler.cpp
+++ b/tests/auto/gui/text/qtextimagehandler/tst_qtextimagehandler.cpp
@@ -6,6 +6,10 @@
#include <QPainter>
#include <private/qtextimagehandler_p.h>
+using namespace Qt::StringLiterals;
+
+// #define DEBUG_WRITE_HTML
+
class tst_QTextImageHandler : public QObject
{
Q_OBJECT
@@ -18,7 +22,11 @@ private slots:
void cleanup();
void cleanupTestCase();
void loadAtNImages_data();
+#ifndef QT_NO_TEXTHTMLPARSER
void loadAtNImages();
+ void maxWidth_data();
+ void maxWidth();
+#endif
};
tst_QTextImageHandler::tst_QTextImageHandler()
@@ -47,6 +55,7 @@ void tst_QTextImageHandler::loadAtNImages_data()
QTest::addRow("qrc_url") << "qrc:/data/image.png";
}
+#ifndef QT_NO_TEXTHTMLPARSER
void tst_QTextImageHandler::loadAtNImages()
{
QFETCH(QString, imageFile);
@@ -58,7 +67,7 @@ void tst_QTextImageHandler::loadAtNImages()
const auto it = std::find_if(formats.begin(), formats.end(), [](const auto &format){
return format.objectType() == QTextFormat::ImageObject;
});
- QVERIFY(it != formats.end());
+ QCOMPARE_NE(it, formats.end());
const QTextImageFormat format = (*it).toImageFormat();
QTextImageHandler handler;
@@ -75,5 +84,64 @@ void tst_QTextImageHandler::loadAtNImages()
}
}
+void tst_QTextImageHandler::maxWidth_data()
+{
+ QTest::addColumn<QString>("imageFile");
+ QTest::addColumn<QSizeF>("pageSize");
+ QTest::addColumn<QTextLength>("maxWidth");
+ QTest::addColumn<QSizeF>("expectedSize");
+
+ QTest::addRow("constrained-percentage") << QFINDTESTDATA("data/image.png") << QSizeF(16, 16) << QTextLength(QTextLength::PercentageLength, 100) << QSizeF(12, 12);
+ QTest::addRow("not-constrained-percentage") << QFINDTESTDATA("data/image.png") << QSizeF(200, 200) << QTextLength(QTextLength::PercentageLength, 100) << QSizeF(16, 16);
+ QTest::addRow("constrained-fixed") << QFINDTESTDATA("data/image.png") << QSizeF(16, 16) << QTextLength(QTextLength::FixedLength, 5) << QSizeF(5, 5);
+ QTest::addRow("not-constrained-fixed") << QFINDTESTDATA("data/image.png") << QSizeF(200, 200) << QTextLength(QTextLength::FixedLength, 5) << QSizeF(5, 5);
+ QTest::addRow("not-constrained-default") << QFINDTESTDATA("data/image.png") << QSizeF(200, 200) << QTextLength(QTextLength::VariableLength, 5) << QSizeF(16, 16);
+}
+
+void tst_QTextImageHandler::maxWidth()
+{
+ QFETCH(QString, imageFile);
+ QFETCH(QSizeF, pageSize);
+ QFETCH(QTextLength, maxWidth);
+ QFETCH(QSizeF, expectedSize);
+
+ QTextDocument doc;
+ doc.setPageSize(pageSize);
+ doc.setDocumentMargin(2);
+ QTextCursor c(&doc);
+ QString style;
+ if (maxWidth.type() == QTextLength::PercentageLength)
+ style = " style=\"max-width:"_L1 + QString::number(maxWidth.rawValue()) + "%;\""_L1;
+ else if (maxWidth.type() == QTextLength::FixedLength)
+ style = " style=\"max-width:"_L1 + QString::number(maxWidth.rawValue()) + "px;\""_L1;
+ const QString html = "<img src=\"" + imageFile + u'\"' + style + "\">";
+ c.insertHtml(html);
+
+#ifdef DEBUG_WRITE_HTML
+ {
+ QFile out("/tmp/" + QLatin1String(QTest::currentDataTag()) + ".html");
+ out.open(QFile::WriteOnly);
+ out.write(html.toLatin1());
+ out.close();
+ }
+ {
+ QFile out("/tmp/" + QLatin1String(QTest::currentDataTag()) + "_rewrite.html");
+ out.open(QFile::WriteOnly);
+ out.write(doc.toHtml().toLatin1());
+ out.close();
+ }
+#endif
+ const auto formats = doc.allFormats();
+ const auto it = std::find_if(formats.begin(), formats.end(), [](const auto &format){
+ return format.objectType() == QTextFormat::ImageObject;
+ });
+ QCOMPARE_NE(it, formats.end());
+ const QTextImageFormat format = (*it).toImageFormat();
+ QTextImageHandler handler;
+
+ QCOMPARE(handler.intrinsicSize(&doc, 0, format), expectedSize);
+}
+#endif
+
QTEST_MAIN(tst_QTextImageHandler)
#include "tst_qtextimagehandler.moc"
diff --git a/tests/auto/gui/text/qtextlist/tst_qtextlist.cpp b/tests/auto/gui/text/qtextlist/tst_qtextlist.cpp
index 28eae93f6a..10d44f6d70 100644
--- a/tests/auto/gui/text/qtextlist/tst_qtextlist.cpp
+++ b/tests/auto/gui/text/qtextlist/tst_qtextlist.cpp
@@ -140,6 +140,7 @@ void tst_QTextList::autoNumberingPrefixAndSuffixHtmlExportImport()
QCOMPARE(list->count(), 28);
+#ifndef QT_NO_TEXTHTMLPARSER
QString htmlExport = doc->toHtml();
QTextDocument importDoc;
importDoc.setHtml(htmlExport);
@@ -152,6 +153,7 @@ void tst_QTextList::autoNumberingPrefixAndSuffixHtmlExportImport()
QCOMPARE(importCursor.currentList()->itemNumber(importCursor.block()), 27);
QCOMPARE(importCursor.currentList()->itemText(importCursor.block()), QLatin1String("\"ab#"));
QCOMPARE(importCursor.currentList()->format().indent(), 10);
+#endif
}
void tst_QTextList::autoNumberingRTL()
diff --git a/tests/auto/gui/text/qtextmarkdownwriter/data/example.md b/tests/auto/gui/text/qtextmarkdownwriter/data/example.md
index 15b30598e6..8fdad207ae 100644
--- a/tests/auto/gui/text/qtextmarkdownwriter/data/example.md
+++ b/tests/auto/gui/text/qtextmarkdownwriter/data/example.md
@@ -40,7 +40,7 @@ numerals in the same list structure:
1. Introduction
2. Qt Tools
1) Qt Assistant
- 2) Qt Designer
+ 2) Qt Widgets Designer
1. Form Editor
2. Component Architecture
3) Qt Linguist
@@ -70,7 +70,7 @@ column spans, text formatting within cells, and size constraints for columns.
|-------------|------------------------------------|---------------------------|-------------------------|
|9:00 - 11:00 |Introduction to Qt |||
|11:00 - 13:00|Using qmake |Object-oriented Programming|Layouts in Qt |
-|13:00 - 15:00|Qt Designer Tutorial |Extreme Programming |Writing Custom Styles |
+|13:00 - 15:00|Qt Widgets Designer Tutorial |Extreme Programming |Writing Custom Styles |
|15:00 - 17:00|Qt Linguist and Internationalization|Test-Driven Development | |
*Try adding text to the cells in the table and experiment with the alignment of
diff --git a/tests/auto/gui/text/qtexttable/tst_qtexttable.cpp b/tests/auto/gui/text/qtexttable/tst_qtexttable.cpp
index 6fb5858c64..a7e319ef62 100644
--- a/tests/auto/gui/text/qtexttable/tst_qtexttable.cpp
+++ b/tests/auto/gui/text/qtexttable/tst_qtexttable.cpp
@@ -75,6 +75,8 @@ private slots:
#endif
void checkBorderAttributes_data();
void checkBorderAttributes();
+ void checkTableBorderAttributes_data();
+ void checkTableBorderAttributes();
#ifndef QT_NO_WIDGETS
void columnWidthWithSpans();
@@ -1234,6 +1236,7 @@ void tst_QTextTable::checkBorderAttributes()
QFETCH(QBrush, leftBorderBrush);
QFETCH(QBrush, rightBorderBrush);
+#ifndef QT_NO_TEXTHTMLPARSER
QTextDocument doc;
doc.setHtml(html);
QTextCursor cursor(doc.firstBlock());
@@ -1259,6 +1262,75 @@ void tst_QTextTable::checkBorderAttributes()
QCOMPARE(cellFormat.brushProperty(QTextFormat::TableCellRightBorderBrush), rightBorderBrush);
}
}
+#endif
+}
+
+void tst_QTextTable::checkTableBorderAttributes_data()
+{
+ QTest::addColumn<QString>("html");
+ QTest::addColumn<qreal>("tableBorderWidth");
+ QTest::addColumn<QTextFrameFormat::BorderStyle>("tableBorderStyle");
+ QTest::addColumn<QBrush>("tableBorderBrush");
+
+ const QString tableHtmlStart = QStringLiteral("<html><head><style>");
+ const QString tableHtmlEnd1 = QStringLiteral("</style></head><body>"
+ "<table><tr><td>One</td><td>Two</td></tr></table>"
+ "</body></html>");
+ const QString tableHtmlEnd2 = QStringLiteral("</style></head><body>"
+ "<table border=10><tr><td>One</td><td>Two</td></tr></table>"
+ "</body></html>");
+
+ QTest::newRow("table-border-attributes-shorthand")
+ << QString("%1"
+ "table {"
+ "border: 2px solid red;"
+ "}"
+ "%2").arg(tableHtmlStart).arg(tableHtmlEnd1)
+ << 2.0 << QTextFrameFormat::BorderStyle_Solid << QBrush(Qt::red);
+
+ QTest::newRow("table-border-attributes-explicit")
+ << QString("%1"
+ "table {"
+ "border-width: 2px;"
+ "border-color: red;"
+ "border-style: dashed;"
+ "}"
+ "%2").arg(tableHtmlStart).arg(tableHtmlEnd1)
+ << 2.0 << QTextFrameFormat::BorderStyle_Dashed << QBrush(Qt::red);
+
+ QTest::newRow("table-border-override")
+ << QString("%1"
+ "table {"
+ "border: 2px solid red;"
+ "}"
+ "%2").arg(tableHtmlStart).arg(tableHtmlEnd2)
+ << 2.0 << QTextFrameFormat::BorderStyle_Solid << QBrush(Qt::red);
+
+ QTest::newRow("table-border-default")
+ << QString("%1"
+ "%2").arg(tableHtmlStart).arg(tableHtmlEnd2)
+ << 10.0 << QTextFrameFormat::BorderStyle_Outset << QBrush(Qt::darkGray);
+}
+
+void tst_QTextTable::checkTableBorderAttributes()
+{
+ QFETCH(QString, html);
+ QFETCH(qreal, tableBorderWidth);
+ QFETCH(QTextFrameFormat::BorderStyle, tableBorderStyle);
+ QFETCH(QBrush, tableBorderBrush);
+
+#ifndef QT_NO_TEXTHTMLPARSER
+ QTextDocument doc;
+ doc.setHtml(html);
+ QTextCursor cursor(doc.firstBlock());
+ cursor.movePosition(QTextCursor::Right);
+
+ QTextTable *currentTable = cursor.currentTable();
+ QVERIFY(currentTable);
+ QCOMPARE(currentTable->format().border(), tableBorderWidth);
+ QCOMPARE(currentTable->format().borderStyle(), tableBorderStyle);
+ QCOMPARE(currentTable->format().borderBrush(), tableBorderBrush);
+#endif
}
#ifndef QT_NO_WIDGETS
@@ -1317,6 +1389,7 @@ void tst_QTextTable::columnWidthWithImage()
QFETCH(QString, rightHtml);
QFETCH(QSize, imageSize);
+#ifndef QT_NO_TEXTHTMLPARSER
QTextDocument doc;
doc.setHtml(tableTemplate.arg(leftHtml).arg(rightHtml));
QTextEdit textEdit;
@@ -1336,6 +1409,7 @@ void tst_QTextTable::columnWidthWithImage()
const QRectF rightRect = currentTable->document()->documentLayout()->blockBoundingRect(block);
QCOMPARE(leftRect.size().toSize(), imageSize);
QVERIFY(rightRect.left() > leftRect.right());
+#endif
}
#endif