LCOV - code coverage report
Current view: top level - xmloff/source/text - txtdropi.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 35 45 77.8 %
Date: 2014-11-03 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          14 : void XMLTextDropCapImportContext::ProcessAttrs(
      61             :         const Reference< xml::sax::XAttributeList >& xAttrList )
      62             : {
      63          14 :     SvXMLTokenMap aTokenMap( aDropAttrTokenMap );
      64             : 
      65          14 :     DropCapFormat aFormat;
      66          14 :     sal_Bool bWholeWord = sal_False;
      67             : 
      68             :     sal_Int32 nTmp;
      69          14 :     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
      70          38 :     for( sal_Int16 i=0; i < nAttrCount; i++ )
      71             :     {
      72          24 :         const OUString& rAttrName = xAttrList->getNameByIndex( i );
      73          48 :         OUString aLocalName;
      74             :         sal_uInt16 nPrefix =
      75          24 :             GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
      76          24 :                                                             &aLocalName );
      77          48 :         const OUString& rValue = xAttrList->getValueByIndex( i );
      78             : 
      79          24 :         switch( aTokenMap.Get( nPrefix, aLocalName ) )
      80             :         {
      81             :         case XML_TOK_DROP_LINES:
      82          12 :             if (::sax::Converter::convertNumber( nTmp, rValue, 0, 255 ))
      83             :             {
      84          12 :                 aFormat.Lines = nTmp < 2 ? 0 : (sal_Int8)nTmp;
      85             :             }
      86          12 :             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          12 :             sStyleName = rValue;
     110          12 :             break;
     111             :         }
     112          24 :     }
     113             : 
     114          14 :     if( aFormat.Lines > 1 && aFormat.Count < 1 )
     115          12 :         aFormat.Count = 1;
     116             : 
     117          14 :     aProp.maValue <<= aFormat;
     118             : 
     119          14 :     aWholeWordProp.maValue.setValue( &bWholeWord, ::getBooleanCppuType() );
     120          14 : }
     121             : 
     122          14 : 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          14 :     aWholeWordProp( nWholeWordIdx )
     131             : {
     132          14 :     ProcessAttrs( xAttrList );
     133          14 : }
     134             : 
     135          28 : XMLTextDropCapImportContext::~XMLTextDropCapImportContext()
     136             : {
     137          28 : }
     138             : 
     139          14 : void XMLTextDropCapImportContext::EndElement()
     140             : {
     141          14 :     SetInsert( true );
     142          14 :     XMLElementPropertyContext::EndElement();
     143             : 
     144          14 :     if( -1 != aWholeWordProp.mnIndex )
     145          14 :         rProperties.push_back( aWholeWordProp );
     146          14 : }
     147             : 
     148             : 
     149             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10