[Libreoffice-commits] core.git: include/vcl vcl/qa vcl/source
Tomaž Vajngerl (via logerrit)
logerrit at kemper.freedesktop.org
Wed Jun 3 07:56:53 UTC 2020
include/vcl/VectorGraphicSearch.hxx | 1
vcl/qa/cppunit/VectorGraphicSearchTest.cxx | 40 +++++++++++++++++++++++++++++
vcl/source/graphic/VectorGraphicSearch.cxx | 14 ++++++++++
3 files changed, 55 insertions(+)
New commits:
commit e20440effc7a47c8a5e8ef0943e6872cd9b3646a
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Fri May 29 23:26:51 2020 +0200
Commit: Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Wed Jun 3 09:56:20 2020 +0200
vcl: add "previous" search to VectorGraphicSearch
Previous moves backwards in the search matches.
Change-Id: I88d402e0b8cb9dc4fd93e7f1ce5b08fb42aadd06
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95381
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>
diff --git a/include/vcl/VectorGraphicSearch.hxx b/include/vcl/VectorGraphicSearch.hxx
index 5420e161448b..a00c212ad61c 100644
--- a/include/vcl/VectorGraphicSearch.hxx
+++ b/include/vcl/VectorGraphicSearch.hxx
@@ -37,6 +37,7 @@ public:
bool search(OUString const& rSearchString);
basegfx::B2DSize pageSize();
bool next();
+ bool previous();
int index();
std::vector<basegfx::B2DRectangle> getTextRectangles();
};
diff --git a/vcl/qa/cppunit/VectorGraphicSearchTest.cxx b/vcl/qa/cppunit/VectorGraphicSearchTest.cxx
index 01022a3fe225..7962c23f4e8f 100644
--- a/vcl/qa/cppunit/VectorGraphicSearchTest.cxx
+++ b/vcl/qa/cppunit/VectorGraphicSearchTest.cxx
@@ -26,9 +26,11 @@ class VectorGraphicSearchTest : public test::BootstrapFixtureBase
}
void test();
+ void testNextPrevious();
CPPUNIT_TEST_SUITE(VectorGraphicSearchTest);
CPPUNIT_TEST(test);
+ CPPUNIT_TEST(testNextPrevious);
CPPUNIT_TEST_SUITE_END();
};
@@ -81,6 +83,44 @@ void VectorGraphicSearchTest::test()
CPPUNIT_ASSERT_DOUBLES_EQUAL(6381.04, aRectangles[3].getMaxY(), 1E-2);
}
+// Test next and previous work as expected to move
+// between search matches.
+void VectorGraphicSearchTest::testNextPrevious()
+{
+ OUString aURL = getFullUrl("Pangram.pdf");
+ SvFileStream aStream(aURL, StreamMode::READ);
+ GraphicFilter& rGraphicFilter = GraphicFilter::GetGraphicFilter();
+ Graphic aGraphic = rGraphicFilter.ImportUnloadedGraphic(aStream);
+ aGraphic.makeAvailable();
+
+ VectorGraphicSearch aSearch(aGraphic);
+ CPPUNIT_ASSERT_EQUAL(true, aSearch.search("lazy"));
+
+ // next - first match found
+ CPPUNIT_ASSERT_EQUAL(true, aSearch.next());
+ CPPUNIT_ASSERT_EQUAL(34, aSearch.index());
+
+ // next - second match found
+ CPPUNIT_ASSERT_EQUAL(true, aSearch.next());
+ CPPUNIT_ASSERT_EQUAL(817, aSearch.index());
+
+ // next - not found, index unchanged
+ CPPUNIT_ASSERT_EQUAL(false, aSearch.next());
+ CPPUNIT_ASSERT_EQUAL(817, aSearch.index());
+
+ // previous - first match
+ CPPUNIT_ASSERT_EQUAL(true, aSearch.previous());
+ CPPUNIT_ASSERT_EQUAL(34, aSearch.index());
+
+ // previous - not found, index unchanged
+ CPPUNIT_ASSERT_EQUAL(false, aSearch.previous());
+ CPPUNIT_ASSERT_EQUAL(34, aSearch.index());
+
+ // next - second match found
+ CPPUNIT_ASSERT_EQUAL(true, aSearch.next());
+ CPPUNIT_ASSERT_EQUAL(817, aSearch.index());
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(VectorGraphicSearchTest);
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/graphic/VectorGraphicSearch.cxx b/vcl/source/graphic/VectorGraphicSearch.cxx
index 36eeae6d2a6c..dd37c9fc98cf 100644
--- a/vcl/source/graphic/VectorGraphicSearch.cxx
+++ b/vcl/source/graphic/VectorGraphicSearch.cxx
@@ -103,6 +103,13 @@ public:
return false;
}
+ bool previous()
+ {
+ if (mpSearchHandle)
+ return FPDFText_FindPrev(mpSearchHandle);
+ return false;
+ }
+
int index()
{
if (mpSearchHandle)
@@ -244,6 +251,13 @@ bool VectorGraphicSearch::next()
return false;
}
+bool VectorGraphicSearch::previous()
+{
+ if (mpSearchContext)
+ return mpSearchContext->previous();
+ return false;
+}
+
int VectorGraphicSearch::index()
{
if (mpSearchContext)
More information about the Libreoffice-commits
mailing list