From e5133f196d97212440219d3b03e5f7c8ffe9f9c6 Mon Sep 17 00:00:00 2001 From: Tomaž Vajngerl Date: Fri, 29 May 2020 23:26:51 +0200 Subject: vcl: add "previous" search to VectorGraphicSearch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 (cherry picked from commit e20440effc7a47c8a5e8ef0943e6872cd9b3646a) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95929 Tested-by: Tomaž Vajngerl (cherry picked from commit 9d653f4962aae4dae6c0d4166f020354a5f82711) --- include/vcl/VectorGraphicSearch.hxx | 1 + vcl/qa/cppunit/VectorGraphicSearchTest.cxx | 40 ++++++++++++++++++++++++++++++ vcl/source/graphic/VectorGraphicSearch.cxx | 14 +++++++++++ 3 files changed, 55 insertions(+) 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 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) -- cgit v1.2.3