summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2020-05-31 13:28:36 +0200
committerTomaž Vajngerl <quikee@gmail.com>2020-06-04 00:43:43 +0200
commit7b2170f6239f0c4f16a1cbd3ec54a861405aa07a (patch)
tree1afc3272d792b4d5fecc9bcc3cc6e5d605ca9db9
parent110b17500acdee1ac1bb97bf53eb422beb67d116 (diff)
sd: add support to search backwards in PDF search
Change-Id: I2c7f75d16a430dcfa892d28fb6b4f64118705ad2 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95459 Tested-by: Tomaž Vajngerl <quikee@gmail.com> Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
-rw-r--r--sd/qa/unit/tiledrendering/LOKitSearchTest.cxx104
-rw-r--r--sd/source/ui/view/Outliner.cxx21
2 files changed, 120 insertions, 5 deletions
diff --git a/sd/qa/unit/tiledrendering/LOKitSearchTest.cxx b/sd/qa/unit/tiledrendering/LOKitSearchTest.cxx
index 2c1e1c0426a3..8c2a41eeca9e 100644
--- a/sd/qa/unit/tiledrendering/LOKitSearchTest.cxx
+++ b/sd/qa/unit/tiledrendering/LOKitSearchTest.cxx
@@ -56,6 +56,7 @@ public:
void testSearchInPDFNonExisting();
void testSearchInPDF();
void testSearchInPDFInMultiplePages();
+ void testSearchInPDFInMultiplePagesBackwards();
void testSearchIn2MixedObjects();
void testSearchIn6MixedObjects();
@@ -69,6 +70,7 @@ public:
CPPUNIT_TEST(testSearchInPDFNonExisting);
CPPUNIT_TEST(testSearchInPDF);
CPPUNIT_TEST(testSearchInPDFInMultiplePages);
+ CPPUNIT_TEST(testSearchInPDFInMultiplePagesBackwards);
CPPUNIT_TEST(testSearchIn2MixedObjects);
CPPUNIT_TEST(testSearchIn6MixedObjects);
CPPUNIT_TEST_SUITE_END();
@@ -123,14 +125,14 @@ LOKitSearchTest::createDoc(const char* pName, const uno::Sequence<beans::Propert
namespace
{
-void lcl_search(const OUString& rKey, bool bFindAll = false)
+void lcl_search(const OUString& rKey, bool bFindAll = false, bool bBackwards = false)
{
Scheduler::ProcessEventsToIdle();
SvxSearchCmd eSearch = bFindAll ? SvxSearchCmd::FIND_ALL : SvxSearchCmd::FIND;
uno::Sequence<beans::PropertyValue> aPropertyValues(comphelper::InitPropertySequence({
{ "SearchItem.SearchString", uno::makeAny(rKey) },
- { "SearchItem.Backward", uno::makeAny(false) },
+ { "SearchItem.Backward", uno::makeAny(bBackwards) },
{ "SearchItem.Command", uno::makeAny(sal_uInt16(eSearch)) },
}));
@@ -422,6 +424,104 @@ void LOKitSearchTest::testSearchInPDFInMultiplePages()
mpCallbackRecorder->m_aSearchResultSelection[0]);
}
+void LOKitSearchTest::testSearchInPDFInMultiplePagesBackwards()
+{
+ SdXImpressDocument* pXImpressDocument = createDoc("PDFSearch.pdf");
+ sd::ViewShell* pViewShell = pXImpressDocument->GetDocShell()->GetViewShell();
+ CPPUNIT_ASSERT(pViewShell);
+ mpCallbackRecorder->registerCallbacksFor(pViewShell->GetViewShellBase());
+
+ SdPage* pPage = pViewShell->GetActualPage();
+ CPPUNIT_ASSERT(pPage);
+
+ {
+ SdrObject* pObject = pPage->GetObj(0);
+ CPPUNIT_ASSERT(pObject);
+
+ SdrGrafObj* pGraphicObject = dynamic_cast<SdrGrafObj*>(pObject);
+ CPPUNIT_ASSERT(pGraphicObject);
+
+ Graphic aGraphic = pGraphicObject->GetGraphic();
+ auto const& pVectorGraphicData = aGraphic.getVectorGraphicData();
+ CPPUNIT_ASSERT(pVectorGraphicData);
+ CPPUNIT_ASSERT_EQUAL(VectorGraphicDataType::Pdf,
+ pVectorGraphicData->getVectorGraphicDataType());
+ }
+
+ // Expected for backwards search is:
+ // - Start with Page 1
+ // + search backwards through objects
+ // + inside objects search backwards through text
+ // - Switch to Page 2
+ // + search backwards through objects
+ // + inside objects search backwards through text
+
+ // Search for "him"
+ lcl_search("him", /*FindAll*/ false, /*Backwards*/ true);
+
+ CPPUNIT_ASSERT_EQUAL(true, mpCallbackRecorder->m_bFound);
+ CPPUNIT_ASSERT_EQUAL(1, mpCallbackRecorder->m_nSearchResultCount);
+
+ CPPUNIT_ASSERT_EQUAL(size_t(1), mpCallbackRecorder->m_aSearchResultSelection.size());
+ CPPUNIT_ASSERT_EQUAL(size_t(1), mpCallbackRecorder->m_aSearchResultPart.size());
+
+ CPPUNIT_ASSERT_EQUAL(0, mpCallbackRecorder->m_aSearchResultPart[0]);
+ CPPUNIT_ASSERT_EQUAL(OString("5592, 5038, 1100, 499"),
+ mpCallbackRecorder->m_aSearchResultSelection[0]);
+
+ // Search for "him"
+ lcl_search("him", /*FindAll*/ false, /*Backwards*/ true);
+
+ CPPUNIT_ASSERT_EQUAL(true, mpCallbackRecorder->m_bFound);
+ CPPUNIT_ASSERT_EQUAL(2, mpCallbackRecorder->m_nSearchResultCount);
+
+ CPPUNIT_ASSERT_EQUAL(size_t(1), mpCallbackRecorder->m_aSearchResultSelection.size());
+ CPPUNIT_ASSERT_EQUAL(size_t(1), mpCallbackRecorder->m_aSearchResultPart.size());
+
+ CPPUNIT_ASSERT_EQUAL(0, mpCallbackRecorder->m_aSearchResultPart[0]);
+ CPPUNIT_ASSERT_EQUAL(OString("9463, 3382, 1099, 499"),
+ mpCallbackRecorder->m_aSearchResultSelection[0]);
+
+ // Search for "him"
+ lcl_search("him", /*FindAll*/ false, /*Backwards*/ true);
+
+ CPPUNIT_ASSERT_EQUAL(true, mpCallbackRecorder->m_bFound);
+ CPPUNIT_ASSERT_EQUAL(3, mpCallbackRecorder->m_nSearchResultCount);
+
+ CPPUNIT_ASSERT_EQUAL(size_t(1), mpCallbackRecorder->m_aSearchResultSelection.size());
+ CPPUNIT_ASSERT_EQUAL(size_t(1), mpCallbackRecorder->m_aSearchResultPart.size());
+
+ CPPUNIT_ASSERT_EQUAL(1, mpCallbackRecorder->m_aSearchResultPart[0]);
+ CPPUNIT_ASSERT_EQUAL(OString("5592, 2964, 1100, 499"),
+ mpCallbackRecorder->m_aSearchResultSelection[0]);
+
+ // Search for "him"
+ lcl_search("him", /*FindAll*/ false, /*Backwards*/ true);
+
+ CPPUNIT_ASSERT_EQUAL(true, mpCallbackRecorder->m_bFound);
+ CPPUNIT_ASSERT_EQUAL(4, mpCallbackRecorder->m_nSearchResultCount);
+
+ CPPUNIT_ASSERT_EQUAL(size_t(1), mpCallbackRecorder->m_aSearchResultSelection.size());
+ CPPUNIT_ASSERT_EQUAL(size_t(1), mpCallbackRecorder->m_aSearchResultPart.size());
+
+ CPPUNIT_ASSERT_EQUAL(1, mpCallbackRecorder->m_aSearchResultPart[0]);
+ CPPUNIT_ASSERT_EQUAL(OString("9463, 1308, 1099, 499"),
+ mpCallbackRecorder->m_aSearchResultSelection[0]);
+
+ // Search for "him" - back to start
+ lcl_search("him", /*FindAll*/ false, /*Backwards*/ true);
+
+ CPPUNIT_ASSERT_EQUAL(true, mpCallbackRecorder->m_bFound);
+ CPPUNIT_ASSERT_EQUAL(5, mpCallbackRecorder->m_nSearchResultCount);
+
+ CPPUNIT_ASSERT_EQUAL(size_t(1), mpCallbackRecorder->m_aSearchResultSelection.size());
+ CPPUNIT_ASSERT_EQUAL(size_t(1), mpCallbackRecorder->m_aSearchResultPart.size());
+
+ CPPUNIT_ASSERT_EQUAL(0, mpCallbackRecorder->m_aSearchResultPart[0]);
+ CPPUNIT_ASSERT_EQUAL(OString("5592, 5038, 1100, 499"),
+ mpCallbackRecorder->m_aSearchResultSelection[0]);
+}
+
// Test searching in document with mixed objects.
// We have 2 objects: 1. Text Object, 2. Graphic Object with PDF
void LOKitSearchTest::testSearchIn2MixedObjects()
diff --git a/sd/source/ui/view/Outliner.cxx b/sd/source/ui/view/Outliner.cxx
index 44ecd9182e6b..3843cd692872 100644
--- a/sd/source/ui/view/Outliner.cxx
+++ b/sd/source/ui/view/Outliner.cxx
@@ -826,7 +826,15 @@ bool SdOutliner::SearchAndReplaceOnce(std::vector<sd::SearchSelection>* pSelecti
if (mpImpl->mbCurrentIsVectorGraphic)
{
- if (mpImpl->mpVectorGraphicSearch->next())
+ bool bBackwards = mpSearchItem->GetBackward();
+
+ bool bResult = false;
+ if (bBackwards)
+ bResult = mpImpl->mpVectorGraphicSearch->previous();
+ else
+ bResult = mpImpl->mpVectorGraphicSearch->next();
+
+ if (bResult)
{
nMatchCount = 1;
@@ -1227,12 +1235,19 @@ void SdOutliner::ProvideNextTextObject()
// contains a vector graphic
auto* pGraphicObject = static_cast<SdrGrafObj*>(mpObj);
OUString const & rString = mpSearchItem->GetSearchString();
+ bool bBackwards = mpSearchItem->GetBackward();
+ SearchStartPosition eSearchStartPosition = bBackwards ? SearchStartPosition::End : SearchStartPosition::Begin;
mpImpl->mpVectorGraphicSearch = std::make_unique<VectorGraphicSearch>(pGraphicObject->GetGraphic());
- bool bResult = mpImpl->mpVectorGraphicSearch->search(rString);
+ bool bResult = mpImpl->mpVectorGraphicSearch->search(rString, eSearchStartPosition);
if (bResult)
- bResult = mpImpl->mpVectorGraphicSearch->next();
+ {
+ if (bBackwards)
+ bResult = mpImpl->mpVectorGraphicSearch->previous();
+ else
+ bResult = mpImpl->mpVectorGraphicSearch->next();
+ }
if (bResult)
{