LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/xmloff/source/style - XMLFootnoteSeparatorImport.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 75 76 98.7 %
Date: 2013-07-09 Functions: 4 9 44.4 %
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             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : 
      21             : #include "XMLFootnoteSeparatorImport.hxx"
      22             : 
      23             : #include <rtl/ustring.hxx>
      24             : 
      25             : #include <com/sun/star/uno/Reference.h>
      26             : #include <com/sun/star/xml/sax/XAttributeList.hpp>
      27             : #include <com/sun/star/text/HorizontalAdjust.hpp>
      28             : 
      29             : #include <tools/debug.hxx>
      30             : 
      31             : #include <sax/tools/converter.hxx>
      32             : 
      33             : #include <xmloff/xmlimp.hxx>
      34             : #include <xmloff/xmltoken.hxx>
      35             : #include <xmloff/xmluconv.hxx>
      36             : #include <xmloff/xmlprmap.hxx>
      37             : #include "xmloff/xmlnmspe.hxx"
      38             : #include <xmloff/nmspmap.hxx>
      39             : #include <xmloff/maptype.hxx>
      40             : 
      41             : #include <xmloff/PageMasterStyleMap.hxx>
      42             : 
      43             : #include <vector>
      44             : 
      45             : 
      46             : using namespace ::com::sun::star;
      47             : using namespace ::xmloff::token;
      48             : 
      49             : using ::std::vector;
      50             : using ::com::sun::star::uno::Any;
      51             : using ::com::sun::star::uno::Reference;
      52             : using ::com::sun::star::xml::sax::XAttributeList;
      53             : 
      54             : 
      55           0 : TYPEINIT1(XMLFootnoteSeparatorImport, SvXMLImportContext);
      56             : 
      57             : 
      58          69 : XMLFootnoteSeparatorImport::XMLFootnoteSeparatorImport(
      59             :     SvXMLImport& rImport,
      60             :     sal_uInt16 nPrefix,
      61             :     const OUString& rLocalName,
      62             :     vector<XMLPropertyState> & rProps,
      63             :     const UniReference<XMLPropertySetMapper> & rMapperRef,
      64             :     sal_Int32 nIndex) :
      65             :         SvXMLImportContext(rImport, nPrefix, rLocalName),
      66             :         rProperties(rProps),
      67             :         rMapper(rMapperRef),
      68          69 :         nPropIndex(nIndex)
      69             : {
      70          69 : }
      71             : 
      72         138 : XMLFootnoteSeparatorImport::~XMLFootnoteSeparatorImport()
      73             : {
      74         138 : }
      75             : 
      76          69 : void XMLFootnoteSeparatorImport::StartElement(
      77             :     const Reference<XAttributeList> & xAttrList)
      78             : {
      79             :     // get the values from the properties
      80          69 :     sal_Int16 nLineWeight = 0;
      81          69 :     sal_Int32 nLineColor = 0;
      82          69 :     sal_Int8 nLineRelWidth = 0;
      83          69 :     sal_Int16 eLineAdjust = text::HorizontalAdjust_LEFT; // enum text::HorizontalAdjust
      84          69 :     sal_Int32 nLineTextDistance = 0;
      85          69 :     sal_Int32 nLineDistance = 0;
      86          69 :     sal_Int8 nLineStyle = 0;
      87             : 
      88             :     // iterate over xattribute list and fill values
      89          69 :     sal_Int16 nLength = xAttrList->getLength();
      90         529 :     for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
      91             :     {
      92         460 :         OUString sLocalName;
      93         460 :         sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
      94         460 :             GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
      95         920 :                               &sLocalName );
      96             : 
      97         460 :         if (XML_NAMESPACE_STYLE == nPrefix)
      98             :         {
      99         460 :             OUString sAttrValue = xAttrList->getValueByIndex(nAttr);
     100             :             sal_Int32 nTmp;
     101         460 :             if (IsXMLToken( sLocalName, XML_WIDTH ))
     102             :             {
     103          67 :                 if (GetImport().GetMM100UnitConverter().convertMeasureToCore(
     104             :                     nTmp, sAttrValue))
     105             :                 {
     106          67 :                     nLineWeight = (sal_Int16)nTmp;
     107             :                 }
     108             :             }
     109         393 :             else if (IsXMLToken( sLocalName, XML_DISTANCE_BEFORE_SEP ))
     110             :             {
     111          67 :                 if (GetImport().GetMM100UnitConverter().convertMeasureToCore(
     112             :                                                         nTmp, sAttrValue))
     113          67 :                     nLineTextDistance = nTmp;
     114             :             }
     115         326 :             else if (IsXMLToken( sLocalName, XML_DISTANCE_AFTER_SEP ))
     116             :             {
     117          67 :                 if (GetImport().GetMM100UnitConverter().convertMeasureToCore(
     118             :                                                         nTmp, sAttrValue))
     119          67 :                     nLineDistance = nTmp;
     120             :             }
     121         259 :             else if (IsXMLToken( sLocalName, XML_ADJUSTMENT ))
     122             :             {
     123             :                 sal_uInt16 nTmpU;
     124             :                 static const SvXMLEnumMapEntry aXML_HorizontalAdjust_Enum[] =
     125             :                 {
     126             :                     { XML_LEFT,     text::HorizontalAdjust_LEFT },
     127             :                     { XML_CENTER,   text::HorizontalAdjust_CENTER },
     128             :                     { XML_RIGHT,    text::HorizontalAdjust_RIGHT },
     129             :                     { XML_TOKEN_INVALID, 0 }
     130             :                 };
     131             : 
     132          69 :                 if (SvXMLUnitConverter::convertEnum(
     133          69 :                             nTmpU, sAttrValue, aXML_HorizontalAdjust_Enum))
     134          69 :                     eLineAdjust = (sal_Int16)nTmpU;
     135             :             }
     136         190 :             else if (IsXMLToken( sLocalName, XML_REL_WIDTH ))
     137             :             {
     138          69 :                 if (::sax::Converter::convertPercent(nTmp, sAttrValue))
     139          69 :                     nLineRelWidth = (sal_uInt8)nTmp;
     140             :             }
     141         121 :             else if (IsXMLToken( sLocalName, XML_COLOR ))
     142             :             {
     143          69 :                 if (::sax::Converter::convertColor(nTmp, sAttrValue))
     144             :                 {
     145          69 :                     nLineColor = nTmp;
     146             :                 }
     147             :             }
     148          52 :             else if (IsXMLToken( sLocalName, XML_LINE_STYLE ))
     149             :             {
     150             :                 sal_uInt16 nTmpU;
     151             :                 static const SvXMLEnumMapEntry aXML_LineStyle_Enum[] =
     152             :                 {
     153             :                     { XML_NONE,     0 },
     154             :                     { XML_SOLID,    1 },
     155             :                     { XML_DOTTED,   2 },
     156             :                     { XML_DASH,     3 },
     157             :                     { XML_TOKEN_INVALID, 0 }
     158             :                 };
     159             : 
     160          52 :                 if (SvXMLUnitConverter::convertEnum(
     161          52 :                             nTmpU, sAttrValue, aXML_LineStyle_Enum))
     162          52 :                     nLineStyle = (sal_Int8)nTmpU;
     163             : 
     164         460 :             }
     165             :         }
     166         460 :     }
     167             : 
     168             :     // OK, now we have all values and can fill the XMLPropertyState vector
     169          69 :     Any aAny;
     170             :     sal_Int32 nIndex;
     171             : 
     172          69 :     aAny <<= eLineAdjust;
     173          69 :     nIndex = rMapper->FindEntryIndex(CTF_PM_FTN_LINE_ADJUST);
     174         138 :     XMLPropertyState aLineAdjust( nIndex, aAny);
     175          69 :     rProperties.push_back(aLineAdjust);
     176             : 
     177          69 :     aAny <<= nLineColor;
     178          69 :     nIndex = rMapper->FindEntryIndex(CTF_PM_FTN_LINE_COLOR);
     179         138 :     XMLPropertyState aLineColor( nIndex, aAny );
     180          69 :     rProperties.push_back(aLineColor);
     181             : 
     182          69 :     aAny <<= nLineStyle;
     183          69 :     nIndex = rMapper->FindEntryIndex(CTF_PM_FTN_LINE_STYLE);
     184         138 :     XMLPropertyState aLineStyle( nIndex, aAny );
     185          69 :     rProperties.push_back(aLineStyle);
     186             : 
     187          69 :     aAny <<= nLineDistance;
     188          69 :     nIndex = rMapper->FindEntryIndex(CTF_PM_FTN_DISTANCE);
     189         138 :     XMLPropertyState aLineDistance( nIndex, aAny );
     190          69 :     rProperties.push_back(aLineDistance);
     191             : 
     192          69 :     aAny <<= nLineRelWidth;
     193          69 :     nIndex = rMapper->FindEntryIndex(CTF_PM_FTN_LINE_WIDTH);
     194         138 :     XMLPropertyState aLineRelWidth( nIndex, aAny);
     195          69 :     rProperties.push_back(aLineRelWidth);
     196             : 
     197          69 :     aAny <<= nLineTextDistance;
     198          69 :     nIndex = rMapper->FindEntryIndex(CTF_PM_FTN_LINE_DISTANCE);
     199         138 :     XMLPropertyState aLineTextDistance( nIndex, aAny);
     200          69 :     rProperties.push_back(aLineTextDistance);
     201             : 
     202             :     DBG_ASSERT( rMapper->FindEntryIndex(CTF_PM_FTN_LINE_WEIGHT) == nPropIndex,
     203             :                 "Received wrong property map index!" );
     204          69 :     aAny <<= nLineWeight;
     205         138 :     XMLPropertyState aLineWeight( nPropIndex, aAny );
     206         138 :     rProperties.push_back(aLineWeight);
     207          69 : }
     208             : 
     209             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10