diff options
author | Albert Astals Cid <aacid@kde.org> | 2018-10-31 17:38:26 +0100 |
---|---|---|
committer | Albert Astals Cid <aacid@kde.org> | 2018-10-31 18:06:36 +0100 |
commit | aeb2c1798ef39b5d3a167f4531e9f09dcb18e88d (patch) | |
tree | 34e43eca41b73cd050881cbf3b357e00cb5e7959 | |
parent | 2d6ba9b1483cd4ae7f90d2f7ddef5a08cc3082a2 (diff) |
qt5: Fix crash when adding Highlight Annotations
-rw-r--r-- | qt5/src/poppler-annotation.cc | 2 | ||||
-rw-r--r-- | qt5/tests/check_annotations.cpp | 31 |
2 files changed, 32 insertions, 1 deletions
diff --git a/qt5/src/poppler-annotation.cc b/qt5/src/poppler-annotation.cc index a30088d6..64190bce 100644 --- a/qt5/src/poppler-annotation.cc +++ b/qt5/src/poppler-annotation.cc @@ -3139,7 +3139,7 @@ QList< HighlightAnnotation::Quad > HighlightAnnotationPrivate::fromQuadrilateral AnnotQuadrilaterals * HighlightAnnotationPrivate::toQuadrilaterals(const QList< HighlightAnnotation::Quad > &quads) const { const int count = quads.size(); - std::unique_ptr<AnnotQuadrilaterals::AnnotQuadrilateral[]> ac; + auto ac = std::make_unique<AnnotQuadrilaterals::AnnotQuadrilateral[]>(count); double MTX[6]; fillTransformationMTX(MTX); diff --git a/qt5/tests/check_annotations.cpp b/qt5/tests/check_annotations.cpp index 36aa1bd3..b4b505dd 100644 --- a/qt5/tests/check_annotations.cpp +++ b/qt5/tests/check_annotations.cpp @@ -16,6 +16,7 @@ class TestAnnotations : public QObject private slots: void checkQColorPrecision(); void checkFontSizeAndColor(); + void checkHighlightFromAndToQuads(); }; /* Is .5f sufficient for 16 bit color channel roundtrip trough save and load on all architectures? */ @@ -100,6 +101,36 @@ void TestAnnotations::checkFontSizeAndColor() } } +namespace Poppler { + static bool operator==(const Poppler::HighlightAnnotation::Quad &a, const Poppler::HighlightAnnotation::Quad &b) + { + // FIXME We do not compare capStart, capEnd and feather since AnnotQuadrilaterals doesn't contain that info and thus + // HighlightAnnotationPrivate::fromQuadrilaterals uses default values + return a.points[0] == b.points[0] && a.points[1] == b.points[1] && a.points[2] == b.points[2] && a.points[3] == b.points[3]; + } +} + +void TestAnnotations::checkHighlightFromAndToQuads() +{ + std::unique_ptr<Poppler::Document> doc{ + Poppler::Document::load(TESTDATADIR "/unittestcases/UseNone.pdf") + }; + + std::unique_ptr<Poppler::Page> page{ + doc->page(0) + }; + + auto ha = std::make_unique<Poppler::HighlightAnnotation>(); + page->addAnnotation(ha.get()); + + const QList<Poppler::HighlightAnnotation::Quad> quads = { + { {{0, 0.1}, {0.2, 0.3}, {0.4, 0.5}, {0.6, 0.7}}, false, false, 0 }, + { {{0.8, 0.9}, {0.1, 0.2}, {0.3, 0.4}, {0.5, 0.6}}, true, false, 0.4 } + }; + ha->setHighlightQuads(quads); + QCOMPARE(ha->highlightQuads(), quads); +} + QTEST_GUILESS_MAIN(TestAnnotations) #include "check_annotations.moc" |