enable the text layout's cache where it is seems to be missed

e.g. in QStaticText, the data is used just to get the line's y-position
and re-calculates just after the loop to determine the bounding rect and to draw the text;

in QWidgetLineControl, the data re-calculated over and over while the result
is seems to remain the same; probably the caching is needed here too

Change-Id: I0f7eb291532f63eccb9c5f749daebb73ff90632f
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com>
This commit is contained in:
Konstantin Ritt 2012-05-15 20:02:53 +03:00 committed by Qt by Nokia
parent 6eae3e1da3
commit 279562172d
8 changed files with 62 additions and 3 deletions

View File

@ -41,6 +41,7 @@
//! [0] //! [0]
int leading = fontMetrics.leading(); int leading = fontMetrics.leading();
qreal height = 0; qreal height = 0;
textLayout.setCacheEnabled(true);
textLayout.beginLayout(); textLayout.beginLayout();
while (1) { while (1) {
QTextLine line = textLayout.createLine(); QTextLine line = textLayout.createLine();

View File

@ -610,6 +610,7 @@ void QStaticTextPrivate::paintText(const QPointF &topLeftPosition, QPainter *p)
textLayout.setText(text); textLayout.setText(text);
textLayout.setFont(font); textLayout.setFont(font);
textLayout.setTextOption(textOption); textLayout.setTextOption(textOption);
textLayout.setCacheEnabled(true);
qreal leading = QFontMetricsF(font).leading(); qreal leading = QFontMetricsF(font).leading();
qreal height = -leading; qreal height = -leading;

View File

@ -351,6 +351,7 @@ void QWidgetLineControl::_q_deleteSelected()
*/ */
void QWidgetLineControl::init(const QString &txt) void QWidgetLineControl::init(const QString &txt)
{ {
m_textLayout.setCacheEnabled(true);
m_text = txt; m_text = txt;
updateDisplayText(); updateDisplayText();
m_cursor = m_text.length(); m_cursor = m_text.length();

View File

@ -244,6 +244,7 @@ void tst_QGlyphRun::textLayoutGlyphIndexes()
QTextLayout layout(s); QTextLayout layout(s);
layout.setFont(m_testFont); layout.setFont(m_testFont);
layout.setCacheEnabled(true);
layout.beginLayout(); layout.beginLayout();
layout.createLine(); layout.createLine();
layout.endLayout(); layout.endLayout();
@ -273,6 +274,7 @@ void tst_QGlyphRun::drawExistingGlyphs()
QTextLayout layout(s); QTextLayout layout(s);
layout.setFont(m_testFont); layout.setFont(m_testFont);
layout.setCacheEnabled(true);
layout.beginLayout(); layout.beginLayout();
layout.createLine(); layout.createLine();
layout.endLayout(); layout.endLayout();
@ -411,6 +413,7 @@ void tst_QGlyphRun::drawMultiScriptText1()
text += QChar(0x03D0); // Greek, beta text += QChar(0x03D0); // Greek, beta
QTextLayout textLayout(text); QTextLayout textLayout(text);
textLayout.setCacheEnabled(true);
textLayout.beginLayout(); textLayout.beginLayout();
textLayout.createLine(); textLayout.createLine();
textLayout.endLayout(); textLayout.endLayout();
@ -451,6 +454,7 @@ void tst_QGlyphRun::drawMultiScriptText2()
text += QChar(0x03D0); // Greek, beta text += QChar(0x03D0); // Greek, beta
QTextLayout textLayout(text); QTextLayout textLayout(text);
textLayout.setCacheEnabled(true);
textLayout.beginLayout(); textLayout.beginLayout();
textLayout.createLine(); textLayout.createLine();
textLayout.endLayout(); textLayout.endLayout();
@ -515,6 +519,7 @@ void tst_QGlyphRun::drawStruckOutText()
QTextLayout layout(s); QTextLayout layout(s);
layout.setFont(font); layout.setFont(font);
layout.setCacheEnabled(true);
layout.beginLayout(); layout.beginLayout();
layout.createLine(); layout.createLine();
layout.endLayout(); layout.endLayout();
@ -556,6 +561,7 @@ void tst_QGlyphRun::drawOverlinedText()
QTextLayout layout(s); QTextLayout layout(s);
layout.setFont(font); layout.setFont(font);
layout.setCacheEnabled(true);
layout.beginLayout(); layout.beginLayout();
layout.createLine(); layout.createLine();
layout.endLayout(); layout.endLayout();
@ -597,6 +603,7 @@ void tst_QGlyphRun::drawUnderlinedText()
QTextLayout layout(s); QTextLayout layout(s);
layout.setFont(font); layout.setFont(font);
layout.setCacheEnabled(true);
layout.beginLayout(); layout.beginLayout();
layout.createLine(); layout.createLine();
layout.endLayout(); layout.endLayout();
@ -640,6 +647,7 @@ void tst_QGlyphRun::drawRightToLeft()
QTextLayout layout(s); QTextLayout layout(s);
layout.setFont(font); layout.setFont(font);
layout.setCacheEnabled(true);
layout.beginLayout(); layout.beginLayout();
layout.createLine(); layout.createLine();
layout.endLayout(); layout.endLayout();

View File

@ -325,6 +325,7 @@ void tst_QRawFont::textLayout()
QTextLayout layout(QLatin1String("Foobar")); QTextLayout layout(QLatin1String("Foobar"));
layout.setFont(font); layout.setFont(font);
layout.setCacheEnabled(true);
layout.beginLayout(); layout.beginLayout();
layout.createLine(); layout.createLine();
layout.endLayout(); layout.endLayout();
@ -822,6 +823,7 @@ void tst_QRawFont::unsupportedWritingSystem()
QTextLayout layout; QTextLayout layout;
layout.setFont(font); layout.setFont(font);
layout.setText(arabicText); layout.setText(arabicText);
layout.setCacheEnabled(true);
layout.beginLayout(); layout.beginLayout();
layout.createLine(); layout.createLine();
layout.endLayout(); layout.endLayout();
@ -862,6 +864,7 @@ void tst_QRawFont::rawFontSetPixelSize()
font.setPixelSize(12); font.setPixelSize(12);
layout.setFont(font); layout.setFont(font);
layout.setCacheEnabled(true);
layout.beginLayout(); layout.beginLayout();
layout.createLine(); layout.createLine();
layout.endLayout(); layout.endLayout();

View File

@ -415,6 +415,8 @@ void tst_QTextLayout::forcedBreaks()
QCOMPARE(qRound(line.naturalTextWidth()), testFont.pixelSize()); QCOMPARE(qRound(line.naturalTextWidth()), testFont.pixelSize());
QCOMPARE((int) line.height(), testFont.pixelSize()); QCOMPARE((int) line.height(), testFont.pixelSize());
QCOMPARE(line.xToCursor(0), line.textStart()); QCOMPARE(line.xToCursor(0), line.textStart());
layout.endLayout();
} }
void tst_QTextLayout::breakAny() void tst_QTextLayout::breakAny()
@ -425,6 +427,7 @@ void tst_QTextLayout::breakAny()
QString text = "ABCD"; QString text = "ABCD";
QTextLayout layout(text, testFont); QTextLayout layout(text, testFont);
layout.setCacheEnabled(true);
QTextLine line; QTextLine line;
QTextOption opt; QTextOption opt;
@ -506,6 +509,7 @@ void tst_QTextLayout::cursorToXForInlineObjects()
void tst_QTextLayout::cursorToXForSetColumns() void tst_QTextLayout::cursorToXForSetColumns()
{ {
QTextLayout lay("abc", testFont); QTextLayout lay("abc", testFont);
lay.setCacheEnabled(true);
QTextOption o = lay.textOption(); QTextOption o = lay.textOption();
o.setWrapMode(QTextOption::WrapAnywhere); o.setWrapMode(QTextOption::WrapAnywhere);
@ -614,6 +618,7 @@ void tst_QTextLayout::xToCursorAtEndOfLine()
const qreal firstLineWidth = QString("FirstLine").length() * testFont.pixelSize(); const qreal firstLineWidth = QString("FirstLine").length() * testFont.pixelSize();
QTextLayout layout(text, testFont); QTextLayout layout(text, testFont);
layout.setCacheEnabled(true);
layout.beginLayout(); layout.beginLayout();
QTextLine line = layout.createLine(); QTextLine line = layout.createLine();
@ -635,6 +640,7 @@ void tst_QTextLayout::boundingRectTopLeft()
text.replace('\n', QChar::LineSeparator); text.replace('\n', QChar::LineSeparator);
QTextLayout layout(text, testFont); QTextLayout layout(text, testFont);
layout.setCacheEnabled(true);
layout.beginLayout(); layout.beginLayout();
QTextLine firstLine = layout.createLine(); QTextLine firstLine = layout.createLine();
@ -711,6 +717,7 @@ void tst_QTextLayout::setNumColumnsWrapAtWordBoundaryOrAnywhere()
{ {
QString txt("This is a small test text"); QString txt("This is a small test text");
QTextLayout layout(txt, testFont); QTextLayout layout(txt, testFont);
layout.setCacheEnabled(true);
QTextOption option = layout.textOption(); QTextOption option = layout.textOption();
option.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere); option.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
layout.setTextOption(option); layout.setTextOption(option);
@ -734,6 +741,7 @@ void tst_QTextLayout::setNumColumnsWordWrap()
{ {
QString txt("This is a small test text"); QString txt("This is a small test text");
QTextLayout layout(txt, testFont); QTextLayout layout(txt, testFont);
layout.setCacheEnabled(true);
QTextOption option = layout.textOption(); QTextOption option = layout.textOption();
option.setWrapMode(QTextOption::WordWrap); option.setWrapMode(QTextOption::WordWrap);
layout.setTextOption(option); layout.setTextOption(option);
@ -757,6 +765,7 @@ void tst_QTextLayout::smallTextLengthNoWrap()
{ {
QString txt("This is a small test text"); QString txt("This is a small test text");
QTextLayout layout(txt, testFont); QTextLayout layout(txt, testFont);
layout.setCacheEnabled(true);
QTextOption option = layout.textOption(); QTextOption option = layout.textOption();
option.setWrapMode(QTextOption::NoWrap); option.setWrapMode(QTextOption::NoWrap);
layout.setTextOption(option); layout.setTextOption(option);
@ -780,6 +789,7 @@ void tst_QTextLayout::smallTextLengthWordWrap()
{ {
QString txt("This is a small test text"); QString txt("This is a small test text");
QTextLayout layout(txt, testFont); QTextLayout layout(txt, testFont);
layout.setCacheEnabled(true);
QTextOption option = layout.textOption(); QTextOption option = layout.textOption();
option.setWrapMode(QTextOption::WordWrap); option.setWrapMode(QTextOption::WordWrap);
layout.setTextOption(option); layout.setTextOption(option);
@ -804,6 +814,7 @@ void tst_QTextLayout::smallTextLengthWrapAtWordBoundaryOrAnywhere()
{ {
QString txt("This is a small test text"); QString txt("This is a small test text");
QTextLayout layout(txt, testFont); QTextLayout layout(txt, testFont);
layout.setCacheEnabled(true);
QTextOption option = layout.textOption(); QTextOption option = layout.textOption();
option.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere); option.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
layout.setTextOption(option); layout.setTextOption(option);
@ -827,6 +838,7 @@ void tst_QTextLayout::smallTextLengthWrapAtWordBoundaryOrAnywhere()
void tst_QTextLayout::testDefaultTabs() void tst_QTextLayout::testDefaultTabs()
{ {
QTextLayout layout("Foo\tBar\ta slightly longer text\tend.", testFont); QTextLayout layout("Foo\tBar\ta slightly longer text\tend.", testFont);
layout.setCacheEnabled(true);
layout.beginLayout(); layout.beginLayout();
QTextLine line = layout.createLine(); QTextLine line = layout.createLine();
line.setLineWidth(1000); line.setLineWidth(1000);
@ -868,6 +880,7 @@ void tst_QTextLayout::testDefaultTabs()
void tst_QTextLayout::testTabs() void tst_QTextLayout::testTabs()
{ {
QTextLayout layout("Foo\tBar.", testFont); QTextLayout layout("Foo\tBar.", testFont);
layout.setCacheEnabled(true);
QTextOption option = layout.textOption(); QTextOption option = layout.textOption();
option.setTabStop(150); option.setTabStop(150);
layout.setTextOption(option); layout.setTextOption(option);
@ -884,6 +897,7 @@ void tst_QTextLayout::testTabs()
void tst_QTextLayout::testMultilineTab() void tst_QTextLayout::testMultilineTab()
{ {
QTextLayout layout("Lorem ipsum dolor sit\tBar.", testFont); QTextLayout layout("Lorem ipsum dolor sit\tBar.", testFont);
layout.setCacheEnabled(true);
// test if this works on the second line. // test if this works on the second line.
layout.beginLayout(); layout.beginLayout();
QTextLine line = layout.createLine(); QTextLine line = layout.createLine();
@ -898,6 +912,7 @@ void tst_QTextLayout::testMultilineTab()
void tst_QTextLayout::testMultiTab() void tst_QTextLayout::testMultiTab()
{ {
QTextLayout layout("Foo\t\t\tBar.", testFont); QTextLayout layout("Foo\t\t\tBar.", testFont);
layout.setCacheEnabled(true);
layout.beginLayout(); layout.beginLayout();
QTextLine line = layout.createLine(); QTextLine line = layout.createLine();
line.setLineWidth(1000.); line.setLineWidth(1000.);
@ -909,6 +924,7 @@ void tst_QTextLayout::testMultiTab()
void tst_QTextLayout::testTabsInAlignedParag() void tst_QTextLayout::testTabsInAlignedParag()
{ {
QTextLayout layout("Foo\tsome more words", testFont); QTextLayout layout("Foo\tsome more words", testFont);
layout.setCacheEnabled(true);
QTextOption option = layout.textOption(); QTextOption option = layout.textOption();
// right // right
option.setAlignment(Qt::AlignRight); option.setAlignment(Qt::AlignRight);
@ -966,6 +982,7 @@ void tst_QTextLayout::testRightTab()
c) tab is after last tab (both auto and defined) and thus moves text to start of next line. c) tab is after last tab (both auto and defined) and thus moves text to start of next line.
d) tab takes space so text until enter fits to tab pos. d) tab takes space so text until enter fits to tab pos.
*/ */
layout.setCacheEnabled(true);
QTextOption option = layout.textOption(); QTextOption option = layout.textOption();
QList<QTextOption::Tab> tabs; QList<QTextOption::Tab> tabs;
@ -1004,6 +1021,7 @@ void tst_QTextLayout::testRightTab()
void tst_QTextLayout::testCenteredTab() void tst_QTextLayout::testCenteredTab()
{ {
QTextLayout layout("Foo\tBar", testFont); QTextLayout layout("Foo\tBar", testFont);
layout.setCacheEnabled(true);
// test if centering the tab works. We expect the center of 'Bar.' to be at the tab point. // test if centering the tab works. We expect the center of 'Bar.' to be at the tab point.
QTextOption option = layout.textOption(); QTextOption option = layout.textOption();
QList<QTextOption::Tab> tabs; QList<QTextOption::Tab> tabs;
@ -1024,6 +1042,7 @@ void tst_QTextLayout::testCenteredTab()
void tst_QTextLayout::testDelimiterTab() void tst_QTextLayout::testDelimiterTab()
{ {
QTextLayout layout("Foo\tBar. Barrabas", testFont); QTextLayout layout("Foo\tBar. Barrabas", testFont);
layout.setCacheEnabled(true);
// try the different delimiter characters to see if the alignment works there. // try the different delimiter characters to see if the alignment works there.
QTextOption option = layout.textOption(); QTextOption option = layout.textOption();
QList<QTextOption::Tab> tabs; QList<QTextOption::Tab> tabs;
@ -1044,6 +1063,7 @@ void tst_QTextLayout::testDelimiterTab()
void tst_QTextLayout::testLineBreakingAllSpaces() void tst_QTextLayout::testLineBreakingAllSpaces()
{ {
QTextLayout layout(" 123", testFont); // thats 20 spaces QTextLayout layout(" 123", testFont); // thats 20 spaces
layout.setCacheEnabled(true);
const qreal firstLineWidth = 17 * TESTFONT_SIZE; const qreal firstLineWidth = 17 * TESTFONT_SIZE;
layout.beginLayout(); layout.beginLayout();
QTextLine line1 = layout.createLine(); QTextLine line1 = layout.createLine();
@ -1073,6 +1093,7 @@ void tst_QTextLayout::tabsForRtl()
c) right tab on RTL is a left tab; so its at width - 240 c) right tab on RTL is a left tab; so its at width - 240
d) center tab is still a centered tab. d) center tab is still a centered tab.
*/ */
layout.setCacheEnabled(true);
QTextOption option = layout.textOption(); QTextOption option = layout.textOption();
QList<QTextOption::Tab> tabs; QList<QTextOption::Tab> tabs;
@ -1135,6 +1156,7 @@ void tst_QTextLayout::testTabDPIScale()
MyPaintDevice pd; MyPaintDevice pd;
QTextLayout layout("text1\ttext2\ttext3\tend", testFont, &pd); QTextLayout layout("text1\ttext2\ttext3\tend", testFont, &pd);
layout.setCacheEnabled(true);
QTextOption option = layout.textOption(); QTextOption option = layout.textOption();
QList<QTextOption::Tab> tabs; QList<QTextOption::Tab> tabs;
@ -1171,6 +1193,7 @@ void tst_QTextLayout::testTabDPIScale()
void tst_QTextLayout::tabHeight() void tst_QTextLayout::tabHeight()
{ {
QTextLayout layout("\t", testFont); QTextLayout layout("\t", testFont);
layout.setCacheEnabled(true);
layout.beginLayout(); layout.beginLayout();
QTextLine line = layout.createLine(); QTextLine line = layout.createLine();
layout.endLayout(); layout.endLayout();
@ -1184,6 +1207,7 @@ void tst_QTextLayout::capitalization_allUpperCase()
QFont font(testFont); QFont font(testFont);
font.setCapitalization(QFont::AllUppercase); font.setCapitalization(QFont::AllUppercase);
QTextLayout layout("Test", font); QTextLayout layout("Test", font);
layout.setCacheEnabled(true);
layout.beginLayout(); layout.beginLayout();
layout.createLine(); layout.createLine();
layout.endLayout(); layout.endLayout();
@ -1199,6 +1223,7 @@ void tst_QTextLayout::capitalization_allLowerCase()
QFont font(testFont); QFont font(testFont);
font.setCapitalization(QFont::AllLowercase); font.setCapitalization(QFont::AllLowercase);
QTextLayout layout("Test", font); QTextLayout layout("Test", font);
layout.setCacheEnabled(true);
layout.beginLayout(); layout.beginLayout();
layout.createLine(); layout.createLine();
layout.endLayout(); layout.endLayout();
@ -1214,6 +1239,7 @@ void tst_QTextLayout::capitalization_smallCaps()
QFont font(testFont); QFont font(testFont);
font.setCapitalization(QFont::SmallCaps); font.setCapitalization(QFont::SmallCaps);
QTextLayout layout("Test", font); QTextLayout layout("Test", font);
layout.setCacheEnabled(true);
layout.beginLayout(); layout.beginLayout();
layout.createLine(); layout.createLine();
layout.endLayout(); layout.endLayout();
@ -1230,6 +1256,7 @@ void tst_QTextLayout::capitalization_capitalize()
QFont font(testFont); QFont font(testFont);
font.setCapitalization(QFont::Capitalize); font.setCapitalization(QFont::Capitalize);
QTextLayout layout("hello\tworld", font); QTextLayout layout("hello\tworld", font);
layout.setCacheEnabled(true);
layout.beginLayout(); layout.beginLayout();
layout.createLine(); layout.createLine();
layout.endLayout(); layout.endLayout();
@ -1250,6 +1277,7 @@ void tst_QTextLayout::longText()
{ {
QTextLayout layout(longText, testFont); QTextLayout layout(longText, testFont);
layout.setCacheEnabled(true);
layout.beginLayout(); layout.beginLayout();
QTextLine line = layout.createLine(); QTextLine line = layout.createLine();
layout.endLayout(); layout.endLayout();
@ -1261,6 +1289,7 @@ void tst_QTextLayout::longText()
QFont f(testFont); QFont f(testFont);
f.setCapitalization(QFont::Capitalization(cap)); f.setCapitalization(QFont::Capitalization(cap));
QTextLayout layout(longText, f); QTextLayout layout(longText, f);
layout.setCacheEnabled(true);
layout.beginLayout(); layout.beginLayout();
QTextLine line = layout.createLine(); QTextLine line = layout.createLine();
layout.endLayout(); layout.endLayout();
@ -1270,6 +1299,7 @@ void tst_QTextLayout::longText()
{ {
QTextLayout layout(longText, testFont); QTextLayout layout(longText, testFont);
layout.setCacheEnabled(true);
layout.setFlags(Qt::TextForceLeftToRight); layout.setFlags(Qt::TextForceLeftToRight);
layout.beginLayout(); layout.beginLayout();
QTextLine line = layout.createLine(); QTextLine line = layout.createLine();
@ -1280,6 +1310,7 @@ void tst_QTextLayout::longText()
{ {
QTextLayout layout(longText, testFont); QTextLayout layout(longText, testFont);
layout.setCacheEnabled(true);
layout.setFlags(Qt::TextForceRightToLeft); layout.setFlags(Qt::TextForceRightToLeft);
layout.beginLayout(); layout.beginLayout();
QTextLine line = layout.createLine(); QTextLine line = layout.createLine();
@ -1334,7 +1365,7 @@ void tst_QTextLayout::columnWrapWithTabs()
void tst_QTextLayout::boundingRectForUnsetLineWidth() void tst_QTextLayout::boundingRectForUnsetLineWidth()
{ {
QTextLayout layout("FOOBAR"); QTextLayout layout("FOOBAR");
layout.setCacheEnabled(true);
layout.beginLayout(); layout.beginLayout();
QTextLine line = layout.createLine(); QTextLine line = layout.createLine();
layout.endLayout(); layout.endLayout();
@ -1345,7 +1376,7 @@ void tst_QTextLayout::boundingRectForUnsetLineWidth()
void tst_QTextLayout::boundingRectForSetLineWidth() void tst_QTextLayout::boundingRectForSetLineWidth()
{ {
QTextLayout layout("FOOBAR"); QTextLayout layout("FOOBAR");
layout.setCacheEnabled(true);
layout.beginLayout(); layout.beginLayout();
QTextLine line = layout.createLine(); QTextLine line = layout.createLine();
line.setLineWidth(QFIXED_MAX - 1); line.setLineWidth(QFIXED_MAX - 1);
@ -1388,6 +1419,7 @@ void tst_QTextLayout::glyphLessItems()
void tst_QTextLayout::textWidthVsWIdth() void tst_QTextLayout::textWidthVsWIdth()
{ {
QTextLayout layout; QTextLayout layout;
layout.setCacheEnabled(true);
QTextOption opt; QTextOption opt;
opt.setWrapMode(QTextOption::WrapAnywhere); opt.setWrapMode(QTextOption::WrapAnywhere);
layout.setTextOption(opt); layout.setTextOption(opt);
@ -1417,6 +1449,7 @@ void tst_QTextLayout::textWithSurrogates_qtbug15679()
{ {
QString str = QString::fromUtf8("🀀a🀀"); QString str = QString::fromUtf8("🀀a🀀");
QTextLayout layout(str); QTextLayout layout(str);
layout.setCacheEnabled(true);
layout.beginLayout(); layout.beginLayout();
QTextLine line = layout.createLine(); QTextLine line = layout.createLine();
layout.endLayout(); layout.endLayout();
@ -1436,6 +1469,7 @@ void tst_QTextLayout::textWidthWithStackedTextEngine()
{ {
QString text = QString::fromUtf8("คลิก ถัดไป เพื่อดำเนินการต่อ"); QString text = QString::fromUtf8("คลิก ถัดไป เพื่อดำเนินการต่อ");
QTextLayout layout(text); QTextLayout layout(text);
layout.setCacheEnabled(true);
layout.beginLayout(); layout.beginLayout();
QTextLine line = layout.createLine(); QTextLine line = layout.createLine();
layout.endLayout(); layout.endLayout();
@ -1465,6 +1499,7 @@ void tst_QTextLayout::cursorInLigatureWithMultipleLines()
QSKIP("This test can only be run on Mac"); QSKIP("This test can only be run on Mac");
#endif #endif
QTextLayout layout("first line finish", QFont("Times", 20)); QTextLayout layout("first line finish", QFont("Times", 20));
layout.setCacheEnabled(true);
layout.beginLayout(); layout.beginLayout();
QTextLine line = layout.createLine(); QTextLine line = layout.createLine();
line.setLineWidth(70); line.setLineWidth(70);
@ -1481,6 +1516,7 @@ void tst_QTextLayout::xToCursorForLigatures()
QSKIP("This test can only be run on Mac"); QSKIP("This test can only be run on Mac");
#endif #endif
QTextLayout layout("fi", QFont("Times", 20)); QTextLayout layout("fi", QFont("Times", 20));
layout.setCacheEnabled(true);
layout.beginLayout(); layout.beginLayout();
QTextLine line = layout.createLine(); QTextLine line = layout.createLine();
layout.endLayout(); layout.endLayout();
@ -1489,7 +1525,7 @@ void tst_QTextLayout::xToCursorForLigatures()
// U+0061 U+0308 // U+0061 U+0308
QTextLayout layout2(QString::fromUtf8("\x61\xCC\x88"), QFont("Times", 20)); QTextLayout layout2(QString::fromUtf8("\x61\xCC\x88"), QFont("Times", 20));
layout2.setCacheEnabled(true);
layout2.beginLayout(); layout2.beginLayout();
line = layout2.createLine(); line = layout2.createLine();
layout2.endLayout(); layout2.endLayout();
@ -1505,6 +1541,7 @@ void tst_QTextLayout::cursorInNonStopChars()
QSKIP("This test can not be run on Mac"); QSKIP("This test can not be run on Mac");
#endif #endif
QTextLayout layout(QString::fromUtf8("\xE0\xA4\xA4\xE0\xA5\x8D\xE0\xA4\xA8")); QTextLayout layout(QString::fromUtf8("\xE0\xA4\xA4\xE0\xA5\x8D\xE0\xA4\xA8"));
layout.setCacheEnabled(true);
layout.beginLayout(); layout.beginLayout();
QTextLine line = layout.createLine(); QTextLine line = layout.createLine();
layout.endLayout(); layout.endLayout();

View File

@ -1231,6 +1231,7 @@ void tst_QTextScriptEngine::mirroredChars()
HB_Glyph rightParenthesis; HB_Glyph rightParenthesis;
{ {
QTextLayout layout(s); QTextLayout layout(s);
layout.setCacheEnabled(true);
layout.beginLayout(); layout.beginLayout();
layout.createLine(); layout.createLine();
layout.endLayout(); layout.endLayout();
@ -1267,6 +1268,7 @@ void tst_QTextScriptEngine::thaiIsolatedSaraAm()
s.append(QChar(0x0e33)); s.append(QChar(0x0e33));
QTextLayout layout(s, QFont("Waree")); QTextLayout layout(s, QFont("Waree"));
layout.setCacheEnabled(true);
layout.beginLayout(); layout.beginLayout();
layout.createLine(); layout.createLine();
layout.endLayout(); layout.endLayout();
@ -1289,6 +1291,7 @@ void tst_QTextScriptEngine::thaiWithZWJ()
#endif #endif
QString s(QString::fromUtf8("ร‍ร‌.ร.“ร…ร”ร\xA0ร本ร") + QChar(0x0363)/*superscript 'a', for testing Inherited class*/); QString s(QString::fromUtf8("ร‍ร‌.ร.“ร…ร”ร\xA0ร本ร") + QChar(0x0363)/*superscript 'a', for testing Inherited class*/);
QTextLayout layout(s); QTextLayout layout(s);
layout.setCacheEnabled(true);
layout.beginLayout(); layout.beginLayout();
layout.createLine(); layout.createLine();
layout.endLayout(); layout.endLayout();
@ -1341,6 +1344,7 @@ void tst_QTextScriptEngine::thaiMultipleVowels()
for (int i = 0; i < 10; i++) for (int i = 0; i < 10; i++)
s += s; //Repeat the string to make it more likely to crash if we have a buffer overflow s += s; //Repeat the string to make it more likely to crash if we have a buffer overflow
QTextLayout layout(s); QTextLayout layout(s);
layout.setCacheEnabled(true);
layout.beginLayout(); layout.beginLayout();
layout.createLine(); layout.createLine();
layout.endLayout(); layout.endLayout();

View File

@ -168,6 +168,7 @@ void tst_QComplexText::bidiCursor_qtbug2795()
QTextLayout l1(str); QTextLayout l1(str);
l1.beginLayout(); l1.beginLayout();
l1.setCacheEnabled(true);
QTextLine line1 = l1.createLine(); QTextLine line1 = l1.createLine();
l1.endLayout(); l1.endLayout();
@ -175,6 +176,7 @@ void tst_QComplexText::bidiCursor_qtbug2795()
str.append("1"); str.append("1");
QTextLayout l2(str); QTextLayout l2(str);
l2.setCacheEnabled(true);
l2.beginLayout(); l2.beginLayout();
QTextLine line2 = l2.createLine(); QTextLine line2 = l2.createLine();
l2.endLayout(); l2.endLayout();
@ -206,6 +208,7 @@ void tst_QComplexText::bidiCursorMovement()
QFETCH(int, basicDir); QFETCH(int, basicDir);
QTextLayout layout(logical); QTextLayout layout(logical);
layout.setCacheEnabled(true);
QTextOption option = layout.textOption(); QTextOption option = layout.textOption();
option.setTextDirection(basicDir == QChar::DirL ? Qt::LeftToRight : Qt::RightToLeft); option.setTextDirection(basicDir == QChar::DirL ? Qt::LeftToRight : Qt::RightToLeft);
@ -273,6 +276,7 @@ void tst_QComplexText::bidiCursor_PDF()
{ {
QString str = QString::fromUtf8("\342\200\252hello\342\200\254"); QString str = QString::fromUtf8("\342\200\252hello\342\200\254");
QTextLayout layout(str); QTextLayout layout(str);
layout.setCacheEnabled(true);
layout.beginLayout(); layout.beginLayout();
QTextLine line = layout.createLine(); QTextLine line = layout.createLine();