From aafcf874a23a73e5e63a426cfec1191148677556 Mon Sep 17 00:00:00 2001 From: Vasily Melenchuk Date: Thu, 11 Nov 2021 10:39:32 +0300 Subject: tdf#81507: word content control support for w:multiLine is now supported for import/export to DOCX. Like other content control items it is stored in grabbag. Change-Id: Id6f1aa0072dc5db980d0fa43cab4b38a0aa047fc Reviewed-on: https://gerrit.libreoffice.org/c/core/+/125024 Tested-by: Jenkins Reviewed-by: Thorsten Behrens Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127128 Tested-by: Thorsten Behrens --- sw/qa/extras/ooxmlexport/data/tdf81507.docx | Bin 0 -> 20183 bytes sw/qa/extras/ooxmlexport/ooxmlexport15.cxx | 21 ++++++++++ sw/source/filter/ww8/docxattributeoutput.cxx | 59 ++++++++++++++++++++++++--- sw/source/filter/ww8/docxattributeoutput.hxx | 3 ++ writerfilter/source/dmapper/DomainMapper.cxx | 3 ++ writerfilter/source/ooxml/model.xml | 5 ++- 6 files changed, 84 insertions(+), 7 deletions(-) create mode 100644 sw/qa/extras/ooxmlexport/data/tdf81507.docx diff --git a/sw/qa/extras/ooxmlexport/data/tdf81507.docx b/sw/qa/extras/ooxmlexport/data/tdf81507.docx new file mode 100644 index 000000000000..2c00ee44cb24 Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/tdf81507.docx differ diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx index 0b175bd83cd3..881d22174c8b 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport15.cxx @@ -127,6 +127,27 @@ DECLARE_OOXMLEXPORT_TEST(testTdf123642_BookmarkAtDocEnd, "tdf123642.docx") CPPUNIT_ASSERT_EQUAL(OUString("Bookmark1"), getXPath(pXmlDoc, "/w:document/w:body/w:p[2]/w:bookmarkStart[1]", "name")); } +DECLARE_OOXMLEXPORT_TEST(testTdf81507, "tdf81507.docx") +{ + xmlDocPtr pXmlDoc = parseExport("word/document.xml"); + if (!pXmlDoc) + return; // initial import, no futher checks + + // Ensure that we have + CPPUNIT_ASSERT_EQUAL(OUString("1"), getXPath(pXmlDoc, "/w:document/w:body/w:sdt[1]/w:sdtPr/w:text", "multiLine")); + + // Ensure that we have + CPPUNIT_ASSERT_EQUAL(OUString("0"), getXPath(pXmlDoc, "/w:document/w:body/w:sdt[2]/w:sdtPr/w:text", "multiLine")); + + // Ensure that we have + getXPath(pXmlDoc, "/w:document/w:body/w:sdt[3]/w:sdtPr/w:text", ""); + + // Ensure that we have no (not quite correct case, but to ensure import/export are okay) + xmlXPathObjectPtr pXmlObj = getXPathNode(pXmlDoc, "/w:document/w:body/w:sdt[4]/w:sdtPr/w:text"); + CPPUNIT_ASSERT_EQUAL(sal_Int32(0), + static_cast(xmlXPathNodeSetGetLength(pXmlObj->nodesetval))); + xmlXPathFreeObject(pXmlObj); +} CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx index 5dbb02ce9eb5..6018a64df1af 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -551,12 +551,18 @@ static OString convertToOOXMLHoriOrientRel(sal_Int16 nOrientRel) } } -static void lcl_deleteAndResetTheLists( rtl::Reference& pSdtPrTokenChildren, rtl::Reference& pSdtPrDataBindingAttrs, OUString& rSdtPrAlias) +static void lcl_deleteAndResetTheLists( + rtl::Reference& pSdtPrTokenChildren, + rtl::Reference& pSdtPrDataBindingAttrs, + rtl::Reference& pSdtPrTextAttrs, + OUString& rSdtPrAlias) { if( pSdtPrTokenChildren.is() ) pSdtPrTokenChildren.clear(); if( pSdtPrDataBindingAttrs.is() ) pSdtPrDataBindingAttrs.clear(); + if (pSdtPrTextAttrs.is()) + pSdtPrTextAttrs.clear(); if (!rSdtPrAlias.isEmpty()) rSdtPrAlias.clear(); } @@ -755,14 +761,14 @@ void DocxAttributeOutput::EndParagraph( ww8::WW8TableNodeInfoInner::Pointer_t pT m_pSerializer->endElementNS( XML_w, XML_p ); // on export sdt blocks are never nested ATM if( !m_bAnchorLinkedToNode && !m_bStartedParaSdt ) - WriteSdtBlock( m_nParagraphSdtPrToken, m_pParagraphSdtPrTokenChildren, m_pParagraphSdtPrTokenAttributes, m_pParagraphSdtPrDataBindingAttrs, m_aParagraphSdtPrAlias, /*bPara=*/true ); + WriteSdtBlock( m_nParagraphSdtPrToken, m_pParagraphSdtPrTokenChildren, m_pParagraphSdtPrTokenAttributes, m_pParagraphSdtPrDataBindingAttrs, m_pParagraphSdtPrTextAttrs, m_aParagraphSdtPrAlias, /*bPara=*/true ); else { //These should be written out to the actual Node and not to the anchor. //Clear them as they will be repopulated when the node is processed. m_nParagraphSdtPrToken = 0; m_bParagraphSdtHasId = false; - lcl_deleteAndResetTheLists( m_pParagraphSdtPrTokenChildren, m_pParagraphSdtPrDataBindingAttrs, m_aParagraphSdtPrAlias ); + lcl_deleteAndResetTheLists( m_pParagraphSdtPrTokenChildren, m_pParagraphSdtPrDataBindingAttrs, m_pParagraphSdtPrTextAttrs, m_aParagraphSdtPrAlias ); } //sdtcontent is written so Set m_bParagraphHasDrawing to false @@ -794,6 +800,7 @@ void DocxAttributeOutput::WriteSdtBlock( sal_Int32& nSdtPrToken, rtl::Reference& pSdtPrTokenChildren, rtl::Reference& pSdtPrTokenAttributes, rtl::Reference& pSdtPrDataBindingAttrs, + rtl::Reference& pSdtPrTextAttrs, OUString& rSdtPrAlias, bool bPara ) { @@ -852,6 +859,13 @@ void DocxAttributeOutput::WriteSdtBlock( sal_Int32& nSdtPrToken, m_pSerializer->singleElementNS(XML_w, XML_dataBinding, xAttrList); } + if (pSdtPrTextAttrs.is()) + { + XFastAttributeListRef xAttrList( pSdtPrTextAttrs.get() ); + pSdtPrTextAttrs.clear(); + m_pSerializer->singleElementNS(XML_w, XML_text, xAttrList); + } + if (!rSdtPrAlias.isEmpty()) m_pSerializer->singleElementNS(XML_w, XML_alias, FSNS(XML_w, XML_val), rSdtPrAlias.toUtf8()); @@ -881,6 +895,7 @@ void DocxAttributeOutput::WriteSdtBlock( sal_Int32& nSdtPrToken, nSdtPrToken = 0; pSdtPrTokenChildren.clear(); pSdtPrDataBindingAttrs.clear(); + pSdtPrTextAttrs.clear(); rSdtPrAlias.clear(); } @@ -1526,14 +1541,14 @@ void DocxAttributeOutput::EndRun(const SwTextNode* pNode, sal_Int32 nPos, bool / if ( !m_bAnchorLinkedToNode && !m_bStartedCharSdt ) { rtl::Reference pRunSdtPrTokenAttributes; - WriteSdtBlock( m_nRunSdtPrToken, m_pRunSdtPrTokenChildren, pRunSdtPrTokenAttributes, m_pRunSdtPrDataBindingAttrs, m_aRunSdtPrAlias, /*bPara=*/false ); + WriteSdtBlock( m_nRunSdtPrToken, m_pRunSdtPrTokenChildren, pRunSdtPrTokenAttributes, m_pRunSdtPrDataBindingAttrs, m_pRunSdtPrTextAttrs, m_aRunSdtPrAlias, /*bPara=*/false ); } else { //These should be written out to the actual Node and not to the anchor. //Clear them as they will be repopulated when the node is processed. m_nRunSdtPrToken = 0; - lcl_deleteAndResetTheLists( m_pRunSdtPrTokenChildren, m_pRunSdtPrDataBindingAttrs, m_aRunSdtPrAlias ); + lcl_deleteAndResetTheLists( m_pRunSdtPrTokenChildren, m_pRunSdtPrDataBindingAttrs, m_pRunSdtPrTextAttrs, m_aRunSdtPrAlias ); } if (bCloseEarlierSDT) @@ -9007,7 +9022,26 @@ void DocxAttributeOutput::ParaGrabBag(const SfxGrabBagItem& rItem) else if (aPropertyValue.Name == "ooxml:CT_SdtPr_group") m_nParagraphSdtPrToken = FSNS( XML_w, XML_group ); else if (aPropertyValue.Name == "ooxml:CT_SdtPr_text") - m_nParagraphSdtPrToken = FSNS(XML_w, XML_text); + { + uno::Sequence aGrabBag; + aPropertyValue.Value >>= aGrabBag; + if (aGrabBag.hasElements()) + { + for (const auto& rProp : std::as_const(aGrabBag)) + { + OUString sValue = rProp.Value.get(); + if (rProp.Name == "ooxml:LN_CT_SdtText_multiLine") + AddToAttrList(m_pParagraphSdtPrTextAttrs, + FSNS(XML_w, XML_multiLine), + OUStringToOString(sValue, RTL_TEXTENCODING_UTF8).getStr()); + } + } + else + { + // We still have w:text, but no attrs + m_nParagraphSdtPrToken = FSNS(XML_w, XML_text); + } + } else if (aPropertyValue.Name == "ooxml:CT_SdtPr_dataBinding" && !m_pParagraphSdtPrDataBindingAttrs.is()) { uno::Sequence aGrabBag; @@ -9223,6 +9257,19 @@ void DocxAttributeOutput::CharGrabBag( const SfxGrabBagItem& rItem ) OUStringToOString( sValue, RTL_TEXTENCODING_UTF8 ).getStr() ); } } + else if (aPropertyValue.Name == "ooxml:CT_SdtPr_text") + { + uno::Sequence aGrabBag; + aPropertyValue.Value >>= aGrabBag; + for (const auto& rProp : std::as_const(aGrabBag)) + { + OUString sValue = rProp.Value.get(); + if (rProp.Name == "ooxml:LN_CT_SdtText_multiLine") + AddToAttrList(m_pRunSdtPrTextAttrs, + FSNS(XML_w, XML_multiLine), + OUStringToOString(sValue, RTL_TEXTENCODING_UTF8).getStr()); + } + } else if (aPropertyValue.Name == "ooxml:CT_SdtPr_dataBinding" && !m_pRunSdtPrDataBindingAttrs.is()) { uno::Sequence aGrabBag; diff --git a/sw/source/filter/ww8/docxattributeoutput.hxx b/sw/source/filter/ww8/docxattributeoutput.hxx index a7733d62209b..4323b72a6a84 100644 --- a/sw/source/filter/ww8/docxattributeoutput.hxx +++ b/sw/source/filter/ww8/docxattributeoutput.hxx @@ -712,6 +712,7 @@ private: rtl::Reference& pSdtPrTokenChildren, rtl::Reference& pSdtPrTokenAttributes, rtl::Reference& pSdtPrDataBindingAttrs, + rtl::Reference& pSdtPrTextAttrs, OUString& rSdtPrAlias, bool bPara); /// Closes a currently open SDT block. @@ -959,12 +960,14 @@ private: rtl::Reference m_pParagraphSdtPrTokenChildren; rtl::Reference m_pParagraphSdtPrTokenAttributes; rtl::Reference m_pParagraphSdtPrDataBindingAttrs; + rtl::Reference m_pParagraphSdtPrTextAttrs; /// members to control the existence of grabbagged SDT properties in the text run sal_Int32 m_nRunSdtPrToken; /// State of the Fly at current position FlyProcessingState m_nStateOfFlyFrame; rtl::Reference m_pRunSdtPrTokenChildren; rtl::Reference m_pRunSdtPrDataBindingAttrs; + rtl::Reference m_pRunSdtPrTextAttrs; /// Value of the paragraph SDT element. OUString m_aParagraphSdtPrAlias; /// Same as m_aParagraphSdtPrAlias, but its content is available till the SDT is closed. diff --git a/writerfilter/source/dmapper/DomainMapper.cxx b/writerfilter/source/dmapper/DomainMapper.cxx index 42ce471a0e3d..d0e152492870 100644 --- a/writerfilter/source/dmapper/DomainMapper.cxx +++ b/writerfilter/source/dmapper/DomainMapper.cxx @@ -1105,6 +1105,9 @@ void DomainMapper::lcl_attribute(Id nName, Value & val) case NS_ooxml::LN_CT_DataBinding_storeItemID: m_pImpl->appendGrabBag(m_pImpl->m_aInteropGrabBag, "ooxml:CT_DataBinding_storeItemID", sStringValue); break; + case NS_ooxml::LN_CT_SdtText_multiLine: + m_pImpl->appendGrabBag(m_pImpl->m_aInteropGrabBag, "ooxml:LN_CT_SdtText_multiLine", sStringValue); + break; case NS_ooxml::LN_CT_PTab_leader: case NS_ooxml::LN_CT_PTab_relativeTo: case NS_ooxml::LN_CT_PTab_alignment: diff --git a/writerfilter/source/ooxml/model.xml b/writerfilter/source/ooxml/model.xml index 17c8f5217fec..4a1ba3988de3 100644 --- a/writerfilter/source/ooxml/model.xml +++ b/writerfilter/source/ooxml/model.xml @@ -13931,7 +13931,7 @@ - + @@ -18150,6 +18150,9 @@ + + + -- cgit