sw/qa/extras/indexing/IndexingExportTest.cxx | 28 ++++++++++++++++--- sw/qa/extras/indexing/data/IndexingExport_Images.odt |binary sw/source/filter/indexing/IndexingExport.cxx | 25 ++++++++++++++-- 3 files changed, 47 insertions(+), 6 deletions(-)
New commits: commit f81115740bac985cad3cd15348f75c2c78b8843a Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Tue Jun 15 13:57:15 2021 +0900 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Sat Jun 19 11:13:11 2021 +0200 indexing: indexing graphics for the IndexingExport Adds handling of graphics to the IndexingExport with exporting the alt text and the name to the indexing xml. Change-Id: I20344dd04c5da4668c8eafbf1f863a26357ad616 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117357 Tested-by: Tomaž Vajngerl <qui...@gmail.com> Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> diff --git a/sw/qa/extras/indexing/IndexingExportTest.cxx b/sw/qa/extras/indexing/IndexingExportTest.cxx index 9d943e3b9593..f76850c1a803 100644 --- a/sw/qa/extras/indexing/IndexingExportTest.cxx +++ b/sw/qa/extras/indexing/IndexingExportTest.cxx @@ -26,10 +26,12 @@ private: SwDoc* createDoc(const char* pName = nullptr); public: - void testIndexingExport(); + void testIndexingExport_Paragraphs(); + void testIndexingExport_Images(); CPPUNIT_TEST_SUITE(IndexingExportTest); - CPPUNIT_TEST(testIndexingExport); + CPPUNIT_TEST(testIndexingExport_Paragraphs); + CPPUNIT_TEST(testIndexingExport_Images); CPPUNIT_TEST_SUITE_END(); }; @@ -45,7 +47,7 @@ SwDoc* IndexingExportTest::createDoc(const char* pName) return pTextDoc->GetDocShell()->GetDoc(); } -void IndexingExportTest::testIndexingExport() +void IndexingExportTest::testIndexingExport_Paragraphs() { SwDoc* pDoc = createDoc("IndexingExport_VariousParagraphs.odt"); CPPUNIT_ASSERT(pDoc); @@ -78,6 +80,26 @@ void IndexingExportTest::testIndexingExport() assertXPathContent(pXmlDoc, "/indexing/paragraph[17]", "Bold Italic Underline Strikeout"); } +void IndexingExportTest::testIndexingExport_Images() +{ + SwDoc* pDoc = createDoc("IndexingExport_Images.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/graphic[1]", "alt", "Image_NonCaption - Alternative text"); + assertXPath(pXmlDoc, "/indexing/graphic[1]", "name", "Image_NonCaption"); + assertXPath(pXmlDoc, "/indexing/graphic[2]", "alt", "Image_InCaption - Alternative text"); + assertXPath(pXmlDoc, "/indexing/graphic[2]", "name", "Image_InCaption"); +} + CPPUNIT_TEST_SUITE_REGISTRATION(IndexingExportTest); CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sw/qa/extras/indexing/data/IndexingExport_Images.odt b/sw/qa/extras/indexing/data/IndexingExport_Images.odt new file mode 100644 index 000000000000..3bf4120e27b4 Binary files /dev/null and b/sw/qa/extras/indexing/data/IndexingExport_Images.odt differ diff --git a/sw/source/filter/indexing/IndexingExport.cxx b/sw/source/filter/indexing/IndexingExport.cxx index 8df7d56f7ff6..8d6e96fd262c 100644 --- a/sw/source/filter/indexing/IndexingExport.cxx +++ b/sw/source/filter/indexing/IndexingExport.cxx @@ -10,7 +10,9 @@ #include <IndexingExport.hxx> +#include <node.hxx> #include <ndtxt.hxx> +#include <ndgrf.hxx> namespace sw { @@ -29,10 +31,27 @@ public: void handleNode(SwNode* pNode) override { - if (!pNode->IsTextNode()) - return; + if (pNode->IsGrfNode()) + { + handleGraphicNode(pNode->GetGrfNode()); + } + else if (pNode->IsTextNode()) + { + handleTextNode(pNode->GetTextNode()); + } + } + + void handleGraphicNode(SwGrfNode* pGraphicNode) + { + auto pFrameFormat = pGraphicNode->GetFlyFormat(); + m_rXmlWriter.startElement("graphic"); + m_rXmlWriter.attribute("alt", pGraphicNode->GetTitle()); + m_rXmlWriter.attribute("name", pFrameFormat->GetName()); + m_rXmlWriter.endElement(); + } - SwTextNode* pTextNode = pNode->GetTextNode(); + void handleTextNode(SwTextNode* pTextNode) + { const OUString& rString = pTextNode->GetText().replaceAll(OUStringChar(CH_TXTATR_BREAKWORD), ""); m_rXmlWriter.startElement("paragraph"); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits