diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2021-06-15 13:57:15 +0900 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2021-08-31 07:11:08 +0200 |
commit | 9d2b575d46de9be4997c9c2a574555c401c4f0c3 (patch) | |
tree | 75d102530092543b234e0f5981ed3de6b6d36c09 /sw | |
parent | 855d4b4e1ce408bda4d213c4e3f544e943f09adf (diff) |
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 <quikee@gmail.com>
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
(cherry picked from commit f81115740bac985cad3cd15348f75c2c78b8843a)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121100
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Diffstat (limited to 'sw')
-rw-r--r-- | sw/qa/extras/indexing/IndexingExportTest.cxx | 28 | ||||
-rw-r--r-- | sw/qa/extras/indexing/data/IndexingExport_Images.odt | bin | 0 -> 14607 bytes | |||
-rw-r--r-- | sw/source/filter/indexing/IndexingExport.cxx | 25 |
3 files changed, 47 insertions, 6 deletions
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 Binary files differnew file mode 100644 index 000000000000..3bf4120e27b4 --- /dev/null +++ b/sw/qa/extras/indexing/data/IndexingExport_Images.odt 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"); |