summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2020-06-04 18:26:58 +0200
committerTomaž Vajngerl <quikee@gmail.com>2020-06-04 22:48:58 +0200
commit112d8113388513d9c6b317e828f5d373b4a54330 (patch)
tree849068d25f39c0d49ec24ba5858235b99ee03df0 /vcl
parent40c577f57fb16d24d5a2f76c3a5126073fff6a98 (diff)
sd: support match case, match whole word for PDF search
THis adds support for match case and match whole word to the VectorGraphicSearch + tests. It uses the new options in PDF seearch in Draw/Impress. Change-Id: I20a6382c22bf01a5a021c8bae1ff78861419c0ef Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95530 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'vcl')
-rw-r--r--vcl/qa/cppunit/VectorGraphicSearchTest.cxx88
-rw-r--r--vcl/source/graphic/VectorGraphicSearch.cxx22
2 files changed, 100 insertions, 10 deletions
diff --git a/vcl/qa/cppunit/VectorGraphicSearchTest.cxx b/vcl/qa/cppunit/VectorGraphicSearchTest.cxx
index 00febce16e71..0659e4e62dcf 100644
--- a/vcl/qa/cppunit/VectorGraphicSearchTest.cxx
+++ b/vcl/qa/cppunit/VectorGraphicSearchTest.cxx
@@ -32,11 +32,15 @@ class VectorGraphicSearchTest : public test::BootstrapFixtureBase
void test();
void testNextPrevious();
void testSearchStringChange();
+ void testSearchMatchWholeWord();
+ void testSearchMatchCase();
CPPUNIT_TEST_SUITE(VectorGraphicSearchTest);
CPPUNIT_TEST(test);
CPPUNIT_TEST(testNextPrevious);
CPPUNIT_TEST(testSearchStringChange);
+ CPPUNIT_TEST(testSearchMatchWholeWord);
+ CPPUNIT_TEST(testSearchMatchCase);
CPPUNIT_TEST_SUITE_END();
};
@@ -134,7 +138,8 @@ void VectorGraphicSearchTest::testNextPrevious()
{ // Start from the end of the page
VectorGraphicSearch aSearch(aGraphic);
- CPPUNIT_ASSERT_EQUAL(true, aSearch.search("lazy", SearchStartPosition::End));
+ CPPUNIT_ASSERT_EQUAL(true,
+ aSearch.search("lazy", { SearchStartPosition::End, false, false }));
// no next - we are at the end
CPPUNIT_ASSERT_EQUAL(false, aSearch.next());
@@ -197,6 +202,87 @@ void VectorGraphicSearchTest::testSearchStringChange()
CPPUNIT_ASSERT_EQUAL(784, aSearch.index());
}
+void VectorGraphicSearchTest::testSearchMatchWholeWord()
+{
+ OUString aURL = getFullUrl("Pangram.pdf");
+ SvFileStream aStream(aURL, StreamMode::READ);
+ GraphicFilter& rGraphicFilter = GraphicFilter::GetGraphicFilter();
+ Graphic aGraphic = rGraphicFilter.ImportUnloadedGraphic(aStream);
+ aGraphic.makeAvailable();
+
+ {
+ VectorGraphicSearch aSearch(aGraphic);
+ // Search, whole word disabled - "Flummoxed" - found
+ CPPUNIT_ASSERT_EQUAL(true, aSearch.search("Flummoxed"));
+ CPPUNIT_ASSERT_EQUAL(true, aSearch.next());
+ CPPUNIT_ASSERT_EQUAL(618, aSearch.index());
+ }
+ {
+ VectorGraphicSearch aSearch(aGraphic);
+ // Search, whole word disabled - "Flummo" - found
+ CPPUNIT_ASSERT_EQUAL(true, aSearch.search("Flummo"));
+ CPPUNIT_ASSERT_EQUAL(true, aSearch.next());
+ CPPUNIT_ASSERT_EQUAL(618, aSearch.index());
+ }
+ {
+ VectorGraphicSearch aSearch(aGraphic);
+ // Search, whole word enabled - "Flummoxed" - found
+ CPPUNIT_ASSERT_EQUAL(
+ true, aSearch.search("Flummoxed", { SearchStartPosition::Begin, false, true }));
+ CPPUNIT_ASSERT_EQUAL(true, aSearch.next());
+ CPPUNIT_ASSERT_EQUAL(618, aSearch.index());
+ }
+ {
+ VectorGraphicSearch aSearch(aGraphic);
+ // Search, whole word enabled - "Flummo" - not found
+ CPPUNIT_ASSERT_EQUAL(true,
+ aSearch.search("Flummo", { SearchStartPosition::Begin, false, true }));
+ CPPUNIT_ASSERT_EQUAL(false, aSearch.next());
+ }
+}
+
+void VectorGraphicSearchTest::testSearchMatchCase()
+{
+ OUString aURL = getFullUrl("Pangram.pdf");
+ SvFileStream aStream(aURL, StreamMode::READ);
+ GraphicFilter& rGraphicFilter = GraphicFilter::GetGraphicFilter();
+ Graphic aGraphic = rGraphicFilter.ImportUnloadedGraphic(aStream);
+ aGraphic.makeAvailable();
+
+ {
+ VectorGraphicSearch aSearch(aGraphic);
+ // Search "Flummoxed" - case insensitive - found
+ CPPUNIT_ASSERT_EQUAL(true, aSearch.search("Flummoxed"));
+ CPPUNIT_ASSERT_EQUAL(true, aSearch.next());
+ CPPUNIT_ASSERT_EQUAL(618, aSearch.index());
+ }
+
+ {
+ VectorGraphicSearch aSearch(aGraphic);
+ // Search "FLUMMOXED" - case insensitive - found
+ CPPUNIT_ASSERT_EQUAL(true, aSearch.search("FLUMMOXED"));
+ CPPUNIT_ASSERT_EQUAL(true, aSearch.next());
+ CPPUNIT_ASSERT_EQUAL(618, aSearch.index());
+ }
+
+ {
+ VectorGraphicSearch aSearch(aGraphic);
+ // Search "Flummoxed" - case sensitive - found
+ CPPUNIT_ASSERT_EQUAL(
+ true, aSearch.search("Flummoxed", { SearchStartPosition::Begin, true, false }));
+ CPPUNIT_ASSERT_EQUAL(true, aSearch.next());
+ CPPUNIT_ASSERT_EQUAL(618, aSearch.index());
+ }
+
+ {
+ VectorGraphicSearch aSearch(aGraphic);
+ // Search to "FLUMMOXED" - case sensitive - not found
+ CPPUNIT_ASSERT_EQUAL(
+ true, aSearch.search("FLUMMOXED", { SearchStartPosition::Begin, true, false }));
+ CPPUNIT_ASSERT_EQUAL(false, aSearch.next());
+ }
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(VectorGraphicSearchTest);
#endif
diff --git a/vcl/source/graphic/VectorGraphicSearch.cxx b/vcl/source/graphic/VectorGraphicSearch.cxx
index 95064407f553..529e8c89c489 100644
--- a/vcl/source/graphic/VectorGraphicSearch.cxx
+++ b/vcl/source/graphic/VectorGraphicSearch.cxx
@@ -35,7 +35,7 @@ public:
sal_Int32 mnPageIndex;
int mnCurrentIndex;
OUString maSearchString;
- SearchStartPosition meStartPosition;
+ VectorGraphicSearchOptions maOptions;
SearchContext(FPDF_DOCUMENT pPdfDocument, sal_Int32 nPageIndex)
: mpPdfDocument(pPdfDocument)
@@ -44,7 +44,6 @@ public:
, mpSearchHandle(nullptr)
, mnPageIndex(nPageIndex)
, mnCurrentIndex(-1)
- , meStartPosition(SearchStartPosition::Begin)
{
}
@@ -73,7 +72,7 @@ public:
return aSize;
}
- bool initialize(OUString const& rSearchString, SearchStartPosition eStartPosition)
+ bool initialize(OUString const& rSearchString, VectorGraphicSearchOptions const& rOptions)
{
if (!mpPdfDocument)
return false;
@@ -91,7 +90,7 @@ public:
FPDF_ClosePage(mpPage);
maSearchString = rSearchString;
- meStartPosition = eStartPosition;
+ maOptions = rOptions;
mpPage = FPDF_LoadPage(mpPdfDocument, mnPageIndex);
if (!mpPage)
@@ -104,7 +103,7 @@ public:
FPDF_WIDESTRING pString = reinterpret_cast<FPDF_WIDESTRING>(maSearchString.getStr());
// Index where to start to search. -1 => at the end
- int nStartIndex = meStartPosition == SearchStartPosition::End ? -1 : 0;
+ int nStartIndex = maOptions.meStartPosition == SearchStartPosition::End ? -1 : 0;
if (mnCurrentIndex >= 0)
nStartIndex = mnCurrentIndex;
@@ -114,6 +113,10 @@ public:
// FPDF_MATCHWHOLEWORD - If not set, it will not match the whole word by default.
// FPDF_CONSECUTIVE - If not set, it will skip past the current match to look for the next match.
int nSearchFlags = 0;
+ if (maOptions.mbMatchCase)
+ nSearchFlags |= FPDF_MATCHCASE;
+ if (maOptions.mbMatchWholeWord)
+ nSearchFlags |= FPDF_MATCHWHOLEWORD;
mpSearchHandle = FPDFText_FindStart(mpTextPage, pString, nSearchFlags, nStartIndex);
@@ -226,7 +229,8 @@ VectorGraphicSearch::VectorGraphicSearch(Graphic const& rGraphic)
VectorGraphicSearch::~VectorGraphicSearch() { mpImplementation.reset(); }
-bool VectorGraphicSearch::search(OUString const& rSearchString, SearchStartPosition eStartPosition)
+bool VectorGraphicSearch::search(OUString const& rSearchString,
+ VectorGraphicSearchOptions const& rOptions)
{
if (!mpImplementation->mpSearchContext)
{
@@ -236,12 +240,12 @@ bool VectorGraphicSearch::search(OUString const& rSearchString, SearchStartPosit
{
if (searchPDF(pData))
{
- return mpImplementation->mpSearchContext->initialize(rSearchString, eStartPosition);
+ return mpImplementation->mpSearchContext->initialize(rSearchString, rOptions);
}
}
return false;
}
- return mpImplementation->mpSearchContext->initialize(rSearchString, eStartPosition);
+ return mpImplementation->mpSearchContext->initialize(rSearchString, rOptions);
}
bool VectorGraphicSearch::searchPDF(std::shared_ptr<VectorGraphicData> const& rData)
@@ -333,7 +337,7 @@ VectorGraphicSearch::VectorGraphicSearch(Graphic const& rGraphic)
VectorGraphicSearch::~VectorGraphicSearch() {}
bool VectorGraphicSearch::search(OUString const& /*rSearchString*/,
- SearchStartPosition /*eStartPosition*/)
+ VectorGraphicSearchOptions const& /*rOptions*/)
{
return false;
}