LCOV - code coverage report
Current view: top level - sw/source/filter/ww8 - docxtablestyleexport.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 387 0.0 %
Date: 2014-04-14 Functions: 0 25 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  */
       9             : 
      10             : #include "docxtablestyleexport.hxx"
      11             : #include "docxhelper.hxx"
      12             : #include <doc.hxx>
      13             : #include <docsh.hxx>
      14             : 
      15             : #include <oox/token/tokens.hxx>
      16             : #include <comphelper/sequenceashashmap.hxx>
      17             : #include <rtl/strbuf.hxx>
      18             : 
      19             : #include <com/sun/star/beans/PropertyValue.hpp>
      20             : #include <com/sun/star/uno/Sequence.h>
      21             : 
      22             : #include <boost/optional.hpp>
      23             : 
      24             : using namespace com::sun::star;
      25             : using namespace oox;
      26             : 
      27             : /// Methods in this class handle values in a table style.
      28           0 : struct DocxTableStyleExport::Impl
      29             : {
      30             :     SwDoc* m_pDoc;
      31             :     sax_fastparser::FSHelperPtr m_pSerializer;
      32             : 
      33             :     void TableStyle(uno::Sequence<beans::PropertyValue>& rStyle);
      34             : 
      35             :     /// Handles a boolean value.
      36             :     void handleBoolean(const OUString& aValue, sal_Int32 nToken);
      37             : 
      38             :     /// Export of w:pPr.
      39             :     void tableStylePPr(uno::Sequence<beans::PropertyValue>& rPPr);
      40             :     /// Export of w:tblStylePr.
      41             :     void tableStyleTblStylePr(uno::Sequence<beans::PropertyValue>& rTblStylePr);
      42             :     /// Export of w:rPr.
      43             :     void tableStyleRPr(uno::Sequence<beans::PropertyValue>& rRPr);
      44             :     /// Export of w:rFonts.
      45             :     void tableStyleRRFonts(uno::Sequence<beans::PropertyValue>& rRFonts);
      46             :     /// Export of w:lang.
      47             :     void tableStyleRLang(uno::Sequence<beans::PropertyValue>& rLang);
      48             :     /// Export of w:ind in a pPr.
      49             :     void tableStylePInd(uno::Sequence<beans::PropertyValue>& rInd);
      50             :     /// Export of w:spacing.
      51             :     void tableStylePSpacing(uno::Sequence<beans::PropertyValue>& rSpacing);
      52             :     /// Export of w:tblPr.
      53             :     void tableStyleTblPr(uno::Sequence<beans::PropertyValue>& rTblPr);
      54             :     /// Export of w:tcPr.
      55             :     void tableStyleTcPr(uno::Sequence<beans::PropertyValue>& rTcPr);
      56             :     /// Export of w:tcBorders (and w:tblBorders).
      57             :     void tableStyleTcBorders(uno::Sequence<beans::PropertyValue>& rTcBorders, sal_Int32 nToken = XML_tcBorders);
      58             :     /// Export of w:tblInd.
      59             :     void tableStyleTblInd(uno::Sequence<beans::PropertyValue>& rTblInd);
      60             :     /// Export of w:tblCellMar (and w:tcMar).
      61             :     void tableStyleTblCellMar(uno::Sequence<beans::PropertyValue>& rTblCellMar, sal_Int32 nType = XML_tblCellMar);
      62             :     /// Export of a given table cell border type.
      63             :     void tableStyleTcBorder(sal_Int32 nToken, const uno::Sequence<beans::PropertyValue>& rTcBorder);
      64             :     /// Export of w:shd.
      65             :     void tableStyleShd(uno::Sequence<beans::PropertyValue>& rShd);
      66             :     /// Export of w:color.
      67             :     void tableStyleRColor(uno::Sequence<beans::PropertyValue>& rColor);
      68             : };
      69             : 
      70           0 : void DocxTableStyleExport::TableStyles(sal_uInt16 nCountStylesToWrite)
      71             : {
      72             :     // Do we have table styles from InteropGrabBag available?
      73           0 :     uno::Reference<beans::XPropertySet> xPropertySet(m_pImpl->m_pDoc->GetDocShell()->GetBaseModel(), uno::UNO_QUERY_THROW);
      74           0 :     uno::Sequence<beans::PropertyValue> aInteropGrabBag;
      75           0 :     xPropertySet->getPropertyValue("InteropGrabBag") >>= aInteropGrabBag;
      76           0 :     uno::Sequence<beans::PropertyValue> aTableStyles;
      77           0 :     for (sal_Int32 i = 0; i < aInteropGrabBag.getLength(); ++i)
      78             :     {
      79           0 :         if (aInteropGrabBag[i].Name == "tableStyles")
      80             :         {
      81           0 :             aInteropGrabBag[i].Value >>= aTableStyles;
      82           0 :             break;
      83             :         }
      84             :     }
      85           0 :     if (!aTableStyles.getLength())
      86           0 :         return;
      87             :     // HACK
      88             :     // Ms Office seems to have an internal limitation of 4091 styles
      89             :     // and refuses to load .docx with more, even though the spec seems to allow that;
      90             :     // so simply if there are more styles, don't export those
      91           0 :     nCountStylesToWrite = (nCountStylesToWrite > aTableStyles.getLength()) ?  aTableStyles.getLength(): nCountStylesToWrite;
      92             : 
      93           0 :     for (sal_Int32 i = 0; i < nCountStylesToWrite; ++i)
      94             :     {
      95           0 :         uno::Sequence<beans::PropertyValue> aTableStyle;
      96           0 :         aTableStyles[i].Value >>= aTableStyle;
      97           0 :         m_pImpl->TableStyle(aTableStyle);
      98           0 :     }
      99             : }
     100             : 
     101           0 : void DocxTableStyleExport::Impl::tableStyleTblCellMar(uno::Sequence<beans::PropertyValue>& rTblCellMar, sal_Int32 nType)
     102             : {
     103             :     static DocxStringTokenMap const aTblCellMarTokens[] =
     104             :     {
     105             :         {"left", XML_left},
     106             :         {"right", XML_right},
     107             :         {"start", XML_start},
     108             :         {"end", XML_end},
     109             :         {"top", XML_top},
     110             :         {"bottom", XML_bottom},
     111             :         {0, 0}
     112             :     };
     113             : 
     114           0 :     if (!rTblCellMar.hasElements())
     115           0 :         return;
     116             : 
     117           0 :     m_pSerializer->startElementNS(XML_w, nType, FSEND);
     118           0 :     for (sal_Int32 i = 0; i < rTblCellMar.getLength(); ++i)
     119             :     {
     120           0 :         if (sal_Int32 nToken = DocxStringGetToken(aTblCellMarTokens, rTblCellMar[i].Name))
     121             :         {
     122           0 :             comphelper::SequenceAsHashMap aMap(rTblCellMar[i].Value.get< uno::Sequence<beans::PropertyValue> >());
     123             :             m_pSerializer->singleElementNS(XML_w, nToken,
     124           0 :                                            FSNS(XML_w, XML_w), OString::number(aMap["w"].get<sal_Int32>()),
     125           0 :                                            FSNS(XML_w, XML_type), OUStringToOString(aMap["type"].get<OUString>(), RTL_TEXTENCODING_UTF8).getStr(),
     126           0 :                                            FSEND);
     127             :         }
     128             :     }
     129           0 :     m_pSerializer->endElementNS(XML_w, nType);
     130             : }
     131             : 
     132           0 : void DocxTableStyleExport::Impl::tableStyleTcBorder(sal_Int32 nToken, const uno::Sequence<beans::PropertyValue>& rTcBorder)
     133             : {
     134             :     static DocxStringTokenMap const aTcBorderTokens[] =
     135             :     {
     136             :         {"val", XML_val},
     137             :         {"sz", XML_sz},
     138             :         {"color", XML_color},
     139             :         {"space", XML_space},
     140             :         {"themeColor", XML_themeColor},
     141             :         {"themeTint", XML_themeTint},
     142             :         {0, 0}
     143             :     };
     144             : 
     145           0 :     if (!rTcBorder.hasElements())
     146           0 :         return;
     147             : 
     148           0 :     sax_fastparser::FastAttributeList* pAttributeList = m_pSerializer->createAttrList();
     149           0 :     for (sal_Int32 i = 0; i < rTcBorder.getLength(); ++i)
     150           0 :         if (sal_Int32 nAttrToken = DocxStringGetToken(aTcBorderTokens, rTcBorder[i].Name))
     151           0 :             pAttributeList->add(FSNS(XML_w, nAttrToken), OUStringToOString(rTcBorder[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8).getStr());
     152             : 
     153           0 :     sax_fastparser::XFastAttributeListRef xAttributeList(pAttributeList);
     154           0 :     m_pSerializer->singleElementNS(XML_w, nToken, xAttributeList);
     155             : }
     156             : 
     157           0 : void DocxTableStyleExport::Impl::tableStyleTcBorders(uno::Sequence<beans::PropertyValue>& rTcBorders, sal_Int32 nToken)
     158             : {
     159             :     static DocxStringTokenMap const aTcBordersTokens[] =
     160             :     {
     161             :         {"left", XML_left},
     162             :         {"right", XML_right},
     163             :         {"start", XML_start},
     164             :         {"end", XML_end},
     165             :         {"top", XML_top},
     166             :         {"bottom", XML_bottom},
     167             :         {"insideH", XML_insideH},
     168             :         {"insideV", XML_insideV},
     169             :         {"tl2br", XML_tl2br},
     170             :         {"tr2bl", XML_tr2bl},
     171             :         {0, 0}
     172             :     };
     173             : 
     174           0 :     if (!rTcBorders.hasElements())
     175           0 :         return;
     176             : 
     177           0 :     m_pSerializer->startElementNS(XML_w, nToken, FSEND);
     178           0 :     for (sal_Int32 i = 0; i < rTcBorders.getLength(); ++i)
     179           0 :         if (sal_Int32 nSubToken = DocxStringGetToken(aTcBordersTokens, rTcBorders[i].Name))
     180           0 :             tableStyleTcBorder(nSubToken, rTcBorders[i].Value.get< uno::Sequence<beans::PropertyValue> >());
     181           0 :     m_pSerializer->endElementNS(XML_w, nToken);
     182             : }
     183             : 
     184           0 : void DocxTableStyleExport::Impl::tableStyleShd(uno::Sequence<beans::PropertyValue>& rShd)
     185             : {
     186           0 :     if (!rShd.hasElements())
     187           0 :         return;
     188             : 
     189           0 :     sax_fastparser::FastAttributeList* pAttributeList = m_pSerializer->createAttrList();
     190           0 :     for (sal_Int32 i = 0; i < rShd.getLength(); ++i)
     191             :     {
     192           0 :         if (rShd[i].Name == "val")
     193           0 :             pAttributeList->add(FSNS(XML_w, XML_val), OUStringToOString(rShd[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8).getStr());
     194           0 :         else if (rShd[i].Name == "color")
     195           0 :             pAttributeList->add(FSNS(XML_w, XML_color), OUStringToOString(rShd[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8).getStr());
     196           0 :         else if (rShd[i].Name == "fill")
     197           0 :             pAttributeList->add(FSNS(XML_w, XML_fill), OUStringToOString(rShd[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8).getStr());
     198           0 :         else if (rShd[i].Name == "themeFill")
     199           0 :             pAttributeList->add(FSNS(XML_w, XML_themeFill), OUStringToOString(rShd[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8).getStr());
     200           0 :         else if (rShd[i].Name == "themeFillShade")
     201           0 :             pAttributeList->add(FSNS(XML_w, XML_themeFillShade), OUStringToOString(rShd[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8).getStr());
     202           0 :         else if (rShd[i].Name == "themeFillTint")
     203           0 :             pAttributeList->add(FSNS(XML_w, XML_themeFillTint), OUStringToOString(rShd[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8).getStr());
     204             :     }
     205           0 :     sax_fastparser::XFastAttributeListRef xAttributeList(pAttributeList);
     206           0 :     m_pSerializer->singleElementNS(XML_w, XML_shd, xAttributeList);
     207             : }
     208             : 
     209           0 : void DocxTableStyleExport::Impl::tableStyleRColor(uno::Sequence<beans::PropertyValue>& rColor)
     210             : {
     211           0 :     if (!rColor.hasElements())
     212           0 :         return;
     213             : 
     214           0 :     sax_fastparser::FastAttributeList* pAttributeList = m_pSerializer->createAttrList();
     215           0 :     for (sal_Int32 i = 0; i < rColor.getLength(); ++i)
     216             :     {
     217           0 :         if (rColor[i].Name == "val")
     218           0 :             pAttributeList->add(FSNS(XML_w, XML_val), OUStringToOString(rColor[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8).getStr());
     219           0 :         else if (rColor[i].Name == "themeColor")
     220           0 :             pAttributeList->add(FSNS(XML_w, XML_themeColor), OUStringToOString(rColor[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8).getStr());
     221           0 :         else if (rColor[i].Name == "themeTint")
     222           0 :             pAttributeList->add(FSNS(XML_w, XML_themeTint), OUStringToOString(rColor[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8).getStr());
     223           0 :         else if (rColor[i].Name == "themeShade")
     224           0 :             pAttributeList->add(FSNS(XML_w, XML_themeShade), OUStringToOString(rColor[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8).getStr());
     225             :     }
     226           0 :     sax_fastparser::XFastAttributeListRef xAttributeList(pAttributeList);
     227           0 :     m_pSerializer->singleElementNS(XML_w, XML_color, xAttributeList);
     228             : }
     229             : 
     230           0 : void DocxTableStyleExport::Impl::tableStyleRLang(uno::Sequence<beans::PropertyValue>& rLang)
     231             : {
     232           0 :     if (!rLang.hasElements())
     233           0 :         return;
     234             : 
     235           0 :     sax_fastparser::FastAttributeList* pAttributeList = m_pSerializer->createAttrList();
     236           0 :     for (sal_Int32 i = 0; i < rLang.getLength(); ++i)
     237             :     {
     238           0 :         if (rLang[i].Name == "eastAsia")
     239           0 :             pAttributeList->add(FSNS(XML_w, XML_eastAsia), OUStringToOString(rLang[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8).getStr());
     240           0 :         else if (rLang[i].Name == "val")
     241           0 :             pAttributeList->add(FSNS(XML_w, XML_val), OUStringToOString(rLang[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8).getStr());
     242           0 :         else if (rLang[i].Name == "bidi")
     243           0 :             pAttributeList->add(FSNS(XML_w, XML_bidi), OUStringToOString(rLang[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8).getStr());
     244             :     }
     245           0 :     sax_fastparser::XFastAttributeListRef xAttributeList(pAttributeList);
     246           0 :     m_pSerializer->singleElementNS(XML_w, XML_lang, xAttributeList);
     247             : }
     248             : 
     249           0 : void DocxTableStyleExport::Impl::tableStyleRRFonts(uno::Sequence<beans::PropertyValue>& rRFonts)
     250             : {
     251           0 :     if (!rRFonts.hasElements())
     252           0 :         return;
     253             : 
     254           0 :     sax_fastparser::FastAttributeList* pAttributeList = m_pSerializer->createAttrList();
     255           0 :     for (sal_Int32 i = 0; i < rRFonts.getLength(); ++i)
     256             :     {
     257           0 :         if (rRFonts[i].Name == "eastAsiaTheme")
     258           0 :             pAttributeList->add(FSNS(XML_w, XML_eastAsiaTheme), OUStringToOString(rRFonts[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8).getStr());
     259           0 :         else if (rRFonts[i].Name == "asciiTheme")
     260           0 :             pAttributeList->add(FSNS(XML_w, XML_asciiTheme), OUStringToOString(rRFonts[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8).getStr());
     261           0 :         else if (rRFonts[i].Name == "cstheme")
     262           0 :             pAttributeList->add(FSNS(XML_w, XML_cstheme), OUStringToOString(rRFonts[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8).getStr());
     263           0 :         else if (rRFonts[i].Name == "hAnsiTheme")
     264           0 :             pAttributeList->add(FSNS(XML_w, XML_hAnsiTheme), OUStringToOString(rRFonts[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8).getStr());
     265             :     }
     266           0 :     sax_fastparser::XFastAttributeListRef xAttributeList(pAttributeList);
     267           0 :     m_pSerializer->singleElementNS(XML_w, XML_rFonts, xAttributeList);
     268             : }
     269             : 
     270           0 : void DocxTableStyleExport::Impl::tableStylePSpacing(uno::Sequence<beans::PropertyValue>& rSpacing)
     271             : {
     272           0 :     if (!rSpacing.hasElements())
     273           0 :         return;
     274             : 
     275           0 :     sax_fastparser::FastAttributeList* pAttributeList = m_pSerializer->createAttrList();
     276           0 :     for (sal_Int32 i = 0; i < rSpacing.getLength(); ++i)
     277             :     {
     278           0 :         if (rSpacing[i].Name == "after")
     279           0 :             pAttributeList->add(FSNS(XML_w, XML_after), OUStringToOString(rSpacing[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8).getStr());
     280           0 :         else if (rSpacing[i].Name == "before")
     281           0 :             pAttributeList->add(FSNS(XML_w, XML_before), OUStringToOString(rSpacing[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8).getStr());
     282           0 :         else if (rSpacing[i].Name == "line")
     283           0 :             pAttributeList->add(FSNS(XML_w, XML_line), OUStringToOString(rSpacing[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8).getStr());
     284           0 :         else if (rSpacing[i].Name == "lineRule")
     285           0 :             pAttributeList->add(FSNS(XML_w, XML_lineRule), OUStringToOString(rSpacing[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8).getStr());
     286           0 :         else if (rSpacing[i].Name == "beforeLines")
     287           0 :             pAttributeList->add(FSNS(XML_w, XML_beforeLines), OUStringToOString(rSpacing[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8).getStr());
     288           0 :         else if (rSpacing[i].Name == "ParaTopMarginBeforeAutoSpacing")
     289             :             // Auto spacing will be available in grab bag only if it was set to true
     290           0 :             pAttributeList->add(FSNS(XML_w, XML_beforeAutospacing), "1");
     291           0 :         else if (rSpacing[i].Name == "afterLines")
     292           0 :             pAttributeList->add(FSNS(XML_w, XML_afterLines), OUStringToOString(rSpacing[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8).getStr());
     293           0 :         else if (rSpacing[i].Name == "ParaBottomMarginAfterAutoSpacing")
     294             :             // Auto spacing will be available in grab bag only if it was set to true
     295           0 :             pAttributeList->add(FSNS(XML_w, XML_afterAutospacing), "1");
     296             :     }
     297           0 :     sax_fastparser::XFastAttributeListRef xAttributeList(pAttributeList);
     298           0 :     m_pSerializer->singleElementNS(XML_w, XML_spacing, xAttributeList);
     299             : }
     300             : 
     301           0 : void DocxTableStyleExport::Impl::tableStylePInd(uno::Sequence<beans::PropertyValue>& rInd)
     302             : {
     303           0 :     if (!rInd.hasElements())
     304           0 :         return;
     305             : 
     306           0 :     sax_fastparser::FastAttributeList* pAttributeList = m_pSerializer->createAttrList();
     307           0 :     for (sal_Int32 i = 0; i < rInd.getLength(); ++i)
     308             :     {
     309           0 :         if (rInd[i].Name == "rightChars")
     310           0 :             pAttributeList->add(FSNS(XML_w, XML_rightChars), OUStringToOString(rInd[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8).getStr());
     311           0 :         else if (rInd[i].Name == "right")
     312           0 :             pAttributeList->add(FSNS(XML_w, XML_right), OUStringToOString(rInd[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8).getStr());
     313             :     }
     314           0 :     sax_fastparser::XFastAttributeListRef xAttributeList(pAttributeList);
     315           0 :     m_pSerializer->singleElementNS(XML_w, XML_ind, xAttributeList);
     316             : }
     317             : 
     318           0 : void DocxTableStyleExport::Impl::tableStyleTblInd(uno::Sequence<beans::PropertyValue>& rTblInd)
     319             : {
     320           0 :     if (!rTblInd.hasElements())
     321           0 :         return;
     322             : 
     323           0 :     sax_fastparser::FastAttributeList* pAttributeList = m_pSerializer->createAttrList();
     324           0 :     for (sal_Int32 i = 0; i < rTblInd.getLength(); ++i)
     325             :     {
     326           0 :         if (rTblInd[i].Name == "w")
     327           0 :             pAttributeList->add(FSNS(XML_w, XML_w), OString::number(rTblInd[i].Value.get<sal_Int32>()));
     328           0 :         else if (rTblInd[i].Name == "type")
     329           0 :             pAttributeList->add(FSNS(XML_w, XML_type), OUStringToOString(rTblInd[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8).getStr());
     330             :     }
     331           0 :     sax_fastparser::XFastAttributeListRef xAttributeList(pAttributeList);
     332           0 :     m_pSerializer->singleElementNS(XML_w, XML_tblInd, xAttributeList);
     333             : }
     334             : 
     335           0 : void DocxTableStyleExport::Impl::handleBoolean(const OUString& aValue, sal_Int32 nToken)
     336             : {
     337           0 :     if (aValue.isEmpty())
     338           0 :         return;
     339           0 :     sax_fastparser::FastAttributeList* pAttributeList = m_pSerializer->createAttrList();
     340           0 :     if (aValue != "1")
     341           0 :         pAttributeList->add(FSNS(XML_w, XML_val), OUStringToOString(aValue, RTL_TEXTENCODING_UTF8).getStr());
     342           0 :     sax_fastparser::XFastAttributeListRef xAttributeList(pAttributeList);
     343           0 :     m_pSerializer->singleElementNS(XML_w, nToken, xAttributeList);
     344             : }
     345             : 
     346           0 : void DocxTableStyleExport::Impl::tableStyleRPr(uno::Sequence<beans::PropertyValue>& rRPr)
     347             : {
     348           0 :     if (!rRPr.hasElements())
     349           0 :         return;
     350             : 
     351           0 :     m_pSerializer->startElementNS(XML_w, XML_rPr, FSEND);
     352             : 
     353           0 :     uno::Sequence<beans::PropertyValue> aRFonts, aLang, aColor, aSpacingSequence;
     354           0 :     bool bSequenceFlag = false ;
     355           0 :     OUString aB, aBCs, aI, aSz, aSzCs, aCaps, aSmallCaps, aSpacing;
     356           0 :     for (sal_Int32 i = 0; i < rRPr.getLength(); ++i)
     357             :     {
     358           0 :         if (rRPr[i].Name == "rFonts")
     359           0 :             aRFonts = rRPr[i].Value.get< uno::Sequence<beans::PropertyValue> >();
     360           0 :         else if (rRPr[i].Name == "lang")
     361           0 :             aLang = rRPr[i].Value.get< uno::Sequence<beans::PropertyValue> >();
     362           0 :         else if (rRPr[i].Name == "b")
     363           0 :             aB = rRPr[i].Value.get<OUString>();
     364           0 :         else if (rRPr[i].Name == "bCs")
     365           0 :             aBCs = rRPr[i].Value.get<OUString>();
     366           0 :         else if (rRPr[i].Name == "i")
     367           0 :             aI = rRPr[i].Value.get<OUString>();
     368           0 :         else if (rRPr[i].Name == "color")
     369           0 :             aColor = rRPr[i].Value.get< uno::Sequence<beans::PropertyValue> >();
     370           0 :         else if (rRPr[i].Name == "sz")
     371           0 :             aSz = rRPr[i].Value.get<OUString>();
     372           0 :         else if (rRPr[i].Name == "szCs")
     373           0 :             aSzCs = rRPr[i].Value.get<OUString>();
     374           0 :         else if (rRPr[i].Name == "caps")
     375           0 :             aCaps = rRPr[i].Value.get<OUString>();
     376           0 :         else if (rRPr[i].Name == "smallCaps")
     377           0 :             aSmallCaps = rRPr[i].Value.get<OUString>();
     378           0 :         else if (rRPr[i].Name == "spacing")
     379             :         {
     380           0 :             if (rRPr[i].Value.has<OUString>())
     381             :             {
     382           0 :                 aSpacing = rRPr[i].Value.get<OUString>();
     383             :             }
     384             :             else
     385             :             {
     386           0 :                 aSpacingSequence = rRPr[i].Value.get< uno::Sequence<beans::PropertyValue> >() ;
     387           0 :                 bSequenceFlag = true ; // set the uno::Sequence flag.
     388             :             }
     389             :         }
     390             :     }
     391           0 :     tableStyleRRFonts(aRFonts);
     392           0 :     tableStyleRLang(aLang);
     393           0 :     handleBoolean(aB, XML_b);
     394           0 :     handleBoolean(aBCs, XML_bCs);
     395           0 :     handleBoolean(aI, XML_i);
     396           0 :     handleBoolean(aCaps, XML_caps);
     397           0 :     handleBoolean(aSmallCaps, XML_smallCaps);
     398           0 :     tableStyleRColor(aColor);
     399           0 :     if (bSequenceFlag)
     400             :     {
     401             :         m_pSerializer->singleElementNS(XML_w, XML_spacing,
     402           0 :                                        FSNS(XML_w, XML_val),OUStringToOString(aSpacingSequence[0].Value.get<OUString>(), RTL_TEXTENCODING_UTF8).getStr(),
     403           0 :                                        FSEND);
     404             :     }
     405           0 :     if (!aSpacing.isEmpty())
     406             :         m_pSerializer->singleElementNS(XML_w, XML_spacing,
     407             :                                        FSNS(XML_w, XML_val), OUStringToOString(aSpacing, RTL_TEXTENCODING_UTF8).getStr(),
     408           0 :                                        FSEND);
     409           0 :     if (!aSz.isEmpty())
     410             :         m_pSerializer->singleElementNS(XML_w, XML_sz,
     411             :                                        FSNS(XML_w, XML_val), OUStringToOString(aSz, RTL_TEXTENCODING_UTF8).getStr(),
     412           0 :                                        FSEND);
     413           0 :     if (!aSzCs.isEmpty())
     414             :         m_pSerializer->singleElementNS(XML_w, XML_szCs,
     415             :                                        FSNS(XML_w, XML_val), OUStringToOString(aSzCs, RTL_TEXTENCODING_UTF8).getStr(),
     416           0 :                                        FSEND);
     417             : 
     418           0 :     m_pSerializer->endElementNS(XML_w, XML_rPr);
     419             : }
     420             : 
     421           0 : void DocxTableStyleExport::Impl::tableStylePPr(uno::Sequence<beans::PropertyValue>& rPPr)
     422             : {
     423           0 :     if (!rPPr.hasElements())
     424           0 :         return;
     425             : 
     426           0 :     m_pSerializer->startElementNS(XML_w, XML_pPr, FSEND);
     427             : 
     428           0 :     uno::Sequence<beans::PropertyValue> aSpacing, aInd;
     429           0 :     bool bWordWrap = false;
     430           0 :     OUString aJc, aSnapToGrid;
     431           0 :     for (sal_Int32 i = 0; i < rPPr.getLength(); ++i)
     432             :     {
     433           0 :         if (rPPr[i].Name == "spacing")
     434           0 :             aSpacing = rPPr[i].Value.get< uno::Sequence<beans::PropertyValue> >();
     435           0 :         else if (rPPr[i].Name == "ind")
     436           0 :             aInd = rPPr[i].Value.get< uno::Sequence<beans::PropertyValue> >();
     437           0 :         else if (rPPr[i].Name == "wordWrap")
     438           0 :             bWordWrap = true;
     439           0 :         else if (rPPr[i].Name == "jc")
     440           0 :             aJc = rPPr[i].Value.get<OUString>();
     441           0 :         else if (rPPr[i].Name == "snapToGrid")
     442           0 :             aSnapToGrid = rPPr[i].Value.get<OUString>();
     443             :     }
     444           0 :     if (bWordWrap)
     445           0 :         m_pSerializer->singleElementNS(XML_w, XML_wordWrap, FSEND);
     446           0 :     tableStylePInd(aInd);
     447           0 :     handleBoolean(aSnapToGrid, XML_snapToGrid);
     448           0 :     tableStylePSpacing(aSpacing);
     449           0 :     if (!aJc.isEmpty())
     450             :         m_pSerializer->singleElementNS(XML_w, XML_jc,
     451             :                                        FSNS(XML_w, XML_val), OUStringToOString(aJc, RTL_TEXTENCODING_UTF8).getStr(),
     452           0 :                                        FSEND);
     453             : 
     454           0 :     m_pSerializer->endElementNS(XML_w, XML_pPr);
     455             : }
     456             : 
     457           0 : void DocxTableStyleExport::Impl::tableStyleTblPr(uno::Sequence<beans::PropertyValue>& rTblPr)
     458             : {
     459           0 :     if (!rTblPr.hasElements())
     460           0 :         return;
     461             : 
     462           0 :     m_pSerializer->startElementNS(XML_w, XML_tblPr, FSEND);
     463             : 
     464           0 :     uno::Sequence<beans::PropertyValue> aTblInd, aTblBorders, aTblCellMar;
     465           0 :     boost::optional<sal_Int32> oTblStyleRowBandSize, oTblStyleColBandSize;
     466           0 :     for (sal_Int32 i = 0; i < rTblPr.getLength(); ++i)
     467             :     {
     468           0 :         if (rTblPr[i].Name == "tblStyleRowBandSize")
     469           0 :             oTblStyleRowBandSize = rTblPr[i].Value.get<sal_Int32>();
     470           0 :         else if (rTblPr[i].Name == "tblStyleColBandSize")
     471           0 :             oTblStyleColBandSize = rTblPr[i].Value.get<sal_Int32>();
     472           0 :         else if (rTblPr[i].Name == "tblInd")
     473           0 :             aTblInd = rTblPr[i].Value.get< uno::Sequence<beans::PropertyValue> >();
     474           0 :         else if (rTblPr[i].Name == "tblBorders")
     475           0 :             aTblBorders = rTblPr[i].Value.get< uno::Sequence<beans::PropertyValue> >();
     476           0 :         else if (rTblPr[i].Name == "tblCellMar")
     477           0 :             aTblCellMar = rTblPr[i].Value.get< uno::Sequence<beans::PropertyValue> >();
     478             :     }
     479           0 :     if (oTblStyleRowBandSize)
     480             :         m_pSerializer->singleElementNS(XML_w, XML_tblStyleRowBandSize,
     481           0 :                                        FSNS(XML_w, XML_val), OString::number(oTblStyleRowBandSize.get()),
     482           0 :                                        FSEND);
     483           0 :     if (oTblStyleColBandSize)
     484             :         m_pSerializer->singleElementNS(XML_w, XML_tblStyleColBandSize,
     485           0 :                                        FSNS(XML_w, XML_val), OString::number(oTblStyleColBandSize.get()),
     486           0 :                                        FSEND);
     487           0 :     tableStyleTblInd(aTblInd);
     488           0 :     tableStyleTcBorders(aTblBorders, XML_tblBorders);
     489           0 :     tableStyleTblCellMar(aTblCellMar);
     490             : 
     491           0 :     m_pSerializer->endElementNS(XML_w, XML_tblPr);
     492             : }
     493             : 
     494           0 : void DocxTableStyleExport::Impl::tableStyleTcPr(uno::Sequence<beans::PropertyValue>& rTcPr)
     495             : {
     496           0 :     if (!rTcPr.hasElements())
     497           0 :         return;
     498             : 
     499           0 :     m_pSerializer->startElementNS(XML_w, XML_tcPr, FSEND);
     500             : 
     501           0 :     uno::Sequence<beans::PropertyValue> aShd, aTcBorders, aTcMar;
     502           0 :     OUString aVAlign;
     503           0 :     for (sal_Int32 i = 0; i < rTcPr.getLength(); ++i)
     504             :     {
     505           0 :         if (rTcPr[i].Name == "shd")
     506           0 :             aShd = rTcPr[i].Value.get< uno::Sequence<beans::PropertyValue> >();
     507           0 :         else if (rTcPr[i].Name == "tcBorders")
     508           0 :             aTcBorders = rTcPr[i].Value.get< uno::Sequence<beans::PropertyValue> >();
     509           0 :         else if (rTcPr[i].Name == "tcMar")
     510           0 :             aTcMar = rTcPr[i].Value.get< uno::Sequence<beans::PropertyValue> >();
     511           0 :         else if (rTcPr[i].Name == "vAlign")
     512           0 :             aVAlign = rTcPr[i].Value.get<OUString>();
     513             :     }
     514           0 :     tableStyleTcBorders(aTcBorders);
     515           0 :     tableStyleTblCellMar(aTcMar, XML_tcMar);
     516           0 :     tableStyleShd(aShd);
     517           0 :     if (!aVAlign.isEmpty())
     518             :         m_pSerializer->singleElementNS(XML_w, XML_vAlign,
     519             :                                        FSNS(XML_w, XML_val), OUStringToOString(aVAlign, RTL_TEXTENCODING_UTF8).getStr(),
     520           0 :                                        FSEND);
     521             : 
     522           0 :     m_pSerializer->endElementNS(XML_w, XML_tcPr);
     523             : }
     524             : 
     525           0 : void DocxTableStyleExport::Impl::tableStyleTblStylePr(uno::Sequence<beans::PropertyValue>& rTblStylePr)
     526             : {
     527           0 :     if (!rTblStylePr.hasElements())
     528           0 :         return;
     529             : 
     530           0 :     OUString aType;
     531           0 :     uno::Sequence<beans::PropertyValue> aPPr, aRPr, aTblPr, aTcPr;
     532           0 :     for (sal_Int32 i = 0; i < rTblStylePr.getLength(); ++i)
     533             :     {
     534           0 :         if (rTblStylePr[i].Name == "type")
     535           0 :             aType = rTblStylePr[i].Value.get<OUString>();
     536           0 :         else if (rTblStylePr[i].Name == "pPr")
     537           0 :             aPPr = rTblStylePr[i].Value.get< uno::Sequence<beans::PropertyValue> >();
     538           0 :         else if (rTblStylePr[i].Name == "rPr")
     539           0 :             aRPr = rTblStylePr[i].Value.get< uno::Sequence<beans::PropertyValue> >();
     540           0 :         else if (rTblStylePr[i].Name == "tblPr")
     541           0 :             aTblPr = rTblStylePr[i].Value.get< uno::Sequence<beans::PropertyValue> >();
     542           0 :         else if (rTblStylePr[i].Name == "tcPr")
     543           0 :             aTcPr = rTblStylePr[i].Value.get< uno::Sequence<beans::PropertyValue> >();
     544             :     }
     545             : 
     546             :     m_pSerializer->startElementNS(XML_w, XML_tblStylePr,
     547             :                                   FSNS(XML_w, XML_type), OUStringToOString(aType, RTL_TEXTENCODING_UTF8).getStr(),
     548           0 :                                   FSEND);
     549             : 
     550           0 :     tableStylePPr(aPPr);
     551           0 :     tableStyleRPr(aRPr);
     552           0 :     if (aTblPr.hasElements())
     553           0 :         tableStyleTblPr(aTblPr);
     554             :     else
     555             :     {
     556             :         // Even if we have an empty container, write it out, as Word does.
     557           0 :         m_pSerializer->singleElementNS(XML_w, XML_tblPr, FSEND);
     558             :     }
     559           0 :     tableStyleTcPr(aTcPr);
     560             : 
     561           0 :     m_pSerializer->endElementNS(XML_w, XML_tblStylePr);
     562             : }
     563             : 
     564           0 : void DocxTableStyleExport::Impl::TableStyle(uno::Sequence<beans::PropertyValue>& rStyle)
     565             : {
     566           0 :     bool bDefault = false, bCustomStyle = false, bQFormat = false, bSemiHidden = false, bUnhideWhenUsed = false;
     567           0 :     OUString aStyleId, aName, aBasedOn, aRsid, aUiPriority;
     568           0 :     uno::Sequence<beans::PropertyValue> aPPr, aRPr, aTblPr, aTcPr;
     569           0 :     std::vector< uno::Sequence<beans::PropertyValue> > aTblStylePrs;
     570           0 :     for (sal_Int32 i = 0; i < rStyle.getLength(); ++i)
     571             :     {
     572           0 :         if (rStyle[i].Name == "default")
     573           0 :             bDefault = rStyle[i].Value.get<sal_Bool>();
     574           0 :         else if (rStyle[i].Name == "customStyle")
     575           0 :             bCustomStyle = rStyle[i].Value.get<sal_Bool>();
     576           0 :         else if (rStyle[i].Name == "styleId")
     577           0 :             aStyleId = rStyle[i].Value.get<OUString>();
     578           0 :         else if (rStyle[i].Name == "name")
     579           0 :             aName = rStyle[i].Value.get<OUString>();
     580           0 :         else if (rStyle[i].Name == "basedOn")
     581           0 :             aBasedOn = rStyle[i].Value.get<OUString>();
     582           0 :         else if (rStyle[i].Name == "uiPriority")
     583           0 :             aUiPriority = rStyle[i].Value.get<OUString>();
     584           0 :         else if (rStyle[i].Name == "qFormat")
     585           0 :             bQFormat = true;
     586           0 :         else if (rStyle[i].Name == "semiHidden")
     587           0 :             bSemiHidden = true;
     588           0 :         else if (rStyle[i].Name == "unhideWhenUsed")
     589           0 :             bUnhideWhenUsed = true;
     590           0 :         else if (rStyle[i].Name == "rsid")
     591           0 :             aRsid = rStyle[i].Value.get<OUString>();
     592           0 :         else if (rStyle[i].Name == "pPr")
     593           0 :             aPPr = rStyle[i].Value.get< uno::Sequence<beans::PropertyValue> >();
     594           0 :         else if (rStyle[i].Name == "rPr")
     595           0 :             aRPr = rStyle[i].Value.get< uno::Sequence<beans::PropertyValue> >();
     596           0 :         else if (rStyle[i].Name == "tblPr")
     597           0 :             aTblPr = rStyle[i].Value.get< uno::Sequence<beans::PropertyValue> >();
     598           0 :         else if (rStyle[i].Name == "tcPr")
     599           0 :             aTcPr = rStyle[i].Value.get< uno::Sequence<beans::PropertyValue> >();
     600           0 :         else if (rStyle[i].Name == "tblStylePr")
     601           0 :             aTblStylePrs.push_back(rStyle[i].Value.get< uno::Sequence<beans::PropertyValue> >());
     602             :     }
     603             : 
     604           0 :     sax_fastparser::FastAttributeList* pAttributeList = m_pSerializer->createAttrList();
     605           0 :     pAttributeList->add(FSNS(XML_w, XML_type), "table");
     606           0 :     if (bDefault)
     607           0 :         pAttributeList->add(FSNS(XML_w, XML_default), "1");
     608           0 :     if (bCustomStyle)
     609           0 :         pAttributeList->add(FSNS(XML_w, XML_customStyle), "1");
     610           0 :     if (!aStyleId.isEmpty())
     611           0 :         pAttributeList->add(FSNS(XML_w, XML_styleId), OUStringToOString(aStyleId, RTL_TEXTENCODING_UTF8).getStr());
     612           0 :     sax_fastparser::XFastAttributeListRef xAttributeList(pAttributeList);
     613           0 :     m_pSerializer->startElementNS(XML_w, XML_style, xAttributeList);
     614             : 
     615             :     m_pSerializer->singleElementNS(XML_w, XML_name,
     616             :                                    FSNS(XML_w, XML_val), OUStringToOString(aName, RTL_TEXTENCODING_UTF8).getStr(),
     617           0 :                                    FSEND);
     618           0 :     if (!aBasedOn.isEmpty())
     619             :         m_pSerializer->singleElementNS(XML_w, XML_basedOn,
     620             :                                        FSNS(XML_w, XML_val), OUStringToOString(aBasedOn, RTL_TEXTENCODING_UTF8).getStr(),
     621           0 :                                        FSEND);
     622           0 :     if (!aUiPriority.isEmpty())
     623             :         m_pSerializer->singleElementNS(XML_w, XML_uiPriority,
     624             :                                        FSNS(XML_w, XML_val), OUStringToOString(aUiPriority, RTL_TEXTENCODING_UTF8).getStr(),
     625           0 :                                        FSEND);
     626           0 :     if (bSemiHidden)
     627           0 :         m_pSerializer->singleElementNS(XML_w, XML_semiHidden, FSEND);
     628           0 :     if (bUnhideWhenUsed)
     629           0 :         m_pSerializer->singleElementNS(XML_w, XML_unhideWhenUsed, FSEND);
     630           0 :     if (bQFormat)
     631           0 :         m_pSerializer->singleElementNS(XML_w, XML_qFormat, FSEND);
     632           0 :     if (!aRsid.isEmpty())
     633             :         m_pSerializer->singleElementNS(XML_w, XML_rsid,
     634             :                                        FSNS(XML_w, XML_val), OUStringToOString(aRsid, RTL_TEXTENCODING_UTF8).getStr(),
     635           0 :                                        FSEND);
     636             : 
     637           0 :     tableStylePPr(aPPr);
     638           0 :     tableStyleRPr(aRPr);
     639           0 :     tableStyleTblPr(aTblPr);
     640           0 :     tableStyleTcPr(aTcPr);
     641           0 :     for (size_t i = 0; i < aTblStylePrs.size(); ++i)
     642           0 :         tableStyleTblStylePr(aTblStylePrs[i]);
     643             : 
     644           0 :     m_pSerializer->endElementNS(XML_w, XML_style);
     645           0 : }
     646             : 
     647           0 : void DocxTableStyleExport::SetSerializer(sax_fastparser::FSHelperPtr pSerializer)
     648             : {
     649           0 :     m_pImpl->m_pSerializer = pSerializer;
     650           0 : }
     651             : 
     652           0 : DocxTableStyleExport::DocxTableStyleExport(SwDoc* pDoc, sax_fastparser::FSHelperPtr pSerializer)
     653           0 :     : m_pImpl(new Impl)
     654             : {
     655           0 :     m_pImpl->m_pDoc = pDoc;
     656           0 :     m_pImpl->m_pSerializer = pSerializer;
     657           0 : }
     658             : 
     659           0 : DocxTableStyleExport::~DocxTableStyleExport()
     660             : {
     661           0 : }
     662             : 
     663             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10