From fb3502396382d7aa6063e9f6a0227fdc9bbf5bf4 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Wed, 9 Oct 2013 10:56:38 +0200 Subject: DOCX export of CT_LatentStyles and CT_LsdException Change-Id: I32a594464c71215ee7557823aadaa72b8b72b4e2 --- sw/source/filter/ww8/docxattributeoutput.cxx | 94 ++++++++++++++++++++++++++++ sw/source/filter/ww8/docxattributeoutput.hxx | 3 + 2 files changed, 97 insertions(+) (limited to 'sw/source/filter') diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx index 48af82b8c63a..2f2a2c91e9e5 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -102,6 +102,7 @@ #include #include #include +#include #include #include @@ -2357,6 +2358,99 @@ void DocxAttributeOutput::StartStyles() FSEND ); DocDefaults(); + LatentStyles(); +} + +namespace { +struct StringTokenMap +{ + const char* pToken; + sal_Int32 nToken; +}; + +StringTokenMap aDefaultTokens[] { + {"defQFormat", XML_defQFormat}, + {"defUnhideWhenUsed", XML_defUnhideWhenUsed}, + {"defSemiHidden", XML_defSemiHidden}, + {"count", XML_count}, + {"defUIPriority", XML_defUIPriority}, + {"defLockedState", XML_defLockedState}, + {0, 0} +}; + +StringTokenMap aExceptionTokens[] { + {"name", XML_name}, + {"locked", XML_locked}, + {"uiPriority", XML_uiPriority}, + {"semiHidden", XML_semiHidden}, + {"unhideWhenUsed", XML_unhideWhenUsed}, + {"qFormat", XML_qFormat}, + {0, 0} +}; + +sal_Int32 lcl_getToken(StringTokenMap* pMap, OUString aName) +{ + OString sName = OUStringToOString(aName, RTL_TEXTENCODING_UTF8); + while (pMap->pToken) + { + if (sName == pMap->pToken) + return pMap->nToken; + ++pMap; + } + return 0; +} +} + +void DocxAttributeOutput::LatentStyles() +{ + // Do we have latent styles available? + uno::Reference xPropertySet(m_rExport.pDoc->GetDocShell()->GetBaseModel(), uno::UNO_QUERY_THROW); + uno::Sequence aInteropGrabBag; + xPropertySet->getPropertyValue("InteropGrabBag") >>= aInteropGrabBag; + uno::Sequence aLatentStyles; + for (sal_Int32 i = 0; i < aInteropGrabBag.getLength(); ++i) + { + if (aInteropGrabBag[i].Name == "latentStyles") + { + aInteropGrabBag[i].Value >>= aLatentStyles; + break; + } + } + if (!aLatentStyles.getLength()) + return; + + // Extract default attributes first. + sax_fastparser::FastAttributeList* pAttributeList = m_pSerializer->createAttrList(); + uno::Sequence aLsdExceptions; + for (sal_Int32 i = 0; i < aLatentStyles.getLength(); ++i) + { + if (sal_Int32 nToken = lcl_getToken(aDefaultTokens, aLatentStyles[i].Name)) + pAttributeList->add(FSNS(XML_w, nToken), OUStringToOString(aLatentStyles[i].Value.get(), RTL_TEXTENCODING_UTF8)); + else if (aLatentStyles[i].Name == "lsdExceptions") + aLatentStyles[i].Value >>= aLsdExceptions; + } + + XFastAttributeListRef xAttributeList(pAttributeList); + m_pSerializer->startElementNS(XML_w, XML_latentStyles, xAttributeList); + pAttributeList = 0; + + // Then handle the exceptions. + for (sal_Int32 i = 0; i < aLsdExceptions.getLength(); ++i) + { + pAttributeList = m_pSerializer->createAttrList(); + + uno::Sequence aAttributes; + aLsdExceptions[i].Value >>= aAttributes; + for (sal_Int32 j = 0; j < aAttributes.getLength(); ++j) + if (sal_Int32 nToken = lcl_getToken(aExceptionTokens, aAttributes[j].Name)) + pAttributeList->add(FSNS(XML_w, nToken), OUStringToOString(aAttributes[j].Value.get(), RTL_TEXTENCODING_UTF8)); + + xAttributeList = pAttributeList; + m_pSerializer->singleElementNS(XML_w, XML_lsdException, xAttributeList); + pAttributeList = 0; + } + + m_pSerializer->endElementNS(XML_w, XML_latentStyles); } void DocxAttributeOutput::OutputDefaultItem(const SfxPoolItem& rHt) diff --git a/sw/source/filter/ww8/docxattributeoutput.hxx b/sw/source/filter/ww8/docxattributeoutput.hxx index 8a17e9cb5122..3725de73f0df 100644 --- a/sw/source/filter/ww8/docxattributeoutput.hxx +++ b/sw/source/filter/ww8/docxattributeoutput.hxx @@ -214,6 +214,9 @@ public: /// Write Doc Defaults void DocDefaults( ); + /// Write latent styles. + void LatentStyles(); + /** Similar to OutputItem(), but write something only if it is not the default. This is to output the docDefaults, and we should write something out -- cgit