void tst_qquickstyledtext::longString() { QTextLayout layout; QList<QQuickStyledTextImgTag*> imgTags; bool fontSizeModified = false; QString input(9999999, QChar('.')); QQuickStyledText::parse(input, layout, imgTags, QUrl(), 0, false, &fontSizeModified); QCOMPARE(layout.text(), input); input = QString(9999999, QChar('\t')); // whitespace QQuickStyledText::parse(input, layout, imgTags, QUrl(), 0, false, &fontSizeModified); QCOMPARE(layout.text(), QString("")); }
void tst_qquickstyledtext::textOutput() { QFETCH(QString, input); QFETCH(QString, output); QFETCH(FormatList, formats); QFETCH(bool, modifiesFontSize); QTextLayout layout; QList<QQuickStyledTextImgTag*> imgTags; bool fontSizeModified = false; QQuickStyledText::parse(input, layout, imgTags, QUrl(), 0, false, &fontSizeModified); QCOMPARE(layout.text(), output); QList<QTextLayout::FormatRange> layoutFormats = layout.additionalFormats(); QCOMPARE(layoutFormats.count(), formats.count()); for (int i = 0; i < formats.count(); ++i) { QCOMPARE(layoutFormats.at(i).start, formats.at(i).start); QCOMPARE(layoutFormats.at(i).length, formats.at(i).length); if (formats.at(i).type & Format::Bold) QVERIFY(layoutFormats.at(i).format.fontWeight() == QFont::Bold); else QVERIFY(layoutFormats.at(i).format.fontWeight() == QFont::Normal); QVERIFY(layoutFormats.at(i).format.fontItalic() == bool(formats.at(i).type & Format::Italic)); QVERIFY(layoutFormats.at(i).format.fontUnderline() == bool(formats.at(i).type & Format::Underline)); } QCOMPARE(fontSizeModified, modifiesFontSize); }
void tst_qdeclarativestyledtext::textOutput() { QFETCH(QString, input); QFETCH(QString, output); QTextLayout layout; QDeclarativeStyledText::parse(input, layout); QCOMPARE(layout.text(), output); }
// Origin: Qt static void viewItemTextLayout(QTextLayout &textLayout, int lineWidth, qreal &height, qreal &widthUsed) { height = 0; widthUsed = 0; textLayout.beginLayout(); QString str = textLayout.text(); while (true) { QTextLine line = textLayout.createLine(); if (!line.isValid()) break; if (line.textLength() == 0) break; line.setLineWidth(lineWidth); line.setPosition(QPointF(0, height)); height += line.height(); widthUsed = qMax(widthUsed, line.naturalTextWidth()); } textLayout.endLayout(); }
void tst_qquickstyledtext::anchors() { QFETCH(QString, input); QFETCH(QString, output); QFETCH(FormatList, formats); QTextLayout layout; QList<QQuickStyledTextImgTag*> imgTags; bool fontSizeModified = false; QQuickStyledText::parse(input, layout, imgTags, QUrl(), 0, false, &fontSizeModified); QCOMPARE(layout.text(), output); QList<QTextLayout::FormatRange> layoutFormats = layout.additionalFormats(); QCOMPARE(layoutFormats.count(), formats.count()); for (int i = 0; i < formats.count(); ++i) { QCOMPARE(layoutFormats.at(i).start, formats.at(i).start); QCOMPARE(layoutFormats.at(i).length, formats.at(i).length); QVERIFY(layoutFormats.at(i).format.isAnchor() == bool(formats.at(i).type & Format::Anchor)); } }