LCOV - code coverage report
Current view: top level - xmloff/source/style - xmltabi.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 87 98 88.8 %
Date: 2014-04-11 Functions: 11 22 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             : #include <com/sun/star/style/TabAlign.hpp>
      21             : #include <rtl/ustrbuf.hxx>
      22             : #include <xmloff/xmltkmap.hxx>
      23             : #include <xmloff/nmspmap.hxx>
      24             : #include <xmloff/xmlnmspe.hxx>
      25             : #include <xmloff/xmlimp.hxx>
      26             : #include <com/sun/star/style/TabStop.hpp>
      27             : #include <xmloff/xmltoken.hxx>
      28             : #include <xmloff/i18nmap.hxx>
      29             : #include <xmloff/xmluconv.hxx>
      30             : #include "xmltabi.hxx"
      31             : 
      32             : 
      33             : using namespace ::com::sun::star;
      34             : using namespace ::xmloff::token;
      35             : 
      36             : enum SvXMLTokenMapAttrs
      37             : {
      38             :     XML_TOK_TABSTOP_POSITION,
      39             :     XML_TOK_TABSTOP_TYPE,
      40             :     XML_TOK_TABSTOP_CHAR,
      41             :     XML_TOK_TABSTOP_LEADER_STYLE,
      42             :     XML_TOK_TABSTOP_LEADER_TEXT,
      43             :     XML_TOK_TABSTOP_END=XML_TOK_UNKNOWN
      44             : };
      45             : 
      46             : static SvXMLTokenMapEntry aTabsAttributesAttrTokenMap[] =
      47             : {
      48             :     { XML_NAMESPACE_STYLE, XML_POSITION,     XML_TOK_TABSTOP_POSITION },
      49             :     { XML_NAMESPACE_STYLE, XML_TYPE,         XML_TOK_TABSTOP_TYPE },
      50             :     { XML_NAMESPACE_STYLE, XML_CHAR,         XML_TOK_TABSTOP_CHAR },
      51             :     { XML_NAMESPACE_STYLE, XML_LEADER_TEXT,  XML_TOK_TABSTOP_LEADER_TEXT },
      52             :     { XML_NAMESPACE_STYLE, XML_LEADER_STYLE,  XML_TOK_TABSTOP_LEADER_STYLE },
      53             :     XML_TOKEN_MAP_END
      54             : };
      55             : 
      56             : 
      57             : 
      58             : class SvxXMLTabStopContext_Impl : public SvXMLImportContext
      59             : {
      60             : private:
      61             :      style::TabStop aTabStop;
      62             : 
      63             : public:
      64             :     TYPEINFO_OVERRIDE();
      65             : 
      66             :     SvxXMLTabStopContext_Impl( SvXMLImport& rImport, sal_uInt16 nPrfx,
      67             :                                const OUString& rLName,
      68             :                                const uno::Reference< xml::sax::XAttributeList > & xAttrList );
      69             : 
      70             :     virtual ~SvxXMLTabStopContext_Impl();
      71             : 
      72             :     virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
      73             :                                    const OUString& rLocalName,
      74             :                                    const uno::Reference< xml::sax::XAttributeList > & xAttrList ) SAL_OVERRIDE;
      75             : 
      76        1876 :     const style::TabStop& getTabStop() const { return aTabStop; }
      77             : };
      78             : 
      79           0 : TYPEINIT1( SvxXMLTabStopContext_Impl, SvXMLImportContext );
      80             : 
      81         938 : SvxXMLTabStopContext_Impl::SvxXMLTabStopContext_Impl(
      82             :                                SvXMLImport& rImport, sal_uInt16 nPrfx,
      83             :                                const OUString& rLName,
      84             :                                const uno::Reference< xml::sax::XAttributeList > & xAttrList )
      85         938 : : SvXMLImportContext( rImport, nPrfx, rLName )
      86             : {
      87         938 :     aTabStop.Position = 0;
      88         938 :     aTabStop.Alignment = style::TabAlign_LEFT;
      89         938 :     aTabStop.DecimalChar = ',';
      90         938 :     aTabStop.FillChar = ' ';
      91         938 :     sal_Unicode cTextFillChar = 0;
      92             : 
      93         938 :     SvXMLTokenMap aTokenMap( aTabsAttributesAttrTokenMap );
      94             : 
      95         938 :     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
      96        2195 :     for( sal_Int16 i=0; i < nAttrCount; i++ )
      97             :     {
      98        1257 :         const OUString& rAttrName = xAttrList->getNameByIndex( i );
      99        2514 :         OUString aLocalName;
     100             :         sal_uInt16 nPrefix =
     101        1257 :             GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
     102        1257 :                                                             &aLocalName );
     103        2514 :         const OUString& rValue = xAttrList->getValueByIndex( i );
     104             : 
     105             :         sal_Int32 nVal;
     106        1257 :         switch( aTokenMap.Get( nPrefix, aLocalName ) )
     107             :         {
     108             :         case XML_TOK_TABSTOP_POSITION:
     109         938 :             if (GetImport().GetMM100UnitConverter().convertMeasureToCore(
     110             :                     nVal, rValue))
     111             :             {
     112         938 :                 aTabStop.Position = nVal;
     113             :             }
     114         938 :             break;
     115             :         case XML_TOK_TABSTOP_TYPE:
     116         175 :             if( IsXMLToken( rValue, XML_LEFT ) )
     117             :             {
     118           0 :                 aTabStop.Alignment = style::TabAlign_LEFT;
     119             :             }
     120         175 :             else if( IsXMLToken( rValue, XML_RIGHT ) )
     121             :             {
     122          73 :                 aTabStop.Alignment = style::TabAlign_RIGHT;
     123             :             }
     124         102 :             else if( IsXMLToken( rValue, XML_CENTER ) )
     125             :             {
     126          58 :                 aTabStop.Alignment = style::TabAlign_CENTER;
     127             :             }
     128          44 :             else if( IsXMLToken( rValue, XML_CHAR ) )
     129             :             {
     130          44 :                 aTabStop.Alignment = style::TabAlign_DECIMAL;
     131             :             }
     132           0 :             else if( IsXMLToken( rValue, XML_DEFAULT ) )
     133             :             {
     134           0 :                 aTabStop.Alignment = style::TabAlign_DEFAULT;
     135             :             }
     136         175 :             break;
     137             :         case XML_TOK_TABSTOP_CHAR:
     138          44 :             if( !rValue.isEmpty() )
     139          44 :                 aTabStop.DecimalChar = rValue[0];
     140          44 :             break;
     141             :         case XML_TOK_TABSTOP_LEADER_STYLE:
     142          50 :             if( IsXMLToken( rValue, XML_NONE ) )
     143           0 :                 aTabStop.FillChar = ' ';
     144          50 :             else if( IsXMLToken( rValue, XML_DOTTED ) )
     145          17 :                 aTabStop.FillChar = '.';
     146             :             else
     147          33 :                 aTabStop.FillChar = '_';
     148          50 :             break;
     149             :         case XML_TOK_TABSTOP_LEADER_TEXT:
     150          50 :             if( !rValue.isEmpty() )
     151          50 :                 cTextFillChar = rValue[0];
     152          50 :             break;
     153             :         }
     154        1257 :     }
     155             : 
     156         938 :     if( cTextFillChar != 0 && aTabStop.FillChar != ' ' )
     157          50 :         aTabStop.FillChar = cTextFillChar;
     158         938 : }
     159             : 
     160        1876 : SvxXMLTabStopContext_Impl::~SvxXMLTabStopContext_Impl()
     161             : {
     162        1876 : }
     163             : 
     164           0 : SvXMLImportContext *SvxXMLTabStopContext_Impl::CreateChildContext(
     165             :                                    sal_uInt16 nPrefix,
     166             :                                    const OUString& rLocalName,
     167             :                                    const uno::Reference< xml::sax::XAttributeList > & )
     168             : {
     169           0 :     return new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
     170             : }
     171             : 
     172             : 
     173             : 
     174             : 
     175         406 : class SvxXMLTabStopArray_Impl : public std::vector<SvxXMLTabStopContext_Impl *> {};
     176             : 
     177             : 
     178             : 
     179             : 
     180           0 : TYPEINIT1( SvxXMLTabStopImportContext, XMLElementPropertyContext );
     181             : 
     182         378 : SvxXMLTabStopImportContext::SvxXMLTabStopImportContext(
     183             :                                 SvXMLImport& rImport, sal_uInt16 nPrfx,
     184             :                                 const OUString& rLName,
     185             :                                 const XMLPropertyState& rProp,
     186             :                                  ::std::vector< XMLPropertyState > &rProps )
     187             : : XMLElementPropertyContext( rImport, nPrfx, rLName, rProp, rProps ),
     188         378 :   mpTabStops( NULL )
     189             : {
     190         378 : }
     191             : 
     192        1134 : SvxXMLTabStopImportContext::~SvxXMLTabStopImportContext()
     193             : {
     194         378 :     if( mpTabStops )
     195             :     {
     196        1344 :         while( !mpTabStops->empty() )
     197             :         {
     198         938 :             SvxXMLTabStopContext_Impl *pTabStop = mpTabStops->back();
     199         938 :             mpTabStops->pop_back();
     200         938 :             pTabStop->ReleaseRef();
     201             :         }
     202             :     }
     203             : 
     204         378 :     delete mpTabStops;
     205         756 : }
     206             : 
     207         938 : SvXMLImportContext *SvxXMLTabStopImportContext::CreateChildContext(
     208             :                                    sal_uInt16 nPrefix,
     209             :                                    const OUString& rLocalName,
     210             :                                    const uno::Reference< xml::sax::XAttributeList > & xAttrList )
     211             : {
     212         938 :     SvXMLImportContext *pContext = 0;
     213             : 
     214         938 :     if( XML_NAMESPACE_STYLE == nPrefix && IsXMLToken( rLocalName, XML_TAB_STOP ) )
     215             :     {
     216             :         // create new tabstop import context
     217             :         SvxXMLTabStopContext_Impl *pTabStopContext =
     218         938 :             new SvxXMLTabStopContext_Impl( GetImport(), nPrefix, rLocalName,
     219         938 :                                            xAttrList );
     220             : 
     221             :         // add new tabstop to array of tabstops
     222         938 :         if( !mpTabStops )
     223         203 :             mpTabStops = new SvxXMLTabStopArray_Impl;
     224             : 
     225         938 :         mpTabStops->push_back( pTabStopContext );
     226         938 :         pTabStopContext->AddRef();
     227             : 
     228         938 :         pContext = pTabStopContext;
     229             :     }
     230             :     else
     231             :     {
     232           0 :         pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
     233             :     }
     234             : 
     235         938 :     return pContext;
     236             : }
     237             : 
     238         378 : void SvxXMLTabStopImportContext::EndElement( )
     239             : {
     240         378 :     sal_uInt16 nCount = mpTabStops ? mpTabStops->size() : 0;
     241         378 :     uno::Sequence< style::TabStop> aSeq( nCount );
     242             : 
     243         378 :     if( mpTabStops )
     244             :     {
     245         203 :         sal_uInt16 nNewCount = 0;
     246             : 
     247         203 :         style::TabStop* pTabStops = aSeq.getArray();
     248        1141 :         for( sal_uInt16 i=0; i < nCount; i++ )
     249             :         {
     250         938 :             SvxXMLTabStopContext_Impl *pTabStopContext = (*mpTabStops)[i];
     251         938 :             const style::TabStop& rTabStop = pTabStopContext->getTabStop();
     252         938 :             sal_Bool bDflt = style::TabAlign_DEFAULT == rTabStop.Alignment;
     253         938 :             if( !bDflt || 0==i )
     254             :             {
     255         938 :                 *pTabStops++ = pTabStopContext->getTabStop();
     256         938 :                 nNewCount++;
     257             :             }
     258         938 :             if( bDflt && 0==i )
     259           0 :                 break;
     260             :         }
     261             : 
     262         203 :         if( nCount != nNewCount )
     263           0 :             aSeq.realloc( nNewCount );
     264             :     }
     265         378 :     aProp.maValue <<= aSeq;
     266             : 
     267         378 :     SetInsert( sal_True );
     268         378 :     XMLElementPropertyContext::EndElement();
     269             : 
     270         378 : }
     271             : 
     272             : 
     273             : 
     274             : 
     275             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10