summaryrefslogtreecommitdiffstats
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-07-31 05:29:32 +0200
commitd08af13e06a428a1639807bce0b53e17ae5ee694 (patch)
tree4e7c6d75583c60e1e6153102fa3354190d73b314
parentsd: add test to search inside PDF in multiple pages (diff)
downloadcore-d08af13e06a428a1639807bce0b53e17ae5ee694.tar.gz
core-d08af13e06a428a1639807bce0b53e17ae5ee694.zip
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> (cherry picked from commit 7b2170f6239f0c4f16a1cbd3ec54a861405aa07a) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95945 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> (cherry picked from commit da05adafeea785eea26cab98b77753341fc60f8b) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/99814
-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 eba4152f1bcf..5b079144f21c 100644
--- a/sd/qa/unit/tiledrendering/LOKitSearchTest.cxx
+++ b/sd/qa/unit/tiledrendering/LOKitSearchTest.cxx
@@ -58,6 +58,7 @@ public:
void testSearchInPDFNonExisting();
void testSearchInPDF();
void testSearchInPDFInMultiplePages();
+ void testSearchInPDFInMultiplePagesBackwards();
void testSearchIn2MixedObjects();
void testSearchIn6MixedObjects();
@@ -71,6 +72,7 @@ public:
CPPUNIT_TEST(testSearchInPDFNonExisting);
CPPUNIT_TEST(testSearchInPDF);
CPPUNIT_TEST(testSearchInPDFInMultiplePages);
+ CPPUNIT_TEST(testSearchInPDFInMultiplePagesBackwards);
CPPUNIT_TEST(testSearchIn2MixedObjects);
CPPUNIT_TEST(testSearchIn6MixedObjects);
CPPUNIT_TEST_SUITE_END();
@@ -125,14 +127,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)) },
}));
@@ -424,6 +426,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 441a0d3ac242..8365fb47a1ff 100644
--- a/sd/source/ui/view/Outliner.cxx
+++ b/sd/source/ui/view/Outliner.cxx
@@ -854,7 +854,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;
@@ -1255,12 +1263,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)
{