diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2013-10-24 17:52:09 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2013-10-24 17:54:08 +0200 |
commit | b391da28fffa1f71967079189e7d60ff16ec2784 (patch) | |
tree | b501e562d94d46eff033c58a138a6b17f9538e38 | |
parent | b7efab3a9841a9f01c5da07db870a22866b65b04 (diff) |
DOCX filter: initial table style export based on InteropGrabBag
Change-Id: I7b31322b50c8c924e5df3c32e3c2da8093709938
-rw-r--r-- | sw/source/filter/ww8/docxattributeoutput.cxx | 128 | ||||
-rw-r--r-- | sw/source/filter/ww8/docxattributeoutput.hxx | 4 |
2 files changed, 132 insertions, 0 deletions
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx index c5a80a43120c..fe48ee09c7e3 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -2660,8 +2660,136 @@ void DocxAttributeOutput::DocDefaults( ) m_pSerializer->endElementNS(XML_w, XML_docDefaults); } +void DocxAttributeOutput::TableStyles() +{ + // Do we have table styles from InteropGrabBag 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> aTableStyles; + for (sal_Int32 i = 0; i < aInteropGrabBag.getLength(); ++i) + { + if (aInteropGrabBag[i].Name == "tableStyles") + { + aInteropGrabBag[i].Value >>= aTableStyles; + break; + } + } + if (!aTableStyles.getLength()) + return; + + for (sal_Int32 i = 0; i < aTableStyles.getLength(); ++i) + { + uno::Sequence<beans::PropertyValue> aTableStyle; + aTableStyles[i].Value >>= aTableStyle; + TableStyle(aTableStyle); + } +} + +StringTokenMap const aTblCellMarTokens[] = { + {"left", XML_left}, + {"right", XML_right}, + {"start", XML_start}, + {"end", XML_end}, + {"top", XML_top}, + {"bottom", XML_bottom}, + {0, 0} +}; + +/// Export of w:tblCellMar in a table style. +void lcl_TableStyleTblCellMar(sax_fastparser::FSHelperPtr pSerializer, uno::Sequence<beans::PropertyValue>& rTblCellMar) +{ + if (!rTblCellMar.hasElements()) + return; + + pSerializer->startElementNS(XML_w, XML_tblCellMar, FSEND); + for (sal_Int32 i = 0; i < rTblCellMar.getLength(); ++i) + { + if (sal_Int32 nToken = lcl_getToken(aTblCellMarTokens, rTblCellMar[i].Name)) + { + comphelper::SequenceAsHashMap aMap(rTblCellMar[i].Value.get< uno::Sequence<beans::PropertyValue> >()); + pSerializer->singleElementNS(XML_w, nToken, + FSNS(XML_w, XML_w), OString::number(aMap["w"].get<sal_Int32>()), + FSNS(XML_w, XML_type), OUStringToOString(aMap["type"].get<OUString>(), RTL_TEXTENCODING_UTF8).getStr(), + FSEND); + } + } + pSerializer->endElementNS(XML_w, XML_tblCellMar); +} + +/// Export of w:tblInd in a table style. +void lcl_TableStyleTblInd(sax_fastparser::FSHelperPtr pSerializer, uno::Sequence<beans::PropertyValue>& rTblInd) +{ + if (!rTblInd.hasElements()) + return; + + sax_fastparser::FastAttributeList* pAttributeList = pSerializer->createAttrList(); + for (sal_Int32 i = 0; i < rTblInd.getLength(); ++i) + { + if (rTblInd[i].Name == "w") + pAttributeList->add(FSNS(XML_w, XML_w), OString::number(rTblInd[i].Value.get<sal_Int32>())); + else if (rTblInd[i].Name == "type") + pAttributeList->add(FSNS(XML_w, XML_type), OUStringToOString(rTblInd[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8).getStr()); + } + XFastAttributeListRef xAttributeList(pAttributeList); + pSerializer->singleElementNS(XML_w, XML_tblInd, xAttributeList); +} + +/// Export of w:tblPr in a table style. +void lcl_TableStyleTblPr(sax_fastparser::FSHelperPtr pSerializer, uno::Sequence<beans::PropertyValue>& rTblPr) +{ + if (!rTblPr.hasElements()) + return; + + pSerializer->startElementNS(XML_w, XML_tblPr, FSEND); + + uno::Sequence<beans::PropertyValue> aTblInd, aTblCellMar; + for (sal_Int32 i = 0; i < rTblPr.getLength(); ++i) + { + if (rTblPr[i].Name == "tblInd") + aTblInd = rTblPr[i].Value.get< uno::Sequence<beans::PropertyValue> >(); + else if (rTblPr[i].Name == "tblCellMar") + aTblCellMar = rTblPr[i].Value.get< uno::Sequence<beans::PropertyValue> >(); + } + lcl_TableStyleTblInd(pSerializer, aTblInd); + lcl_TableStyleTblCellMar(pSerializer, aTblCellMar); + + pSerializer->endElementNS(XML_w, XML_tblPr); +} + +void DocxAttributeOutput::TableStyle(uno::Sequence<beans::PropertyValue>& rStyle) +{ + bool bDefault = false; + OUString aStyleId, aName; + uno::Sequence<beans::PropertyValue> aTblPr; + for (sal_Int32 i = 0; i < rStyle.getLength(); ++i) + { + if (rStyle[i].Name == "default") + bDefault = rStyle[i].Value.get<sal_Bool>(); + else if (rStyle[i].Name == "styleId") + aStyleId = rStyle[i].Value.get<OUString>(); + else if (rStyle[i].Name == "name") + aName = rStyle[i].Value.get<OUString>(); + else if (rStyle[i].Name == "tblPr") + aTblPr = rStyle[i].Value.get< uno::Sequence<beans::PropertyValue> >(); + } + m_pSerializer->startElementNS(XML_w, XML_style, + FSNS(XML_w, XML_type), "table", + FSNS(XML_w, XML_default), bDefault ? "true" : "false", + FSNS(XML_w, XML_styleId), OUStringToOString(aStyleId, RTL_TEXTENCODING_UTF8).getStr(), + FSEND); + m_pSerializer->singleElementNS(XML_w, XML_name, + FSNS(XML_w, XML_val), OUStringToOString(aName, RTL_TEXTENCODING_UTF8).getStr(), + FSEND); + + lcl_TableStyleTblPr(m_pSerializer, aTblPr); + + m_pSerializer->endElementNS(XML_w, XML_style); +} + void DocxAttributeOutput::EndStyles( sal_uInt16 /*nNumberOfStyles*/ ) { + TableStyles(); m_pSerializer->endElementNS( XML_w, XML_styles ); } diff --git a/sw/source/filter/ww8/docxattributeoutput.hxx b/sw/source/filter/ww8/docxattributeoutput.hxx index 5e8f90f2d180..4aa0b10424cd 100644 --- a/sw/source/filter/ww8/docxattributeoutput.hxx +++ b/sw/source/filter/ww8/docxattributeoutput.hxx @@ -217,6 +217,10 @@ public: /// Write latent styles. void LatentStyles(); + /// Write table styles from InteropGrabBag. + void TableStyles(); + void TableStyle(com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue>& rStyle); + /** 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 |