diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2020-05-29 23:26:51 +0200 |
---|---|---|
committer | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2020-07-30 15:06:59 +0200 |
commit | e5133f196d97212440219d3b03e5f7c8ffe9f9c6 (patch) | |
tree | 5c072a80e606888eefc5a4bec8d9c96ca7025189 | |
parent | dfa1a57c62edb48c1b3ca5f454074f66e899cfd6 (diff) |
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@gmail.com>
(cherry picked from commit e20440effc7a47c8a5e8ef0943e6872cd9b3646a)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95929
Tested-by: Tomaž Vajngerl <quikee@gmail.com>
(cherry picked from commit 9d653f4962aae4dae6c0d4166f020354a5f82711)
-rw-r--r-- | include/vcl/VectorGraphicSearch.hxx | 1 | ||||
-rw-r--r-- | vcl/qa/cppunit/VectorGraphicSearchTest.cxx | 40 | ||||
-rw-r--r-- | vcl/source/graphic/VectorGraphicSearch.cxx | 14 |
3 files changed, 55 insertions, 0 deletions
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 d54f32930276..8b73cab71340 100644 --- a/vcl/source/graphic/VectorGraphicSearch.cxx +++ b/vcl/source/graphic/VectorGraphicSearch.cxx @@ -104,6 +104,13 @@ public: return false; } + bool previous() + { + if (mpSearchHandle) + return FPDFText_FindPrev(mpSearchHandle); + return false; + } + int index() { if (mpSearchHandle) @@ -245,6 +252,13 @@ bool VectorGraphicSearch::next() return false; } +bool VectorGraphicSearch::previous() +{ + if (mpSearchContext) + return mpSearchContext->previous(); + return false; +} + int VectorGraphicSearch::index() { if (mpSearchContext) |