diff options
author | Jacobo Aragunde Pérez <jaragunde@igalia.com> | 2014-03-22 21:11:33 +0100 |
---|---|---|
committer | Jacobo Aragunde Pérez <jaragunde@igalia.com> | 2014-03-22 23:58:16 +0100 |
commit | 8931ab3fc27acb0665fa636eb6390034cbb3eec6 (patch) | |
tree | 75ba94d916c9cc0579e4995ae3bd5d644caecbc0 | |
parent | 452469f1b825ac4dfa2b9b096175f7cfc9a1aa36 (diff) |
ooxml: preserve rich text sdt controls
These controls don't have a special property, like for example
unformatted text controls have. So we use the id property as a
marker; we will grab-bag it together with other sdt properties and
use the existing mechanism to write the sdt block on export.
A grab bag that only contains an id property is for sure a rich text
control so we add it to the character props and not to the paragraph
props, like in the case of the unformatted text control.
Word doesn't allow us to write an empty <w:id/> tag, so we fill
it with a random number.
Finally, modified an existing unit test to add a rich text control and
check it is exported correctly.
Change-Id: If403a4a2393d4ee069a628645e364d21f104a859
-rw-r--r-- | sw/qa/extras/ooxmlexport/data/simple-sdts.docx | bin | 25212 -> 25424 bytes | |||
-rw-r--r-- | sw/qa/extras/ooxmlexport/ooxmlexport.cxx | 1 | ||||
-rw-r--r-- | sw/source/filter/ww8/docxattributeoutput.cxx | 8 | ||||
-rw-r--r-- | writerfilter/source/dmapper/DomainMapper.cxx | 5 | ||||
-rw-r--r-- | writerfilter/source/dmapper/SdtHelper.cxx | 5 | ||||
-rw-r--r-- | writerfilter/source/dmapper/SdtHelper.hxx | 1 |
6 files changed, 19 insertions, 1 deletions
diff --git a/sw/qa/extras/ooxmlexport/data/simple-sdts.docx b/sw/qa/extras/ooxmlexport/data/simple-sdts.docx Binary files differindex 294ae7934870..95c5d00a6a50 100644 --- a/sw/qa/extras/ooxmlexport/data/simple-sdts.docx +++ b/sw/qa/extras/ooxmlexport/data/simple-sdts.docx diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx index bac36e4ab488..557a3f58a195 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx @@ -2920,6 +2920,7 @@ DECLARE_OOXMLEXPORT_TEST(testSimpleSdts, "simple-sdts.docx") return; assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:sdt/w:sdtPr/w:text", 1); + assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:sdt/w:sdtPr/w:id", 1); assertXPath(pXmlDoc, "/w:document/w:body/w:sdt/w:sdtPr/w:picture", 1); assertXPath(pXmlDoc, "/w:document/w:body/w:sdt/w:sdtPr/w:group", 1); assertXPath(pXmlDoc, "/w:document/w:body/w:sdt/w:sdtPr/w:citation", 1); diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx index 48366e4a9f75..546b0a4ef7e1 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -406,6 +406,11 @@ void DocxAttributeOutput::WriteSdtBlock( sal_Int32& nSdtPrToken, ::sax_fastparse m_pSerializer->endElement( nSdtPrToken ); } + else if( nSdtPrToken == FSNS( XML_w, XML_id ) ) + //Word won't open a document with an empty id tag, we fill it with a random number + m_pSerializer->singleElement( nSdtPrToken, + FSNS(XML_w, XML_val), OString::number( rand() ), + FSEND ); else if( nSdtPrToken > 0 ) m_pSerializer->singleElement( nSdtPrToken, FSEND ); @@ -7141,6 +7146,9 @@ void DocxAttributeOutput::CharGrabBag( const SfxGrabBagItem& rItem ) } else if (aPropertyValue.Name == "ooxml:CT_SdtPr_text") m_nRunSdtPrToken = FSNS( XML_w, XML_text ); + else if (aPropertyValue.Name == "ooxml:CT_SdtPr_id" && m_nRunSdtPrToken == 0) + // only write id token as a marker if no other exist + m_nRunSdtPrToken = FSNS( XML_w, XML_id ); } } else diff --git a/writerfilter/source/dmapper/DomainMapper.cxx b/writerfilter/source/dmapper/DomainMapper.cxx index ed3dc13953b5..f36db6570a0b 100644 --- a/writerfilter/source/dmapper/DomainMapper.cxx +++ b/writerfilter/source/dmapper/DomainMapper.cxx @@ -2251,6 +2251,7 @@ void DomainMapper::sprmWithProps( Sprm& rSprm, PropertyMapPtr rContext ) case NS_ooxml::LN_CT_SdtPr_citation: case NS_ooxml::LN_CT_SdtPr_group: case NS_ooxml::LN_CT_SdtPr_text: + case NS_ooxml::LN_CT_SdtPr_id: { // this is an unsupported SDT property, create a grab bag for it OUString sName = OUString::createFromAscii((*QNameToString::Instance())(nSprmId).c_str()); @@ -2669,7 +2670,9 @@ void DomainMapper::lcl_utext(const sal_uInt8 * data_, size_t len) // save them in the paragraph interop grab bag if(m_pImpl->m_pSdtHelper->containedInInteropGrabBag("ooxml:CT_SdtPr_checkbox") || m_pImpl->m_pSdtHelper->containedInInteropGrabBag("ooxml:CT_SdtPr_text") || - m_pImpl->m_pSdtHelper->containedInInteropGrabBag("ooxml:CT_SdtPr_dataBinding")) + m_pImpl->m_pSdtHelper->containedInInteropGrabBag("ooxml:CT_SdtPr_dataBinding") || + (m_pImpl->m_pSdtHelper->containedInInteropGrabBag("ooxml:CT_SdtPr_id") && + m_pImpl->m_pSdtHelper->getInteropGrabBagSize() == 1)) m_pImpl->GetTopContextOfType(CONTEXT_CHARACTER)->Insert(PROP_SDTPR, uno::makeAny(m_pImpl->m_pSdtHelper->getInteropGrabBagAndClear()), true, CHAR_GRAB_BAG); else diff --git a/writerfilter/source/dmapper/SdtHelper.cxx b/writerfilter/source/dmapper/SdtHelper.cxx index daf9b81455da..22f11986fef7 100644 --- a/writerfilter/source/dmapper/SdtHelper.cxx +++ b/writerfilter/source/dmapper/SdtHelper.cxx @@ -215,6 +215,11 @@ bool SdtHelper::isInteropGrabBagEmpty() return m_aGrabBag.getLength() == 0; } +sal_Int32 SdtHelper::getInteropGrabBagSize() +{ + return m_aGrabBag.getLength(); +} + bool SdtHelper::containedInInteropGrabBag(OUString rValueName) { for (sal_Int32 i=0; i < m_aGrabBag.getLength(); ++i) diff --git a/writerfilter/source/dmapper/SdtHelper.hxx b/writerfilter/source/dmapper/SdtHelper.hxx index a69628729ad2..cfdd875e7b6b 100644 --- a/writerfilter/source/dmapper/SdtHelper.hxx +++ b/writerfilter/source/dmapper/SdtHelper.hxx @@ -88,6 +88,7 @@ public: com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue> getInteropGrabBagAndClear(); bool isInteropGrabBagEmpty(); bool containedInInteropGrabBag(OUString rValueName); + sal_Int32 getInteropGrabBagSize(); }; } // namespace dmapper |