diff options
author | Eirik Aavitsland <eirik.aavitsland@qt.io> | 2017-02-13 12:38:10 +0100 |
---|---|---|
committer | Eirik Aavitsland <eirik.aavitsland@qt.io> | 2017-02-14 13:56:52 +0000 |
commit | 914e25bf01e6264dd80b6f27e50b45a578a7fe89 (patch) | |
tree | 90b852d8ad4d9a36997c2a1e4e79ae0ff6de7596 /tests/auto | |
parent | 8ea914c667e3d021d6618915e694a4d8bed5fe9f (diff) | |
download | qtsvg-914e25bf01e6264dd80b6f27e50b45a578a7fe89.tar.gz |
Add support for pattern brushes to svg generator
Pattern brushes was not implemented in the svg generator. Shapes
drawn with such brushes would not be included in the svg file.
[ChangeLog][][QSvgGenerator] Add support for pattern brushes
Task-number: QTBUG-58148
Change-Id: Ib275661c596631fea64cb250c9743a529cd7b834
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/qsvggenerator/tst_qsvggenerator.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/auto/qsvggenerator/tst_qsvggenerator.cpp b/tests/auto/qsvggenerator/tst_qsvggenerator.cpp index 4795b55..b55b687 100644 --- a/tests/auto/qsvggenerator/tst_qsvggenerator.cpp +++ b/tests/auto/qsvggenerator/tst_qsvggenerator.cpp @@ -58,6 +58,7 @@ private slots: void fractionalFontSize(); void titleAndDescription(); void gradientInterpolation(); + void patternBrush(); }; tst_QSvgGenerator::tst_QSvgGenerator() @@ -423,5 +424,46 @@ void tst_QSvgGenerator::gradientInterpolation() QVERIFY(sqrImageDiff(image, refImage) < 2); // pixel error < 1.41 (L2-norm) } +void tst_QSvgGenerator::patternBrush() +{ + { // Pattern brush should create mask and pattern used as fill + QSvgGenerator generator; + QByteArray byteArray; + QBuffer buffer(&byteArray); + generator.setOutputDevice(&buffer); + QPainter painter(&generator); + painter.setBrush(Qt::CrossPattern); + painter.drawRect(0, 0, 100, 100); + painter.end(); + + QVERIFY(byteArray.contains("<mask id=\"patternmask")); + QVERIFY(byteArray.contains("<pattern id=\"fillpattern")); + QVERIFY(byteArray.contains("<g fill=\"url(#fillpattern")); + } + + { // Masks and patterns should be reused, not regenerated + QSvgGenerator generator; + QByteArray byteArray; + QBuffer buffer(&byteArray); + generator.setOutputDevice(&buffer); + QPainter painter(&generator); + painter.setBrush(QBrush(Qt::red, Qt::Dense3Pattern)); + painter.drawRect(0, 0, 100, 100); + painter.drawEllipse(200, 50, 50, 50); + painter.setBrush(QBrush(Qt::green, Qt::Dense3Pattern)); + painter.drawRoundedRect(0, 200, 100, 100, 10, 10); + painter.setBrush(QBrush(Qt::blue, Qt::Dense4Pattern)); + painter.drawRect(200, 200, 100, 100); + painter.setBrush(QBrush(Qt::red, Qt::Dense3Pattern)); + painter.drawRoundedRect(120, 120, 60, 60, 5, 5); + painter.end(); + + QCOMPARE(byteArray.count("<mask id=\"patternmask"), 2); + QCOMPARE(byteArray.count("<pattern id=\"fillpattern"), 3); + QVERIFY(byteArray.count("<g fill=\"url(#fillpattern") >= 4); + } + +} + QTEST_MAIN(tst_QSvgGenerator) #include "tst_qsvggenerator.moc" |