summaryrefslogtreecommitdiff
path: root/sw/source/filter
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.co.uk>2013-10-09 10:56:38 +0200
committerMiklos Vajna <vmiklos@collabora.co.uk>2013-10-09 11:05:25 +0200
commitfb3502396382d7aa6063e9f6a0227fdc9bbf5bf4 (patch)
treeae6e101a40ba6e1eff51198ce817a2749f578864 /sw/source/filter
parent57a8f39ba6e351a037e03f95f9ad49e26b34856b (diff)
DOCX export of CT_LatentStyles and CT_LsdException
Change-Id: I32a594464c71215ee7557823aadaa72b8b72b4e2
Diffstat (limited to 'sw/source/filter')
-rw-r--r--sw/source/filter/ww8/docxattributeoutput.cxx94
-rw-r--r--sw/source/filter/ww8/docxattributeoutput.hxx3
2 files changed, 97 insertions, 0 deletions
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 <txtftn.hxx>
#include <txtinet.hxx>
#include <fmtautofmt.hxx>
+#include <docsh.hxx>
#include <osl/file.hxx>
#include <rtl/tencinfo.h>
@@ -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<beans::XPropertySet> xPropertySet(m_rExport.pDoc->GetDocShell()->GetBaseModel(), uno::UNO_QUERY_THROW);
+ uno::Sequence<beans::PropertyValue> aInteropGrabBag;
+ xPropertySet->getPropertyValue("InteropGrabBag") >>= aInteropGrabBag;
+ uno::Sequence<beans::PropertyValue> 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<beans::PropertyValue> 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<OUString>(), 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<beans::PropertyValue> 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<OUString>(), 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