author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Mon, 04 Oct 2010 01:19:32 +0300 | |
changeset 37 | 758a864f9613 |
parent 33 | 3e2da88830cd |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the test suite of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
||
43 |
/* |
|
44 |
!!!!!! Warning !!!!! |
|
45 |
Please don't save this file in emacs. It contains utf8 text sequences emacs will |
|
46 |
silently convert to a series of question marks. |
|
47 |
*/ |
|
48 |
#include <QtTest/QtTest> |
|
49 |
||
50 |
||
51 |
||
52 |
#include <private/qtextengine_p.h> |
|
53 |
#include <qtextlayout.h> |
|
54 |
||
55 |
#include <qdebug.h> |
|
56 |
||
57 |
||
58 |
#define TESTFONT_SIZE 12 |
|
59 |
||
60 |
//TESTED_CLASS= |
|
61 |
//TESTED_FILES= |
|
62 |
||
63 |
class tst_QTextLayout : public QObject |
|
64 |
{ |
|
65 |
Q_OBJECT |
|
66 |
||
67 |
public: |
|
68 |
tst_QTextLayout(); |
|
69 |
virtual ~tst_QTextLayout(); |
|
70 |
||
71 |
||
72 |
public slots: |
|
73 |
void init(); |
|
74 |
void cleanup(); |
|
75 |
private slots: |
|
76 |
void getSetCheck(); |
|
77 |
void lineBreaking(); |
|
78 |
void simpleBoundingRect(); |
|
79 |
void threeLineBoundingRect(); |
|
80 |
void boundingRectWithLongLineAndNoWrap(); |
|
81 |
void forcedBreaks(); |
|
82 |
void breakAny(); |
|
83 |
void noWrap(); |
|
84 |
void cursorToXForInlineObjects(); |
|
85 |
void cursorToXForSetColumns(); |
|
86 |
void defaultWordSeparators_data(); |
|
87 |
void defaultWordSeparators(); |
|
88 |
void cursorMovementInsideSpaces(); |
|
89 |
void charWordStopOnLineSeparator(); |
|
90 |
void xToCursorAtEndOfLine(); |
|
91 |
void boundingRectTopLeft(); |
|
92 |
void charStopForSurrogatePairs(); |
|
93 |
void tabStops(); |
|
94 |
void integerOverflow(); |
|
95 |
void testDefaultTabs(); |
|
96 |
void testTabs(); |
|
97 |
void testMultilineTab(); |
|
98 |
void testRightTab(); |
|
99 |
void testTabsInAlignedParag(); |
|
100 |
void testCenteredTab(); |
|
101 |
void testDelimiterTab(); |
|
102 |
void testMultiTab(); |
|
103 |
void testTabDPIScale(); |
|
104 |
void tabsForRtl(); |
|
105 |
void tabHeight(); |
|
106 |
void capitalization_allUpperCase(); |
|
107 |
void capitalization_allLowerCase(); |
|
108 |
void capitalization_smallCaps(); |
|
109 |
void capitalization_capitalize(); |
|
110 |
void longText(); |
|
111 |
void widthOfTabs(); |
|
112 |
void columnWrapWithTabs(); |
|
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
113 |
void boundingRectForUnsetLineWidth(); |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
114 |
void boundingRectForSetLineWidth(); |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
115 |
void glyphLessItems(); |
0 | 116 |
|
117 |
// QTextLine stuff |
|
118 |
void setNumColumnsWrapAtWordBoundaryOrAnywhere(); |
|
119 |
void setNumColumnsWordWrap(); |
|
120 |
void smallTextLengthNoWrap(); |
|
121 |
void smallTextLengthWordWrap(); |
|
122 |
void smallTextLengthWrapAtWordBoundaryOrAnywhere(); |
|
123 |
void testLineBreakingAllSpaces(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
124 |
void lineWidthFromBOM(); |
37
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
125 |
void textWidthVsWIdth(); |
0 | 126 |
|
127 |
||
128 |
private: |
|
129 |
QFont testFont; |
|
130 |
}; |
|
131 |
||
132 |
// Testing get/set functions |
|
133 |
void tst_QTextLayout::getSetCheck() |
|
134 |
{ |
|
135 |
QString str("Bogus text"); |
|
136 |
QTextLayout layout(str, testFont); |
|
137 |
layout.beginLayout(); |
|
138 |
QTextEngine *engine = layout.engine(); |
|
139 |
QTextInlineObject obj1(0, engine); |
|
140 |
// qreal QTextInlineObject::width() |
|
141 |
// void QTextInlineObject::setWidth(qreal) |
|
142 |
obj1.setWidth(0.0); |
|
143 |
QCOMPARE(0.0, obj1.width()); |
|
144 |
obj1.setWidth(1.2); |
|
145 |
QVERIFY(1.0 < obj1.width()); |
|
146 |
||
147 |
// qreal QTextInlineObject::ascent() |
|
148 |
// void QTextInlineObject::setAscent(qreal) |
|
149 |
obj1.setAscent(0.0); |
|
150 |
QCOMPARE(0.0, obj1.ascent()); |
|
151 |
obj1.setAscent(1.2); |
|
152 |
QVERIFY(1.0 < obj1.ascent()); |
|
153 |
||
154 |
// qreal QTextInlineObject::descent() |
|
155 |
// void QTextInlineObject::setDescent(qreal) |
|
156 |
obj1.setDescent(0.0); |
|
157 |
QCOMPARE(0.0, obj1.descent()); |
|
158 |
obj1.setDescent(1.2); |
|
159 |
QVERIFY(1.0 < obj1.descent()); |
|
160 |
||
161 |
QTextLayout obj2; |
|
162 |
// bool QTextLayout::cacheEnabled() |
|
163 |
// void QTextLayout::setCacheEnabled(bool) |
|
164 |
obj2.setCacheEnabled(false); |
|
165 |
QCOMPARE(false, obj2.cacheEnabled()); |
|
166 |
obj2.setCacheEnabled(true); |
|
167 |
QCOMPARE(true, obj2.cacheEnabled()); |
|
168 |
} |
|
169 |
||
170 |
QT_BEGIN_NAMESPACE |
|
171 |
extern void qt_setQtEnableTestFont(bool value); |
|
172 |
QT_END_NAMESPACE |
|
173 |
||
174 |
tst_QTextLayout::tst_QTextLayout() |
|
175 |
{ |
|
176 |
qt_setQtEnableTestFont(true); |
|
177 |
} |
|
178 |
||
179 |
tst_QTextLayout::~tst_QTextLayout() |
|
180 |
{ |
|
181 |
} |
|
182 |
||
183 |
void tst_QTextLayout::init() |
|
184 |
{ |
|
185 |
testFont = QFont(); |
|
186 |
testFont.setFamily("__Qt__Box__Engine__"); |
|
187 |
testFont.setPixelSize(TESTFONT_SIZE); |
|
188 |
testFont.setWeight(QFont::Normal); |
|
189 |
QCOMPARE(QFontMetrics(testFont).width('a'), testFont.pixelSize()); |
|
190 |
} |
|
191 |
||
192 |
void tst_QTextLayout::cleanup() |
|
193 |
{ |
|
194 |
testFont = QFont(); |
|
195 |
} |
|
196 |
||
197 |
||
198 |
void tst_QTextLayout::lineBreaking() |
|
199 |
{ |
|
200 |
#if defined(Q_WS_X11) |
|
201 |
struct Breaks { |
|
202 |
const char *utf8; |
|
203 |
uchar breaks[32]; |
|
204 |
}; |
|
205 |
Breaks brks[] = { |
|
206 |
{ "11", { false, 0xff } }, |
|
207 |
{ "aa", { false, 0xff } }, |
|
208 |
{ "++", { false, 0xff } }, |
|
209 |
{ "--", { false, 0xff } }, |
|
210 |
{ "((", { false, 0xff } }, |
|
211 |
{ "))", { false, 0xff } }, |
|
212 |
{ "..", { false, 0xff } }, |
|
213 |
{ "\"\"", { false, 0xff } }, |
|
214 |
{ "$$", { false, 0xff } }, |
|
215 |
{ "!!", { false, 0xff } }, |
|
216 |
{ "??", { false, 0xff } }, |
|
217 |
{ ",,", { false, 0xff } }, |
|
218 |
||
219 |
{ ")()", { true, false, 0xff } }, |
|
220 |
{ "?!?", { false, false, 0xff } }, |
|
221 |
{ ".,.", { false, false, 0xff } }, |
|
222 |
{ "+-+", { false, false, 0xff } }, |
|
223 |
{ "+=+", { false, false, 0xff } }, |
|
224 |
{ "+(+", { false, false, 0xff } }, |
|
225 |
{ "+)+", { false, false, 0xff } }, |
|
226 |
||
227 |
{ "a b", { false, true, 0xff } }, |
|
228 |
{ "a(b", { false, false, 0xff } }, |
|
229 |
{ "a)b", { false, false, 0xff } }, |
|
230 |
{ "a-b", { false, true, 0xff } }, |
|
231 |
{ "a.b", { false, false, 0xff } }, |
|
232 |
{ "a+b", { false, false, 0xff } }, |
|
233 |
{ "a?b", { false, false, 0xff } }, |
|
234 |
{ "a!b", { false, false, 0xff } }, |
|
235 |
{ "a$b", { false, false, 0xff } }, |
|
236 |
{ "a,b", { false, false, 0xff } }, |
|
237 |
{ "a/b", { false, false, 0xff } }, |
|
238 |
{ "1/2", { false, false, 0xff } }, |
|
239 |
{ "./.", { false, false, 0xff } }, |
|
240 |
{ ",/,", { false, false, 0xff } }, |
|
241 |
{ "!/!", { false, false, 0xff } }, |
|
242 |
{ "\\/\\", { false, false, 0xff } }, |
|
243 |
{ "1 2", { false, true, 0xff } }, |
|
244 |
{ "1(2", { false, false, 0xff } }, |
|
245 |
{ "1)2", { false, false, 0xff } }, |
|
246 |
{ "1-2", { false, false, 0xff } }, |
|
247 |
{ "1.2", { false, false, 0xff } }, |
|
248 |
{ "1+2", { false, false, 0xff } }, |
|
249 |
{ "1?2", { false, true, 0xff } }, |
|
250 |
{ "1!2", { false, true, 0xff } }, |
|
251 |
{ "1$2", { false, false, 0xff } }, |
|
252 |
{ "1,2", { false, false, 0xff } }, |
|
253 |
{ "1/2", { false, false, 0xff } }, |
|
254 |
{ "\330\260\331\216\331\204\331\220\331\203\331\216", { false, false, false, false, false, 0xff } }, |
|
255 |
{ "\330\247\331\204\331\205 \330\247\331\204\331\205", { false, false, false, true, false, false, 0xff } }, |
|
256 |
{ "1#2", { false, false, 0xff } }, |
|
257 |
{ "!#!", { false, false, 0xff } }, |
|
258 |
{ 0, {} } |
|
259 |
}; |
|
260 |
Breaks *b = brks; |
|
261 |
while (b->utf8) { |
|
262 |
QString str = QString::fromUtf8(b->utf8); |
|
263 |
QTextEngine engine(str, QFont()); |
|
264 |
const HB_CharAttributes *attrs = engine.attributes(); |
|
265 |
int i; |
|
266 |
for (i = 0; i < (int)str.length() - 1; ++i) { |
|
267 |
QVERIFY(b->breaks[i] != 0xff); |
|
268 |
if ( (attrs[i].lineBreakType != HB_NoBreak) != (bool)b->breaks[i] ) { |
|
269 |
qDebug("test case \"%s\" failed at char %d; break type: %d", b->utf8, i, attrs[i].lineBreakType); |
|
270 |
QCOMPARE( (attrs[i].lineBreakType != HB_NoBreak), (bool)b->breaks[i] ); |
|
271 |
} |
|
272 |
} |
|
273 |
QVERIFY(attrs[i].lineBreakType == HB_ForcedBreak); |
|
274 |
QCOMPARE(b->breaks[i], (uchar)0xff); |
|
275 |
++b; |
|
276 |
} |
|
277 |
#else |
|
278 |
QSKIP("This test can not be run on non-X11 platforms", SkipAll); |
|
279 |
#endif |
|
280 |
} |
|
281 |
||
282 |
void tst_QTextLayout::simpleBoundingRect() |
|
283 |
{ |
|
284 |
/* just check if boundingRect() gives sane values. The text is not broken. */ |
|
285 |
||
286 |
QString hello("hello world"); |
|
287 |
||
288 |
const int width = hello.length() * testFont.pixelSize(); |
|
289 |
||
290 |
QTextLayout layout(hello, testFont); |
|
291 |
layout.beginLayout(); |
|
292 |
||
293 |
QTextLine line = layout.createLine(); |
|
294 |
line.setLineWidth(width); |
|
295 |
QCOMPARE(line.textLength(), hello.length()); |
|
296 |
QCOMPARE(layout.boundingRect(), QRectF(0, 0, width, QFontMetrics(testFont).height())); |
|
297 |
} |
|
298 |
||
299 |
void tst_QTextLayout::threeLineBoundingRect() |
|
300 |
{ |
|
301 |
#if defined(Q_WS_MAC) |
|
302 |
QSKIP("QTestFontEngine on the mac does not support logclusters at the moment", SkipAll); |
|
303 |
#endif |
|
304 |
/* stricter check. break text into three lines */ |
|
305 |
||
306 |
QString firstWord("hello"); |
|
307 |
QString secondWord("world"); |
|
308 |
QString thirdWord("test"); |
|
309 |
QString text(firstWord + ' ' + secondWord + ' ' + thirdWord); |
|
310 |
||
311 |
const int firstLineWidth = firstWord.length() * testFont.pixelSize(); |
|
312 |
const int secondLineWidth = secondWord.length() * testFont.pixelSize(); |
|
313 |
const int thirdLineWidth = thirdWord.length() * testFont.pixelSize(); |
|
314 |
||
315 |
const int longestLine = qMax(firstLineWidth, qMax(secondLineWidth, thirdLineWidth)); |
|
316 |
||
317 |
QTextLayout layout(text, testFont); |
|
318 |
layout.beginLayout(); |
|
319 |
||
320 |
int pos = 0; |
|
321 |
int y = 0; |
|
322 |
QTextLine line = layout.createLine(); |
|
323 |
line.setLineWidth(firstLineWidth); |
|
324 |
line.setPosition(QPoint(0, y)); |
|
325 |
QCOMPARE(line.textStart(), pos); |
|
326 |
// + 1 for trailing space |
|
327 |
QCOMPARE(line.textLength(), firstWord.length() + 1); |
|
328 |
QCOMPARE(qRound(line.naturalTextWidth()), firstLineWidth); |
|
329 |
||
330 |
pos += line.textLength(); |
|
331 |
y += qRound(line.ascent() + line.descent()); |
|
332 |
||
333 |
line = layout.createLine(); |
|
334 |
line.setLineWidth(secondLineWidth); |
|
335 |
line.setPosition(QPoint(0, y)); |
|
336 |
// + 1 for trailing space |
|
337 |
QCOMPARE(line.textStart(), pos); |
|
338 |
QCOMPARE(line.textLength(), secondWord.length() + 1); |
|
339 |
QCOMPARE(qRound(line.naturalTextWidth()), secondLineWidth); |
|
340 |
||
341 |
pos += line.textLength(); |
|
342 |
y += qRound(line.ascent() + line.descent()); |
|
343 |
||
344 |
line = layout.createLine(); |
|
345 |
line.setLineWidth(secondLineWidth); |
|
346 |
line.setPosition(QPoint(0, y)); |
|
347 |
// no trailing space here! |
|
348 |
QCOMPARE(line.textStart(), pos); |
|
349 |
QCOMPARE(line.textLength(), thirdWord.length()); |
|
350 |
QCOMPARE(qRound(line.naturalTextWidth()), thirdLineWidth); |
|
351 |
y += qRound(line.ascent() + line.descent()); |
|
352 |
||
353 |
QCOMPARE(layout.boundingRect(), QRectF(0, 0, longestLine, y + 1)); |
|
354 |
} |
|
355 |
||
356 |
void tst_QTextLayout::boundingRectWithLongLineAndNoWrap() |
|
357 |
{ |
|
358 |
QString longString("thisisaverylongstringthatcannotbewrappedatallitjustgoesonandonlikeonebigword"); |
|
359 |
||
360 |
const int width = longString.length() * testFont.pixelSize() / 20; // very small widthx |
|
361 |
||
362 |
QTextLayout layout(longString, testFont); |
|
363 |
layout.beginLayout(); |
|
364 |
QTextLine line = layout.createLine(); |
|
365 |
line.setLineWidth(width); |
|
366 |
||
367 |
QVERIFY(layout.boundingRect().width() >= line.width()); |
|
368 |
QCOMPARE(layout.boundingRect().width(), line.naturalTextWidth()); |
|
369 |
} |
|
370 |
||
371 |
void tst_QTextLayout::forcedBreaks() |
|
372 |
{ |
|
373 |
QString text = "A\n\nB\nC"; |
|
374 |
text.replace('\n', QChar::LineSeparator); |
|
375 |
||
376 |
QTextLayout layout(text, testFont); |
|
377 |
||
378 |
layout.beginLayout(); |
|
379 |
||
380 |
int pos = 0; |
|
381 |
||
382 |
QTextLine line = layout.createLine(); |
|
383 |
line.setLineWidth(0x10000); |
|
384 |
QCOMPARE(line.textStart(), pos); |
|
385 |
QCOMPARE(line.textLength(),2); |
|
386 |
QCOMPARE(qRound(line.naturalTextWidth()),testFont.pixelSize()); |
|
387 |
QCOMPARE((int) line.height(), testFont.pixelSize() + 1); // + 1 baseline |
|
388 |
QCOMPARE(line.xToCursor(0), line.textStart()); |
|
389 |
pos += line.textLength(); |
|
390 |
||
391 |
line = layout.createLine(); |
|
392 |
line.setLineWidth(0x10000); |
|
393 |
QCOMPARE(line.textStart(),pos); |
|
394 |
QCOMPARE(line.textLength(),1); |
|
395 |
QCOMPARE(qRound(line.naturalTextWidth()), 0); |
|
396 |
QCOMPARE((int) line.height(), testFont.pixelSize() + 1); // + 1 baseline |
|
397 |
QCOMPARE(line.xToCursor(0), line.textStart()); |
|
398 |
pos += line.textLength(); |
|
399 |
||
400 |
line = layout.createLine(); |
|
401 |
line.setLineWidth(0x10000); |
|
402 |
QCOMPARE(line.textStart(),pos); |
|
403 |
QCOMPARE(line.textLength(),2); |
|
404 |
QCOMPARE(qRound(line.naturalTextWidth()),testFont.pixelSize()); |
|
405 |
QCOMPARE(qRound(line.height()), testFont.pixelSize() + 1); // + 1 baseline |
|
406 |
QCOMPARE(line.xToCursor(0), line.textStart()); |
|
407 |
pos += line.textLength(); |
|
408 |
||
409 |
line = layout.createLine(); |
|
410 |
line.setLineWidth(0x10000); |
|
411 |
QCOMPARE(line.textStart(),pos); |
|
412 |
QCOMPARE(line.textLength(),1); |
|
413 |
QCOMPARE(qRound(line.naturalTextWidth()), testFont.pixelSize()); |
|
414 |
QCOMPARE((int) line.height(), testFont.pixelSize() + 1); // + 1 baseline |
|
415 |
QCOMPARE(line.xToCursor(0), line.textStart()); |
|
416 |
} |
|
417 |
||
418 |
void tst_QTextLayout::breakAny() |
|
419 |
{ |
|
420 |
#if defined(Q_WS_MAC) |
|
421 |
QSKIP("QTestFontEngine on the mac does not support logclusters at the moment", SkipAll); |
|
422 |
#endif |
|
423 |
QString text = "ABCD"; |
|
424 |
||
425 |
QTextLayout layout(text, testFont); |
|
426 |
QTextLine line; |
|
427 |
||
428 |
QTextOption opt; |
|
429 |
opt.setWrapMode(QTextOption::WrapAnywhere); |
|
430 |
layout.setTextOption(opt); |
|
431 |
layout.beginLayout(); |
|
432 |
||
433 |
line = layout.createLine(); |
|
434 |
line.setLineWidth(testFont.pixelSize() * 2); |
|
435 |
QCOMPARE(line.textStart(), 0); |
|
436 |
QCOMPARE(line.textLength(), 2); |
|
437 |
||
438 |
line = layout.createLine(); |
|
439 |
line.setLineWidth(testFont.pixelSize() * 2); |
|
440 |
QCOMPARE(line.textStart(), 2); |
|
441 |
QCOMPARE(line.textLength(), 2); |
|
442 |
||
443 |
line = layout.createLine(); |
|
444 |
QVERIFY(!line.isValid()); |
|
445 |
||
446 |
layout.endLayout(); |
|
447 |
||
448 |
text = "ABCD EFGH"; |
|
449 |
layout.setText(text); |
|
450 |
layout.beginLayout(); |
|
451 |
||
452 |
line = layout.createLine(); |
|
453 |
line.setLineWidth(testFont.pixelSize() * 7); |
|
454 |
QCOMPARE(line.textStart(), 0); |
|
455 |
QCOMPARE(line.textLength(), 7); |
|
456 |
||
457 |
layout.endLayout(); |
|
458 |
} |
|
459 |
||
460 |
void tst_QTextLayout::noWrap() |
|
461 |
{ |
|
462 |
#if defined(Q_WS_MAC) |
|
463 |
QSKIP("QTestFontEngine on the mac does not support logclusters at the moment", SkipAll); |
|
464 |
#endif |
|
465 |
QString text = "AB CD"; |
|
466 |
||
467 |
QTextLayout layout(text, testFont); |
|
468 |
QTextLine line; |
|
469 |
||
470 |
QTextOption opt; |
|
471 |
opt.setWrapMode(QTextOption::NoWrap); |
|
472 |
layout.setTextOption(opt); |
|
473 |
layout.beginLayout(); |
|
474 |
||
475 |
line = layout.createLine(); |
|
476 |
line.setLineWidth(testFont.pixelSize() * 2); |
|
477 |
QCOMPARE(line.textStart(), 0); |
|
478 |
QCOMPARE(line.textLength(), 5); |
|
479 |
||
480 |
line = layout.createLine(); |
|
481 |
QVERIFY(!line.isValid()); |
|
482 |
||
483 |
layout.endLayout(); |
|
484 |
} |
|
485 |
||
486 |
void tst_QTextLayout::cursorToXForInlineObjects() |
|
487 |
{ |
|
488 |
QChar ch(QChar::ObjectReplacementCharacter); |
|
489 |
QString text(ch); |
|
490 |
QTextLayout layout(text, testFont); |
|
491 |
layout.beginLayout(); |
|
492 |
||
493 |
QTextEngine *engine = layout.engine(); |
|
494 |
const int item = engine->findItem(0); |
|
495 |
engine->layoutData->items[item].width = 32; |
|
496 |
||
497 |
QTextLine line = layout.createLine(); |
|
498 |
line.setLineWidth(0x10000); |
|
499 |
||
500 |
QCOMPARE(line.cursorToX(0), qreal(0)); |
|
501 |
QCOMPARE(line.cursorToX(1), qreal(32)); |
|
502 |
} |
|
503 |
||
504 |
void tst_QTextLayout::cursorToXForSetColumns() |
|
505 |
{ |
|
506 |
QTextLayout lay("abc", testFont); |
|
507 |
QTextOption o = lay.textOption(); |
|
508 |
o.setWrapMode(QTextOption::WrapAnywhere); |
|
509 |
||
510 |
// enable/disable this line for full effect ;) |
|
511 |
o.setAlignment(Qt::AlignHCenter); |
|
512 |
||
513 |
lay.setTextOption(o); |
|
514 |
lay.beginLayout(); |
|
515 |
QTextLine line = lay.createLine(); |
|
516 |
line.setNumColumns(1); |
|
517 |
lay.endLayout(); |
|
518 |
QCOMPARE(line.cursorToX(0), 0.); |
|
519 |
QCOMPARE(line.cursorToX(1), (qreal) TESTFONT_SIZE); |
|
520 |
} |
|
521 |
||
522 |
void tst_QTextLayout::defaultWordSeparators_data() |
|
523 |
{ |
|
524 |
QTest::addColumn<QString>("text"); |
|
525 |
QTest::addColumn<int>("startPos"); |
|
526 |
QTest::addColumn<int>("endPos"); |
|
527 |
||
528 |
QString separators(".,:;-<>[](){}=/+%&^*"); |
|
529 |
separators += QLatin1String("!?"); |
|
530 |
for (int i = 0; i < separators.count(); ++i) { |
|
531 |
QTest::newRow(QString::number(i).toAscii().data()) |
|
532 |
<< QString::fromLatin1("abcd") + separators.at(i) + QString::fromLatin1("efgh") |
|
533 |
<< 0 << 4; |
|
534 |
} |
|
535 |
||
536 |
QTest::newRow("nbsp") |
|
537 |
<< QString::fromLatin1("abcd") + QString(QChar::Nbsp) + QString::fromLatin1("efgh") |
|
538 |
<< 0 << 5; |
|
539 |
||
540 |
QTest::newRow("tab") |
|
541 |
<< QString::fromLatin1("abcd") + QString::fromLatin1("\t") + QString::fromLatin1("efgh") |
|
542 |
<< 0 << 5; |
|
543 |
||
544 |
QTest::newRow("lineseparator") |
|
545 |
<< QString::fromLatin1("abcd") + QString(QChar::LineSeparator) + QString::fromLatin1("efgh") |
|
546 |
<< 0 << 5; |
|
547 |
} |
|
548 |
||
549 |
void tst_QTextLayout::defaultWordSeparators() |
|
550 |
{ |
|
551 |
QFETCH(QString, text); |
|
552 |
QFETCH(int, startPos); |
|
553 |
QFETCH(int, endPos); |
|
554 |
QTextLayout layout(text, testFont); |
|
555 |
||
556 |
QCOMPARE(layout.nextCursorPosition(startPos, QTextLayout::SkipWords), endPos); |
|
557 |
QCOMPARE(layout.previousCursorPosition(endPos, QTextLayout::SkipWords), startPos); |
|
558 |
} |
|
559 |
||
560 |
void tst_QTextLayout::cursorMovementInsideSpaces() |
|
561 |
{ |
|
562 |
QTextLayout layout("ABC DEF", testFont); |
|
563 |
||
564 |
QCOMPARE(layout.previousCursorPosition(6, QTextLayout::SkipWords), 0); |
|
565 |
QCOMPARE(layout.nextCursorPosition(6, QTextLayout::SkipWords), 15); |
|
566 |
} |
|
567 |
||
568 |
void tst_QTextLayout::charWordStopOnLineSeparator() |
|
569 |
{ |
|
570 |
const QChar lineSeparator(QChar::LineSeparator); |
|
571 |
QString txt; |
|
572 |
txt.append(lineSeparator); |
|
573 |
txt.append(lineSeparator); |
|
574 |
QTextLayout layout(txt, testFont); |
|
575 |
QTextEngine *engine = layout.engine(); |
|
576 |
const HB_CharAttributes *attrs = engine->attributes(); |
|
577 |
QVERIFY(attrs); |
|
578 |
QVERIFY(attrs[1].charStop); |
|
579 |
} |
|
580 |
||
581 |
void tst_QTextLayout::xToCursorAtEndOfLine() |
|
582 |
{ |
|
583 |
#if defined(Q_WS_MAC) |
|
584 |
QSKIP("QTestFontEngine on the mac does not support logclusters at the moment", SkipAll); |
|
585 |
#endif |
|
586 |
QString text = "FirstLine SecondLine"; |
|
587 |
text.replace('\n', QChar::LineSeparator); |
|
588 |
||
589 |
const qreal firstLineWidth = QString("FirstLine").length() * testFont.pixelSize(); |
|
590 |
||
591 |
QTextLayout layout(text, testFont); |
|
592 |
||
593 |
layout.beginLayout(); |
|
594 |
QTextLine line = layout.createLine(); |
|
595 |
QVERIFY(line.isValid()); |
|
596 |
line.setLineWidth(firstLineWidth); |
|
597 |
QVERIFY(layout.createLine().isValid()); |
|
598 |
QVERIFY(!layout.createLine().isValid()); |
|
599 |
layout.endLayout(); |
|
600 |
||
601 |
line = layout.lineAt(0); |
|
602 |
QCOMPARE(line.xToCursor(100000), 9); |
|
603 |
line = layout.lineAt(1); |
|
604 |
QCOMPARE(line.xToCursor(100000), 20); |
|
605 |
} |
|
606 |
||
607 |
void tst_QTextLayout::boundingRectTopLeft() |
|
608 |
{ |
|
609 |
QString text = "FirstLine\nSecondLine"; |
|
610 |
text.replace('\n', QChar::LineSeparator); |
|
611 |
||
612 |
QTextLayout layout(text, testFont); |
|
613 |
||
614 |
layout.beginLayout(); |
|
615 |
QTextLine firstLine = layout.createLine(); |
|
616 |
QVERIFY(firstLine.isValid()); |
|
617 |
firstLine.setPosition(QPointF(10, 10)); |
|
618 |
QTextLine secondLine = layout.createLine(); |
|
619 |
QVERIFY(secondLine.isValid()); |
|
620 |
secondLine.setPosition(QPointF(20, 20)); |
|
621 |
layout.endLayout(); |
|
622 |
||
623 |
QCOMPARE(layout.boundingRect().topLeft(), firstLine.position()); |
|
624 |
} |
|
625 |
||
626 |
void tst_QTextLayout::charStopForSurrogatePairs() |
|
627 |
{ |
|
628 |
QString txt; |
|
629 |
txt.append("a"); |
|
630 |
txt.append(0xd87e); |
|
631 |
txt.append(0xdc25); |
|
632 |
txt.append("b"); |
|
633 |
QTextLayout layout(txt, testFont); |
|
634 |
QTextEngine *engine = layout.engine(); |
|
635 |
const HB_CharAttributes *attrs = engine->attributes(); |
|
636 |
QVERIFY(attrs); |
|
637 |
QVERIFY(attrs[0].charStop); |
|
638 |
QVERIFY(attrs[1].charStop); |
|
639 |
QVERIFY(!attrs[2].charStop); |
|
640 |
QVERIFY(attrs[3].charStop); |
|
641 |
} |
|
642 |
||
643 |
void tst_QTextLayout::tabStops() |
|
644 |
{ |
|
645 |
#if defined(Q_WS_MAC) |
|
646 |
QSKIP("QTestFontEngine on the mac does not support logclusters at the moment", SkipAll); |
|
647 |
#endif |
|
648 |
QString txt("Hello there\tworld"); |
|
649 |
QTextLayout layout(txt, testFont); |
|
650 |
layout.beginLayout(); |
|
651 |
QTextLine line = layout.createLine(); |
|
652 |
||
653 |
QVERIFY(line.isValid()); |
|
654 |
line.setNumColumns(11); |
|
655 |
QCOMPARE(line.textLength(), TESTFONT_SIZE); |
|
656 |
||
657 |
line = layout.createLine(); |
|
658 |
QVERIFY(line.isValid()); |
|
659 |
line.setNumColumns(5); |
|
660 |
QCOMPARE(line.textLength(), 5); |
|
661 |
||
662 |
layout.endLayout(); |
|
663 |
} |
|
664 |
||
665 |
void tst_QTextLayout::integerOverflow() |
|
666 |
{ |
|
667 |
QString txt("Hello world... "); |
|
668 |
||
669 |
for (int i = 0; i < 8; ++i) |
|
670 |
txt += txt; |
|
671 |
||
672 |
QTextLayout layout(txt, testFont); |
|
673 |
layout.beginLayout(); |
|
674 |
QTextLine line = layout.createLine(); |
|
675 |
||
676 |
QVERIFY(line.isValid()); |
|
677 |
line.setLineWidth(INT_MAX); |
|
678 |
QCOMPARE(line.textLength(), txt.length()); |
|
679 |
||
680 |
QVERIFY(!layout.createLine().isValid()); |
|
681 |
||
682 |
layout.endLayout(); |
|
683 |
} |
|
684 |
||
685 |
void tst_QTextLayout::setNumColumnsWrapAtWordBoundaryOrAnywhere() |
|
686 |
{ |
|
687 |
QString txt("This is a small test text"); |
|
688 |
QTextLayout layout(txt, testFont); |
|
689 |
QTextOption option = layout.textOption(); |
|
690 |
option.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere); |
|
691 |
layout.setTextOption(option); |
|
692 |
||
693 |
layout.beginLayout(); |
|
694 |
QTextLine line1 = layout.createLine(); |
|
695 |
QVERIFY(line1.isValid()); |
|
696 |
line1.setNumColumns(1); |
|
697 |
||
698 |
// qDebug() << line1.naturalTextWidth(); |
|
699 |
QCOMPARE(line1.textLength(), 1); |
|
700 |
QVERIFY(line1.naturalTextWidth() == testFont.pixelSize()); // contains only one character |
|
701 |
||
702 |
QTextLine line2 = layout.createLine(); |
|
703 |
QVERIFY(line2.isValid()); |
|
704 |
||
705 |
layout.endLayout(); |
|
706 |
} |
|
707 |
||
708 |
void tst_QTextLayout::setNumColumnsWordWrap() |
|
709 |
{ |
|
710 |
QString txt("This is a small test text"); |
|
711 |
QTextLayout layout(txt, testFont); |
|
712 |
QTextOption option = layout.textOption(); |
|
713 |
option.setWrapMode(QTextOption::WordWrap); |
|
714 |
layout.setTextOption(option); |
|
715 |
||
716 |
layout.beginLayout(); |
|
717 |
QTextLine line1 = layout.createLine(); |
|
718 |
QVERIFY(line1.isValid()); |
|
719 |
line1.setNumColumns(1); |
|
720 |
||
721 |
// qDebug() << line1.naturalTextWidth(); |
|
722 |
QCOMPARE(line1.textLength(), 5); |
|
723 |
QVERIFY(line1.naturalTextWidth() > 20.0); // contains the whole first word. |
|
724 |
||
725 |
QTextLine line2 = layout.createLine(); |
|
726 |
QVERIFY(line2.isValid()); |
|
727 |
||
728 |
layout.endLayout(); |
|
729 |
} |
|
730 |
||
731 |
void tst_QTextLayout::smallTextLengthNoWrap() |
|
732 |
{ |
|
733 |
QString txt("This is a small test text"); |
|
734 |
QTextLayout layout(txt, testFont); |
|
735 |
QTextOption option = layout.textOption(); |
|
736 |
option.setWrapMode(QTextOption::NoWrap); |
|
737 |
layout.setTextOption(option); |
|
738 |
||
739 |
/// NoWrap |
|
740 |
layout.beginLayout(); |
|
741 |
QTextLine line1 = layout.createLine(); |
|
742 |
QVERIFY(line1.isValid()); |
|
743 |
line1.setLineWidth(5); // most certainly too short for the word 'This' to fit. |
|
744 |
||
745 |
QCOMPARE(line1.width(), 5.0); |
|
746 |
QVERIFY(line1.naturalTextWidth() > 70); // contains all the text. |
|
747 |
||
748 |
QTextLine line2 = layout.createLine(); |
|
749 |
QVERIFY(! line2.isValid()); |
|
750 |
||
751 |
layout.endLayout(); |
|
752 |
} |
|
753 |
||
754 |
void tst_QTextLayout::smallTextLengthWordWrap() |
|
755 |
{ |
|
756 |
QString txt("This is a small test text"); |
|
757 |
QTextLayout layout(txt, testFont); |
|
758 |
QTextOption option = layout.textOption(); |
|
759 |
option.setWrapMode(QTextOption::WordWrap); |
|
760 |
layout.setTextOption(option); |
|
761 |
||
762 |
/// WordWrap |
|
763 |
layout.beginLayout(); |
|
764 |
QTextLine line1 = layout.createLine(); |
|
765 |
QVERIFY(line1.isValid()); |
|
766 |
line1.setLineWidth(5); // most certainly too short for the word 'This' to fit. |
|
767 |
||
768 |
QCOMPARE(line1.width(), 5.0); |
|
769 |
QVERIFY(line1.naturalTextWidth() > 20.0); // contains the whole first word. |
|
770 |
QCOMPARE(line1.textLength(), 5); |
|
771 |
||
772 |
QTextLine line2 = layout.createLine(); |
|
773 |
QVERIFY(line2.isValid()); |
|
774 |
||
775 |
layout.endLayout(); |
|
776 |
} |
|
777 |
||
778 |
void tst_QTextLayout::smallTextLengthWrapAtWordBoundaryOrAnywhere() |
|
779 |
{ |
|
780 |
QString txt("This is a small test text"); |
|
781 |
QTextLayout layout(txt, testFont); |
|
782 |
QTextOption option = layout.textOption(); |
|
783 |
option.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere); |
|
784 |
layout.setTextOption(option); |
|
785 |
||
786 |
layout.beginLayout(); |
|
787 |
QTextLine line1 = layout.createLine(); |
|
788 |
QVERIFY(line1.isValid()); |
|
789 |
line1.setLineWidth(5); // most certainly too short for the word 'This' to fit. |
|
790 |
||
791 |
QCOMPARE(line1.width(), 5.0); |
|
792 |
// qDebug() << line1.naturalTextWidth(); |
|
793 |
QCOMPARE(line1.textLength(), 1); |
|
794 |
QVERIFY(line1.naturalTextWidth() == testFont.pixelSize()); // contains just the characters that fit. |
|
795 |
||
796 |
QTextLine line2 = layout.createLine(); |
|
797 |
QVERIFY(line2.isValid()); |
|
798 |
||
799 |
layout.endLayout(); |
|
800 |
} |
|
801 |
||
802 |
void tst_QTextLayout::testDefaultTabs() |
|
803 |
{ |
|
804 |
QTextLayout layout("Foo\tBar\ta slightly longer text\tend.", testFont); |
|
805 |
layout.beginLayout(); |
|
806 |
QTextLine line = layout.createLine(); |
|
807 |
line.setLineWidth(1000); |
|
808 |
layout.endLayout(); |
|
809 |
||
810 |
//qDebug() << "After the tab: " << line.cursorToX(4); |
|
811 |
QCOMPARE(line.cursorToX(4), 80.); // default tab is 80 |
|
812 |
QCOMPARE(line.cursorToX(8), 160.); |
|
813 |
QCOMPARE(line.cursorToX(31), 480.); |
|
814 |
||
815 |
QTextOption option = layout.textOption(); |
|
816 |
option.setTabStop(90); |
|
817 |
layout.setTextOption(option); |
|
818 |
layout.beginLayout(); |
|
819 |
line = layout.createLine(); |
|
820 |
line.setLineWidth(1000); |
|
821 |
layout.endLayout(); |
|
822 |
||
823 |
QCOMPARE(line.cursorToX(4), 90.); |
|
824 |
QCOMPARE(line.cursorToX(8), 180.); |
|
825 |
QCOMPARE(line.cursorToX(31), 450.); |
|
826 |
||
827 |
QList<QTextOption::Tab> tabs; |
|
828 |
QTextOption::Tab tab; |
|
829 |
tab.position = 110; // set one tab to 110, but since the rest is unset they will be at the normal interval again. |
|
830 |
tabs.append(tab); |
|
831 |
option.setTabs(tabs); |
|
832 |
layout.setTextOption(option); |
|
833 |
layout.beginLayout(); |
|
834 |
line = layout.createLine(); |
|
835 |
line.setLineWidth(1000); |
|
836 |
layout.endLayout(); |
|
837 |
||
838 |
QCOMPARE(line.cursorToX(4), 110.); |
|
839 |
QCOMPARE(line.cursorToX(8), 180.); |
|
840 |
QCOMPARE(line.cursorToX(31), 450.); |
|
841 |
} |
|
842 |
||
843 |
void tst_QTextLayout::testTabs() |
|
844 |
{ |
|
845 |
QTextLayout layout("Foo\tBar.", testFont); |
|
846 |
QTextOption option = layout.textOption(); |
|
847 |
option.setTabStop(150); |
|
848 |
layout.setTextOption(option); |
|
849 |
||
850 |
layout.beginLayout(); |
|
851 |
QTextLine line = layout.createLine(); |
|
852 |
line.setLineWidth(200.); |
|
853 |
layout.endLayout(); |
|
854 |
||
855 |
QVERIFY(line.naturalTextWidth() > 150); |
|
856 |
QCOMPARE(line.cursorToX(4), 150.); |
|
857 |
} |
|
858 |
||
859 |
void tst_QTextLayout::testMultilineTab() |
|
860 |
{ |
|
861 |
QTextLayout layout("Lorem ipsum dolor sit\tBar.", testFont); |
|
862 |
// test if this works on the second line. |
|
863 |
layout.beginLayout(); |
|
864 |
QTextLine line = layout.createLine(); |
|
865 |
line.setLineWidth(220.); // moves 'sit' to next line. |
|
866 |
line = layout.createLine(); |
|
867 |
line.setLineWidth(220.); |
|
868 |
layout.endLayout(); |
|
869 |
||
870 |
QCOMPARE(line.cursorToX(22), 80.); |
|
871 |
} |
|
872 |
||
873 |
void tst_QTextLayout::testMultiTab() |
|
874 |
{ |
|
875 |
QTextLayout layout("Foo\t\t\tBar.", testFont); |
|
876 |
layout.beginLayout(); |
|
877 |
QTextLine line = layout.createLine(); |
|
878 |
line.setLineWidth(1000.); |
|
879 |
layout.endLayout(); |
|
880 |
||
881 |
QCOMPARE(line.cursorToX(6), 80. * 3); |
|
882 |
} |
|
883 |
||
884 |
void tst_QTextLayout::testTabsInAlignedParag() |
|
885 |
{ |
|
886 |
QTextLayout layout("Foo\tsome more words", testFont); |
|
887 |
QTextOption option = layout.textOption(); |
|
888 |
// right |
|
889 |
option.setAlignment(Qt::AlignRight); |
|
890 |
layout.setTextOption(option); |
|
891 |
||
892 |
layout.beginLayout(); |
|
893 |
QTextLine line = layout.createLine(); |
|
894 |
line.setLineWidth(300.); |
|
895 |
layout.endLayout(); |
|
896 |
||
897 |
const qreal textWidth = 80 + 15 * TESTFONT_SIZE; // 15 chars right of the tab |
|
898 |
QCOMPARE(line.naturalTextWidth(), textWidth); |
|
899 |
QCOMPARE(line.cursorToX(0), 300. - textWidth); |
|
900 |
||
901 |
// centered |
|
902 |
option.setAlignment(Qt::AlignCenter); |
|
903 |
layout.setTextOption(option); |
|
904 |
||
905 |
layout.beginLayout(); |
|
906 |
line = layout.createLine(); |
|
907 |
line.setLineWidth(300.); |
|
908 |
layout.endLayout(); |
|
909 |
||
910 |
QCOMPARE(line.naturalTextWidth(), textWidth); |
|
911 |
QCOMPARE(line.cursorToX(0), (300. - textWidth) / 2.); |
|
912 |
||
913 |
// justified |
|
914 |
option.setAlignment(Qt::AlignJustify); |
|
915 |
layout.setTextOption(option); |
|
916 |
||
917 |
layout.beginLayout(); |
|
918 |
line = layout.createLine(); |
|
919 |
line.setLineWidth(textWidth - 10); // make the last word slip to the next line so justification actually happens. |
|
920 |
layout.endLayout(); |
|
921 |
||
922 |
QCOMPARE(line.cursorToX(0), 0.); |
|
923 |
QCOMPARE(line.cursorToX(4), 80.); |
|
924 |
||
925 |
//QTextLayout layout2("Foo\tUt wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis", testFont); // means it will be more then one line long. |
|
926 |
} |
|
927 |
||
928 |
void tst_QTextLayout::testRightTab() |
|
929 |
{ |
|
930 |
QTextLayout layout("Foo\tLorem ipsum te sit\tBar baz\tText\tEnd", testFont); |
|
931 |
/* ^ a ^ b ^ c ^ d |
|
932 |
a = 4, b = 22, c = 30, d = 35 (position) |
|
933 |
||
934 |
I expect the output to be: |
|
935 |
Foo Lorem ipsum te |
|
936 |
sit Bar Baz |
|
937 |
Text End |
|
938 |
||
939 |
a) tab replaced with a single space due to the text not fitting before the tab. |
|
940 |
b) tab takes space so the text until the 3th tab fits to the tab pos. |
|
941 |
c) tab is after last tab (both auto and defined) and thus moves text to start of next line. |
|
942 |
d) tab takes space so text until enter fits to tab pos. |
|
943 |
*/ |
|
944 |
||
945 |
QTextOption option = layout.textOption(); |
|
946 |
QList<QTextOption::Tab> tabs; |
|
947 |
QTextOption::Tab tab; |
|
948 |
tab.type = QTextOption::RightTab; |
|
949 |
tab.position = 190; // which means only 15(.8) chars of our test font fit left of it. |
|
950 |
tabs.append(tab); |
|
951 |
option.setTabs(tabs); |
|
952 |
layout.setTextOption(option); |
|
953 |
||
954 |
layout.beginLayout(); |
|
955 |
QTextLine line1 = layout.createLine(); |
|
956 |
line1.setLineWidth(220.); |
|
957 |
// qDebug() << "=====line 2"; |
|
958 |
QTextLine line2 = layout.createLine(); |
|
959 |
QVERIFY(line2.isValid()); |
|
960 |
line2.setLineWidth(220.); |
|
961 |
// qDebug() << "=====line 3"; |
|
962 |
QTextLine line3 = layout.createLine(); |
|
963 |
QVERIFY(line3.isValid()); |
|
964 |
line3.setLineWidth(220.); |
|
965 |
// qDebug() << "=====line 4"; |
|
966 |
QTextLine line4 = layout.createLine(); |
|
967 |
QVERIFY(! line4.isValid()); |
|
968 |
layout.endLayout(); |
|
969 |
// qDebug() << "--------"; |
|
970 |
||
971 |
QCOMPARE(line1.cursorToX(4), 3. * TESTFONT_SIZE ); // a |
|
972 |
QCOMPARE(line1.textLength(), 19); |
|
973 |
QCOMPARE(line2.cursorToX(23), 190. - 7. * TESTFONT_SIZE); // b |
|
974 |
QCOMPARE(line2.textLength(), 12); |
|
975 |
QCOMPARE(line3.cursorToX(31), 0.); // c |
|
976 |
QCOMPARE(line3.cursorToX(36), 190 - 3. * TESTFONT_SIZE); // d |
|
977 |
} |
|
978 |
||
979 |
void tst_QTextLayout::testCenteredTab() |
|
980 |
{ |
|
981 |
QTextLayout layout("Foo\tBar", testFont); |
|
982 |
// test if centering the tab works. We expect the center of 'Bar.' to be at the tab point. |
|
983 |
QTextOption option = layout.textOption(); |
|
984 |
QList<QTextOption::Tab> tabs; |
|
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
985 |
QTextOption::Tab tab(150, QTextOption::CenterTab); |
0 | 986 |
tabs.append(tab); |
987 |
option.setTabs(tabs); |
|
988 |
layout.setTextOption(option); |
|
989 |
||
990 |
layout.beginLayout(); |
|
991 |
QTextLine line = layout.createLine(); |
|
992 |
line.setLineWidth(200.); |
|
993 |
layout.endLayout(); |
|
994 |
||
995 |
const qreal wordLength = 3 * TESTFONT_SIZE; // the length of 'Bar' |
|
996 |
QCOMPARE(line.cursorToX(4), 150 - wordLength / 2.); |
|
997 |
} |
|
998 |
||
999 |
void tst_QTextLayout::testDelimiterTab() |
|
1000 |
{ |
|
1001 |
QTextLayout layout("Foo\tBar. Barrabas", testFont); |
|
1002 |
// try the different delimiter characters to see if the alignment works there. |
|
1003 |
QTextOption option = layout.textOption(); |
|
1004 |
QList<QTextOption::Tab> tabs; |
|
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1005 |
QTextOption::Tab tab(100, QTextOption::DelimiterTab, QChar('.')); |
0 | 1006 |
tabs.append(tab); |
1007 |
option.setTabs(tabs); |
|
1008 |
layout.setTextOption(option); |
|
1009 |
||
1010 |
layout.beginLayout(); |
|
1011 |
QTextLine line = layout.createLine(); |
|
1012 |
line.setLineWidth(200.); |
|
1013 |
layout.endLayout(); |
|
1014 |
||
1015 |
const qreal distanceBeforeTab = 3.5 * TESTFONT_SIZE; // the length of 'bar' and half the width of the dot. |
|
1016 |
QCOMPARE(line.cursorToX(4), 100 - distanceBeforeTab); |
|
1017 |
} |
|
1018 |
||
1019 |
void tst_QTextLayout::testLineBreakingAllSpaces() |
|
1020 |
{ |
|
1021 |
QTextLayout layout(" 123", testFont); // thats 20 spaces |
|
1022 |
const qreal firstLineWidth = 17 * TESTFONT_SIZE; |
|
1023 |
layout.beginLayout(); |
|
1024 |
QTextLine line1 = layout.createLine(); |
|
1025 |
line1.setLineWidth(firstLineWidth); |
|
1026 |
QTextLine line2 = layout.createLine(); |
|
1027 |
line2.setLineWidth(1000); // the rest |
|
1028 |
layout.endLayout(); |
|
1029 |
QCOMPARE(line1.width(), firstLineWidth); |
|
1030 |
QCOMPARE(line1.naturalTextWidth(), 0.); // spaces don't take space |
|
1031 |
QCOMPARE(line1.textLength(), 20); |
|
1032 |
QCOMPARE(line2.textLength(), 3); |
|
1033 |
QCOMPARE(line2.naturalTextWidth(), 3. * TESTFONT_SIZE); |
|
1034 |
} |
|
1035 |
||
1036 |
void tst_QTextLayout::tabsForRtl() |
|
1037 |
{ |
|
1038 |
QString word(QChar(0x5e9)); // a hebrew character |
|
1039 |
word = word + word + word; // 3 hebrew characters ;) |
|
1040 |
||
1041 |
QTextLayout layout(word +'\t'+ word +'\t'+ word +'\t'+ word, testFont); |
|
1042 |
//QTextLayout layout(word +' '+ word +' '+ word +' '+ word, testFont);// tester ;) |
|
1043 |
/* ^ a ^ b ^ c |
|
1044 |
a = 4, b = 8, c = 12, d = 16 (position) |
|
1045 |
||
1046 |
a) Left tab in RTL is a righ tab; so a is at width - 80 |
|
1047 |
b) Like a |
|
1048 |
c) right tab on RTL is a left tab; so its at width - 240 |
|
1049 |
d) center tab is still a centered tab. |
|
1050 |
*/ |
|
1051 |
||
1052 |
QTextOption option = layout.textOption(); |
|
1053 |
QList<QTextOption::Tab> tabs; |
|
1054 |
QTextOption::Tab tab; |
|
1055 |
tab.position = 80; |
|
1056 |
tabs.append(tab); |
|
1057 |
tab.position = 160; |
|
1058 |
tabs.append(tab); |
|
1059 |
tab.position = 240; |
|
1060 |
tab.type = QTextOption::RightTab; |
|
1061 |
tabs.append(tab); |
|
1062 |
option.setTabs(tabs); |
|
1063 |
option.setTextDirection(Qt::RightToLeft); |
|
1064 |
option.setAlignment(Qt::AlignRight); |
|
1065 |
layout.setTextOption(option); |
|
1066 |
||
1067 |
layout.beginLayout(); |
|
1068 |
QTextLine line = layout.createLine(); |
|
1069 |
const qreal WIDTH = 400.; |
|
1070 |
line.setLineWidth(WIDTH); |
|
1071 |
layout.endLayout(); |
|
1072 |
||
1073 |
//qDebug() << "layout ended --------------"; |
|
1074 |
||
1075 |
QCOMPARE(line.cursorToX(0), WIDTH); |
|
1076 |
QCOMPARE(line.cursorToX(1), WIDTH - TESTFONT_SIZE); // check its right-aligned |
|
1077 |
QCOMPARE(line.cursorToX(4), WIDTH - 80 + 3 * TESTFONT_SIZE); |
|
1078 |
QCOMPARE(line.cursorToX(8), WIDTH - 160 + 3 * TESTFONT_SIZE); |
|
1079 |
QCOMPARE(line.cursorToX(12), WIDTH - 240); |
|
1080 |
} |
|
1081 |
||
1082 |
QT_BEGIN_NAMESPACE |
|
1083 |
extern int qt_defaultDpiY(); |
|
1084 |
QT_END_NAMESPACE |
|
1085 |
||
1086 |
void tst_QTextLayout::testTabDPIScale() |
|
1087 |
{ |
|
1088 |
class MyPaintDevice : public QPaintDevice { |
|
1089 |
QPaintEngine *paintEngine () const { return 0; } |
|
1090 |
int metric (QPaintDevice::PaintDeviceMetric metric) const { |
|
1091 |
switch(metric) { |
|
1092 |
case QPaintDevice::PdmWidth: |
|
1093 |
case QPaintDevice::PdmHeight: |
|
1094 |
case QPaintDevice::PdmWidthMM: |
|
1095 |
case QPaintDevice::PdmHeightMM: |
|
1096 |
case QPaintDevice::PdmNumColors: |
|
1097 |
return INT_MAX; |
|
1098 |
case QPaintDevice::PdmDepth: |
|
1099 |
return 32; |
|
1100 |
case QPaintDevice::PdmDpiX: |
|
1101 |
case QPaintDevice::PdmDpiY: |
|
1102 |
case QPaintDevice::PdmPhysicalDpiX: |
|
1103 |
case QPaintDevice::PdmPhysicalDpiY: |
|
1104 |
return 72; |
|
1105 |
} |
|
1106 |
return 0; |
|
1107 |
} |
|
1108 |
}; |
|
1109 |
||
1110 |
MyPaintDevice pd; |
|
1111 |
||
1112 |
QTextLayout layout("text1\ttext2\ttext3\tend", testFont, &pd); |
|
1113 |
||
1114 |
QTextOption option = layout.textOption(); |
|
1115 |
QList<QTextOption::Tab> tabs; |
|
1116 |
QTextOption::Tab tab; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1117 |
tab.position = 300; |
0 | 1118 |
tabs.append(tab); |
1119 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1120 |
tab.position = 600; |
0 | 1121 |
tab.type = QTextOption::RightTab; |
1122 |
tabs.append(tab); |
|
1123 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1124 |
tab.position = 800; |
0 | 1125 |
tab.type = QTextOption::CenterTab; |
1126 |
tabs.append(tab); |
|
1127 |
option.setTabs(tabs); |
|
1128 |
layout.setTextOption(option); |
|
1129 |
||
1130 |
layout.beginLayout(); |
|
1131 |
QTextLine line = layout.createLine(); |
|
1132 |
line.setLineWidth(1500.); |
|
1133 |
layout.endLayout(); |
|
1134 |
QCOMPARE(line.cursorToX(0), 0.); |
|
1135 |
QCOMPARE(line.cursorToX(1), (double) TESTFONT_SIZE); // check that the font does not resize |
|
1136 |
qreal scale = 72 / (qreal) qt_defaultDpiY(); |
|
1137 |
// lets do the transformation of deminishing resolution that QFixed has as effect. |
|
1138 |
int fixedScale = (int)( scale * qreal(64)); // into a QFixed |
|
1139 |
scale = ((qreal)fixedScale)/(qreal)64; // and out of a QFixed |
|
1140 |
||
1141 |
QCOMPARE(line.cursorToX(6), tabs.at(0).position * scale); |
|
1142 |
QCOMPARE(line.cursorToX(12), tabs.at(1).position * scale - TESTFONT_SIZE * 5); |
|
1143 |
QCOMPARE(line.cursorToX(18), tabs.at(2).position * scale - TESTFONT_SIZE * 3 / 2.0); |
|
1144 |
} |
|
1145 |
||
1146 |
void tst_QTextLayout::tabHeight() |
|
1147 |
{ |
|
1148 |
QTextLayout layout("\t", testFont); |
|
1149 |
layout.beginLayout(); |
|
1150 |
QTextLine line = layout.createLine(); |
|
1151 |
layout.endLayout(); |
|
1152 |
||
1153 |
QCOMPARE(qRound(line.ascent()), QFontMetrics(testFont).ascent()); |
|
1154 |
QCOMPARE(qRound(line.descent()), QFontMetrics(testFont).descent()); |
|
1155 |
} |
|
1156 |
||
1157 |
void tst_QTextLayout::capitalization_allUpperCase() |
|
1158 |
{ |
|
1159 |
QFont font(testFont); |
|
1160 |
font.setCapitalization(QFont::AllUppercase); |
|
1161 |
QTextLayout layout("Test", font); |
|
1162 |
layout.beginLayout(); |
|
1163 |
QTextLine line = layout.createLine(); |
|
1164 |
layout.endLayout(); |
|
1165 |
||
1166 |
QTextEngine *engine = layout.engine(); |
|
1167 |
engine->itemize(); |
|
1168 |
QCOMPARE(engine->layoutData->items.count(), 1); |
|
1169 |
QVERIFY(engine->layoutData->items.at(0).analysis.flags == QScriptAnalysis::Uppercase); |
|
1170 |
} |
|
1171 |
||
1172 |
void tst_QTextLayout::capitalization_allLowerCase() |
|
1173 |
{ |
|
1174 |
QFont font(testFont); |
|
1175 |
font.setCapitalization(QFont::AllLowercase); |
|
1176 |
QTextLayout layout("Test", font); |
|
1177 |
layout.beginLayout(); |
|
1178 |
QTextLine line = layout.createLine(); |
|
1179 |
layout.endLayout(); |
|
1180 |
||
1181 |
QTextEngine *engine = layout.engine(); |
|
1182 |
engine->itemize(); |
|
1183 |
QCOMPARE(engine->layoutData->items.count(), 1); |
|
1184 |
QVERIFY(engine->layoutData->items.at(0).analysis.flags == QScriptAnalysis::Lowercase); |
|
1185 |
} |
|
1186 |
||
1187 |
void tst_QTextLayout::capitalization_smallCaps() |
|
1188 |
{ |
|
1189 |
QFont font(testFont); |
|
1190 |
font.setCapitalization(QFont::SmallCaps); |
|
1191 |
QTextLayout layout("Test", font); |
|
1192 |
layout.beginLayout(); |
|
1193 |
QTextLine line = layout.createLine(); |
|
1194 |
layout.endLayout(); |
|
1195 |
||
1196 |
QTextEngine *engine = layout.engine(); |
|
1197 |
engine->itemize(); |
|
1198 |
QCOMPARE(engine->layoutData->items.count(), 2); |
|
1199 |
QVERIFY(engine->layoutData->items.at(0).analysis.flags == QScriptAnalysis::None); |
|
1200 |
QVERIFY(engine->layoutData->items.at(1).analysis.flags == QScriptAnalysis::SmallCaps); |
|
1201 |
} |
|
1202 |
||
1203 |
void tst_QTextLayout::capitalization_capitalize() |
|
1204 |
{ |
|
1205 |
QFont font(testFont); |
|
1206 |
font.setCapitalization(QFont::Capitalize); |
|
1207 |
QTextLayout layout("hello\tworld", font); |
|
1208 |
layout.beginLayout(); |
|
1209 |
QTextLine line = layout.createLine(); |
|
1210 |
layout.endLayout(); |
|
1211 |
||
1212 |
QTextEngine *engine = layout.engine(); |
|
1213 |
engine->itemize(); |
|
1214 |
QCOMPARE(engine->layoutData->items.count(), 5); |
|
1215 |
QVERIFY(engine->layoutData->items.at(0).analysis.flags == QScriptAnalysis::Uppercase); |
|
1216 |
QVERIFY(engine->layoutData->items.at(1).analysis.flags == QScriptAnalysis::None); |
|
1217 |
QVERIFY(engine->layoutData->items.at(2).analysis.flags == QScriptAnalysis::Tab); |
|
1218 |
QVERIFY(engine->layoutData->items.at(3).analysis.flags == QScriptAnalysis::Uppercase); |
|
1219 |
QVERIFY(engine->layoutData->items.at(4).analysis.flags == QScriptAnalysis::None); |
|
1220 |
} |
|
1221 |
||
1222 |
void tst_QTextLayout::longText() |
|
1223 |
{ |
|
1224 |
QString longText(128000, 'a'); |
|
1225 |
||
1226 |
{ |
|
1227 |
QTextLayout layout(longText, testFont); |
|
1228 |
layout.beginLayout(); |
|
1229 |
QTextLine line = layout.createLine(); |
|
1230 |
layout.endLayout(); |
|
1231 |
QVERIFY(line.isValid()); |
|
1232 |
QVERIFY(line.cursorToX(line.textLength() - 1) > 0); |
|
1233 |
} |
|
1234 |
||
1235 |
for (int cap = QFont::MixedCase; cap < QFont::Capitalize + 1; ++cap) { |
|
1236 |
QFont f(testFont); |
|
1237 |
f.setCapitalization(QFont::Capitalization(cap)); |
|
1238 |
QTextLayout layout(longText, f); |
|
1239 |
layout.beginLayout(); |
|
1240 |
QTextLine line = layout.createLine(); |
|
1241 |
layout.endLayout(); |
|
1242 |
QVERIFY(line.isValid()); |
|
1243 |
QVERIFY(line.cursorToX(line.textLength() - 1) > 0); |
|
1244 |
} |
|
1245 |
||
1246 |
{ |
|
1247 |
QTextLayout layout(longText, testFont); |
|
1248 |
layout.setFlags(Qt::TextForceLeftToRight); |
|
1249 |
layout.beginLayout(); |
|
1250 |
QTextLine line = layout.createLine(); |
|
1251 |
layout.endLayout(); |
|
1252 |
QVERIFY(line.isValid()); |
|
1253 |
QVERIFY(line.cursorToX(line.textLength() - 1) > 0); |
|
1254 |
} |
|
1255 |
||
1256 |
{ |
|
1257 |
QTextLayout layout(longText, testFont); |
|
1258 |
layout.setFlags(Qt::TextForceRightToLeft); |
|
1259 |
layout.beginLayout(); |
|
1260 |
QTextLine line = layout.createLine(); |
|
1261 |
layout.endLayout(); |
|
1262 |
QVERIFY(line.isValid()); |
|
1263 |
QVERIFY(line.cursorToX(line.textLength() - 1) > 0); |
|
1264 |
} |
|
1265 |
} |
|
1266 |
||
1267 |
void tst_QTextLayout::widthOfTabs() |
|
1268 |
{ |
|
1269 |
QTextEngine engine("ddd\t\t", testFont); |
|
1270 |
engine.ignoreBidi = true; |
|
1271 |
engine.itemize(); |
|
1272 |
QCOMPARE(qRound(engine.width(0, 5)), qRound(engine.boundingBox(0, 5).width)); |
|
1273 |
} |
|
1274 |
||
1275 |
void tst_QTextLayout::columnWrapWithTabs() |
|
1276 |
{ |
|
1277 |
QTextLayout textLayout; |
|
1278 |
{ |
|
1279 |
QTextOption textOption; |
|
1280 |
textOption.setWrapMode(QTextOption::WordWrap); |
|
1281 |
textLayout.setTextOption(textOption); |
|
1282 |
} |
|
1283 |
||
1284 |
// Make sure string with spaces does not break |
|
1285 |
{ |
|
1286 |
QString text = "Foo bar foo bar foo bar"; |
|
1287 |
textLayout.setText(text); |
|
1288 |
||
1289 |
textLayout.beginLayout(); |
|
1290 |
QTextLine line = textLayout.createLine(); |
|
1291 |
line.setNumColumns(30); |
|
1292 |
QCOMPARE(line.textLength(), text.length()); |
|
1293 |
textLayout.endLayout(); |
|
1294 |
} |
|
1295 |
||
1296 |
// Make sure string with tabs breaks |
|
1297 |
{ |
|
1298 |
QString text = "Foo\tbar\tfoo\tbar\tfoo\tbar"; |
|
1299 |
textLayout.setText(text); |
|
1300 |
textLayout.beginLayout(); |
|
1301 |
QTextLine line = textLayout.createLine(); |
|
1302 |
line.setNumColumns(30); |
|
1303 |
QVERIFY(line.textLength() < text.length()); |
|
1304 |
textLayout.endLayout(); |
|
1305 |
} |
|
1306 |
||
1307 |
} |
|
1308 |
||
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1309 |
void tst_QTextLayout::boundingRectForUnsetLineWidth() |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1310 |
{ |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1311 |
QTextLayout layout("FOOBAR"); |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1312 |
|
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1313 |
layout.beginLayout(); |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1314 |
QTextLine line = layout.createLine(); |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1315 |
layout.endLayout(); |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1316 |
|
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1317 |
QCOMPARE(layout.boundingRect().width(), line.naturalTextWidth()); |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1318 |
} |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1319 |
|
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1320 |
void tst_QTextLayout::boundingRectForSetLineWidth() |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1321 |
{ |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1322 |
QTextLayout layout("FOOBAR"); |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1323 |
|
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1324 |
layout.beginLayout(); |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1325 |
QTextLine line = layout.createLine(); |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1326 |
line.setLineWidth(QFIXED_MAX - 1); |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1327 |
layout.endLayout(); |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1328 |
|
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1329 |
QCOMPARE(layout.boundingRect().width(), qreal(QFIXED_MAX - 1)); |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1330 |
} |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1331 |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1332 |
void tst_QTextLayout::lineWidthFromBOM() |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1333 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1334 |
const QString string(QChar(0xfeff)); // BYTE ORDER MARK |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1335 |
QTextLayout layout(string); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1336 |
layout.beginLayout(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1337 |
QTextLine line = layout.createLine(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1338 |
line.setLineWidth(INT_MAX / 256); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1339 |
layout.endLayout(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1340 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1341 |
// Don't spin into an infinite loop |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1342 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1343 |
|
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1344 |
void tst_QTextLayout::glyphLessItems() |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1345 |
{ |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1346 |
{ |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1347 |
QTextLayout layout; |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1348 |
layout.setText("\t\t"); |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1349 |
layout.beginLayout(); |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1350 |
layout.createLine(); |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1351 |
layout.endLayout(); |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1352 |
} |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1353 |
|
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1354 |
{ |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1355 |
QTextLayout layout; |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1356 |
layout.setText(QString::fromLatin1("AA") + QChar(QChar::LineSeparator)); |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1357 |
layout.beginLayout(); |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1358 |
layout.createLine(); |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1359 |
layout.endLayout(); |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1360 |
} |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1361 |
} |
0 | 1362 |
|
37
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1363 |
void tst_QTextLayout::textWidthVsWIdth() |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1364 |
{ |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1365 |
QTextLayout layout; |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1366 |
QTextOption opt; |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1367 |
opt.setWrapMode(QTextOption::WrapAnywhere); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1368 |
layout.setTextOption(opt); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1369 |
layout.setText(QString::fromLatin1( |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1370 |
"g++ -c -m64 -pipe -g -fvisibility=hidden -fvisibility-inlines-hidden -Wall -W -D_REENTRANT -fPIC -DCORE_LIBRARY -DIDE_LIBRARY_BASENAME=\"lib\" -DWITH_TESTS " |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1371 |
"-DQT_NO_CAST_TO_ASCII -DQT_USE_FAST_OPERATOR_PLUS -DQT_USE_FAST_CONCATENATION -DQT_PLUGIN -DQT_TESTLIB_LIB -DQT_SCRIPT_LIB -DQT_SVG_LIB -DQT_SQL_LIB -DQT_XM" |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1372 |
"L_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_SHARED -I../../../../qt-qml/mkspecs/linux-g++-64 -I. -I../../../../qt-qml/include/QtCore -I../../../." |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1373 |
"./qt-qml/include/QtNetwork -I../../../../qt-qml/include/QtGui -I../../../../qt-qml/include/QtXml -I../../../../qt-qml/include/QtSql -I../../../../qt-qml/inc" |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1374 |
"lude/QtSvg -I../../../../qt-qml/include/QtScript -I../../../../qt-qml/include/QtTest -I../../../../qt-qml/include -I../../../../qt-qml/include/QtHelp -I../." |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1375 |
"./libs -I/home/ettrich/dev/creator/tools -I../../plugins -I../../shared/scriptwrapper -I../../libs/3rdparty/botan/build -Idialogs -Iactionmanager -Ieditorma" |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1376 |
"nager -Iprogressmanager -Iscriptmanager -I.moc/debug-shared -I.uic -o .obj/debug-shared/sidebar.o sidebar.cpp")); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1377 |
|
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1378 |
// textWidth includes right bearing, but it should never be LARGER than width if there is space for at least one character |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1379 |
for (int width = 100; width < 1000; ++width) { |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1380 |
layout.beginLayout(); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1381 |
QTextLine line = layout.createLine(); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1382 |
line.setLineWidth(width); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1383 |
layout.endLayout(); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1384 |
|
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1385 |
qreal textWidthIsLargerBy = qMax(qreal(0), line.naturalTextWidth() - line.width()); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1386 |
qreal thisMustBeZero = 0; |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1387 |
QCOMPARE(textWidthIsLargerBy, thisMustBeZero); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1388 |
} |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1389 |
} |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1390 |
|
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1391 |
|
0 | 1392 |
QTEST_MAIN(tst_QTextLayout) |
1393 |
#include "tst_qtextlayout.moc" |