[Libreoffice-commits] core.git: desktop/qa sw/source
Tomaž Vajngerl (via logerrit)
logerrit at kemper.freedesktop.org
Tue Aug 10 06:33:33 UTC 2021
desktop/qa/desktop_lib/test_desktop_lib.cxx | 7 ++--
sw/source/uibase/uno/unotxdoc.cxx | 49 ++++++++++++++++++++--------
2 files changed, 40 insertions(+), 16 deletions(-)
New commits:
commit 7da5537f6a43c1b82afc5e0c8d18b8d847293fda
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Mon Aug 2 22:27:28 2021 +0900
Commit: Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Tue Aug 10 08:32:57 2021 +0200
indexing: use XML as input that is identical to indexing XML
Change-Id: I2242b4bd77220b55e67c2e0f0fe54f008759d282
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120194
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>
diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx
index f23f9709416e..dc8b4caf1de4 100644
--- a/desktop/qa/desktop_lib/test_desktop_lib.cxx
+++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx
@@ -3117,13 +3117,16 @@ void DesktopLOKTest::testRenderSearchResult()
Scheduler::ProcessEventsToIdle();
unsigned char* pBuffer = nullptr;
- OString aJSON = "{ \"type\" : 1, \"node_index\" : 19 }";
+ OString aPayload =
+ "<indexing>"
+ "<paragraph type=\"1\" index=\"19\">ABC</paragraph>"
+ "</indexing>";
int nWidth = 0;
int nHeight = 0;
size_t nByteSize = 0;
- bool bResult = pDocument->m_pDocumentClass->renderSearchResult(pDocument, aJSON.getStr(), &pBuffer, &nWidth, &nHeight, &nByteSize);
+ bool bResult = pDocument->m_pDocumentClass->renderSearchResult(pDocument, aPayload.getStr(), &pBuffer, &nWidth, &nHeight, &nByteSize);
CPPUNIT_ASSERT(bResult);
CPPUNIT_ASSERT(pBuffer);
diff --git a/sw/source/uibase/uno/unotxdoc.cxx b/sw/source/uibase/uno/unotxdoc.cxx
index 2940c52b8256..51dfac84254c 100644
--- a/sw/source/uibase/uno/unotxdoc.cxx
+++ b/sw/source/uibase/uno/unotxdoc.cxx
@@ -122,7 +122,6 @@
#include <swruler.hxx>
#include <docufld.hxx>
-
#include <EnhancedPDFExportHelper.hxx>
#include <numrule.hxx>
@@ -164,7 +163,7 @@
#include <IDocumentOutlineNodes.hxx>
#include <SearchResultLocator.hxx>
-#include <boost/property_tree/json_parser.hpp>
+#include <tools/XmlWalker.hxx>
#define TWIPS_PER_PIXEL 15
@@ -3397,23 +3396,45 @@ 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);
+ const OString aPayloadString(pPayload);
- sw::search::SearchIndexData aData;
+ SvMemoryStream aStream(const_cast<char *>(aPayloadString.getStr()), aPayloadString.getLength(), StreamMode::READ);
+ tools::XmlWalker aWalker;
+ if (!aWalker.open(&aStream))
+ return aRectangles;
- int nType = aTree.get<int>("type");
+ if (aWalker.name() == "indexing")
+ {
+ SwDoc* pDoc = m_pDocShell->GetDoc();
- aData.nNodeIndex = sal_uInt32(aTree.get<int>("node_index"));
- aData.eType = sw::search::NodeType(nType);
+ sw::search::SearchIndexData aData;
- SwDoc* pDoc = m_pDocShell->GetDoc();
+ aWalker.children();
+ while (aWalker.isValid())
+ {
+ if (aWalker.name() == "paragraph")
+ {
+ OString sType = aWalker.attribute("type");
+ OString sIndex = aWalker.attribute("index");
+
+ if (!sType.isEmpty() && !sIndex.isEmpty())
+ {
+ aData.nNodeIndex = sIndex.toInt32();
+ aData.eType = sw::search::NodeType(sType.toInt32());
- sw::search::SearchResultLocator aLocator(pDoc);
- sw::search::LocationResult aResult = aLocator.find(aData);
- if (aResult.mbFound)
- aRectangles = aResult.maRectangles;
+ sw::search::SearchResultLocator aLocator(pDoc);
+ sw::search::LocationResult aResult = aLocator.find(aData);
+ if (aResult.mbFound)
+ {
+ for (auto const & rRect : aResult.maRectangles)
+ aRectangles.push_back(rRect);
+ }
+ }
+ }
+ aWalker.next();
+ }
+ aWalker.parent();
+ }
return aRectangles;
}
More information about the Libreoffice-commits
mailing list