LCOV - code coverage report
Current view: top level - sc/source/filter/oox - stylesfragment.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 96 127 75.6 %
Date: 2015-06-13 12:38:46 Functions: 16 17 94.1 %
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 "stylesfragment.hxx"
      21             : 
      22             : #include <oox/helper/attributelist.hxx>
      23             : 
      24             : namespace oox {
      25             : namespace xls {
      26             : 
      27             : using namespace ::oox::core;
      28             : 
      29          30 : IndexedColorsContext::IndexedColorsContext( WorkbookFragmentBase& rFragment ) :
      30          30 :     WorkbookContextBase( rFragment )
      31             : {
      32          30 : }
      33             : 
      34        1704 : ContextHandlerRef IndexedColorsContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
      35             : {
      36        1704 :     switch( getCurrentElement() )
      37             :     {
      38             :         case XLS_TOKEN( indexedColors ):
      39        1704 :             if( nElement == XLS_TOKEN( rgbColor ) ) getStyles().importPaletteColor( rAttribs );
      40        1704 :         break;
      41             :     }
      42        1704 :     return 0;
      43             : }
      44             : 
      45           0 : ContextHandlerRef IndexedColorsContext::onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm )
      46             : {
      47           0 :     switch( getCurrentElement() )
      48             :     {
      49             :         case BIFF12_ID_INDEXEDCOLORS:
      50           0 :             if( nRecId == BIFF12_ID_RGBCOLOR ) getStyles().importPaletteColor( rStrm );
      51           0 :         break;
      52             :     }
      53           0 :     return 0;
      54             : }
      55             : 
      56        1603 : ContextHandlerRef FontContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
      57             : {
      58        1603 :     if( mxFont.get() )
      59        1603 :         mxFont->importAttribs( nElement, rAttribs );
      60        1603 :     return 0;
      61             : }
      62             : 
      63        1224 : void BorderContext::onStartElement( const AttributeList& rAttribs )
      64             : {
      65        1224 :     if( mxBorder.get() && (getCurrentElement() == XLS_TOKEN( border )) )
      66         204 :         mxBorder->importBorder( rAttribs );
      67        1224 : }
      68             : 
      69        1037 : ContextHandlerRef BorderContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
      70             : {
      71        1037 :     if( mxBorder.get() ) switch( getCurrentElement() )
      72             :     {
      73             :         case XLS_TOKEN( border ):
      74        1020 :             mxBorder->importStyle( nElement, rAttribs );
      75        1020 :             return this;
      76             : 
      77             :         default:
      78          17 :             if( nElement == XLS_TOKEN( color ) )
      79          17 :                 mxBorder->importColor( getCurrentElement(), rAttribs );
      80             :     }
      81          17 :     return 0;
      82             : }
      83             : 
      84         296 : ContextHandlerRef FillContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
      85             : {
      86         296 :     if( mxFill.get() ) switch( getCurrentElement() )
      87             :     {
      88             :         case XLS_TOKEN( fill ):
      89         290 :             switch( nElement )
      90             :             {
      91         290 :                 case XLS_TOKEN( patternFill ):  mxFill->importPatternFill( rAttribs );  return this;
      92           0 :                 case XLS_TOKEN( gradientFill ): mxFill->importGradientFill( rAttribs ); return this;
      93             :             }
      94           0 :         break;
      95             :         case XLS_TOKEN( patternFill ):
      96           6 :             switch( nElement )
      97             :             {
      98           2 :                 case XLS_TOKEN( fgColor ):      mxFill->importFgColor( rAttribs );      break;
      99           4 :                 case XLS_TOKEN( bgColor ):      mxFill->importBgColor( rAttribs );      break;
     100             :             }
     101           6 :         break;
     102             :         case XLS_TOKEN( gradientFill ):
     103           0 :             if( nElement == XLS_TOKEN( stop ) )
     104             :             {
     105           0 :                 mfGradPos = rAttribs.getDouble( XML_position, -1.0 );
     106           0 :                 return this;
     107             :             }
     108           0 :         break;
     109             :         case XLS_TOKEN( stop ):
     110           0 :             if( nElement == XLS_TOKEN( color ) )
     111           0 :                 mxFill->importColor( rAttribs, mfGradPos );
     112           0 :         break;
     113             :     }
     114           6 :     return 0;
     115             : }
     116             : 
     117        1593 : void XfContext::onStartElement( const AttributeList& rAttribs )
     118             : {
     119        1593 :     if( mxXf.get() && (getCurrentElement() == XLS_TOKEN( xf )) )
     120        1593 :         mxXf->importXf( rAttribs, mbCellXf );
     121        1593 : }
     122             : 
     123         397 : ContextHandlerRef XfContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
     124             : {
     125         397 :     if( mxXf.get() ) switch( getCurrentElement() )
     126             :     {
     127             :         case XLS_TOKEN( xf ):
     128         397 :             switch( nElement )
     129             :             {
     130         211 :                 case XLS_TOKEN( alignment ):    mxXf->importAlignment( rAttribs );  break;
     131         186 :                 case XLS_TOKEN( protection ):   mxXf->importProtection( rAttribs ); break;
     132             :             }
     133         397 :         break;
     134             :     }
     135         397 :     return 0;
     136             : }
     137             : 
     138          40 : ContextHandlerRef DxfContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
     139             : {
     140          40 :     if( mxDxf.get() ) switch( getCurrentElement() )
     141             :     {
     142             :         case XLS_TOKEN( dxf ):
     143          40 :             switch( nElement )
     144             :             {
     145           0 :                 case XLS_TOKEN( font ):         return new FontContext( *this, mxDxf->createFont() );
     146           0 :                 case XLS_TOKEN( border ):       return new BorderContext( *this, mxDxf->createBorder() );
     147           2 :                 case XLS_TOKEN( fill ):         return new FillContext( *this, mxDxf->createFill() );
     148             : 
     149          38 :                 case XLS_TOKEN( numFmt ):       mxDxf->importNumFmt( rAttribs );        break;
     150             : #if 0
     151             :                 case XLS_TOKEN( alignment ):    mxDxf->importAlignment( rAttribs );     break;
     152             :                 case XLS_TOKEN( protection ):   mxDxf->importProtection( rAttribs );    break;
     153             : #endif
     154             :             }
     155          38 :         break;
     156             :     }
     157          38 :     return 0;
     158             : }
     159             : 
     160         145 : StylesFragment::StylesFragment( const WorkbookHelper& rHelper, const OUString& rFragmentPath ) :
     161         145 :     WorkbookFragmentBase( rHelper, rFragmentPath )
     162             : {
     163         145 : }
     164             : 
     165        4425 : ContextHandlerRef StylesFragment::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
     166             : {
     167        4425 :     switch( getCurrentElement() )
     168             :     {
     169             :         case XML_ROOT_CONTEXT:
     170         143 :             if( nElement == XLS_TOKEN( styleSheet ) ) return this;
     171           0 :         break;
     172             : 
     173             :         case XLS_TOKEN( styleSheet ):
     174        1186 :             switch( nElement )
     175             :             {
     176             :                 case XLS_TOKEN( colors ):
     177             :                 case XLS_TOKEN( numFmts ):
     178             :                 case XLS_TOKEN( fonts ):
     179             :                 case XLS_TOKEN( borders ):
     180             :                 case XLS_TOKEN( fills ):
     181             :                 case XLS_TOKEN( cellXfs ):
     182             :                 case XLS_TOKEN( cellStyleXfs ):
     183             :                 case XLS_TOKEN( dxfs ):
     184        1036 :                 case XLS_TOKEN( cellStyles ):   return this;
     185             :             }
     186         150 :         break;
     187             : 
     188             :         case XLS_TOKEN( colors ):
     189          30 :             if( nElement == XLS_TOKEN( indexedColors ) ) return new IndexedColorsContext( *this );
     190           0 :         break;
     191             :         case XLS_TOKEN( numFmts ):
     192          84 :             if( nElement == XLS_TOKEN( numFmt ) ) getStyles().importNumFmt( rAttribs );
     193          84 :         break;
     194             :         case XLS_TOKEN( fonts ):
     195         398 :             if( nElement == XLS_TOKEN( font ) ) return new FontContext( *this, getStyles().createFont() );
     196           0 :         break;
     197             :         case XLS_TOKEN( borders ):
     198         204 :             if( nElement == XLS_TOKEN( border ) ) return new BorderContext( *this, getStyles().createBorder() );
     199           0 :         break;
     200             :         case XLS_TOKEN( fills ):
     201         288 :             if( nElement == XLS_TOKEN( fill ) ) return new FillContext( *this, getStyles().createFill() );
     202           0 :         break;
     203             :         case XLS_TOKEN( cellXfs ):
     204         294 :             if( nElement == XLS_TOKEN( xf ) ) return new XfContext( *this, getStyles().createCellXf(), true );
     205           0 :         break;
     206             :         case XLS_TOKEN( cellStyleXfs ):
     207        1299 :             if( nElement == XLS_TOKEN( xf ) ) return new XfContext( *this, getStyles().createStyleXf(), false );
     208           0 :         break;
     209             :         case XLS_TOKEN( dxfs ):
     210          40 :             if( nElement == XLS_TOKEN( dxf ) ) return new DxfContext( *this, getStyles().createDxf() );
     211           0 :         break;
     212             :         case XLS_TOKEN( cellStyles ):
     213         459 :             if( nElement == XLS_TOKEN( cellStyle ) ) getStyles().importCellStyle( rAttribs );
     214         459 :         break;
     215             :     }
     216         693 :     return 0;
     217             : }
     218             : 
     219          51 : ContextHandlerRef StylesFragment::onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm )
     220             : {
     221          51 :     switch( getCurrentElement() )
     222             :     {
     223             :         case XML_ROOT_CONTEXT:
     224           2 :             if( nRecId == BIFF12_ID_STYLESHEET ) return this;
     225           0 :         break;
     226             : 
     227             :         case BIFF12_ID_STYLESHEET:
     228          28 :             switch( nRecId )
     229             :             {
     230             :                 case BIFF12_ID_COLORS:
     231             :                 case BIFF12_ID_NUMFMTS:
     232             :                 case BIFF12_ID_FONTS:
     233             :                 case BIFF12_ID_BORDERS:
     234             :                 case BIFF12_ID_FILLS:
     235             :                 case BIFF12_ID_CELLXFS:
     236             :                 case BIFF12_ID_CELLSTYLEXFS:
     237             :                 case BIFF12_ID_DXFS:
     238          14 :                 case BIFF12_ID_CELLSTYLES:      return this;
     239             :             }
     240          14 :         break;
     241             : 
     242             :         case BIFF12_ID_COLORS:
     243           0 :             if( nRecId == BIFF12_ID_INDEXEDCOLORS ) return new IndexedColorsContext( *this );
     244           0 :         break;
     245             :         case BIFF12_ID_NUMFMTS:
     246           0 :             if( nRecId == BIFF12_ID_NUMFMT ) getStyles().importNumFmt( rStrm );
     247           0 :         break;
     248             :         case BIFF12_ID_FONTS:
     249           8 :             if( nRecId == BIFF12_ID_FONT ) getStyles().createFont()->importFont( rStrm );
     250           8 :         break;
     251             :         case BIFF12_ID_BORDERS:
     252           2 :             if( nRecId == BIFF12_ID_BORDER ) getStyles().createBorder()->importBorder( rStrm );
     253           2 :         break;
     254             :         case BIFF12_ID_FILLS:
     255           4 :             if( nRecId == BIFF12_ID_FILL ) getStyles().createFill()->importFill( rStrm );
     256           4 :         break;
     257             :         case BIFF12_ID_CELLXFS:
     258           3 :             if( nRecId == BIFF12_ID_XF ) getStyles().createCellXf()->importXf( rStrm, true );
     259           3 :         break;
     260             :         case BIFF12_ID_CELLSTYLEXFS:
     261           2 :             if( nRecId == BIFF12_ID_XF ) getStyles().createStyleXf()->importXf( rStrm, false );
     262           2 :         break;
     263             :         case BIFF12_ID_DXFS:
     264           0 :             if( nRecId == BIFF12_ID_DXF ) getStyles().createDxf()->importDxf( rStrm );
     265           0 :         break;
     266             :         case BIFF12_ID_CELLSTYLES:
     267           2 :             if( nRecId == BIFF12_ID_CELLSTYLE ) getStyles().importCellStyle( rStrm );
     268           2 :         break;
     269             :     }
     270          35 :     return 0;
     271             : }
     272             : 
     273           2 : const RecordInfo* StylesFragment::getRecordInfos() const
     274             : {
     275             :     static const RecordInfo spRecInfos[] =
     276             :     {
     277             :         { BIFF12_ID_BORDERS,        BIFF12_ID_BORDERS + 1       },
     278             :         { BIFF12_ID_CELLSTYLES,     BIFF12_ID_CELLSTYLES + 1    },
     279             :         { BIFF12_ID_CELLSTYLEXFS,   BIFF12_ID_CELLSTYLEXFS + 1  },
     280             :         { BIFF12_ID_CELLXFS,        BIFF12_ID_CELLXFS + 1       },
     281             :         { BIFF12_ID_COLORS,         BIFF12_ID_COLORS + 1        },
     282             :         { BIFF12_ID_DXFS,           BIFF12_ID_DXFS + 1          },
     283             :         { BIFF12_ID_FILLS,          BIFF12_ID_FILLS + 1         },
     284             :         { BIFF12_ID_FONTS,          BIFF12_ID_FONTS + 1         },
     285             :         { BIFF12_ID_INDEXEDCOLORS,  BIFF12_ID_INDEXEDCOLORS + 1 },
     286             :         { BIFF12_ID_MRUCOLORS,      BIFF12_ID_MRUCOLORS + 1     },
     287             :         { BIFF12_ID_NUMFMTS,        BIFF12_ID_NUMFMTS + 1       },
     288             :         { BIFF12_ID_STYLESHEET,     BIFF12_ID_STYLESHEET + 1    },
     289             :         { BIFF12_ID_TABLESTYLES,    BIFF12_ID_TABLESTYLES + 1   },
     290             :         { -1,                       -1                          }
     291             :     };
     292           2 :     return spRecInfos;
     293             : }
     294             : 
     295         145 : void StylesFragment::finalizeImport()
     296             : {
     297         145 :     getStyles().finalizeImport();
     298         145 : }
     299             : 
     300             : } // namespace xls
     301          30 : } // namespace oox
     302             : 
     303             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11