summaryrefslogtreecommitdiff
path: root/sw/source/filter
diff options
context:
space:
mode:
authorSerge Krot <Serge.Krot@cib.de>2018-12-06 19:11:58 +0100
committerMichael Stahl <Michael.Stahl@cib.de>2019-01-15 19:01:57 +0100
commit736a38419f49d4b96bd845f5767a028df59e4cff (patch)
tree18d202a7b89c09cbd1692fea8663423a1685a4a2 /sw/source/filter
parent6aa9f0980612d5c7dcc02cfe11babb73605be4ca (diff)
sw: DOCX: recognize TOC title during import
Change-Id: Ifa4fb59858d61580f76e3d104aa4caa6b5902d1b Reviewed-on: https://gerrit.libreoffice.org/64735 Tested-by: Jenkins Reviewed-by: Thorsten Behrens <Thorsten.Behrens@CIB.de> tdf#121561: sw: DOCX: add std/stdPr/stdContent around TOC During export into DOCX from ODT we need to do it because in this case the TOC title will be recognized inside MS Word as part of the TOC. Later we could add support of these keywords in LO import in order to detect TOC title from DOCX input. Added unit test for export. Change-Id: I7135e91dc04d4c0501e6074a046fc473e041f014 Reviewed-on: https://gerrit.libreoffice.org/63786 Tested-by: Jenkins Reviewed-by: Thorsten Behrens <Thorsten.Behrens@CIB.de> Reviewed-on: https://gerrit.libreoffice.org/66307 Reviewed-by: Michael Stahl <Michael.Stahl@cib.de>
Diffstat (limited to 'sw/source/filter')
-rw-r--r--sw/source/filter/ww8/wrtw8nds.cxx96
-rw-r--r--sw/source/filter/ww8/wrtww8.hxx1
2 files changed, 97 insertions, 0 deletions
diff --git a/sw/source/filter/ww8/wrtw8nds.cxx b/sw/source/filter/ww8/wrtw8nds.cxx
index c1d94eda7f6c..f147adce2078 100644
--- a/sw/source/filter/ww8/wrtw8nds.cxx
+++ b/sw/source/filter/ww8/wrtw8nds.cxx
@@ -91,6 +91,8 @@
#include <com/sun/star/text/RubyPosition.hpp>
#include <oox/export/vmlexport.hxx>
#include <sfx2/docfile.hxx>
+#include <sal/log.hxx>
+#include <comphelper/propertysequence.hxx>
#include "sprmids.hxx"
@@ -3083,7 +3085,101 @@ void MSWordExportBase::OutputSectionNode( const SwSectionNode& rSectionNode )
}
}
if ( TOX_CONTENT_SECTION == rSection.GetType() )
+ {
m_bStartTOX = true;
+ UpdateTocSectionNodeProperties(rSectionNode);
+ }
+}
+
+// tdf#121561: During export of the ODT file with TOC inside into DOCX format,
+// the TOC title is being exported as regular paragraph. We should surround it
+// with <w:sdt><w:sdtPr><w:sdtContent> to make it (TOC title) recognizable
+// by MS Word as part of the TOC.
+void MSWordExportBase::UpdateTocSectionNodeProperties(const SwSectionNode& rSectionNode)
+{
+ // check section type
+ {
+ const SwSection& rSection = rSectionNode.GetSection();
+ if (TOX_CONTENT_SECTION != rSection.GetType())
+ return;
+
+ const SwTOXBase* pTOX = rSection.GetTOXBase();
+ if (pTOX)
+ {
+ TOXTypes type = pTOX->GetType();
+ if (type != TOXTypes::TOX_CONTENT)
+ return;
+ }
+ }
+
+ // get section node, skip toc-header node
+ const SwSectionNode* pSectNd = &rSectionNode;
+ {
+ SwNodeIndex aIdxNext( *pSectNd, 1 );
+ const SwNode& rNdNext = aIdxNext.GetNode();
+
+ if (rNdNext.IsSectionNode())
+ {
+ const SwSectionNode* pSectNdNext = static_cast<const SwSectionNode*>(&rNdNext);
+ if (TOX_HEADER_SECTION == pSectNdNext->GetSection().GetType() &&
+ pSectNdNext->StartOfSectionNode()->IsSectionNode())
+ {
+ pSectNd = pSectNdNext;
+ }
+ }
+ }
+
+ // get node of the first paragraph inside TOC
+ SwNodeIndex aIdxNext( *pSectNd, 1 );
+ const SwNode& rNdTocPara = aIdxNext.GetNode();
+ const SwContentNode* pNode = rNdTocPara.GetContentNode();
+ if (!pNode)
+ return;
+
+ // put required flags into grab bag of the first node in TOC
+ {
+ uno::Sequence<beans::PropertyValue> aDocPropertyValues(comphelper::InitPropertySequence(
+ {
+ {"ooxml:CT_SdtDocPart_docPartGallery", uno::makeAny(OUString("Table of Contents"))},
+ {"ooxml:CT_SdtDocPart_docPartUnique", uno::makeAny(OUString("true"))},
+ }));
+
+ uno::Sequence<beans::PropertyValue> aSdtPrPropertyValues(comphelper::InitPropertySequence(
+ {
+ {"ooxml:CT_SdtPr_docPartObj", uno::makeAny(aDocPropertyValues)},
+ }));
+
+ SfxGrabBagItem aGrabBag(RES_PARATR_GRABBAG);
+ aGrabBag.GetGrabBag()["SdtPr"] <<= aSdtPrPropertyValues;
+
+ // create temp attr set
+ SwAttrSet aSet(pNode->GetSwAttrSet());
+ aSet.Put(aGrabBag);
+
+ // set new attr to node
+ const_cast<SwContentNode*>(pNode)->SetAttr(aSet);
+ }
+
+ // set flag for the next node after TOC
+ // in order to indicate that std area has been finished
+ // see, DomainMapper::lcl_startParagraphGroup() for the same functionality during load
+ {
+ SwNodeIndex aEndTocNext( *rSectionNode.EndOfSectionNode(), 1 );
+ const SwNode& rEndTocNextNode = aEndTocNext.GetNode();
+ const SwContentNode* pNodeAfterToc = rEndTocNextNode.GetContentNode();
+ if (pNodeAfterToc)
+ {
+ SfxGrabBagItem aGrabBag(RES_PARATR_GRABBAG);
+ aGrabBag.GetGrabBag()["ParaSdtEndBefore"] <<= true;
+
+ // create temp attr set
+ SwAttrSet aSet(pNodeAfterToc->GetSwAttrSet());
+ aSet.Put(aGrabBag);
+
+ // set new attr to node
+ const_cast<SwContentNode*>(pNodeAfterToc)->SetAttr(aSet);
+ }
+ }
}
void WW8Export::AppendSection( const SwPageDesc *pPageDesc, const SwSectionFormat* pFormat, sal_uLong nLnNum )
diff --git a/sw/source/filter/ww8/wrtww8.hxx b/sw/source/filter/ww8/wrtww8.hxx
index 8a911bd381e9..ec31a1b41622 100644
--- a/sw/source/filter/ww8/wrtww8.hxx
+++ b/sw/source/filter/ww8/wrtww8.hxx
@@ -847,6 +847,7 @@ protected:
/// Output SwSectionNode
void OutputSectionNode( const SwSectionNode& );
+ static void UpdateTocSectionNodeProperties(const SwSectionNode& rSectionNode);
virtual void AppendSection( const SwPageDesc *pPageDesc, const SwSectionFormat* pFormat, sal_uLong nLnNum ) = 0;