fixed paragraph layout to handle forced breaks
This commit is contained in:
6 files changed
+142
-11
No files matched your search
@@ -80,6 +80,44 @@ private slots:
|
||||
auto lines = KnuthPlass::breakLines(items, 100);
|
||||
QCOMPARE(lines.size(), 1);
|
||||
}
|
||||
|
||||
void inlineLineBreakFinishLine()
|
||||
{
|
||||
// "Line 1" <br/> "Line 2"
|
||||
QVector<KnuthPlass::Item> items;
|
||||
items.append(KnuthPlass::Item::box(30, 0));
|
||||
items.append(KnuthPlass::Item::glue(10, 5, 3, -1));
|
||||
items.append(KnuthPlass::Item::box(30, 1));
|
||||
KnuthPlass::finishLine(items);
|
||||
items.append(KnuthPlass::Item::box(40, 2));
|
||||
items.append(KnuthPlass::Item::glue(10, 5, 3, -1));
|
||||
items.append(KnuthPlass::Item::box(40, 3));
|
||||
KnuthPlass::finishParagraph(items);
|
||||
|
||||
// Line width 200: both lines are short.
|
||||
// Because finishLine inserted infinite stretch glue, line 1 must have ratio 0.0 (like line 2).
|
||||
auto lines = KnuthPlass::breakLines(items, 200);
|
||||
QCOMPARE(lines.size(), 2);
|
||||
QCOMPARE(lines[0].ratio, 0.0);
|
||||
QCOMPARE(lines[1].ratio, 0.0);
|
||||
}
|
||||
|
||||
void consecutiveLineBreaks()
|
||||
{
|
||||
// "Line 1" <br/> <br/> "Line 2"
|
||||
QVector<KnuthPlass::Item> items;
|
||||
items.append(KnuthPlass::Item::box(30, 0));
|
||||
KnuthPlass::finishLine(items);
|
||||
KnuthPlass::finishLine(items); // consecutive break with empty line
|
||||
items.append(KnuthPlass::Item::box(40, 1));
|
||||
KnuthPlass::finishParagraph(items);
|
||||
|
||||
auto lines = KnuthPlass::breakLines(items, 200);
|
||||
QCOMPARE(lines.size(), 3);
|
||||
QCOMPARE(lines[0].ratio, 0.0);
|
||||
QCOMPARE(lines[1].ratio, 0.0);
|
||||
QCOMPARE(lines[2].ratio, 0.0);
|
||||
}
|
||||
};
|
||||
|
||||
QTEST_MAIN(KnuthPlassTest)
|
||||
|
||||
Reference in new issue
Block a user