summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2021-06-17 15:31:11 +0900
committerTomaž Vajngerl <quikee@gmail.com>2021-06-19 11:14:01 +0200
commitc23408aeafc1f2ce3f7dde685d0b519d8e2daff7 (patch)
tree93d0669bb6c3fa907bb5f3dcb9e62e6fe31d5ca3
parent37cd5bd4fdf2317709882c933844c4cc67e4cee4 (diff)
indexing: indexing shapes/text boxes for the IndexingExport
Adds handling of shapes and text boxes to the IndexingExport with exporting the the name, alt text, description and paragraphs of the inner shape text to the indexing xml. Change-Id: I3db68078b7e793cab552b4f7f8e8ddf9bfd1a6f2 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117359 Tested-by: Tomaž Vajngerl <quikee@gmail.com> Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
-rw-r--r--sw/qa/extras/indexing/IndexingExportTest.cxx30
-rw-r--r--sw/qa/extras/indexing/data/IndexingExport_Shapes.odtbin0 -> 11209 bytes
-rw-r--r--sw/source/core/inc/ModelTraverser.hxx2
-rw-r--r--sw/source/core/model/ModelTraverser.cxx21
-rw-r--r--sw/source/filter/indexing/IndexingExport.cxx33
5 files changed, 85 insertions, 1 deletions
diff --git a/sw/qa/extras/indexing/IndexingExportTest.cxx b/sw/qa/extras/indexing/IndexingExportTest.cxx
index 807f84ab6934..350e75c3d49f 100644
--- a/sw/qa/extras/indexing/IndexingExportTest.cxx
+++ b/sw/qa/extras/indexing/IndexingExportTest.cxx
@@ -29,11 +29,13 @@ public:
void testIndexingExport_Paragraphs();
void testIndexingExport_Images();
void testIndexingExport_OLE();
+ void testIndexingExport_Shapes();
CPPUNIT_TEST_SUITE(IndexingExportTest);
CPPUNIT_TEST(testIndexingExport_Paragraphs);
CPPUNIT_TEST(testIndexingExport_Images);
CPPUNIT_TEST(testIndexingExport_OLE);
+ CPPUNIT_TEST(testIndexingExport_Shapes);
CPPUNIT_TEST_SUITE_END();
};
@@ -120,6 +122,34 @@ void IndexingExportTest::testIndexingExport_OLE()
assertXPath(pXmlDoc, "/indexing/ole[1]", "alt", "Alt Text");
}
+void IndexingExportTest::testIndexingExport_Shapes()
+{
+ SwDoc* pDoc = createDoc("IndexingExport_Shapes.odt");
+ CPPUNIT_ASSERT(pDoc);
+
+ SvMemoryStream aMemoryStream;
+ sw::IndexingExport aIndexingExport(aMemoryStream, pDoc);
+ aIndexingExport.runExport();
+ aMemoryStream.Seek(0);
+
+ xmlDocUniquePtr pXmlDoc = parseXmlStream(&aMemoryStream);
+ CPPUNIT_ASSERT(pXmlDoc);
+
+ assertXPath(pXmlDoc, "/indexing");
+
+ assertXPath(pXmlDoc, "/indexing/shape[1]", "name", "Circle");
+ assertXPathContent(pXmlDoc, "/indexing/shape[1]/paragraph[1]", "This is a circle");
+ assertXPathContent(pXmlDoc, "/indexing/shape[1]/paragraph[2]", "This is a second paragraph");
+
+ assertXPath(pXmlDoc, "/indexing/shape[2]", "name", "Diamond");
+ assertXPathContent(pXmlDoc, "/indexing/shape[2]/paragraph[1]", "This is a diamond");
+
+ assertXPath(pXmlDoc, "/indexing/shape[3]", "name", "Text Frame 1");
+ assertXPathContent(pXmlDoc, "/indexing/shape[3]/paragraph[1]", "This is a TextBox - Para1");
+ assertXPathContent(pXmlDoc, "/indexing/shape[3]/paragraph[2]", "Para2");
+ assertXPathContent(pXmlDoc, "/indexing/shape[3]/paragraph[3]", "Para3");
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(IndexingExportTest);
CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/qa/extras/indexing/data/IndexingExport_Shapes.odt b/sw/qa/extras/indexing/data/IndexingExport_Shapes.odt
new file mode 100644
index 000000000000..8d37145ea30a
--- /dev/null
+++ b/sw/qa/extras/indexing/data/IndexingExport_Shapes.odt
Binary files differ
diff --git a/sw/source/core/inc/ModelTraverser.hxx b/sw/source/core/inc/ModelTraverser.hxx
index ab38032773df..e6aab62c998f 100644
--- a/sw/source/core/inc/ModelTraverser.hxx
+++ b/sw/source/core/inc/ModelTraverser.hxx
@@ -13,6 +13,7 @@
#include <doc.hxx>
class SwNode;
+class SdrObject;
namespace sw
{
@@ -22,6 +23,7 @@ public:
virtual ~ModelTraverseHandler() {}
virtual void handleNode(SwNode* pNode) = 0;
+ virtual void handleSdrObject(SdrObject* pObject) = 0;
};
class SW_DLLPUBLIC ModelTraverser
diff --git a/sw/source/core/model/ModelTraverser.cxx b/sw/source/core/model/ModelTraverser.cxx
index f46e173eca9f..0a01f5cd97c5 100644
--- a/sw/source/core/model/ModelTraverser.cxx
+++ b/sw/source/core/model/ModelTraverser.cxx
@@ -11,6 +11,9 @@
#include <ModelTraverser.hxx>
#include <node.hxx>
#include <ndarr.hxx>
+#include <IDocumentDrawModelAccess.hxx>
+#include <svx/svdpage.hxx>
+#include <drawdoc.hxx>
namespace sw
{
@@ -32,6 +35,24 @@ void ModelTraverser::traverse()
}
}
}
+
+ IDocumentDrawModelAccess& rDrawModelAccess = m_pDoc->getIDocumentDrawModelAccess();
+ auto* pModel = rDrawModelAccess.GetDrawModel();
+ for (sal_uInt16 nPage = 0; nPage < pModel->GetPageCount(); ++nPage)
+ {
+ SdrPage* pPage = pModel->GetPage(nPage);
+ for (size_t nObject = 0; nObject < pPage->GetObjCount(); ++nObject)
+ {
+ SdrObject* pObject = pPage->GetObj(nObject);
+ if (pObject)
+ {
+ for (auto& pNodeHandler : mpNodeHandler)
+ {
+ pNodeHandler->handleSdrObject(pObject);
+ }
+ }
+ }
+ }
}
} // end sw namespace
diff --git a/sw/source/filter/indexing/IndexingExport.cxx b/sw/source/filter/indexing/IndexingExport.cxx
index 601d67ed1b21..3ec39c1d338c 100644
--- a/sw/source/filter/indexing/IndexingExport.cxx
+++ b/sw/source/filter/indexing/IndexingExport.cxx
@@ -10,11 +10,14 @@
#include <IndexingExport.hxx>
-#include <node.hxx>
#include <ndtxt.hxx>
#include <ndole.hxx>
#include <ndnotxt.hxx>
#include <ndgrf.hxx>
+#include <svx/svdobj.hxx>
+#include <svx/svdotext.hxx>
+#include <editeng/outlobj.hxx>
+#include <editeng/editobj.hxx>
namespace sw
{
@@ -74,6 +77,34 @@ public:
m_rXmlWriter.content(rString);
m_rXmlWriter.endElement();
}
+
+ void handleSdrObject(SdrObject* pObject) override
+ {
+ if (pObject->GetName().isEmpty())
+ return;
+ m_rXmlWriter.startElement("shape");
+ m_rXmlWriter.attribute("name", pObject->GetName());
+ m_rXmlWriter.attribute("alt", pObject->GetTitle());
+ m_rXmlWriter.attribute("description", pObject->GetDescription());
+
+ SdrTextObj* pTextObject = dynamic_cast<SdrTextObj*>(pObject);
+ if (pTextObject)
+ {
+ OutlinerParaObject* pOutlinerParagraphObject = pTextObject->GetOutlinerParaObject();
+ const EditTextObject& aEdit = pOutlinerParagraphObject->GetTextObject();
+ for (sal_Int32 nParagraph = 0; nParagraph < aEdit.GetParagraphCount(); ++nParagraph)
+ {
+ OUString sText = aEdit.GetText(nParagraph);
+
+ m_rXmlWriter.startElement("paragraph");
+ m_rXmlWriter.attribute("index", nParagraph);
+ m_rXmlWriter.content(sText);
+ m_rXmlWriter.endElement();
+ }
+ }
+
+ m_rXmlWriter.endElement();
+ }
};
} // end anonymous namespace