diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2021-07-09 14:41:21 +0900 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2021-09-02 08:38:39 +0200 |
commit | 494b562a69899fdad2d88c1ae2439971acdbee3c (patch) | |
tree | a8bcff1c7ae4b7c082702f38b70e087513324c39 /sw | |
parent | db8f4754e4ffd6ab51697a85a533b7317f620e41 (diff) |
indexing: add LOKit API to render the search result into a bitmap
This adds a new LOKit API to render the search result into a bitmap
buffer. It combines the SearchResultLocator to get the location
inside the document of the search result (a series of rectangles)
and the existing LOKit paintTile API to render the result into
a bitmap (byte) buffer.
It also adds a LOKit test to show how the API is used and to render
a search result of a example document.
Change-Id: I4284d90188777fd28158d029daa04151e71022bb
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118670
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
(cherry picked from commit e1511ce551f27a5560600029193f076fd65ece17)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121110
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Diffstat (limited to 'sw')
-rw-r--r-- | sw/inc/unotxdoc.hxx | 3 | ||||
-rw-r--r-- | sw/qa/extras/indexing/SearchResultLocatorTest.cxx | 7 | ||||
-rw-r--r-- | sw/source/uibase/uno/unotxdoc.cxx | 25 |
3 files changed, 30 insertions, 5 deletions
diff --git a/sw/inc/unotxdoc.hxx b/sw/inc/unotxdoc.hxx index d6d66ff3021f..e9bcc7eba36a 100644 --- a/sw/inc/unotxdoc.hxx +++ b/sw/inc/unotxdoc.hxx @@ -447,6 +447,9 @@ public: /// @see vcl::ITiledRenderable::executeFromFieldEvent(). virtual void executeFromFieldEvent(const StringMap& aArguments) override; + /// @see vcl::ITiledRenderable::getSearchResultRectangles(). + std::vector<basegfx::B2DRange> getSearchResultRectangles(const char* pPayload) override; + // css::tiledrendering::XTiledRenderable virtual void SAL_CALL paintTile( const ::css::uno::Any& Parent, ::sal_Int32 nOutputWidth, ::sal_Int32 nOutputHeight, ::sal_Int32 nTilePosX, ::sal_Int32 nTilePosY, ::sal_Int32 nTileWidth, ::sal_Int32 nTileHeight ) override; diff --git a/sw/qa/extras/indexing/SearchResultLocatorTest.cxx b/sw/qa/extras/indexing/SearchResultLocatorTest.cxx index e93c36b7fa7a..07ccc8da1c58 100644 --- a/sw/qa/extras/indexing/SearchResultLocatorTest.cxx +++ b/sw/qa/extras/indexing/SearchResultLocatorTest.cxx @@ -47,10 +47,6 @@ SwDoc* SearchResultLocatorTest::createDoc(const char* pName) void SearchResultLocatorTest::testSearchResultLocator() { -#if !defined(_WIN32) && !defined(MACOSX) - if (!IsDefaultDPI()) - return; - SwDoc* pDoc = createDoc("IndexingExport_VariousParagraphs.odt"); CPPUNIT_ASSERT(pDoc); @@ -60,8 +56,9 @@ void SearchResultLocatorTest::testSearchResultLocator() sw::LocationResult aResult = aLocator.find(aData); CPPUNIT_ASSERT_EQUAL(size_t(1), aResult.maRectangles.size()); - auto aRectangle = aResult.maRectangles[0]; +#if !defined(_WIN32) && !defined(MACOSX) + auto aRectangle = aResult.maRectangles[0]; CPPUNIT_ASSERT_DOUBLES_EQUAL(1418.0, aRectangle.getMinX(), 1e-4); CPPUNIT_ASSERT_DOUBLES_EQUAL(4444.0, aRectangle.getMinY(), 1e-4); diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx index 53e7e3292b3e..8bff5487fc7d 100644 --- a/sw/source/uibase/uno/unotxdoc.cxx +++ b/sw/source/uibase/uno/unotxdoc.cxx @@ -162,6 +162,8 @@ #include <xmloff/odffields.hxx> #include <tools/json_writer.hxx> +#include <SearchResultLocator.hxx> +#include <boost/property_tree/json_parser.hpp> #define TWIPS_PER_PIXEL 15 using namespace ::com::sun::star; @@ -3406,6 +3408,29 @@ void SwXTextDocument::executeFromFieldEvent(const StringMap& aArguments) } } +std::vector<basegfx::B2DRange> +SwXTextDocument::getSearchResultRectangles(const char* pPayload) +{ + std::vector<basegfx::B2DRange> aRectangles; + + boost::property_tree::ptree aTree; + std::stringstream aStream(pPayload); + boost::property_tree::read_json(aStream, aTree); + + sw::SearchIndexData aData; + + aData.nNodeIndex = sal_uInt32(aTree.get<int>("node_index")); + + SwDoc* pDoc = m_pDocShell->GetDoc(); + + sw::SearchResultLocator aLocator(pDoc); + sw::LocationResult aResult = aLocator.find(aData); + if (aResult.mbFound) + aRectangles = aResult.maRectangles; + + return aRectangles; +} + int SwXTextDocument::getPart() { SolarMutexGuard aGuard; |