LCOV - code coverage report
Current view: top level - xmloff/source/text - XMLIndexTabStopEntryContext.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 48 53 90.6 %
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 "XMLIndexTabStopEntryContext.hxx"
      22             : 
      23             : #include <sax/tools/converter.hxx>
      24             : 
      25             : #include "XMLIndexTemplateContext.hxx"
      26             : #include <xmloff/xmlictxt.hxx>
      27             : #include <xmloff/xmlimp.hxx>
      28             : #include <xmloff/txtimp.hxx>
      29             : #include <xmloff/nmspmap.hxx>
      30             : #include <xmloff/xmlnmspe.hxx>
      31             : #include <xmloff/xmltoken.hxx>
      32             : #include <xmloff/xmluconv.hxx>
      33             : #include <rtl/ustring.hxx>
      34             : #include <tools/debug.hxx>
      35             : 
      36             : using namespace ::xmloff::token;
      37             : 
      38             : using ::com::sun::star::uno::Sequence;
      39             : using ::com::sun::star::uno::Reference;
      40             : using ::com::sun::star::uno::Any;
      41             : using ::com::sun::star::beans::PropertyValue;
      42             : using ::com::sun::star::xml::sax::XAttributeList;
      43             : 
      44             : 
      45           0 : TYPEINIT1( XMLIndexTabStopEntryContext, XMLIndexSimpleEntryContext );
      46             : 
      47         121 : XMLIndexTabStopEntryContext::XMLIndexTabStopEntryContext(
      48             :     SvXMLImport& rImport,
      49             :     XMLIndexTemplateContext& rTemplate,
      50             :     sal_uInt16 nPrfx,
      51             :     const OUString& rLocalName ) :
      52             :         XMLIndexSimpleEntryContext(rImport, rTemplate.sTokenTabStop,
      53             :                                    rTemplate, nPrfx, rLocalName),
      54             :         sLeaderChar(),
      55             :         nTabPosition(0),
      56             :         bTabPositionOK(false),
      57             :         bTabRightAligned(false),
      58             :         bLeaderCharOK(false),
      59         121 :         bWithTab(true) // #i21237#
      60             : {
      61         121 : }
      62             : 
      63         242 : XMLIndexTabStopEntryContext::~XMLIndexTabStopEntryContext()
      64             : {
      65         242 : }
      66             : 
      67         121 : void XMLIndexTabStopEntryContext::StartElement(
      68             :     const Reference<XAttributeList> & xAttrList)
      69             : {
      70             :     // process three attributes: type, position, leader char
      71         121 :     sal_Int16 nLength = xAttrList->getLength();
      72         372 :     for(sal_Int16 nAttr = 0; nAttr < nLength; nAttr++)
      73             :     {
      74         251 :         OUString sLocalName;
      75         251 :         sal_uInt16 nPrefix = GetImport().GetNamespaceMap().
      76         251 :             GetKeyByAttrName( xAttrList->getNameByIndex(nAttr),
      77         502 :                               &sLocalName );
      78         502 :         OUString sAttr = xAttrList->getValueByIndex(nAttr);
      79         251 :         if (XML_NAMESPACE_STYLE == nPrefix)
      80             :         {
      81         251 :             if ( IsXMLToken( sLocalName, XML_TYPE ) )
      82             :             {
      83             :                 // if it's neither left nor right, value is
      84             :                 // ignored. Since left is default, we only need to
      85             :                 // check for right
      86         121 :                 bTabRightAligned = IsXMLToken( sAttr, XML_RIGHT );
      87             :             }
      88         130 :             else if ( IsXMLToken( sLocalName, XML_POSITION ) )
      89             :             {
      90             :                 sal_Int32 nTmp;
      91           9 :                 if (GetImport().GetMM100UnitConverter().
      92             :                                         convertMeasureToCore(nTmp, sAttr))
      93             :                 {
      94           9 :                     nTabPosition = nTmp;
      95           9 :                     bTabPositionOK = true;
      96             :                 }
      97             :             }
      98         121 :             else if ( IsXMLToken( sLocalName, XML_LEADER_CHAR ) )
      99             :             {
     100         121 :                 sLeaderChar = sAttr;
     101             :                 // valid only, if we have a char!
     102         121 :                 bLeaderCharOK = !sAttr.isEmpty();
     103             :             }
     104             :             // #i21237#
     105           0 :             else if ( IsXMLToken( sLocalName, XML_WITH_TAB ) )
     106             :             {
     107           0 :                 bool bTmp(false);
     108           0 :                 if (::sax::Converter::convertBool(bTmp, sAttr))
     109           0 :                     bWithTab = bTmp;
     110             :             }
     111             :             // else: unknown style: attribute -> ignore
     112             :         }
     113             :         // else: no style attribute -> ignore
     114         251 :     }
     115             : 
     116             :     // how many entries? #i21237#
     117         121 :     nValues += 2 + (bTabPositionOK ? 1 : 0) + (bLeaderCharOK ? 1 : 0);
     118             : 
     119             :     // now try parent class (for character style)
     120         121 :     XMLIndexSimpleEntryContext::StartElement( xAttrList );
     121         121 : }
     122             : 
     123         121 : void XMLIndexTabStopEntryContext::FillPropertyValues(
     124             :     Sequence<PropertyValue> & rValues)
     125             : {
     126             :     // fill vlues from parent class (type + style name)
     127         121 :     XMLIndexSimpleEntryContext::FillPropertyValues(rValues);
     128             : 
     129             :     // get values array and next entry to be written;
     130         121 :     sal_Int32 nNextEntry = bCharStyleNameOK ? 2 : 1;
     131         121 :     PropertyValue* pValues = rValues.getArray();
     132             : 
     133             :     // right aligned?
     134         121 :     pValues[nNextEntry].Name = rTemplateContext.sTabStopRightAligned;
     135         121 :     pValues[nNextEntry].Value.setValue( &bTabRightAligned,
     136         242 :                                         cppu::UnoType<bool>::get());
     137         121 :     nNextEntry++;
     138             : 
     139             :     // position
     140         121 :     if (bTabPositionOK)
     141             :     {
     142           9 :         pValues[nNextEntry].Name = rTemplateContext.sTabStopPosition;
     143           9 :         pValues[nNextEntry].Value <<= nTabPosition;
     144           9 :         nNextEntry++;
     145             :     }
     146             : 
     147             :     // leader char
     148         121 :     if (bLeaderCharOK)
     149             :     {
     150         121 :         pValues[nNextEntry].Name = rTemplateContext.sTabStopFillCharacter;
     151         121 :         pValues[nNextEntry].Value <<= sLeaderChar;
     152         121 :         nNextEntry++;
     153             :     }
     154             : 
     155             :     // tab character #i21237#
     156         121 :      pValues[nNextEntry].Name = "WithTab";
     157         121 :     pValues[nNextEntry].Value.setValue( &bWithTab,
     158         242 :                                         cppu::UnoType<bool>::get());
     159         121 :     nNextEntry++;
     160             : 
     161             :     // check whether we really filled all elements of the sequence
     162             :     DBG_ASSERT( nNextEntry == rValues.getLength(),
     163             :                 "length incorrectly precumputed!" );
     164         121 : }
     165             : 
     166             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11