LCOV - code coverage report
Current view: top level - sw/source/filter/ww8 - docxtablestyleexport.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 379 387 97.9 %
Date: 2014-04-11 Functions: 25 25 100.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         544 : 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         272 : void DocxTableStyleExport::TableStyles(sal_uInt16 nCountStylesToWrite)
      71             : {
      72             :     // Do we have table styles from InteropGrabBag available?
      73         272 :     uno::Reference<beans::XPropertySet> xPropertySet(m_pImpl->m_pDoc->GetDocShell()->GetBaseModel(), uno::UNO_QUERY_THROW);
      74         504 :     uno::Sequence<beans::PropertyValue> aInteropGrabBag;
      75         272 :     xPropertySet->getPropertyValue("InteropGrabBag") >>= aInteropGrabBag;
      76         504 :     uno::Sequence<beans::PropertyValue> aTableStyles;
      77        3046 :     for (sal_Int32 i = 0; i < aInteropGrabBag.getLength(); ++i)
      78             :     {
      79        3006 :         if (aInteropGrabBag[i].Name == "tableStyles")
      80             :         {
      81         232 :             aInteropGrabBag[i].Value >>= aTableStyles;
      82         232 :             break;
      83             :         }
      84             :     }
      85         272 :     if (!aTableStyles.getLength())
      86         312 :         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         232 :     nCountStylesToWrite = (nCountStylesToWrite > aTableStyles.getLength()) ?  aTableStyles.getLength(): nCountStylesToWrite;
      92             : 
      93         582 :     for (sal_Int32 i = 0; i < nCountStylesToWrite; ++i)
      94             :     {
      95         350 :         uno::Sequence<beans::PropertyValue> aTableStyle;
      96         350 :         aTableStyles[i].Value >>= aTableStyle;
      97         350 :         m_pImpl->TableStyle(aTableStyle);
      98         582 :     }
      99             : }
     100             : 
     101         604 : 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         604 :     if (!rTblCellMar.hasElements())
     115         854 :         return;
     116             : 
     117         354 :     m_pSerializer->startElementNS(XML_w, nType, FSEND);
     118        1768 :     for (sal_Int32 i = 0; i < rTblCellMar.getLength(); ++i)
     119             :     {
     120        1414 :         if (sal_Int32 nToken = DocxStringGetToken(aTblCellMarTokens, rTblCellMar[i].Name))
     121             :         {
     122        1414 :             comphelper::SequenceAsHashMap aMap(rTblCellMar[i].Value.get< uno::Sequence<beans::PropertyValue> >());
     123             :             m_pSerializer->singleElementNS(XML_w, nToken,
     124        2828 :                                            FSNS(XML_w, XML_w), OString::number(aMap["w"].get<sal_Int32>()),
     125        2828 :                                            FSNS(XML_w, XML_type), OUStringToOString(aMap["type"].get<OUString>(), RTL_TEXTENCODING_UTF8).getStr(),
     126        5656 :                                            FSEND);
     127             :         }
     128             :     }
     129         354 :     m_pSerializer->endElementNS(XML_w, nType);
     130             : }
     131             : 
     132        1153 : 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        1153 :     if (!rTcBorder.hasElements())
     146        1153 :         return;
     147             : 
     148        1153 :     sax_fastparser::FastAttributeList* pAttributeList = m_pSerializer->createAttrList();
     149        5447 :     for (sal_Int32 i = 0; i < rTcBorder.getLength(); ++i)
     150        4294 :         if (sal_Int32 nAttrToken = DocxStringGetToken(aTcBorderTokens, rTcBorder[i].Name))
     151        4294 :             pAttributeList->add(FSNS(XML_w, nAttrToken), OUStringToOString(rTcBorder[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8).getStr());
     152             : 
     153        1153 :     sax_fastparser::XFastAttributeListRef xAttributeList(pAttributeList);
     154        1153 :     m_pSerializer->singleElementNS(XML_w, nToken, xAttributeList);
     155             : }
     156             : 
     157         604 : 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         604 :     if (!rTcBorders.hasElements())
     175         904 :         return;
     176             : 
     177         304 :     m_pSerializer->startElementNS(XML_w, nToken, FSEND);
     178        1457 :     for (sal_Int32 i = 0; i < rTcBorders.getLength(); ++i)
     179        1153 :         if (sal_Int32 nSubToken = DocxStringGetToken(aTcBordersTokens, rTcBorders[i].Name))
     180        1153 :             tableStyleTcBorder(nSubToken, rTcBorders[i].Value.get< uno::Sequence<beans::PropertyValue> >());
     181         304 :     m_pSerializer->endElementNS(XML_w, nToken);
     182             : }
     183             : 
     184         254 : void DocxTableStyleExport::Impl::tableStyleShd(uno::Sequence<beans::PropertyValue>& rShd)
     185             : {
     186         254 :     if (!rShd.hasElements())
     187         396 :         return;
     188             : 
     189         112 :     sax_fastparser::FastAttributeList* pAttributeList = m_pSerializer->createAttrList();
     190         477 :     for (sal_Int32 i = 0; i < rShd.getLength(); ++i)
     191             :     {
     192         365 :         if (rShd[i].Name == "val")
     193         112 :             pAttributeList->add(FSNS(XML_w, XML_val), OUStringToOString(rShd[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8).getStr());
     194         253 :         else if (rShd[i].Name == "color")
     195         112 :             pAttributeList->add(FSNS(XML_w, XML_color), OUStringToOString(rShd[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8).getStr());
     196         141 :         else if (rShd[i].Name == "fill")
     197         112 :             pAttributeList->add(FSNS(XML_w, XML_fill), OUStringToOString(rShd[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8).getStr());
     198          29 :         else if (rShd[i].Name == "themeFill")
     199          20 :             pAttributeList->add(FSNS(XML_w, XML_themeFill), OUStringToOString(rShd[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8).getStr());
     200           9 :         else if (rShd[i].Name == "themeFillShade")
     201           3 :             pAttributeList->add(FSNS(XML_w, XML_themeFillShade), OUStringToOString(rShd[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8).getStr());
     202           6 :         else if (rShd[i].Name == "themeFillTint")
     203           6 :             pAttributeList->add(FSNS(XML_w, XML_themeFillTint), OUStringToOString(rShd[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8).getStr());
     204             :     }
     205         112 :     sax_fastparser::XFastAttributeListRef xAttributeList(pAttributeList);
     206         112 :     m_pSerializer->singleElementNS(XML_w, XML_shd, xAttributeList);
     207             : }
     208             : 
     209         208 : void DocxTableStyleExport::Impl::tableStyleRColor(uno::Sequence<beans::PropertyValue>& rColor)
     210             : {
     211         208 :     if (!rColor.hasElements())
     212         340 :         return;
     213             : 
     214          76 :     sax_fastparser::FastAttributeList* pAttributeList = m_pSerializer->createAttrList();
     215         174 :     for (sal_Int32 i = 0; i < rColor.getLength(); ++i)
     216             :     {
     217          98 :         if (rColor[i].Name == "val")
     218          76 :             pAttributeList->add(FSNS(XML_w, XML_val), OUStringToOString(rColor[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8).getStr());
     219          22 :         else if (rColor[i].Name == "themeColor")
     220          15 :             pAttributeList->add(FSNS(XML_w, XML_themeColor), OUStringToOString(rColor[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8).getStr());
     221           7 :         else if (rColor[i].Name == "themeTint")
     222           1 :             pAttributeList->add(FSNS(XML_w, XML_themeTint), OUStringToOString(rColor[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8).getStr());
     223           6 :         else if (rColor[i].Name == "themeShade")
     224           6 :             pAttributeList->add(FSNS(XML_w, XML_themeShade), OUStringToOString(rColor[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8).getStr());
     225             :     }
     226          76 :     sax_fastparser::XFastAttributeListRef xAttributeList(pAttributeList);
     227          76 :     m_pSerializer->singleElementNS(XML_w, XML_color, xAttributeList);
     228             : }
     229             : 
     230         208 : void DocxTableStyleExport::Impl::tableStyleRLang(uno::Sequence<beans::PropertyValue>& rLang)
     231             : {
     232         208 :     if (!rLang.hasElements())
     233         401 :         return;
     234             : 
     235          15 :     sax_fastparser::FastAttributeList* pAttributeList = m_pSerializer->createAttrList();
     236          33 :     for (sal_Int32 i = 0; i < rLang.getLength(); ++i)
     237             :     {
     238          18 :         if (rLang[i].Name == "eastAsia")
     239           6 :             pAttributeList->add(FSNS(XML_w, XML_eastAsia), OUStringToOString(rLang[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8).getStr());
     240          12 :         else if (rLang[i].Name == "val")
     241           3 :             pAttributeList->add(FSNS(XML_w, XML_val), OUStringToOString(rLang[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8).getStr());
     242           9 :         else if (rLang[i].Name == "bidi")
     243           9 :             pAttributeList->add(FSNS(XML_w, XML_bidi), OUStringToOString(rLang[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8).getStr());
     244             :     }
     245          15 :     sax_fastparser::XFastAttributeListRef xAttributeList(pAttributeList);
     246          15 :     m_pSerializer->singleElementNS(XML_w, XML_lang, xAttributeList);
     247             : }
     248             : 
     249         208 : void DocxTableStyleExport::Impl::tableStyleRRFonts(uno::Sequence<beans::PropertyValue>& rRFonts)
     250             : {
     251         208 :     if (!rRFonts.hasElements())
     252         401 :         return;
     253             : 
     254          15 :     sax_fastparser::FastAttributeList* pAttributeList = m_pSerializer->createAttrList();
     255          44 :     for (sal_Int32 i = 0; i < rRFonts.getLength(); ++i)
     256             :     {
     257          29 :         if (rRFonts[i].Name == "eastAsiaTheme")
     258          13 :             pAttributeList->add(FSNS(XML_w, XML_eastAsiaTheme), OUStringToOString(rRFonts[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8).getStr());
     259          16 :         else if (rRFonts[i].Name == "asciiTheme")
     260           6 :             pAttributeList->add(FSNS(XML_w, XML_asciiTheme), OUStringToOString(rRFonts[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8).getStr());
     261          10 :         else if (rRFonts[i].Name == "cstheme")
     262           4 :             pAttributeList->add(FSNS(XML_w, XML_cstheme), OUStringToOString(rRFonts[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8).getStr());
     263           6 :         else if (rRFonts[i].Name == "hAnsiTheme")
     264           6 :             pAttributeList->add(FSNS(XML_w, XML_hAnsiTheme), OUStringToOString(rRFonts[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8).getStr());
     265             :     }
     266          15 :     sax_fastparser::XFastAttributeListRef xAttributeList(pAttributeList);
     267          15 :     m_pSerializer->singleElementNS(XML_w, XML_rFonts, xAttributeList);
     268             : }
     269             : 
     270         109 : void DocxTableStyleExport::Impl::tableStylePSpacing(uno::Sequence<beans::PropertyValue>& rSpacing)
     271             : {
     272         109 :     if (!rSpacing.hasElements())
     273         112 :         return;
     274             : 
     275         106 :     sax_fastparser::FastAttributeList* pAttributeList = m_pSerializer->createAttrList();
     276         488 :     for (sal_Int32 i = 0; i < rSpacing.getLength(); ++i)
     277             :     {
     278         382 :         if (rSpacing[i].Name == "after")
     279          97 :             pAttributeList->add(FSNS(XML_w, XML_after), OUStringToOString(rSpacing[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8).getStr());
     280         285 :         else if (rSpacing[i].Name == "before")
     281          61 :             pAttributeList->add(FSNS(XML_w, XML_before), OUStringToOString(rSpacing[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8).getStr());
     282         224 :         else if (rSpacing[i].Name == "line")
     283         104 :             pAttributeList->add(FSNS(XML_w, XML_line), OUStringToOString(rSpacing[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8).getStr());
     284         120 :         else if (rSpacing[i].Name == "lineRule")
     285         104 :             pAttributeList->add(FSNS(XML_w, XML_lineRule), OUStringToOString(rSpacing[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8).getStr());
     286          16 :         else if (rSpacing[i].Name == "beforeLines")
     287           8 :             pAttributeList->add(FSNS(XML_w, XML_beforeLines), OUStringToOString(rSpacing[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8).getStr());
     288           8 :         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           8 :         else if (rSpacing[i].Name == "afterLines")
     292           8 :             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         106 :     sax_fastparser::XFastAttributeListRef xAttributeList(pAttributeList);
     298         106 :     m_pSerializer->singleElementNS(XML_w, XML_spacing, xAttributeList);
     299             : }
     300             : 
     301         109 : void DocxTableStyleExport::Impl::tableStylePInd(uno::Sequence<beans::PropertyValue>& rInd)
     302             : {
     303         109 :     if (!rInd.hasElements())
     304         209 :         return;
     305             : 
     306           9 :     sax_fastparser::FastAttributeList* pAttributeList = m_pSerializer->createAttrList();
     307          24 :     for (sal_Int32 i = 0; i < rInd.getLength(); ++i)
     308             :     {
     309          15 :         if (rInd[i].Name == "rightChars")
     310           6 :             pAttributeList->add(FSNS(XML_w, XML_rightChars), OUStringToOString(rInd[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8).getStr());
     311           9 :         else if (rInd[i].Name == "right")
     312           9 :             pAttributeList->add(FSNS(XML_w, XML_right), OUStringToOString(rInd[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8).getStr());
     313             :     }
     314           9 :     sax_fastparser::XFastAttributeListRef xAttributeList(pAttributeList);
     315           9 :     m_pSerializer->singleElementNS(XML_w, XML_ind, xAttributeList);
     316             : }
     317             : 
     318         350 : void DocxTableStyleExport::Impl::tableStyleTblInd(uno::Sequence<beans::PropertyValue>& rTblInd)
     319             : {
     320         350 :     if (!rTblInd.hasElements())
     321         350 :         return;
     322             : 
     323         350 :     sax_fastparser::FastAttributeList* pAttributeList = m_pSerializer->createAttrList();
     324        1050 :     for (sal_Int32 i = 0; i < rTblInd.getLength(); ++i)
     325             :     {
     326         700 :         if (rTblInd[i].Name == "w")
     327         350 :             pAttributeList->add(FSNS(XML_w, XML_w), OString::number(rTblInd[i].Value.get<sal_Int32>()));
     328         350 :         else if (rTblInd[i].Name == "type")
     329         350 :             pAttributeList->add(FSNS(XML_w, XML_type), OUStringToOString(rTblInd[i].Value.get<OUString>(), RTL_TEXTENCODING_UTF8).getStr());
     330             :     }
     331         350 :     sax_fastparser::XFastAttributeListRef xAttributeList(pAttributeList);
     332         350 :     m_pSerializer->singleElementNS(XML_w, XML_tblInd, xAttributeList);
     333             : }
     334             : 
     335        1149 : void DocxTableStyleExport::Impl::handleBoolean(const OUString& aValue, sal_Int32 nToken)
     336             : {
     337        1149 :     if (aValue.isEmpty())
     338        2026 :         return;
     339         272 :     sax_fastparser::FastAttributeList* pAttributeList = m_pSerializer->createAttrList();
     340         272 :     if (aValue != "1")
     341          43 :         pAttributeList->add(FSNS(XML_w, XML_val), OUStringToOString(aValue, RTL_TEXTENCODING_UTF8).getStr());
     342         272 :     sax_fastparser::XFastAttributeListRef xAttributeList(pAttributeList);
     343         272 :     m_pSerializer->singleElementNS(XML_w, nToken, xAttributeList);
     344             : }
     345             : 
     346         596 : void DocxTableStyleExport::Impl::tableStyleRPr(uno::Sequence<beans::PropertyValue>& rRPr)
     347             : {
     348         596 :     if (!rRPr.hasElements())
     349         984 :         return;
     350             : 
     351         208 :     m_pSerializer->startElementNS(XML_w, XML_rPr, FSEND);
     352             : 
     353         416 :     uno::Sequence<beans::PropertyValue> aRFonts, aLang, aColor, aSpacingSequence;
     354         208 :     bool bSequenceFlag = false ;
     355         416 :     OUString aB, aBCs, aI, aSz, aSzCs, aCaps, aSmallCaps, aSpacing;
     356         662 :     for (sal_Int32 i = 0; i < rRPr.getLength(); ++i)
     357             :     {
     358         454 :         if (rRPr[i].Name == "rFonts")
     359          33 :             aRFonts = rRPr[i].Value.get< uno::Sequence<beans::PropertyValue> >();
     360         421 :         else if (rRPr[i].Name == "lang")
     361          15 :             aLang = rRPr[i].Value.get< uno::Sequence<beans::PropertyValue> >();
     362         406 :         else if (rRPr[i].Name == "b")
     363         127 :             aB = rRPr[i].Value.get<OUString>();
     364         279 :         else if (rRPr[i].Name == "bCs")
     365         117 :             aBCs = rRPr[i].Value.get<OUString>();
     366         162 :         else if (rRPr[i].Name == "i")
     367          24 :             aI = rRPr[i].Value.get<OUString>();
     368         138 :         else if (rRPr[i].Name == "color")
     369          76 :             aColor = rRPr[i].Value.get< uno::Sequence<beans::PropertyValue> >();
     370          62 :         else if (rRPr[i].Name == "sz")
     371          33 :             aSz = rRPr[i].Value.get<OUString>();
     372          29 :         else if (rRPr[i].Name == "szCs")
     373          25 :             aSzCs = rRPr[i].Value.get<OUString>();
     374           4 :         else if (rRPr[i].Name == "caps")
     375           2 :             aCaps = rRPr[i].Value.get<OUString>();
     376           2 :         else if (rRPr[i].Name == "smallCaps")
     377           1 :             aSmallCaps = rRPr[i].Value.get<OUString>();
     378           1 :         else if (rRPr[i].Name == "spacing")
     379             :         {
     380           1 :             if (rRPr[i].Value.has<OUString>())
     381             :             {
     382           1 :                 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         208 :     tableStyleRRFonts(aRFonts);
     392         208 :     tableStyleRLang(aLang);
     393         208 :     handleBoolean(aB, XML_b);
     394         208 :     handleBoolean(aBCs, XML_bCs);
     395         208 :     handleBoolean(aI, XML_i);
     396         208 :     handleBoolean(aCaps, XML_caps);
     397         208 :     handleBoolean(aSmallCaps, XML_smallCaps);
     398         208 :     tableStyleRColor(aColor);
     399         208 :     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         208 :     if (!aSpacing.isEmpty())
     406             :         m_pSerializer->singleElementNS(XML_w, XML_spacing,
     407             :                                        FSNS(XML_w, XML_val), OUStringToOString(aSpacing, RTL_TEXTENCODING_UTF8).getStr(),
     408           1 :                                        FSEND);
     409         208 :     if (!aSz.isEmpty())
     410             :         m_pSerializer->singleElementNS(XML_w, XML_sz,
     411             :                                        FSNS(XML_w, XML_val), OUStringToOString(aSz, RTL_TEXTENCODING_UTF8).getStr(),
     412          33 :                                        FSEND);
     413         208 :     if (!aSzCs.isEmpty())
     414             :         m_pSerializer->singleElementNS(XML_w, XML_szCs,
     415             :                                        FSNS(XML_w, XML_val), OUStringToOString(aSzCs, RTL_TEXTENCODING_UTF8).getStr(),
     416          25 :                                        FSEND);
     417             : 
     418         416 :     m_pSerializer->endElementNS(XML_w, XML_rPr);
     419             : }
     420             : 
     421         596 : void DocxTableStyleExport::Impl::tableStylePPr(uno::Sequence<beans::PropertyValue>& rPPr)
     422             : {
     423         596 :     if (!rPPr.hasElements())
     424        1083 :         return;
     425             : 
     426         109 :     m_pSerializer->startElementNS(XML_w, XML_pPr, FSEND);
     427             : 
     428         218 :     uno::Sequence<beans::PropertyValue> aSpacing, aInd;
     429         109 :     bool bWordWrap = false;
     430         218 :     OUString aJc, aSnapToGrid;
     431         246 :     for (sal_Int32 i = 0; i < rPPr.getLength(); ++i)
     432             :     {
     433         137 :         if (rPPr[i].Name == "spacing")
     434         106 :             aSpacing = rPPr[i].Value.get< uno::Sequence<beans::PropertyValue> >();
     435          31 :         else if (rPPr[i].Name == "ind")
     436          10 :             aInd = rPPr[i].Value.get< uno::Sequence<beans::PropertyValue> >();
     437          21 :         else if (rPPr[i].Name == "wordWrap")
     438          10 :             bWordWrap = true;
     439          11 :         else if (rPPr[i].Name == "jc")
     440          10 :             aJc = rPPr[i].Value.get<OUString>();
     441           1 :         else if (rPPr[i].Name == "snapToGrid")
     442           1 :             aSnapToGrid = rPPr[i].Value.get<OUString>();
     443             :     }
     444         109 :     if (bWordWrap)
     445          10 :         m_pSerializer->singleElementNS(XML_w, XML_wordWrap, FSEND);
     446         109 :     tableStylePInd(aInd);
     447         109 :     handleBoolean(aSnapToGrid, XML_snapToGrid);
     448         109 :     tableStylePSpacing(aSpacing);
     449         109 :     if (!aJc.isEmpty())
     450             :         m_pSerializer->singleElementNS(XML_w, XML_jc,
     451             :                                        FSNS(XML_w, XML_val), OUStringToOString(aJc, RTL_TEXTENCODING_UTF8).getStr(),
     452          10 :                                        FSEND);
     453             : 
     454         218 :     m_pSerializer->endElementNS(XML_w, XML_pPr);
     455             : }
     456             : 
     457         350 : void DocxTableStyleExport::Impl::tableStyleTblPr(uno::Sequence<beans::PropertyValue>& rTblPr)
     458             : {
     459         350 :     if (!rTblPr.hasElements())
     460         350 :         return;
     461             : 
     462         350 :     m_pSerializer->startElementNS(XML_w, XML_tblPr, FSEND);
     463             : 
     464         700 :     uno::Sequence<beans::PropertyValue> aTblInd, aTblBorders, aTblCellMar;
     465         700 :     boost::optional<sal_Int32> oTblStyleRowBandSize, oTblStyleColBandSize;
     466        1183 :     for (sal_Int32 i = 0; i < rTblPr.getLength(); ++i)
     467             :     {
     468         833 :         if (rTblPr[i].Name == "tblStyleRowBandSize")
     469          17 :             oTblStyleRowBandSize = rTblPr[i].Value.get<sal_Int32>();
     470         816 :         else if (rTblPr[i].Name == "tblStyleColBandSize")
     471          13 :             oTblStyleColBandSize = rTblPr[i].Value.get<sal_Int32>();
     472         803 :         else if (rTblPr[i].Name == "tblInd")
     473         350 :             aTblInd = rTblPr[i].Value.get< uno::Sequence<beans::PropertyValue> >();
     474         453 :         else if (rTblPr[i].Name == "tblBorders")
     475         104 :             aTblBorders = rTblPr[i].Value.get< uno::Sequence<beans::PropertyValue> >();
     476         349 :         else if (rTblPr[i].Name == "tblCellMar")
     477         349 :             aTblCellMar = rTblPr[i].Value.get< uno::Sequence<beans::PropertyValue> >();
     478             :     }
     479         350 :     if (oTblStyleRowBandSize)
     480             :         m_pSerializer->singleElementNS(XML_w, XML_tblStyleRowBandSize,
     481          17 :                                        FSNS(XML_w, XML_val), OString::number(oTblStyleRowBandSize.get()),
     482          17 :                                        FSEND);
     483         350 :     if (oTblStyleColBandSize)
     484             :         m_pSerializer->singleElementNS(XML_w, XML_tblStyleColBandSize,
     485          13 :                                        FSNS(XML_w, XML_val), OString::number(oTblStyleColBandSize.get()),
     486          13 :                                        FSEND);
     487         350 :     tableStyleTblInd(aTblInd);
     488         350 :     tableStyleTcBorders(aTblBorders, XML_tblBorders);
     489         350 :     tableStyleTblCellMar(aTblCellMar);
     490             : 
     491         700 :     m_pSerializer->endElementNS(XML_w, XML_tblPr);
     492             : }
     493             : 
     494         596 : void DocxTableStyleExport::Impl::tableStyleTcPr(uno::Sequence<beans::PropertyValue>& rTcPr)
     495             : {
     496         596 :     if (!rTcPr.hasElements())
     497         938 :         return;
     498             : 
     499         254 :     m_pSerializer->startElementNS(XML_w, XML_tcPr, FSEND);
     500             : 
     501         508 :     uno::Sequence<beans::PropertyValue> aShd, aTcBorders, aTcMar;
     502         508 :     OUString aVAlign;
     503         578 :     for (sal_Int32 i = 0; i < rTcPr.getLength(); ++i)
     504             :     {
     505         324 :         if (rTcPr[i].Name == "shd")
     506         112 :             aShd = rTcPr[i].Value.get< uno::Sequence<beans::PropertyValue> >();
     507         212 :         else if (rTcPr[i].Name == "tcBorders")
     508         200 :             aTcBorders = rTcPr[i].Value.get< uno::Sequence<beans::PropertyValue> >();
     509          12 :         else if (rTcPr[i].Name == "tcMar")
     510           5 :             aTcMar = rTcPr[i].Value.get< uno::Sequence<beans::PropertyValue> >();
     511           7 :         else if (rTcPr[i].Name == "vAlign")
     512           7 :             aVAlign = rTcPr[i].Value.get<OUString>();
     513             :     }
     514         254 :     tableStyleTcBorders(aTcBorders);
     515         254 :     tableStyleTblCellMar(aTcMar, XML_tcMar);
     516         254 :     tableStyleShd(aShd);
     517         254 :     if (!aVAlign.isEmpty())
     518             :         m_pSerializer->singleElementNS(XML_w, XML_vAlign,
     519             :                                        FSNS(XML_w, XML_val), OUStringToOString(aVAlign, RTL_TEXTENCODING_UTF8).getStr(),
     520           7 :                                        FSEND);
     521             : 
     522         508 :     m_pSerializer->endElementNS(XML_w, XML_tcPr);
     523             : }
     524             : 
     525         246 : void DocxTableStyleExport::Impl::tableStyleTblStylePr(uno::Sequence<beans::PropertyValue>& rTblStylePr)
     526             : {
     527         246 :     if (!rTblStylePr.hasElements())
     528         246 :         return;
     529             : 
     530         246 :     OUString aType;
     531         492 :     uno::Sequence<beans::PropertyValue> aPPr, aRPr, aTblPr, aTcPr;
     532        1118 :     for (sal_Int32 i = 0; i < rTblStylePr.getLength(); ++i)
     533             :     {
     534         872 :         if (rTblStylePr[i].Name == "type")
     535         246 :             aType = rTblStylePr[i].Value.get<OUString>();
     536         626 :         else if (rTblStylePr[i].Name == "pPr")
     537          20 :             aPPr = rTblStylePr[i].Value.get< uno::Sequence<beans::PropertyValue> >();
     538         606 :         else if (rTblStylePr[i].Name == "rPr")
     539         172 :             aRPr = rTblStylePr[i].Value.get< uno::Sequence<beans::PropertyValue> >();
     540         434 :         else if (rTblStylePr[i].Name == "tblPr")
     541         217 :             aTblPr = rTblStylePr[i].Value.get< uno::Sequence<beans::PropertyValue> >();
     542         217 :         else if (rTblStylePr[i].Name == "tcPr")
     543         217 :             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         246 :                                   FSEND);
     549             : 
     550         246 :     tableStylePPr(aPPr);
     551         246 :     tableStyleRPr(aRPr);
     552         246 :     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         246 :         m_pSerializer->singleElementNS(XML_w, XML_tblPr, FSEND);
     558             :     }
     559         246 :     tableStyleTcPr(aTcPr);
     560             : 
     561         492 :     m_pSerializer->endElementNS(XML_w, XML_tblStylePr);
     562             : }
     563             : 
     564         350 : void DocxTableStyleExport::Impl::TableStyle(uno::Sequence<beans::PropertyValue>& rStyle)
     565             : {
     566         350 :     bool bDefault = false, bCustomStyle = false, bQFormat = false, bSemiHidden = false, bUnhideWhenUsed = false;
     567         700 :     OUString aStyleId, aName, aBasedOn, aRsid, aUiPriority;
     568         700 :     uno::Sequence<beans::PropertyValue> aPPr, aRPr, aTblPr, aTcPr;
     569         700 :     std::vector< uno::Sequence<beans::PropertyValue> > aTblStylePrs;
     570        3097 :     for (sal_Int32 i = 0; i < rStyle.getLength(); ++i)
     571             :     {
     572        2747 :         if (rStyle[i].Name == "default")
     573         231 :             bDefault = rStyle[i].Value.get<sal_Bool>();
     574        2516 :         else if (rStyle[i].Name == "customStyle")
     575          28 :             bCustomStyle = rStyle[i].Value.get<sal_Bool>();
     576        2488 :         else if (rStyle[i].Name == "styleId")
     577         350 :             aStyleId = rStyle[i].Value.get<OUString>();
     578        2138 :         else if (rStyle[i].Name == "name")
     579         350 :             aName = rStyle[i].Value.get<OUString>();
     580        1788 :         else if (rStyle[i].Name == "basedOn")
     581         119 :             aBasedOn = rStyle[i].Value.get<OUString>();
     582        1669 :         else if (rStyle[i].Name == "uiPriority")
     583         274 :             aUiPriority = rStyle[i].Value.get<OUString>();
     584        1395 :         else if (rStyle[i].Name == "qFormat")
     585          54 :             bQFormat = true;
     586        1341 :         else if (rStyle[i].Name == "semiHidden")
     587         230 :             bSemiHidden = true;
     588        1111 :         else if (rStyle[i].Name == "unhideWhenUsed")
     589         230 :             bUnhideWhenUsed = true;
     590         881 :         else if (rStyle[i].Name == "rsid")
     591         119 :             aRsid = rStyle[i].Value.get<OUString>();
     592         762 :         else if (rStyle[i].Name == "pPr")
     593          91 :             aPPr = rStyle[i].Value.get< uno::Sequence<beans::PropertyValue> >();
     594         671 :         else if (rStyle[i].Name == "rPr")
     595          36 :             aRPr = rStyle[i].Value.get< uno::Sequence<beans::PropertyValue> >();
     596         635 :         else if (rStyle[i].Name == "tblPr")
     597         350 :             aTblPr = rStyle[i].Value.get< uno::Sequence<beans::PropertyValue> >();
     598         285 :         else if (rStyle[i].Name == "tcPr")
     599          38 :             aTcPr = rStyle[i].Value.get< uno::Sequence<beans::PropertyValue> >();
     600         247 :         else if (rStyle[i].Name == "tblStylePr")
     601         246 :             aTblStylePrs.push_back(rStyle[i].Value.get< uno::Sequence<beans::PropertyValue> >());
     602             :     }
     603             : 
     604         350 :     sax_fastparser::FastAttributeList* pAttributeList = m_pSerializer->createAttrList();
     605         350 :     pAttributeList->add(FSNS(XML_w, XML_type), "table");
     606         350 :     if (bDefault)
     607         231 :         pAttributeList->add(FSNS(XML_w, XML_default), "1");
     608         350 :     if (bCustomStyle)
     609          28 :         pAttributeList->add(FSNS(XML_w, XML_customStyle), "1");
     610         350 :     if (!aStyleId.isEmpty())
     611         350 :         pAttributeList->add(FSNS(XML_w, XML_styleId), OUStringToOString(aStyleId, RTL_TEXTENCODING_UTF8).getStr());
     612         700 :     sax_fastparser::XFastAttributeListRef xAttributeList(pAttributeList);
     613         350 :     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         350 :                                    FSEND);
     618         350 :     if (!aBasedOn.isEmpty())
     619             :         m_pSerializer->singleElementNS(XML_w, XML_basedOn,
     620             :                                        FSNS(XML_w, XML_val), OUStringToOString(aBasedOn, RTL_TEXTENCODING_UTF8).getStr(),
     621         119 :                                        FSEND);
     622         350 :     if (!aUiPriority.isEmpty())
     623             :         m_pSerializer->singleElementNS(XML_w, XML_uiPriority,
     624             :                                        FSNS(XML_w, XML_val), OUStringToOString(aUiPriority, RTL_TEXTENCODING_UTF8).getStr(),
     625         274 :                                        FSEND);
     626         350 :     if (bSemiHidden)
     627         230 :         m_pSerializer->singleElementNS(XML_w, XML_semiHidden, FSEND);
     628         350 :     if (bUnhideWhenUsed)
     629         230 :         m_pSerializer->singleElementNS(XML_w, XML_unhideWhenUsed, FSEND);
     630         350 :     if (bQFormat)
     631          54 :         m_pSerializer->singleElementNS(XML_w, XML_qFormat, FSEND);
     632         350 :     if (!aRsid.isEmpty())
     633             :         m_pSerializer->singleElementNS(XML_w, XML_rsid,
     634             :                                        FSNS(XML_w, XML_val), OUStringToOString(aRsid, RTL_TEXTENCODING_UTF8).getStr(),
     635         119 :                                        FSEND);
     636             : 
     637         350 :     tableStylePPr(aPPr);
     638         350 :     tableStyleRPr(aRPr);
     639         350 :     tableStyleTblPr(aTblPr);
     640         350 :     tableStyleTcPr(aTcPr);
     641         596 :     for (size_t i = 0; i < aTblStylePrs.size(); ++i)
     642         246 :         tableStyleTblStylePr(aTblStylePrs[i]);
     643             : 
     644         700 :     m_pSerializer->endElementNS(XML_w, XML_style);
     645         350 : }
     646             : 
     647        1468 : void DocxTableStyleExport::SetSerializer(sax_fastparser::FSHelperPtr pSerializer)
     648             : {
     649        1468 :     m_pImpl->m_pSerializer = pSerializer;
     650        1468 : }
     651             : 
     652         272 : DocxTableStyleExport::DocxTableStyleExport(SwDoc* pDoc, sax_fastparser::FSHelperPtr pSerializer)
     653         272 :     : m_pImpl(new Impl)
     654             : {
     655         272 :     m_pImpl->m_pDoc = pDoc;
     656         272 :     m_pImpl->m_pSerializer = pSerializer;
     657         272 : }
     658             : 
     659         272 : DocxTableStyleExport::~DocxTableStyleExport()
     660             : {
     661         305 : }
     662             : 
     663             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10