[Libreoffice-commits] core.git: Branch 'feature/drawinglayercore' - include/vcl vcl/qa vcl/source
Rebased ref, commits from common ancestor: commit f5f846460272653a9ea3d3b16300cb65c58d21d1 Author: Tomaž Vajngerl AuthorDate: Sun May 31 14:03:36 2020 +0200 Commit: Tomaž Vajngerl CommitDate: Sun May 31 21:58:31 2020 +0200 vcl: VectorGraphicSearch - support changing search string Initial implementation only allowed to set the search string once. This change allows to change the search string and still retain the last position of a found string, so the search continues from this positon forward or backwards. This mimicks how we search through the GUI (which is the main use for this functionallity anyway). Change-Id: I8a7aee4b6b6525f483f105feaa1f83c4a0ad9594 diff --git a/include/vcl/VectorGraphicSearch.hxx b/include/vcl/VectorGraphicSearch.hxx index 2dc8cca3b76a..c9faaa51f1c9 100644 --- a/include/vcl/VectorGraphicSearch.hxx +++ b/include/vcl/VectorGraphicSearch.hxx @@ -32,8 +32,7 @@ private: std::unique_ptr mpImplementation; Graphic maGraphic; -bool searchPDF(std::shared_ptr const& rData, OUString const& rSearchString, - SearchStartPosition eStartPosition); +bool searchPDF(std::shared_ptr const& rData); public: VectorGraphicSearch(Graphic const& rGraphic); diff --git a/vcl/qa/cppunit/VectorGraphicSearchTest.cxx b/vcl/qa/cppunit/VectorGraphicSearchTest.cxx index 5f65b4ba7e3d..8dbdcac0e2e1 100644 --- a/vcl/qa/cppunit/VectorGraphicSearchTest.cxx +++ b/vcl/qa/cppunit/VectorGraphicSearchTest.cxx @@ -27,10 +27,12 @@ class VectorGraphicSearchTest : public test::BootstrapFixtureBase void test(); void testNextPrevious(); +void testSearchStringChange(); CPPUNIT_TEST_SUITE(VectorGraphicSearchTest); CPPUNIT_TEST(test); CPPUNIT_TEST(testNextPrevious); +CPPUNIT_TEST(testSearchStringChange); CPPUNIT_TEST_SUITE_END(); }; @@ -160,6 +162,37 @@ void VectorGraphicSearchTest::testNextPrevious() } } +void VectorGraphicSearchTest::testSearchStringChange() +{ +OUString aURL = getFullUrl("Pangram.pdf"); +SvFileStream aStream(aURL, StreamMode::READ); +GraphicFilter& rGraphicFilter = GraphicFilter::GetGraphicFilter(); +Graphic aGraphic = rGraphicFilter.ImportUnloadedGraphic(aStream); +aGraphic.makeAvailable(); + +VectorGraphicSearch aSearch(aGraphic); + +// Set search to "lazy" +CPPUNIT_ASSERT_EQUAL(true, aSearch.search("lazy")); + +CPPUNIT_ASSERT_EQUAL(true, aSearch.next()); +CPPUNIT_ASSERT_EQUAL(34, aSearch.index()); + +CPPUNIT_ASSERT_EQUAL(true, aSearch.next()); +CPPUNIT_ASSERT_EQUAL(817, aSearch.index()); + +// Change search to "fox" +CPPUNIT_ASSERT_EQUAL(true, aSearch.search("fox")); + +CPPUNIT_ASSERT_EQUAL(true, aSearch.next()); +CPPUNIT_ASSERT_EQUAL(822, aSearch.index()); + +// Change search to "Quick" +CPPUNIT_ASSERT_EQUAL(true, aSearch.search("Quick")); +CPPUNIT_ASSERT_EQUAL(true, aSearch.previous()); +CPPUNIT_ASSERT_EQUAL(784, 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 db17df2539ec..07e4b19afc08 100644 --- a/vcl/source/graphic/VectorGraphicSearch.cxx +++ b/vcl/source/graphic/VectorGraphicSearch.cxx @@ -56,18 +56,18 @@ private: public: sal_Int32 mnPageIndex; +int mnCurrentIndex; OUString maSearchString; SearchStartPosition meStartPosition; -SearchContext(FPDF_DOCUMENT pPdfDocument, sal_Int32 nPageIndex, OUString const& rSearchString, - SearchStartPosition eStartPosition) +SearchContext(FPDF_DOCUMENT pPdfDocument, sal_Int32 nPageIndex) : mpPdfDocument(pPdfDocument) , mpPage(nullptr) , mpTextPage(nullptr) , mpSearchHandle(nullptr) , mnPageIndex(nPageIndex) -, maSearchString(rSearchString) -, meStartPosition(eStartPosition) +, mnCurrentIndex(-1) +, meStartPosition(SearchStartPosition::Begin) { } @@ -96,13 +96,30 @@ public: return aSize; } -bool initialize() +bool initialize(OUString const& rSearchString, SearchStartPosition eStartPosition) { if (!mpPdfDocument) return false; + +if (rSearchString == maSearchString) +return true; + +if (mpSearchHandle) +FPDFText_FindClose(mpSearchHandle); + +if (mpTextPage) +FPDFText_ClosePage(mpTextPage); + +if (mpPage) +FPDF_ClosePage(mpPage); + +maSearchString = rSearchString; +meStartPosition = eStartPosition; + mpPage = FPDF_LoadPage(mpPdfDocument, mnPageIndex); if (!mpPage) return false; + mpTextPage = FPDFText_LoadPage(mpPage); if (!mpTextPage) return false; @@ -112,6 +129,9 @@ public: // Index where to
[Libreoffice-commits] core.git: Branch 'feature/drawinglayercore' - include/vcl vcl/qa vcl/source
include/vcl/VectorGraphicSearch.hxx|3 - vcl/qa/cppunit/VectorGraphicSearchTest.cxx | 33 + vcl/source/graphic/VectorGraphicSearch.cxx | 72 +++-- 3 files changed, 82 insertions(+), 26 deletions(-) New commits: commit 7ab1794e5eb2f6d5a4f35affc4ffd6e08a3eb089 Author: Tomaž Vajngerl AuthorDate: Sun May 31 14:03:36 2020 +0200 Commit: Tomaž Vajngerl CommitDate: Sun May 31 14:03:36 2020 +0200 vcl: VectorGraphicSearch - support changing search string Initial implementation only allowed to set the search string once. This change allows to change the search string and still retain the last position of a found string, so the search continues from this positon forward or backwards. This mimicks how we search through the GUI (which is the main use for this functionallity anyway). Change-Id: I8a7aee4b6b6525f483f105feaa1f83c4a0ad9594 diff --git a/include/vcl/VectorGraphicSearch.hxx b/include/vcl/VectorGraphicSearch.hxx index 2dc8cca3b76a..c9faaa51f1c9 100644 --- a/include/vcl/VectorGraphicSearch.hxx +++ b/include/vcl/VectorGraphicSearch.hxx @@ -32,8 +32,7 @@ private: std::unique_ptr mpImplementation; Graphic maGraphic; -bool searchPDF(std::shared_ptr const& rData, OUString const& rSearchString, - SearchStartPosition eStartPosition); +bool searchPDF(std::shared_ptr const& rData); public: VectorGraphicSearch(Graphic const& rGraphic); diff --git a/vcl/qa/cppunit/VectorGraphicSearchTest.cxx b/vcl/qa/cppunit/VectorGraphicSearchTest.cxx index 5f65b4ba7e3d..8dbdcac0e2e1 100644 --- a/vcl/qa/cppunit/VectorGraphicSearchTest.cxx +++ b/vcl/qa/cppunit/VectorGraphicSearchTest.cxx @@ -27,10 +27,12 @@ class VectorGraphicSearchTest : public test::BootstrapFixtureBase void test(); void testNextPrevious(); +void testSearchStringChange(); CPPUNIT_TEST_SUITE(VectorGraphicSearchTest); CPPUNIT_TEST(test); CPPUNIT_TEST(testNextPrevious); +CPPUNIT_TEST(testSearchStringChange); CPPUNIT_TEST_SUITE_END(); }; @@ -160,6 +162,37 @@ void VectorGraphicSearchTest::testNextPrevious() } } +void VectorGraphicSearchTest::testSearchStringChange() +{ +OUString aURL = getFullUrl("Pangram.pdf"); +SvFileStream aStream(aURL, StreamMode::READ); +GraphicFilter& rGraphicFilter = GraphicFilter::GetGraphicFilter(); +Graphic aGraphic = rGraphicFilter.ImportUnloadedGraphic(aStream); +aGraphic.makeAvailable(); + +VectorGraphicSearch aSearch(aGraphic); + +// Set search to "lazy" +CPPUNIT_ASSERT_EQUAL(true, aSearch.search("lazy")); + +CPPUNIT_ASSERT_EQUAL(true, aSearch.next()); +CPPUNIT_ASSERT_EQUAL(34, aSearch.index()); + +CPPUNIT_ASSERT_EQUAL(true, aSearch.next()); +CPPUNIT_ASSERT_EQUAL(817, aSearch.index()); + +// Change search to "fox" +CPPUNIT_ASSERT_EQUAL(true, aSearch.search("fox")); + +CPPUNIT_ASSERT_EQUAL(true, aSearch.next()); +CPPUNIT_ASSERT_EQUAL(822, aSearch.index()); + +// Change search to "Quick" +CPPUNIT_ASSERT_EQUAL(true, aSearch.search("Quick")); +CPPUNIT_ASSERT_EQUAL(true, aSearch.previous()); +CPPUNIT_ASSERT_EQUAL(784, 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 db17df2539ec..95059c00cd7a 100644 --- a/vcl/source/graphic/VectorGraphicSearch.cxx +++ b/vcl/source/graphic/VectorGraphicSearch.cxx @@ -56,18 +56,18 @@ private: public: sal_Int32 mnPageIndex; +int mnCurrentIndex; OUString maSearchString; SearchStartPosition meStartPosition; -SearchContext(FPDF_DOCUMENT pPdfDocument, sal_Int32 nPageIndex, OUString const& rSearchString, - SearchStartPosition eStartPosition) +SearchContext(FPDF_DOCUMENT pPdfDocument, sal_Int32 nPageIndex) : mpPdfDocument(pPdfDocument) , mpPage(nullptr) , mpTextPage(nullptr) , mpSearchHandle(nullptr) , mnPageIndex(nPageIndex) -, maSearchString(rSearchString) -, meStartPosition(eStartPosition) +, mnCurrentIndex(-1) +, meStartPosition(SearchStartPosition::Begin) { } @@ -96,13 +96,27 @@ public: return aSize; } -bool initialize() +bool initialize(OUString const& rSearchString, SearchStartPosition eStartPosition) { if (!mpPdfDocument) return false; + +if (mpSearchHandle) +FPDFText_FindClose(mpSearchHandle); + +if (mpTextPage) +FPDFText_ClosePage(mpTextPage); + +if (mpPage) +FPDF_ClosePage(mpPage); + +maSearchString = rSearchString; +meStartPosition = eStartPosition; + mpPage = FPDF_LoadPage(mpPdfDocument, mnPageIndex); if (!mpPage) return false; +
[Libreoffice-commits] core.git: Branch 'feature/drawinglayercore' - include/vcl vcl/qa vcl/source
include/vcl/VectorGraphicSearch.hxx|3 + vcl/qa/cppunit/VectorGraphicSearchTest.cxx | 23 + vcl/source/graphic/VectorGraphicSearch.cxx | 49 - 3 files changed, 74 insertions(+), 1 deletion(-) New commits: commit 423cf93f347528e11a538b927e7587ab06e30e5b Author: Tomaž Vajngerl AuthorDate: Sat May 16 19:45:41 2020 +0200 Commit: Tomaž Vajngerl CommitDate: Sat May 16 19:45:41 2020 +0200 vcl: VectorGraphicSearch - add search result selection rectangles Change-Id: Ia0c5610f600719bcfb5de503f3876fc896cb630a diff --git a/include/vcl/VectorGraphicSearch.hxx b/include/vcl/VectorGraphicSearch.hxx index 6c2589db1d01..41c7745d0cf5 100644 --- a/include/vcl/VectorGraphicSearch.hxx +++ b/include/vcl/VectorGraphicSearch.hxx @@ -14,6 +14,8 @@ #include #include +#include + #include class SearchContext; @@ -34,6 +36,7 @@ public: bool search(OUString const& rSearchString); bool next(); int index(); +std::vector getTextRectangles(); }; /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/qa/cppunit/VectorGraphicSearchTest.cxx b/vcl/qa/cppunit/VectorGraphicSearchTest.cxx index 0ed21ccf9e26..112748d23bbe 100644 --- a/vcl/qa/cppunit/VectorGraphicSearchTest.cxx +++ b/vcl/qa/cppunit/VectorGraphicSearchTest.cxx @@ -9,6 +9,7 @@ #include #include + #include #include @@ -43,6 +44,28 @@ void VectorGraphicSearchTest::test() CPPUNIT_ASSERT_EQUAL(true, aSearch.search("lazy")); CPPUNIT_ASSERT_EQUAL(true, aSearch.next()); CPPUNIT_ASSERT_EQUAL(34, aSearch.index()); +auto aRectangles = aSearch.getTextRectangles(); +CPPUNIT_ASSERT_EQUAL(size_t(4), aRectangles.size()); + +CPPUNIT_ASSERT_DOUBLES_EQUAL(229.00, aRectangles[0].getMinX(), 1E-2); +CPPUNIT_ASSERT_DOUBLES_EQUAL(231.85, aRectangles[0].getMaxX(), 1E-2); +CPPUNIT_ASSERT_DOUBLES_EQUAL(724.10, aRectangles[0].getMinY(), 1E-2); +CPPUNIT_ASSERT_DOUBLES_EQUAL(732.42, aRectangles[0].getMaxY(), 1E-2); + +CPPUNIT_ASSERT_DOUBLES_EQUAL(232.47, aRectangles[1].getMinX(), 1E-2); +CPPUNIT_ASSERT_DOUBLES_EQUAL(237.22, aRectangles[1].getMaxX(), 1E-2); +CPPUNIT_ASSERT_DOUBLES_EQUAL(723.99, aRectangles[1].getMinY(), 1E-2); +CPPUNIT_ASSERT_DOUBLES_EQUAL(729.72, aRectangles[1].getMaxY(), 1E-2); + +CPPUNIT_ASSERT_DOUBLES_EQUAL(237.68, aRectangles[2].getMinX(), 1E-2); +CPPUNIT_ASSERT_DOUBLES_EQUAL(242.35, aRectangles[2].getMaxX(), 1E-2); +CPPUNIT_ASSERT_DOUBLES_EQUAL(724.09, aRectangles[2].getMinY(), 1E-2); +CPPUNIT_ASSERT_DOUBLES_EQUAL(729.60, aRectangles[2].getMaxY(), 1E-2); + +CPPUNIT_ASSERT_DOUBLES_EQUAL(242.81, aRectangles[3].getMinX(), 1E-2); +CPPUNIT_ASSERT_DOUBLES_EQUAL(248.61, aRectangles[3].getMaxX(), 1E-2); +CPPUNIT_ASSERT_DOUBLES_EQUAL(721.51, aRectangles[3].getMinY(), 1E-2); +CPPUNIT_ASSERT_DOUBLES_EQUAL(729.60, aRectangles[3].getMaxY(), 1E-2); } CPPUNIT_TEST_SUITE_REGISTRATION(VectorGraphicSearchTest); diff --git a/vcl/source/graphic/VectorGraphicSearch.cxx b/vcl/source/graphic/VectorGraphicSearch.cxx index 34ac0abd6654..8e90145cbecb 100644 --- a/vcl/source/graphic/VectorGraphicSearch.cxx +++ b/vcl/source/graphic/VectorGraphicSearch.cxx @@ -8,9 +8,10 @@ * */ -#include #include +#include + #include #include @@ -93,6 +94,44 @@ public: return FPDFText_GetSchResultIndex(mpSearchHandle); return -1; } + +int size() +{ +if (mpSearchHandle) +return FPDFText_GetSchCount(mpSearchHandle); +return -1; +} + +std::vector getTextRectangles() +{ +std::vector aRectangles; + +if (!mpTextPage || !mpSearchHandle) +return aRectangles; + +int nIndex = index(); +if (nIndex < 0) +return aRectangles; + +int nSize = size(); +if (nSize <= 0) +return aRectangles; + +for (int nCount = 0; nCount < nSize; nCount++) +{ +double left = 0.0; +double right = 0.0; +double bottom = 0.0; +double top = 0.0; + +if (FPDFText_GetCharBox(mpTextPage, nIndex + nCount, , , , )) +{ +aRectangles.emplace_back(left, bottom, right, top); +} +} + +return aRectangles; +} }; VectorGraphicSearch::VectorGraphicSearch(Graphic const& rGraphic) @@ -182,4 +221,12 @@ int VectorGraphicSearch::index() return -1; } +std::vector VectorGraphicSearch::getTextRectangles() +{ +if (mpSearchContext) +return mpSearchContext->getTextRectangles(); + +return std::vector(); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits