LCOV - code coverage report
Current view: top level - xmloff/source/text - txtdropi.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 35 45 77.8 %
Date: 2015-06-13 12:38:46 Functions: 5 10 50.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             :  * 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 "txtdropi.hxx"
      22             : 
      23             : #include <com/sun/star/style/DropCapFormat.hpp>
      24             : 
      25             : #include <sax/tools/converter.hxx>
      26             : 
      27             : #include <xmloff/xmltkmap.hxx>
      28             : #include <xmloff/xmluconv.hxx>
      29             : #include <xmloff/nmspmap.hxx>
      30             : #include <xmloff/xmlnmspe.hxx>
      31             : #include <xmloff/xmlimp.hxx>
      32             : #include <xmloff/xmltoken.hxx>
      33             : 
      34             : 
      35             : using namespace ::com::sun::star;
      36             : using namespace ::com::sun::star::uno;
      37             : using namespace ::com::sun::star::style;
      38             : using namespace ::xmloff::token;
      39             : 
      40             : 
      41             : enum SvXMLTokenMapDropAttrs
      42             : {
      43             :     XML_TOK_DROP_LINES,
      44             :     XML_TOK_DROP_LENGTH,
      45             :     XML_TOK_DROP_DISTANCE,
      46             :     XML_TOK_DROP_STYLE,
      47             :     XML_TOK_DROP_END=XML_TOK_UNKNOWN
      48             : };
      49             : 
      50             : static const SvXMLTokenMapEntry aDropAttrTokenMap[] =
      51             : {
      52             :     { XML_NAMESPACE_STYLE, XML_LINES,       XML_TOK_DROP_LINES  },
      53             :     { XML_NAMESPACE_STYLE, XML_LENGTH,      XML_TOK_DROP_LENGTH },
      54             :     { XML_NAMESPACE_STYLE, XML_DISTANCE,    XML_TOK_DROP_DISTANCE   },
      55             :     { XML_NAMESPACE_STYLE, XML_STYLE_NAME,  XML_TOK_DROP_STYLE  },
      56             :     XML_TOKEN_MAP_END
      57             : };
      58             : 
      59           0 : TYPEINIT1( XMLTextDropCapImportContext, XMLElementPropertyContext );
      60          11 : void XMLTextDropCapImportContext::ProcessAttrs(
      61             :         const Reference< xml::sax::XAttributeList >& xAttrList )
      62             : {
      63          11 :     SvXMLTokenMap aTokenMap( aDropAttrTokenMap );
      64             : 
      65          11 :     DropCapFormat aFormat;
      66          11 :     sal_Bool bWholeWord = sal_False;
      67             : 
      68             :     sal_Int32 nTmp;
      69          11 :     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
      70          26 :     for( sal_Int16 i=0; i < nAttrCount; i++ )
      71             :     {
      72          15 :         const OUString& rAttrName = xAttrList->getNameByIndex( i );
      73          30 :         OUString aLocalName;
      74             :         sal_uInt16 nPrefix =
      75          15 :             GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
      76          15 :                                                             &aLocalName );
      77          30 :         const OUString& rValue = xAttrList->getValueByIndex( i );
      78             : 
      79          15 :         switch( aTokenMap.Get( nPrefix, aLocalName ) )
      80             :         {
      81             :         case XML_TOK_DROP_LINES:
      82           9 :             if (::sax::Converter::convertNumber( nTmp, rValue, 0, 255 ))
      83             :             {
      84           9 :                 aFormat.Lines = nTmp < 2 ? 0 : (sal_Int8)nTmp;
      85             :             }
      86           9 :             break;
      87             : 
      88             :         case XML_TOK_DROP_LENGTH:
      89           0 :             if( IsXMLToken( rValue, XML_WORD ) )
      90             :             {
      91           0 :                 bWholeWord = sal_True;
      92             :             }
      93           0 :             else if (::sax::Converter::convertNumber( nTmp, rValue, 1, 255 ))
      94             :             {
      95           0 :                 bWholeWord = sal_False;
      96           0 :                 aFormat.Count = (sal_Int8)nTmp;
      97             :             }
      98           0 :             break;
      99             : 
     100             :         case XML_TOK_DROP_DISTANCE:
     101           0 :             if (GetImport().GetMM100UnitConverter().convertMeasureToCore(
     102             :                         nTmp, rValue, 0 ))
     103             :             {
     104           0 :                 aFormat.Distance = (sal_uInt16)nTmp;
     105             :             }
     106           0 :             break;
     107             : 
     108             :         case XML_TOK_DROP_STYLE:
     109           6 :             sStyleName = rValue;
     110           6 :             break;
     111             :         }
     112          15 :     }
     113             : 
     114          11 :     if( aFormat.Lines > 1 && aFormat.Count < 1 )
     115           9 :         aFormat.Count = 1;
     116             : 
     117          11 :     aProp.maValue <<= aFormat;
     118             : 
     119          11 :     aWholeWordProp.maValue.setValue( &bWholeWord, cppu::UnoType<bool>::get() );
     120          11 : }
     121             : 
     122          11 : XMLTextDropCapImportContext::XMLTextDropCapImportContext(
     123             :         SvXMLImport& rImport, sal_uInt16 nPrfx,
     124             :         const OUString& rLName,
     125             :         const Reference< xml::sax::XAttributeList > & xAttrList,
     126             :         const XMLPropertyState& rProp,
     127             :         sal_Int32 nWholeWordIdx,
     128             :         ::std::vector< XMLPropertyState > &rProps ) :
     129             :     XMLElementPropertyContext( rImport, nPrfx, rLName, rProp, rProps ),
     130          11 :     aWholeWordProp( nWholeWordIdx )
     131             : {
     132          11 :     ProcessAttrs( xAttrList );
     133          11 : }
     134             : 
     135          22 : XMLTextDropCapImportContext::~XMLTextDropCapImportContext()
     136             : {
     137          22 : }
     138             : 
     139          11 : void XMLTextDropCapImportContext::EndElement()
     140             : {
     141          11 :     SetInsert( true );
     142          11 :     XMLElementPropertyContext::EndElement();
     143             : 
     144          11 :     if( -1 != aWholeWordProp.mnIndex )
     145          11 :         rProperties.push_back( aWholeWordProp );
     146          11 : }
     147             : 
     148             : 
     149             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11