diff options
-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) |