Changeset View
Changeset View
Standalone View
Standalone View
libs/textlayout/tests/TestBlockLayout.cpp
Show All 32 Lines | |||||
33 | 33 | | |||
34 | #include <QSharedPointer> | 34 | #include <QSharedPointer> | ||
35 | #include <QVariant> | 35 | #include <QVariant> | ||
36 | #include <QTest> | 36 | #include <QTest> | ||
37 | 37 | | |||
38 | #include <TextLayoutDebug.h> | 38 | #include <TextLayoutDebug.h> | ||
39 | 39 | | |||
40 | #define FRAME_SPACING 10.0 | 40 | #define FRAME_SPACING 10.0 | ||
41 | 41 | #define LINESPACING_FACTOR 1.16 | |||
42 | 42 | | |||
43 | void TestBlockLayout::initTestCase() | 43 | void TestBlockLayout::initTestCase() | ||
44 | { | 44 | { | ||
45 | m_doc = 0; | 45 | m_doc = 0; | ||
46 | m_layout = 0; | 46 | m_layout = 0; | ||
47 | 47 | | |||
48 | m_loremIpsum = QString("Lorem ipsum dolor sit amet, XgXgectetuer adiXiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi."); | 48 | m_loremIpsum = QString("Lorem ipsum dolor sit amet, XgXgectetuer adiXiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi."); | ||
49 | } | 49 | } | ||
50 | 50 | | |||
51 | void TestBlockLayout::setupTest(const QString &initText) | 51 | void TestBlockLayout::setupTest(const QString &initText) | ||
52 | { | 52 | { | ||
53 | m_doc = new QTextDocument; | 53 | m_doc = new QTextDocument; | ||
54 | Q_ASSERT(m_doc); | 54 | Q_ASSERT(m_doc); | ||
55 | 55 | | |||
56 | MockRootAreaProvider *provider = new MockRootAreaProvider(); | 56 | MockRootAreaProvider *provider = new MockRootAreaProvider(); | ||
57 | Q_ASSERT(provider); | 57 | Q_ASSERT(provider); | ||
58 | KoTextDocument(m_doc).setInlineTextObjectManager(new KoInlineTextObjectManager); | 58 | KoTextDocument(m_doc).setInlineTextObjectManager(new KoInlineTextObjectManager); | ||
59 | 59 | | |||
60 | m_doc->setDefaultFont(QFont("Sans Serif", 12, QFont::Normal, false)); //do it manually since we do not load the appDefaultStyle | 60 | m_doc->setDefaultFont(QFont("Sans Serif", 12.0, QFont::Normal, false)); //do it manually since we do not load the appDefaultStyle | ||
61 | 61 | | |||
62 | m_styleManager = new KoStyleManager(0); | 62 | m_styleManager = new KoStyleManager(0); | ||
63 | KoTextDocument(m_doc).setStyleManager(m_styleManager); | 63 | KoTextDocument(m_doc).setStyleManager(m_styleManager); | ||
64 | 64 | | |||
65 | m_layout = new KoTextDocumentLayout(m_doc, provider); | 65 | m_layout = new KoTextDocumentLayout(m_doc, provider); | ||
66 | Q_ASSERT(m_layout); | 66 | Q_ASSERT(m_layout); | ||
67 | m_doc->setDocumentLayout(m_layout); | 67 | m_doc->setDocumentLayout(m_layout); | ||
68 | 68 | | |||
Show All 29 Lines | |||||
98 | void TestBlockLayout::testBasicLineSpacing() | 98 | void TestBlockLayout::testBasicLineSpacing() | ||
99 | { | 99 | { | ||
100 | /// Tests incrementing Y pos based on the font size | 100 | /// Tests incrementing Y pos based on the font size | ||
101 | setupTest(m_loremIpsum); | 101 | setupTest(m_loremIpsum); | ||
102 | QTextCursor cursor(m_doc); | 102 | QTextCursor cursor(m_doc); | ||
103 | cursor.setPosition(0); | 103 | cursor.setPosition(0); | ||
104 | cursor.setPosition(m_loremIpsum.length() - 1, QTextCursor::KeepAnchor); | 104 | cursor.setPosition(m_loremIpsum.length() - 1, QTextCursor::KeepAnchor); | ||
105 | QTextCharFormat charFormat = cursor.charFormat(); | 105 | QTextCharFormat charFormat = cursor.charFormat(); | ||
106 | charFormat.setFontPointSize(12); | 106 | charFormat.setFontPointSize(12.0); | ||
107 | cursor.mergeCharFormat(charFormat); | 107 | cursor.mergeCharFormat(charFormat); | ||
108 | m_layout->layout(); | 108 | m_layout->layout(); | ||
109 | QTextLayout *blockLayout = m_block.layout(); | 109 | QTextLayout *blockLayout = m_block.layout(); | ||
110 | 110 | | |||
111 | const qreal fontHeight12 = 12; | 111 | const qreal fontHeight12 = 12.0; | ||
112 | qreal lineSpacing12 = fontHeight12 * 1.2; // 120% is the normal lineSpacing. | 112 | qreal lineSpacing12 = fontHeight12 * LINESPACING_FACTOR; | ||
113 | const qreal fontHeight18 = 18; | 113 | const qreal fontHeight18 = 18.0; | ||
114 | qreal lineSpacing18 = fontHeight18 * 1.2; // 120% is the normal lineSpacing. | 114 | qreal lineSpacing18 = fontHeight18 * LINESPACING_FACTOR; | ||
115 | 115 | | |||
116 | // QCOMPARE(blockLayout->lineCount(), 15); | 116 | // QCOMPARE(blockLayout->lineCount(), 15); | ||
117 | QTextLine line; | 117 | QTextLine line; | ||
118 | for (int i = 0; i < 15; i++) { | 118 | for (int i = 0; i < 15; i++) { | ||
119 | line = blockLayout->lineAt(i); | 119 | line = blockLayout->lineAt(i); | ||
120 | QVERIFY(line.isValid()); | 120 | QVERIFY(line.isValid()); | ||
121 | // The reason for this weird check is that the values are stored internally | 121 | // The reason for this weird check is that the values are stored internally | ||
122 | // as 26.6 fixed point integers. The entire internal text layout is | 122 | // as 26.6 fixed point integers. The entire internal text layout is | ||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Line(s) | 163 | { | |||
171 | QVERIFY(block.isValid()); | 171 | QVERIFY(block.isValid()); | ||
172 | blockLayout = block.layout(); | 172 | blockLayout = block.layout(); | ||
173 | QCOMPARE(blockLayout->lineCount(), 1); | 173 | QCOMPARE(blockLayout->lineCount(), 1); | ||
174 | 174 | | |||
175 | block = block.next(); | 175 | block = block.next(); | ||
176 | QVERIFY(block.isValid()); | 176 | QVERIFY(block.isValid()); | ||
177 | blockLayout = block.layout(); | 177 | blockLayout = block.layout(); | ||
178 | //qDebug() << blockLayout->lineAt(0).y(); | 178 | //qDebug() << blockLayout->lineAt(0).y(); | ||
179 | QVERIFY(qAbs(blockLayout->lineAt(0).y() - (28.8 + 100.0)) < ROUNDING); | 179 | QVERIFY(qAbs(blockLayout->lineAt(0).y() - (2*12.0*LINESPACING_FACTOR + 100.0)) < ROUNDING); | ||
180 | } | 180 | } | ||
181 | 181 | | |||
182 | void TestBlockLayout::testFixedLineSpacing() | 182 | void TestBlockLayout::testFixedLineSpacing() | ||
183 | { | 183 | { | ||
184 | setupTest(QString("Line1")+QChar(0x2028)+"Line2"+QChar(0x2028)+"Line3"); | 184 | setupTest(QString("Line1")+QChar(0x2028)+"Line2"+QChar(0x2028)+"Line3"); | ||
185 | 185 | | |||
186 | KoParagraphStyle style; | 186 | KoParagraphStyle style; | ||
187 | style.setFontPointSize(12.0); | 187 | style.setFontPointSize(12.0); | ||
Show All 28 Lines | |||||
216 | } | 216 | } | ||
217 | 217 | | |||
218 | void TestBlockLayout::testPercentageLineSpacing() | 218 | void TestBlockLayout::testPercentageLineSpacing() | ||
219 | { | 219 | { | ||
220 | setupTest(QString("Line1")+QChar(0x2028)+"Line2"+QChar(0x2028)+"Line3"); | 220 | setupTest(QString("Line1")+QChar(0x2028)+"Line2"+QChar(0x2028)+"Line3"); | ||
221 | 221 | | |||
222 | KoParagraphStyle style; | 222 | KoParagraphStyle style; | ||
223 | style.setFontPointSize(12.0); | 223 | style.setFontPointSize(12.0); | ||
224 | style.setLineHeightPercent(150); | 224 | style.setLineHeightPercent(150); // NOTE: This is *PercentLineHeight*, so operates on font size * linespacing | ||
225 | QTextBlock block = m_doc->begin(); | 225 | QTextBlock block = m_doc->begin(); | ||
226 | style.applyStyle(block); | 226 | style.applyStyle(block); | ||
227 | 227 | | |||
228 | QCOMPARE(block.blockFormat().doubleProperty(KoParagraphStyle::PercentLineHeight), 150.0); | 228 | QCOMPARE(block.blockFormat().doubleProperty(KoParagraphStyle::PercentLineHeight), 150.0); | ||
229 | 229 | | |||
230 | m_layout->layout(); | 230 | m_layout->layout(); | ||
231 | QTextLayout *blockLayout = block.layout(); | 231 | QTextLayout *blockLayout = block.layout(); | ||
232 | 232 | | |||
233 | const qreal origlineheight = 12.0 * LINESPACING_FACTOR; | ||||
234 | qreal newlineheight = origlineheight * 1.5; | ||||
235 | | ||||
233 | QCOMPARE(blockLayout->lineAt(0).y(), 0.0 + 100.0); | 236 | QCOMPARE(blockLayout->lineAt(0).y(), 0.0 + 100.0); | ||
234 | QCOMPARE(blockLayout->lineAt(1).y(), 0.0 + 18.0 + 100.0); | 237 | QVERIFY(qAbs(blockLayout->lineAt(1).y() - (0.0 + newlineheight + 100.0)) < ROUNDING); | ||
235 | QCOMPARE(blockLayout->lineAt(2).y(), 0.0 + 18.0 + 18.0 + 100.0); | 238 | QVERIFY(qAbs(blockLayout->lineAt(2).y() - (0.0 + newlineheight + newlineheight + 100.0)) < ROUNDING); | ||
236 | 239 | | |||
237 | style.setLineHeightPercent(50); | 240 | style.setLineHeightPercent(50); | ||
238 | style.applyStyle(block); | 241 | style.applyStyle(block); | ||
239 | 242 | | |||
240 | QCOMPARE(block.blockFormat().doubleProperty(KoParagraphStyle::PercentLineHeight), 50.0); | 243 | QCOMPARE(block.blockFormat().doubleProperty(KoParagraphStyle::PercentLineHeight), 50.0); | ||
241 | 244 | | |||
242 | m_layout->layout(); | 245 | m_layout->layout(); | ||
243 | blockLayout = block.layout(); | 246 | blockLayout = block.layout(); | ||
244 | 247 | | |||
248 | newlineheight = origlineheight * 0.5; | ||||
249 | | ||||
245 | QCOMPARE(blockLayout->lineAt(0).y(), 0.0 + 100.0); | 250 | QCOMPARE(blockLayout->lineAt(0).y(), 0.0 + 100.0); | ||
246 | QCOMPARE(blockLayout->lineAt(1).y(), 0.0 + 6.0 + 100.0); | 251 | QVERIFY(qAbs(blockLayout->lineAt(1).y() - (0.0 + newlineheight + 100.0)) < ROUNDING); | ||
247 | QCOMPARE(blockLayout->lineAt(2).y(), 0.0 + 6.0 + 6.0 + 100.0); | 252 | QVERIFY(qAbs(blockLayout->lineAt(2).y() - (0.0 + newlineheight + newlineheight + 100.0)) < ROUNDING); | ||
248 | } | 253 | } | ||
249 | 254 | | |||
250 | void TestBlockLayout::testAdvancedLineSpacing() | 255 | void TestBlockLayout::testAdvancedLineSpacing() | ||
251 | { | 256 | { | ||
252 | setupTest("Line1\nLine2\nLine3\nLine4\nLine5\nLine6\nLine7"); | 257 | setupTest("Line1\nLine2\nLine3\nLine4\nLine5\nLine6\nLine7"); | ||
253 | 258 | | |||
254 | KoParagraphStyle style; | 259 | KoParagraphStyle style; | ||
255 | style.setFontPointSize(12.0); | 260 | style.setFontPointSize(12.0); | ||
256 | style.setLineHeightPercent(80); | 261 | style.setLineHeightPercent(80); | ||
257 | QTextBlock block = m_doc->begin(); | 262 | QTextBlock block = m_doc->begin(); | ||
258 | style.applyStyle(block); | 263 | style.applyStyle(block); //line1 | ||
259 | 264 | | |||
260 | // check if styles do their work ;) | 265 | // check if styles do their work ;) | ||
261 | QCOMPARE(block.blockFormat().doubleProperty(KoParagraphStyle::PercentLineHeight), 80.0); | 266 | QCOMPARE(block.blockFormat().doubleProperty(KoParagraphStyle::PercentLineHeight), 80.0); | ||
262 | 267 | | |||
263 | block = block.next(); | 268 | block = block.next(); | ||
264 | QVERIFY(block.isValid()); //line2 | 269 | QVERIFY(block.isValid()); //line2 | ||
265 | style.setLineHeightAbsolute(28.0); // removes the percentage | 270 | style.setLineHeightAbsolute(28.0); // removes the percentage | ||
266 | style.applyStyle(block); | 271 | style.applyStyle(block); | ||
Show All 20 Lines | |||||
287 | style.applyStyle(block); | 292 | style.applyStyle(block); | ||
288 | block = block.next(); | 293 | block = block.next(); | ||
289 | QVERIFY(block.isValid()); // line6 | 294 | QVERIFY(block.isValid()); // line6 | ||
290 | style.setLineSpacingFromFont(true); | 295 | style.setLineSpacingFromFont(true); | ||
291 | style.setLineHeightPercent(100); | 296 | style.setLineHeightPercent(100); | ||
292 | style.remove(KoParagraphStyle::LineSpacing); | 297 | style.remove(KoParagraphStyle::LineSpacing); | ||
293 | style.applyStyle(block); | 298 | style.applyStyle(block); | ||
294 | 299 | | |||
295 | block = m_block; // line1 | 300 | const qreal lineheight = 12.0 * LINESPACING_FACTOR; | ||
301 | | ||||
296 | m_layout->layout(); | 302 | m_layout->layout(); | ||
303 | | ||||
304 | block = m_doc->begin(); // line1 | ||||
305 | for (int i = 1; i < 7; ++i) { | ||||
306 | qInfo()<<i<<block.layout()->lineAt(0).y(); | ||||
307 | block = block.next(); | ||||
308 | } | ||||
309 | | ||||
310 | const qreal line1_y = 0.0 + 100.0; | ||||
311 | const qreal line1_height = 0.8 * lineheight; | ||||
312 | const qreal line2_y = line1_y + line1_height + 28.0 - lineheight; // bottom aligned | ||||
313 | const qreal line2_height = 28.0; | ||||
314 | const qreal line3_y = line1_y + line1_height + line2_height; | ||||
315 | const qreal line3_height = 1.2 * lineheight; // percentage overrides minimum so percentage value is the right to test against | ||||
316 | const qreal line4_y = line1_y + line1_height + line2_height + line3_height; | ||||
317 | const qreal line4_height = lineheight; | ||||
318 | const qreal line5_y = line1_y + line1_height + line2_height + line3_height + line4_height; | ||||
319 | const qreal line5_height = lineheight + 8.0 /*spacing*/; // minimum of 5 is irelevant (Note: percentage of 1.2 has been removed) | ||||
320 | const qreal line6_y = line1_y + line1_height + line2_height + line3_height + line4_height + line5_height; | ||||
321 | const qreal line6_height = lineheight; | ||||
322 | const qreal line7_y = line1_y + line1_height + line2_height + line3_height + line4_height + line5_height + line6_height; | ||||
323 | | ||||
324 | block = m_block; // line1 | ||||
325 | QVERIFY(block.isValid()); | ||||
297 | QTextLayout *blockLayout = block.layout(); | 326 | QTextLayout *blockLayout = block.layout(); | ||
298 | QVERIFY(qAbs(blockLayout->lineAt(0).y() - (0.0 + 100.0)) < ROUNDING); | 327 | QVERIFY2(qAbs(blockLayout->lineAt(0).y() - line1_y) < ROUNDING, QString("Actual: %1 Expected: %2").arg(blockLayout->lineAt(0).y()).arg(line1_y).toLatin1()); | ||
299 | 328 | | |||
300 | block = block.next(); // line2 with fixed we are bottom aligned so offset by 28.0-12.0 | 329 | block = block.next(); // line2 with fixed we are bottom aligned so offset by 28.0-lineheight | ||
301 | QVERIFY(block.isValid()); | 330 | QVERIFY(block.isValid()); | ||
302 | blockLayout = block.layout(); | 331 | blockLayout = block.layout(); | ||
303 | //qDebug() << blockLayout->lineAt(0).y(); | 332 | //qDebug() << blockLayout->lineAt(0).y(); | ||
304 | QVERIFY(qAbs(blockLayout->lineAt(0).y() - (0.8*12 + 28.0-12.0 + 100.0)) < ROUNDING); | 333 | QEXPECT_FAIL("", "FIXME: Should not this calculate with lineheight and not fontsize?", Continue); | ||
334 | QVERIFY2(qAbs(blockLayout->lineAt(0).y() - line2_y) < ROUNDING, QString("Actual: %1 Expected: %2").arg(blockLayout->lineAt(0).y()).arg(line2_y).toLatin1()); | ||||
boemann: yes I think so | |||||
305 | 335 | | |||
306 | block = block.next(); // line3 | 336 | block = block.next(); // line3 | ||
307 | QVERIFY(block.isValid()); | 337 | QVERIFY(block.isValid()); | ||
308 | blockLayout = block.layout(); | 338 | blockLayout = block.layout(); | ||
309 | //qDebug() << blockLayout->lineAt(0).y(); | 339 | //qDebug() << blockLayout->lineAt(0).y(); | ||
310 | QVERIFY(qAbs(blockLayout->lineAt(0).y() - (0.8*12 + 28.0 + 100.0)) < ROUNDING); | 340 | QVERIFY2(qAbs(blockLayout->lineAt(0).y() - line3_y) < ROUNDING, QString("Actual: %1 Expected: %2").arg(blockLayout->lineAt(0).y()).arg(line3_y).toLatin1()); | ||
311 | 341 | | |||
312 | block = block.next(); // line4 | 342 | block = block.next(); // line4 | ||
313 | QVERIFY(block.isValid()); | 343 | QVERIFY(block.isValid()); | ||
314 | blockLayout = block.layout(); | 344 | blockLayout = block.layout(); | ||
315 | //qDebug() << blockLayout->lineAt(0).y(); | 345 | //qDebug() << blockLayout->lineAt(0).y(); | ||
316 | // percentage overrides minimum so percentage value is the right to test against | 346 | // percentage overrides minimum so percentage value is the right to test against | ||
317 | //QVERIFY(qAbs(blockLayout->lineAt(0).y() - (0.8*12 + 28.0 + 40.0 + 100.0)) < ROUNDING); | 347 | //QVERIFY(qAbs(blockLayout->lineAt(0).y() - (0.8*12 + 28.0 + 40.0 + 100.0)) < ROUNDING); | ||
318 | QVERIFY(qAbs(blockLayout->lineAt(0).y() - (0.8*12 + 28.0 + 1.2*12 + 100.0)) < ROUNDING); | 348 | QVERIFY2(qAbs(blockLayout->lineAt(0).y() - line4_y) < ROUNDING, QString("Actual: %1 Expected: %2").arg(blockLayout->lineAt(0).y()).arg(line4_y).toLatin1()); | ||
319 | 349 | | |||
320 | block = block.next(); // line5 | 350 | block = block.next(); // line5 | ||
321 | QVERIFY(block.isValid()); | 351 | QVERIFY(block.isValid()); | ||
322 | blockLayout = block.layout(); | 352 | blockLayout = block.layout(); | ||
323 | //qDebug() << blockLayout->lineAt(0).y(); | 353 | //qDebug() << blockLayout->lineAt(0).y(); | ||
324 | // minimum of 5 is irelevant and percentage of 1.2 was still there | 354 | // minimum of 5 is irelevant and percentage of 1.2 was still there | ||
325 | QVERIFY(qAbs(blockLayout->lineAt(0).y() - (0.8*12 + 28.0 + 1.2*12 + 1.2*12 + 100.0)) < ROUNDING); | 355 | QVERIFY2(qAbs(blockLayout->lineAt(0).y() - line5_y) < ROUNDING, QString("Actual: %1 Expected: %2").arg(blockLayout->lineAt(0).y()).arg(line5_y).toLatin1()); | ||
326 | 356 | | |||
327 | block = block.next(); // line6 | 357 | block = block.next(); // line6 | ||
328 | QVERIFY(block.isValid()); | 358 | QVERIFY(block.isValid()); | ||
329 | blockLayout = block.layout(); | 359 | blockLayout = block.layout(); | ||
330 | //qDebug() << blockLayout->lineAt(0).y(); | 360 | //qDebug() << blockLayout->lineAt(0).y(); | ||
331 | QVERIFY(qAbs(blockLayout->lineAt(0).y() - (0.8*12 + 28.0 + 1.2*12 + 1.2*12 + 12+8 + 100.0)) < ROUNDING); | 361 | QEXPECT_FAIL("", "FIXME: Should not this calculate with lineheight and not fontsize?", Continue); | ||
362 | QVERIFY2(qAbs(blockLayout->lineAt(0).y() - line6_y) < ROUNDING, QString("Actual: %1 Expected: %2").arg(blockLayout->lineAt(0).y()).arg(line6_y).toLatin1()); | ||||
332 | 363 | | |||
333 | block = block.next(); // line 7 | 364 | block = block.next(); // line 7 | ||
334 | QVERIFY(block.isValid()); | 365 | QVERIFY(block.isValid()); | ||
335 | blockLayout = block.layout(); | 366 | blockLayout = block.layout(); | ||
336 | //qDebug() << blockLayout->lineAt(0).y(); | 367 | //qDebug() << blockLayout->lineAt(0).y(); | ||
337 | QVERIFY(qAbs(blockLayout->lineAt(0).y() - (0.8*12 + 28.0 + 1.2*12 + 1.2*12 + 12+8 + 1.2*12 + 100.0)) < ROUNDING); | 368 | QEXPECT_FAIL("", "FIXME: setLineSpacingFromFont(true) has been set on line 6, so what will the linespacing be then?", Continue); | ||
369 | QVERIFY2(qAbs(blockLayout->lineAt(0).y() - line7_y) < ROUNDING, QString("Actual: %1 Expected: %2").arg(blockLayout->lineAt(0).y()).arg(line7_y).toLatin1()); | ||||
338 | } | 370 | } | ||
339 | 371 | | |||
340 | void TestBlockLayout::testEmptyLineHeights() | 372 | void TestBlockLayout::testEmptyLineHeights() | ||
341 | { | 373 | { | ||
342 | // 1) a blank line is affected by the line break after | 374 | // 1) a blank line is affected by the line break after | ||
343 | // 1b) a line with contents is not affected by the linebreak | 375 | // 1b) a line with contents is not affected by the linebreak | ||
344 | // 2) a final line if blank can have it's height specified by a special textstyle | 376 | // 2) a final line if blank can have it's height specified by a special textstyle | ||
345 | // If the special style is empty the par style is used for the line | 377 | // If the special style is empty the par style is used for the line | ||
Show All 20 Lines | |||||
366 | cursor.setPosition(1); | 398 | cursor.setPosition(1); | ||
367 | cursor.setPosition(2, QTextCursor::KeepAnchor); | 399 | cursor.setPosition(2, QTextCursor::KeepAnchor); | ||
368 | cursor.mergeCharFormat(smallCharFormat); | 400 | cursor.mergeCharFormat(smallCharFormat); | ||
369 | 401 | | |||
370 | 402 | | |||
371 | m_layout->layout(); | 403 | m_layout->layout(); | ||
372 | QTextLayout *blockLayout = block.layout(); | 404 | QTextLayout *blockLayout = block.layout(); | ||
373 | QCOMPARE(blockLayout->lineAt(0).y(), 0.0 + 100.0); | 405 | QCOMPARE(blockLayout->lineAt(0).y(), 0.0 + 100.0); | ||
374 | QCOMPARE(blockLayout->lineAt(1).y(), 20.0 + 100.0); | 406 | | ||
375 | QCOMPARE(blockLayout->lineAt(2).y(), 20.0 + 8.0 + 100.0); | 407 | qreal exp = (20.0 * LINESPACING_FACTOR) + 100.0; | ||
408 | QVERIFY2(qAbs(blockLayout->lineAt(1).y() - exp) < ROUNDING, QString("Actual: %1 Expected: %2").arg(blockLayout->lineAt(1).y()).arg(exp).toLatin1()); | ||||
409 | | ||||
410 | exp = (20.0 * LINESPACING_FACTOR) + (8.0 * LINESPACING_FACTOR) + 100.0; | ||||
411 | QVERIFY2(qAbs(blockLayout->lineAt(2).y() - exp) < ROUNDING, QString("Actual: %1 Expected: %2").arg(blockLayout->lineAt(2).y()).arg(exp).toLatin1()); | ||||
376 | block = block.next(); | 412 | block = block.next(); | ||
377 | QVERIFY(block.isValid()); | 413 | QVERIFY(block.isValid()); | ||
378 | blockLayout = block.layout(); | 414 | blockLayout = block.layout(); | ||
379 | QCOMPARE(blockLayout->lineAt(0).y(), 20.0 + 8.0 + 12.0 + 100.0); | 415 | exp = (20.0 * LINESPACING_FACTOR) + (8.0 * LINESPACING_FACTOR) + (12.0 * LINESPACING_FACTOR) + 100.0; | ||
416 | QVERIFY2(qAbs(blockLayout->lineAt(0).y() - exp) < ROUNDING, QString("Actual: %1 Expected: %2").arg(blockLayout->lineAt(0).y()).arg(exp).toLatin1()); | ||||
380 | 417 | | |||
381 | // Now do the test again but with last line having bigger font | 418 | // Now do the test again but with last line having bigger font | ||
382 | block = m_doc->begin(); | 419 | block = m_doc->begin(); | ||
383 | QTextBlockFormat blockFormat = block.blockFormat(); | 420 | QTextBlockFormat blockFormat = block.blockFormat(); | ||
384 | KoCharacterStyle charStyle; | 421 | KoCharacterStyle charStyle; | ||
385 | charStyle.setFontPointSize(20.0); | 422 | charStyle.setFontPointSize(20.0); | ||
386 | blockFormat.setProperty(KoParagraphStyle::EndCharStyle, QVariant::fromValue< QSharedPointer<KoCharacterStyle> >(QSharedPointer<KoCharacterStyle>(&charStyle))); | 423 | blockFormat.setProperty(KoParagraphStyle::EndCharStyle, QVariant::fromValue< QSharedPointer<KoCharacterStyle> >(QSharedPointer<KoCharacterStyle>(&charStyle))); | ||
387 | cursor.setBlockFormat(blockFormat); | 424 | cursor.setBlockFormat(blockFormat); | ||
388 | 425 | | |||
389 | m_layout->layout(); | 426 | m_layout->layout(); | ||
390 | blockLayout = block.layout(); | 427 | blockLayout = block.layout(); | ||
391 | QCOMPARE(blockLayout->lineAt(0).y(), 0.0 + 100.0); | 428 | QCOMPARE(blockLayout->lineAt(0).y(), 0.0 + 100.0); | ||
392 | QCOMPARE(blockLayout->lineAt(1).y(), 20.0 + 100.0); | 429 | exp = (20.0 * LINESPACING_FACTOR) + 100.0; | ||
393 | QCOMPARE(blockLayout->lineAt(2).y(), 20.0 + 8.0 + 100.0); | 430 | QVERIFY2(qAbs(blockLayout->lineAt(1).y() - exp) < ROUNDING, QString("Actual: %1 Expected: %2").arg(blockLayout->lineAt(1).y()).arg(exp).toLatin1()); | ||
431 | exp = (20.0 * LINESPACING_FACTOR) + (8.0 * LINESPACING_FACTOR) + 100.0; | ||||
432 | QVERIFY2(qAbs(blockLayout->lineAt(2).y() - exp) < ROUNDING, QString("Actual: %1 Expected: %2").arg(blockLayout->lineAt(2).y()).arg(exp).toLatin1()); | ||||
394 | block = block.next(); | 433 | block = block.next(); | ||
395 | QVERIFY(block.isValid()); | 434 | QVERIFY(block.isValid()); | ||
396 | blockLayout = block.layout(); | 435 | blockLayout = block.layout(); | ||
397 | QCOMPARE(blockLayout->lineAt(0).y(), 20.0 + 8.0 + 20.0 + 100.0); | 436 | exp = (20.0 + 8.0 + 20.0) * LINESPACING_FACTOR + 100.0; | ||
437 | QVERIFY2(qAbs(blockLayout->lineAt(0).y() - exp) < ROUNDING, QString("Actual: %1 Expected: %2").arg(blockLayout->lineAt(0).y()).arg(exp).toLatin1()); | ||||
398 | 438 | | |||
399 | // Now do the test again but with last line having a small font | 439 | // Now do the test again but with last line having a small font | ||
400 | block = m_doc->begin(); | 440 | block = m_doc->begin(); | ||
401 | KoCharacterStyle charStyle2; | 441 | KoCharacterStyle charStyle2; | ||
402 | charStyle2.setFontPointSize(6.0); | 442 | charStyle2.setFontPointSize(6.0); | ||
403 | blockFormat.setProperty(KoParagraphStyle::EndCharStyle, QVariant::fromValue< QSharedPointer<KoCharacterStyle> >(QSharedPointer<KoCharacterStyle>(&charStyle2))); | 443 | blockFormat.setProperty(KoParagraphStyle::EndCharStyle, QVariant::fromValue< QSharedPointer<KoCharacterStyle> >(QSharedPointer<KoCharacterStyle>(&charStyle2))); | ||
404 | cursor.setBlockFormat(blockFormat); | 444 | cursor.setBlockFormat(blockFormat); | ||
405 | 445 | | |||
406 | m_layout->layout(); | 446 | m_layout->layout(); | ||
407 | blockLayout = block.layout(); | 447 | blockLayout = block.layout(); | ||
408 | QCOMPARE(blockLayout->lineAt(0).y(), 0.0 + 100.0); | 448 | QCOMPARE(blockLayout->lineAt(0).y(), 0.0 + 100.0); | ||
409 | QCOMPARE(blockLayout->lineAt(1).y(), 20.0 + 100.0); | 449 | exp = (20.0 * LINESPACING_FACTOR) + 100.0; | ||
410 | QCOMPARE(blockLayout->lineAt(2).y(), 20.0 + 8.0 + 100.0); | 450 | QVERIFY2(qAbs(blockLayout->lineAt(1).y() - exp) < ROUNDING, QString("Actual: %1 Expected: %2").arg(blockLayout->lineAt(1).y()).arg(exp).toLatin1()); | ||
451 | exp = (20.0 * LINESPACING_FACTOR) + (8.0 * LINESPACING_FACTOR) + 100.0; | ||||
452 | QVERIFY2(qAbs(blockLayout->lineAt(2).y() - exp) < ROUNDING, QString("Actual: %1 Expected: %2").arg(blockLayout->lineAt(2).y()).arg(exp).toLatin1()); | ||||
411 | block = block.next(); | 453 | block = block.next(); | ||
412 | QVERIFY(block.isValid()); | 454 | QVERIFY(block.isValid()); | ||
413 | blockLayout = block.layout(); | 455 | blockLayout = block.layout(); | ||
414 | QCOMPARE(blockLayout->lineAt(0).y(), 20.0 + 8.0 + 6.0 + 100.0); | 456 | exp = (20.0 * LINESPACING_FACTOR) + (8.0 * LINESPACING_FACTOR) + (6.0 * LINESPACING_FACTOR) + 100.0; | ||
457 | QVERIFY2(qAbs(blockLayout->lineAt(0).y() - exp) < ROUNDING, QString("Actual: %1 Expected: %2").arg(blockLayout->lineAt(0).y()).arg(exp).toLatin1()); | ||||
415 | } | 458 | } | ||
416 | 459 | | |||
417 | 460 | | |||
418 | // Test that spacing between blocks are the max of bottomMargin and topMargin | 461 | // Test that spacing between blocks are the max of bottomMargin and topMargin | ||
419 | // of the top and bottom block respectively | 462 | // of the top and bottom block respectively | ||
420 | // If the block doesn't connect to another block (top and bottom of pages or | 463 | // If the block doesn't connect to another block (top and bottom of pages or | ||
421 | // table cells, oif blocks are intersperced with say a table. Then it's | 464 | // table cells, oif blocks are intersperced with say a table. Then it's | ||
422 | // just the plain margin | 465 | // just the plain margin | ||
Show All 23 Lines | 468 | { | |||
446 | // and test spacing between blocks | 489 | // and test spacing between blocks | ||
447 | QTextBlockFormat bf1 = cursor1.blockFormat(); | 490 | QTextBlockFormat bf1 = cursor1.blockFormat(); | ||
448 | QTextLayout *block1Layout = m_block.layout(); | 491 | QTextLayout *block1Layout = m_block.layout(); | ||
449 | QTextBlockFormat bf2 = cursor2.blockFormat(); | 492 | QTextBlockFormat bf2 = cursor2.blockFormat(); | ||
450 | QTextLayout *block2Layout = block2.layout(); | 493 | QTextLayout *block2Layout = block2.layout(); | ||
451 | QTextBlockFormat bf3 = cursor3.blockFormat(); | 494 | QTextBlockFormat bf3 = cursor3.blockFormat(); | ||
452 | QTextLayout *block3Layout = block3.layout(); | 495 | QTextLayout *block3Layout = block3.layout(); | ||
453 | int lastLineNum = block1Layout->lineCount() - 1; | 496 | int lastLineNum = block1Layout->lineCount() - 1; | ||
454 | const qreal lineSpacing = 12.0 * 1.2; | 497 | const qreal lineSpacing = 12.0 * LINESPACING_FACTOR; | ||
anthonyfieroni: Can you use macro again? | |||||
455 | KoTextDocument(m_doc).setParaTableSpacingAtStart(false); | 498 | KoTextDocument(m_doc).setParaTableSpacingAtStart(false); | ||
456 | bool paraTableSpacingAtStart = KoTextDocument(m_doc).paraTableSpacingAtStart(); | 499 | bool paraTableSpacingAtStart = KoTextDocument(m_doc).paraTableSpacingAtStart(); | ||
457 | 500 | | |||
458 | qreal spaces[3] = {0.0, 3.0, 6.0}; | 501 | qreal spaces[3] = {0.0, 3.0, 6.0}; | ||
459 | for (int t1 = 0; t1 < 3; ++t1) { | 502 | for (int t1 = 0; t1 < 3; ++t1) { | ||
460 | for (int t2 = 0; t2 < 3; ++t2) { | 503 | for (int t2 = 0; t2 < 3; ++t2) { | ||
461 | for (int t3 = 0; t3 < 3; ++t3) { | 504 | for (int t3 = 0; t3 < 3; ++t3) { | ||
462 | for (int b1 = 0; b1 < 3; ++b1) { | 505 | for (int b1 = 0; b1 < 3; ++b1) { | ||
▲ Show 20 Lines • Show All 390 Lines • ▼ Show 20 Line(s) | 881 | { | |||
853 | QTextBlock block = m_doc->begin(); | 896 | QTextBlock block = m_doc->begin(); | ||
854 | QTextLayout *blockLayout = block.layout(); | 897 | QTextLayout *blockLayout = block.layout(); | ||
855 | QCOMPARE(blockLayout->lineAt(0).x(), 8.0 + 100.0); | 898 | QCOMPARE(blockLayout->lineAt(0).x(), 8.0 + 100.0); | ||
856 | QCOMPARE(blockLayout->lineAt(0).y(), 9.0 + 100.0); | 899 | QCOMPARE(blockLayout->lineAt(0).y(), 9.0 + 100.0); | ||
857 | QCOMPARE(blockLayout->lineAt(0).width(), 200.0 - 8.0 - 11.0); | 900 | QCOMPARE(blockLayout->lineAt(0).width(), 200.0 - 8.0 - 11.0); | ||
858 | block = block.next(); | 901 | block = block.next(); | ||
859 | blockLayout = block.layout(); | 902 | blockLayout = block.layout(); | ||
860 | //warnTextLayout << "blockLayout->lineAt(0).y() "<<blockLayout->lineAt(0).y(); | 903 | //warnTextLayout << "blockLayout->lineAt(0).y() "<<blockLayout->lineAt(0).y(); | ||
861 | QVERIFY(qAbs(blockLayout->lineAt(0).y() - (9.0 + 14.4 + 10.0 + 100.0)) < ROUNDING); // 14.4 is 12 pt font + 20% linespacing | 904 | qreal exp = 9.0 + (12.0 * LINESPACING_FACTOR) + 10.0 + 100.0; | ||
905 | QVERIFY2(qAbs(blockLayout->lineAt(0).y() - exp) < ROUNDING, QString("Actual: %1 Expected: %2").arg(blockLayout->lineAt(0).y()).arg(exp).toLatin1()); | ||||
862 | 906 | | |||
863 | // borders + padding create the total inset. | 907 | // borders + padding create the total inset. | ||
864 | bf.setProperty(KoParagraphStyle::LeftPadding, 5.0); | 908 | bf.setProperty(KoParagraphStyle::LeftPadding, 5.0); | ||
865 | bf.setProperty(KoParagraphStyle::RightPadding, 5.0); | 909 | bf.setProperty(KoParagraphStyle::RightPadding, 5.0); | ||
866 | bf.setProperty(KoParagraphStyle::TopPadding, 5.0); | 910 | bf.setProperty(KoParagraphStyle::TopPadding, 5.0); | ||
867 | bf.setProperty(KoParagraphStyle::BottomPadding, 5.0); | 911 | bf.setProperty(KoParagraphStyle::BottomPadding, 5.0); | ||
868 | cursor.setBlockFormat(bf); | 912 | cursor.setBlockFormat(bf); | ||
869 | 913 | | |||
870 | m_layout->layout(); | 914 | m_layout->layout(); | ||
871 | block = m_doc->begin(); | 915 | block = m_doc->begin(); | ||
872 | blockLayout = block.layout(); | 916 | blockLayout = block.layout(); | ||
873 | QCOMPARE(blockLayout->lineAt(0).x(), 13.0 + 100.0); | 917 | QCOMPARE(blockLayout->lineAt(0).x(), 13.0 + 100.0); | ||
874 | QCOMPARE(blockLayout->lineAt(0).y(), 14.0 + 100.0); | 918 | QCOMPARE(blockLayout->lineAt(0).y(), 14.0 + 100.0); | ||
875 | QCOMPARE(blockLayout->lineAt(0).width(), 200.0 - 8.0 - 11.0 - 5.0 * 2); | 919 | QCOMPARE(blockLayout->lineAt(0).width(), 200.0 - 8.0 - 11.0 - 5.0 * 2); | ||
876 | block = block.next(); | 920 | block = block.next(); | ||
877 | blockLayout = block.layout(); | 921 | blockLayout = block.layout(); | ||
878 | //qDebug() << blockLayout->lineAt(0).y() << (9.0 + 14.4 + 10 + 5.0 * 2); | 922 | //qDebug() << blockLayout->lineAt(0).y() << (9.0 + 14.4 + 10 + 5.0 * 2); | ||
879 | QVERIFY(qAbs(blockLayout->lineAt(0).y() - (9.0 + 14.4 + 10 + 5.0 * 2 + 100.0)) < ROUNDING); | 923 | exp = 9.0 + (12.0 * LINESPACING_FACTOR) + 10 + 5.0 * 2 + 100.0; | ||
924 | QVERIFY2(qAbs(blockLayout->lineAt(0).y() - exp) < ROUNDING, QString("Actual: %1 Expected: %2").arg(blockLayout->lineAt(0).y()).arg(exp).toLatin1()); | ||||
880 | 925 | | |||
881 | // borders are positioned outside the padding, lets check that to be the case. | 926 | // borders are positioned outside the padding, lets check that to be the case. | ||
882 | block = m_doc->begin(); | 927 | block = m_doc->begin(); | ||
883 | KoTextBlockData data(block); | 928 | KoTextBlockData data(block); | ||
884 | KoTextBlockBorderData *border = data.border(); | 929 | KoTextBlockBorderData *border = data.border(); | ||
885 | QVERIFY(border); | 930 | QVERIFY(border); | ||
886 | QCOMPARE(border->hasBorders(), true); | 931 | QCOMPARE(border->hasBorders(), true); | ||
887 | /* | 932 | /* | ||
Show All 18 Lines | |||||
906 | block = m_doc->begin(); | 951 | block = m_doc->begin(); | ||
907 | blockLayout = block.layout(); | 952 | blockLayout = block.layout(); | ||
908 | QCOMPARE(blockLayout->lineAt(0).x(), 15.0 + 100.0); | 953 | QCOMPARE(blockLayout->lineAt(0).x(), 15.0 + 100.0); | ||
909 | QCOMPARE(blockLayout->lineAt(0).y(), 16.0 + 100.0); | 954 | QCOMPARE(blockLayout->lineAt(0).y(), 16.0 + 100.0); | ||
910 | QCOMPARE(blockLayout->lineAt(0).width(), 200.0 - 8.0 - 11.0 - (5.0 + 2.0) * 2); | 955 | QCOMPARE(blockLayout->lineAt(0).width(), 200.0 - 8.0 - 11.0 - (5.0 + 2.0) * 2); | ||
911 | block = block.next(); | 956 | block = block.next(); | ||
912 | blockLayout = block.layout(); | 957 | blockLayout = block.layout(); | ||
913 | //qDebug() << blockLayout->lineAt(0).y(); | 958 | //qDebug() << blockLayout->lineAt(0).y(); | ||
914 | QVERIFY(qAbs(blockLayout->lineAt(0).y() - (9.0 + 14.4 + 10 + (5.0 + 2.0) * 2 + 100.0)) < ROUNDING); | 959 | QVERIFY(qAbs(blockLayout->lineAt(0).y() - (9.0 + (12.0 * LINESPACING_FACTOR) + 10 + (5.0 + 2.0) * 2 + 100.0)) < ROUNDING); | ||
915 | 960 | | |||
916 | // and last, make the 2 qreal border have a blank space in the middle. | 961 | // and last, make the 2 qreal border have a blank space in the middle. | ||
917 | bf.setProperty(KoParagraphStyle::LeftBorderSpacing, 3.0); | 962 | bf.setProperty(KoParagraphStyle::LeftBorderSpacing, 3.0); | ||
918 | bf.setProperty(KoParagraphStyle::RightBorderSpacing, 3.0); | 963 | bf.setProperty(KoParagraphStyle::RightBorderSpacing, 3.0); | ||
919 | bf.setProperty(KoParagraphStyle::BottomBorderSpacing, 3.0); | 964 | bf.setProperty(KoParagraphStyle::BottomBorderSpacing, 3.0); | ||
920 | bf.setProperty(KoParagraphStyle::TopBorderSpacing, 3.0); | 965 | bf.setProperty(KoParagraphStyle::TopBorderSpacing, 3.0); | ||
921 | cursor.setBlockFormat(bf); | 966 | cursor.setBlockFormat(bf); | ||
922 | 967 | | |||
923 | m_layout->layout(); | 968 | m_layout->layout(); | ||
924 | block = m_doc->begin(); | 969 | block = m_doc->begin(); | ||
925 | blockLayout = block.layout(); | 970 | blockLayout = block.layout(); | ||
926 | QCOMPARE(blockLayout->lineAt(0).x(), 18.0 + 100.0); | 971 | QCOMPARE(blockLayout->lineAt(0).x(), 18.0 + 100.0); | ||
927 | QCOMPARE(blockLayout->lineAt(0).y(), 19.0 + 100.0); | 972 | QCOMPARE(blockLayout->lineAt(0).y(), 19.0 + 100.0); | ||
928 | QCOMPARE(blockLayout->lineAt(0).width(), 200.0 - 8.0 - 11.0 - (5.0 + 2.0 + 3.0) * 2); | 973 | QCOMPARE(blockLayout->lineAt(0).width(), 200.0 - 8.0 - 11.0 - (5.0 + 2.0 + 3.0) * 2); | ||
929 | block = block.next(); | 974 | block = block.next(); | ||
930 | blockLayout = block.layout(); | 975 | blockLayout = block.layout(); | ||
931 | //qDebug() << blockLayout->lineAt(0).y(); | 976 | //qDebug() << blockLayout->lineAt(0).y(); | ||
932 | QVERIFY(qAbs(blockLayout->lineAt(0).y() - (9.0 + 14.4 + 10 + (5.0 + 2.0 + 3.0) * 2 + 100.0)) < ROUNDING); | 977 | QVERIFY(qAbs(blockLayout->lineAt(0).y() - (9.0 + (12.0 * LINESPACING_FACTOR) + 10 + (5.0 + 2.0 + 3.0) * 2 + 100.0)) < ROUNDING); | ||
933 | } | 978 | } | ||
934 | 979 | | |||
935 | void TestBlockLayout::testParagraphMargins() | 980 | void TestBlockLayout::testParagraphMargins() | ||
936 | { | 981 | { | ||
937 | setupTest("Emtpy\nParagraph\nAnother parag\n"); | 982 | setupTest("Emtpy\nParagraph\nAnother parag\n"); | ||
938 | 983 | | |||
939 | KoParagraphStyle style; | 984 | KoParagraphStyle style; | ||
940 | style.setFontPointSize(12.0); | 985 | style.setFontPointSize(12.0); | ||
Show All 13 Lines | |||||
954 | style.applyStyle(block); | 999 | style.applyStyle(block); | ||
955 | 1000 | | |||
956 | m_layout->layout(); | 1001 | m_layout->layout(); | ||
957 | 1002 | | |||
958 | block = m_doc->begin().next(); | 1003 | block = m_doc->begin().next(); | ||
959 | KoTextBlockData data(block); | 1004 | KoTextBlockData data(block); | ||
960 | KoTextBlockBorderData *border = data.border(); | 1005 | KoTextBlockBorderData *border = data.border(); | ||
961 | QVERIFY(border); | 1006 | QVERIFY(border); | ||
962 | QCOMPARE(data.counterPosition(), QPointF(3 + 100.0, 24.4 + 100.0)); | 1007 | QCOMPARE(data.counterPosition(), QPointF(3 + 100.0, (12.0 * LINESPACING_FACTOR) + 10.0 + 100.0)); | ||
963 | 1008 | | |||
964 | block = block.next(); | 1009 | block = block.next(); | ||
965 | KoTextBlockData data2(block); | 1010 | KoTextBlockData data2(block); | ||
966 | QCOMPARE(data2.counterPosition(), QPointF(3 + 100.0, 48.8 + 100.0)); | 1011 | QCOMPARE(data2.counterPosition(), QPointF(3 + 100.0, (12.0 * LINESPACING_FACTOR + 10) * 2 + 100.0)); | ||
967 | 1012 | | |||
968 | 1013 | | |||
969 | style.setBottomMargin(QTextLength(QTextLength::FixedLength, 5)); //bottom spacing | 1014 | style.setBottomMargin(QTextLength(QTextLength::FixedLength, 5)); //bottom spacing | ||
970 | // manually reapply and relayout to force immediate reaction. | 1015 | // manually reapply and relayout to force immediate reaction. | ||
971 | block = m_doc->begin().next(); | 1016 | block = m_doc->begin().next(); | ||
972 | style.applyStyle(block); | 1017 | style.applyStyle(block); | ||
973 | block = block.next(); | 1018 | block = block.next(); | ||
974 | style.applyStyle(block); | 1019 | style.applyStyle(block); | ||
975 | m_layout->layout(); | 1020 | m_layout->layout(); | ||
976 | 1021 | | |||
977 | block = m_doc->begin().next(); | 1022 | block = m_doc->begin().next(); | ||
978 | border = data2.border(); | 1023 | border = data2.border(); | ||
979 | QVERIFY(border); | 1024 | QVERIFY(border); | ||
980 | 1025 | | |||
981 | KoTextBlockData data3(block); | 1026 | KoTextBlockData data3(block); | ||
982 | QCOMPARE(data3.counterPosition(), QPointF(3 + 100.0, 24.4 + 100.0)); | 1027 | QCOMPARE(data3.counterPosition(), QPointF(3 + 100.0, (12.0 * LINESPACING_FACTOR) + 10.0 + 100.0)); | ||
983 | 1028 | | |||
984 | block = block.next(); | 1029 | block = block.next(); | ||
985 | KoTextBlockData data4(block); | 1030 | KoTextBlockData data4(block); | ||
986 | QCOMPARE(data4.counterPosition(), QPointF(3 + 100.0, 48.8 + 100.0)); // same y as before as we take max spacing | 1031 | QCOMPARE(data4.counterPosition(), QPointF(3 + 100.0, (12.0 * LINESPACING_FACTOR + 10.0) * 2 + 100.0)); // same y as before as we take max spacing | ||
987 | } | 1032 | } | ||
988 | 1033 | | |||
989 | void TestBlockLayout::testEmptyParag() | 1034 | void TestBlockLayout::testEmptyParag() | ||
990 | { | 1035 | { | ||
991 | setupTest("Foo\n\nBar\n"); | 1036 | setupTest("Foo\n\nBar\n"); | ||
992 | m_layout->layout(); | 1037 | m_layout->layout(); | ||
993 | QTextBlock block = m_doc->begin(); | 1038 | QTextBlock block = m_doc->begin(); | ||
994 | QTextLayout *lay = block.layout(); | 1039 | QTextLayout *lay = block.layout(); | ||
995 | QVERIFY(lay); | 1040 | QVERIFY(lay); | ||
996 | QCOMPARE(lay->lineCount(), 1); | 1041 | QCOMPARE(lay->lineCount(), 1); | ||
997 | const qreal y = lay->lineAt(0).position().y(); | 1042 | const qreal y = lay->lineAt(0).position().y(); | ||
998 | 1043 | | |||
999 | block = block.next(); | 1044 | block = block.next(); | ||
1000 | lay = block.layout(); | 1045 | lay = block.layout(); | ||
1001 | QVERIFY(lay); | 1046 | QVERIFY(lay); | ||
1002 | QCOMPARE(lay->lineCount(), 1); | 1047 | QCOMPARE(lay->lineCount(), 1); | ||
1003 | QVERIFY(lay->lineAt(0).position().y() > y); | 1048 | QVERIFY(lay->lineAt(0).position().y() > y); | ||
1004 | QVERIFY(qAbs(lay->lineAt(0).position().y() - (14.4 + 100.0)) < ROUNDING); | 1049 | qInfo()<<lay->lineAt(0).position().y(); | ||
1050 | QVERIFY(qAbs(lay->lineAt(0).position().y() - (12.0*LINESPACING_FACTOR + 100.0)) < ROUNDING); | ||||
1005 | } | 1051 | } | ||
1006 | 1052 | | |||
1007 | void TestBlockLayout::testDropCapsLongText() | 1053 | void TestBlockLayout::testDropCapsLongText() | ||
1008 | { | 1054 | { | ||
1009 | // This text should be so long that it is split into more lines | 1055 | // This text should be so long that it is split into more lines | ||
1010 | // than the number of dropcap lines. | 1056 | // than the number of dropcap lines. | ||
1011 | // This is the normal use case, with a shorter line dropcaps doesn't work well | 1057 | // This is the normal use case, with a shorter line dropcaps doesn't work well | ||
1012 | setupTest(m_loremIpsum); | 1058 | setupTest(m_loremIpsum); | ||
▲ Show 20 Lines • Show All 215 Lines • Show Last 20 Lines |
yes I think so