diff options
author | Serge Krot <Serge.Krot@cib.de> | 2018-12-06 19:11:58 +0100 |
---|---|---|
committer | Michael Stahl <Michael.Stahl@cib.de> | 2019-01-15 19:01:57 +0100 |
commit | 736a38419f49d4b96bd845f5767a028df59e4cff (patch) | |
tree | 18d202a7b89c09cbd1692fea8663423a1685a4a2 /sw/source | |
parent | 6aa9f0980612d5c7dcc02cfe11babb73605be4ca (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')
-rw-r--r-- | sw/source/core/doc/doctxm.cxx | 16 | ||||
-rw-r--r-- | sw/source/core/unocore/unoidx.cxx | 6 | ||||
-rw-r--r-- | sw/source/filter/ww8/wrtw8nds.cxx | 96 | ||||
-rw-r--r-- | sw/source/filter/ww8/wrtww8.hxx | 1 |
4 files changed, 110 insertions, 9 deletions
diff --git a/sw/source/core/doc/doctxm.cxx b/sw/source/core/doc/doctxm.cxx index 84d57cff5cf4..1305dfe90a1f 100644 --- a/sw/source/core/doc/doctxm.cxx +++ b/sw/source/core/doc/doctxm.cxx @@ -333,14 +333,22 @@ const SwTOXMark& SwDoc::GotoTOXMark( const SwTOXMark& rCurTOXMark, } SwTOXBaseSection* SwDoc::InsertTableOf( const SwPosition& rPos, - const SwTOXBase& rTOX, - const SfxItemSet* pSet, - bool bExpand ) + const SwTOXBase& rTOX, + const SfxItemSet* pSet, + bool bExpand) +{ + SwPaM aPam( rPos ); + return InsertTableOf( aPam, rTOX, pSet, bExpand ); +} + +SwTOXBaseSection* SwDoc::InsertTableOf( const SwPaM& aPam, + const SwTOXBase& rTOX, + const SfxItemSet* pSet, + bool bExpand ) { GetIDocumentUndoRedo().StartUndo( SwUndoId::INSTOX, nullptr ); OUString sSectNm = GetUniqueTOXBaseName( *rTOX.GetTOXType(), rTOX.GetTOXName() ); - SwPaM aPam( rPos ); SwSectionData aSectionData( TOX_CONTENT_SECTION, sSectNm ); SwTOXBaseSection *const pNewSection = dynamic_cast<SwTOXBaseSection *>( InsertSwSection( aPam, aSectionData, & rTOX, pSet, false )); diff --git a/sw/source/core/unocore/unoidx.cxx b/sw/source/core/unocore/unoidx.cxx index 76f4faf3e09b..8bb22a061b4f 100644 --- a/sw/source/core/unocore/unoidx.cxx +++ b/sw/source/core/unocore/unoidx.cxx @@ -1339,10 +1339,6 @@ SwXDocumentIndex::attach(const uno::Reference< text::XTextRange > & xTextRange) } UnoActionContext aAction(pDoc); - if (aPam.HasMark()) - { - pDoc->getIDocumentContentOperations().DeleteAndJoin(aPam); - } SwTOXBase & rTOXBase = m_pImpl->m_pProps->GetTOXBase(); SwTOXType const*const pTOXType = rTOXBase.GetTOXType(); @@ -1353,7 +1349,7 @@ SwXDocumentIndex::attach(const uno::Reference< text::XTextRange > & xTextRange) } //TODO: apply Section attributes (columns and background) SwTOXBaseSection *const pTOX = - pDoc->InsertTableOf( *aPam.GetPoint(), rTOXBase ); + pDoc->InsertTableOf( aPam, rTOXBase ); pDoc->SetTOXBaseName(*pTOX, m_pImpl->m_pProps->GetTOXBase().GetTOXName()); 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; |