LCOV - code coverage report
Current view: top level - xmloff/source/style - XMLFootnoteSeparatorImport.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 73 74 98.6 %
Date: 2015-06-13 12:38:46 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         648 : XMLFootnoteSeparatorImport::XMLFootnoteSeparatorImport(
      59             :     SvXMLImport& rImport,
      60             :     sal_uInt16 nPrefix,
      61             :     const OUString& rLocalName,
      62             :     vector<XMLPropertyState> & rProps,
      63             :     const rtl::Reference<XMLPropertySetMapper> & rMapperRef,
      64             :     sal_Int32 nIndex) :
      65             :         SvXMLImportContext(rImport, nPrefix, rLocalName),
      66             :         rProperties(rProps),
      67             :         rMapper(rMapperRef),
      68         648 :         nPropIndex(nIndex)
      69             : {
      70         648 : }
      71             : 
      72        1296 : XMLFootnoteSeparatorImport::~XMLFootnoteSeparatorImport()
      73             : {
      74        1296 : }
      75             : 
      76         648 : void XMLFootnoteSeparatorImport::StartElement(
      77             :     const Reference<XAttributeList> & xAttrList)
      78             : {
      79             :     // get the values from the properties
      80         648 :     sal_Int16 nLineWeight = 0;
      81         648 :     sal_Int32 nLineColor = 0;
      82         648 :     sal_Int8 nLineRelWidth = 0;
      83         648 :     sal_Int16 eLineAdjust = text::HorizontalAdjust_LEFT; // enum text::HorizontalAdjust
      84         648 :     sal_Int32 nLineTextDistance = 0;
      85         648 :     sal_Int32 nLineDistance = 0;
      86         648 :     sal_Int8 nLineStyle = 0;
      87             : 
      88             :     // iterate over xattribute list and fill values
      89         648 :     sal_Int16 nLength = xAttrList->getLength();
      90        4607 :     for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
      91             :     {
      92        3959 :         OUString sLocalName;
      93        3959 :         sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
      94        3959 :             GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
      95        7918 :                               &sLocalName );
      96             : 
      97        3959 :         if (XML_NAMESPACE_STYLE == nPrefix)
      98             :         {
      99        3959 :             OUString sAttrValue = xAttrList->getValueByIndex(nAttr);
     100             :             sal_Int32 nTmp;
     101        3959 :             if (IsXMLToken( sLocalName, XML_WIDTH ))
     102             :             {
     103         549 :                 if (GetImport().GetMM100UnitConverter().convertMeasureToCore(
     104             :                     nTmp, sAttrValue))
     105             :                 {
     106         549 :                     nLineWeight = (sal_Int16)nTmp;
     107             :                 }
     108             :             }
     109        3410 :             else if (IsXMLToken( sLocalName, XML_DISTANCE_BEFORE_SEP ))
     110             :             {
     111         549 :                 if (GetImport().GetMM100UnitConverter().convertMeasureToCore(
     112             :                                                         nTmp, sAttrValue))
     113         549 :                     nLineTextDistance = nTmp;
     114             :             }
     115        2861 :             else if (IsXMLToken( sLocalName, XML_DISTANCE_AFTER_SEP ))
     116             :             {
     117         549 :                 if (GetImport().GetMM100UnitConverter().convertMeasureToCore(
     118             :                                                         nTmp, sAttrValue))
     119         549 :                     nLineDistance = nTmp;
     120             :             }
     121        2312 :             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         648 :                 if (SvXMLUnitConverter::convertEnum(
     133             :                             nTmpU, sAttrValue, aXML_HorizontalAdjust_Enum))
     134         648 :                     eLineAdjust = (sal_Int16)nTmpU;
     135             :             }
     136        1664 :             else if (IsXMLToken( sLocalName, XML_REL_WIDTH ))
     137             :             {
     138         648 :                 if (::sax::Converter::convertPercent(nTmp, sAttrValue))
     139         648 :                     nLineRelWidth = (sal_uInt8)nTmp;
     140             :             }
     141        1016 :             else if (IsXMLToken( sLocalName, XML_COLOR ))
     142             :             {
     143         648 :                 if (::sax::Converter::convertColor(nTmp, sAttrValue))
     144             :                 {
     145         648 :                     nLineColor = nTmp;
     146             :                 }
     147             :             }
     148         368 :             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         368 :                 if (SvXMLUnitConverter::convertEnum(
     161             :                             nTmpU, sAttrValue, aXML_LineStyle_Enum))
     162         368 :                     nLineStyle = (sal_Int8)nTmpU;
     163             : 
     164        3959 :             }
     165             :         }
     166        3959 :     }
     167             : 
     168             :     // OK, now we have all values and can fill the XMLPropertyState vector
     169         648 :     Any aAny;
     170             :     sal_Int32 nIndex;
     171             : 
     172         648 :     aAny <<= eLineAdjust;
     173         648 :     nIndex = rMapper->FindEntryIndex(CTF_PM_FTN_LINE_ADJUST);
     174        1296 :     XMLPropertyState aLineAdjust( nIndex, aAny);
     175         648 :     rProperties.push_back(aLineAdjust);
     176             : 
     177         648 :     aAny <<= nLineColor;
     178         648 :     nIndex = rMapper->FindEntryIndex(CTF_PM_FTN_LINE_COLOR);
     179        1296 :     XMLPropertyState aLineColor( nIndex, aAny );
     180         648 :     rProperties.push_back(aLineColor);
     181             : 
     182         648 :     aAny <<= nLineStyle;
     183         648 :     nIndex = rMapper->FindEntryIndex(CTF_PM_FTN_LINE_STYLE);
     184        1296 :     XMLPropertyState aLineStyle( nIndex, aAny );
     185         648 :     rProperties.push_back(aLineStyle);
     186             : 
     187         648 :     aAny <<= nLineDistance;
     188         648 :     nIndex = rMapper->FindEntryIndex(CTF_PM_FTN_DISTANCE);
     189        1296 :     XMLPropertyState aLineDistance( nIndex, aAny );
     190         648 :     rProperties.push_back(aLineDistance);
     191             : 
     192         648 :     aAny <<= nLineRelWidth;
     193         648 :     nIndex = rMapper->FindEntryIndex(CTF_PM_FTN_LINE_WIDTH);
     194        1296 :     XMLPropertyState aLineRelWidth( nIndex, aAny);
     195         648 :     rProperties.push_back(aLineRelWidth);
     196             : 
     197         648 :     aAny <<= nLineTextDistance;
     198         648 :     nIndex = rMapper->FindEntryIndex(CTF_PM_FTN_LINE_DISTANCE);
     199        1296 :     XMLPropertyState aLineTextDistance( nIndex, aAny);
     200         648 :     rProperties.push_back(aLineTextDistance);
     201             : 
     202             :     DBG_ASSERT( rMapper->FindEntryIndex(CTF_PM_FTN_LINE_WEIGHT) == nPropIndex,
     203             :                 "Received wrong property map index!" );
     204         648 :     aAny <<= nLineWeight;
     205        1296 :     XMLPropertyState aLineWeight( nPropIndex, aAny );
     206        1296 :     rProperties.push_back(aLineWeight);
     207         648 : }
     208             : 
     209             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11