LCOV - code coverage report
Current view: top level - sc/source/filter/oox - stylesfragment.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 75 127 59.1 %
Date: 2014-11-03 Functions: 14 17 82.4 %
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          18 : IndexedColorsContext::IndexedColorsContext( WorkbookFragmentBase& rFragment ) :
      30          18 :     WorkbookContextBase( rFragment )
      31             : {
      32          18 : }
      33             : 
      34        1024 : ContextHandlerRef IndexedColorsContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
      35             : {
      36        1024 :     switch( getCurrentElement() )
      37             :     {
      38             :         case XLS_TOKEN( indexedColors ):
      39        1024 :             if( nElement == XLS_TOKEN( rgbColor ) ) getStyles().importPaletteColor( rAttribs );
      40        1024 :         break;
      41             :     }
      42        1024 :     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        1586 : ContextHandlerRef FontContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
      57             : {
      58        1586 :     if( mxFont.get() )
      59        1586 :         mxFont->importAttribs( nElement, rAttribs );
      60        1586 :     return 0;
      61             : }
      62             : 
      63        1500 : void BorderContext::onStartElement( const AttributeList& rAttribs )
      64             : {
      65        1500 :     if( mxBorder.get() && (getCurrentElement() == XLS_TOKEN( border )) )
      66         250 :         mxBorder->importBorder( rAttribs );
      67        1500 : }
      68             : 
      69        1284 : ContextHandlerRef BorderContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
      70             : {
      71        1284 :     if( mxBorder.get() ) switch( getCurrentElement() )
      72             :     {
      73             :         case XLS_TOKEN( border ):
      74        1250 :             mxBorder->importStyle( nElement, rAttribs );
      75        1250 :             return this;
      76             : 
      77             :         default:
      78          34 :             if( nElement == XLS_TOKEN( color ) )
      79          34 :                 mxBorder->importColor( getCurrentElement(), rAttribs );
      80             :     }
      81          34 :     return 0;
      82             : }
      83             : 
      84         268 : ContextHandlerRef FillContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
      85             : {
      86         268 :     if( mxFill.get() ) switch( getCurrentElement() )
      87             :     {
      88             :         case XLS_TOKEN( fill ):
      89         260 :             switch( nElement )
      90             :             {
      91         260 :                 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           8 :             switch( nElement )
      97             :             {
      98           4 :                 case XLS_TOKEN( fgColor ):      mxFill->importFgColor( rAttribs );      break;
      99           4 :                 case XLS_TOKEN( bgColor ):      mxFill->importBgColor( rAttribs );      break;
     100             :             }
     101           8 :         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           8 :     return 0;
     115             : }
     116             : 
     117        1758 : void XfContext::onStartElement( const AttributeList& rAttribs )
     118             : {
     119        1758 :     if( mxXf.get() && (getCurrentElement() == XLS_TOKEN( xf )) )
     120        1758 :         mxXf->importXf( rAttribs, mbCellXf );
     121        1758 : }
     122             : 
     123         548 : ContextHandlerRef XfContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
     124             : {
     125         548 :     if( mxXf.get() ) switch( getCurrentElement() )
     126             :     {
     127             :         case XLS_TOKEN( xf ):
     128         548 :             switch( nElement )
     129             :             {
     130         298 :                 case XLS_TOKEN( alignment ):    mxXf->importAlignment( rAttribs );  break;
     131         250 :                 case XLS_TOKEN( protection ):   mxXf->importProtection( rAttribs ); break;
     132             :             }
     133         548 :         break;
     134             :     }
     135         548 :     return 0;
     136             : }
     137             : 
     138          96 : ContextHandlerRef DxfContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
     139             : {
     140          96 :     if( mxDxf.get() ) switch( getCurrentElement() )
     141             :     {
     142             :         case XLS_TOKEN( dxf ):
     143          96 :             switch( nElement )
     144             :             {
     145          20 :                 case XLS_TOKEN( font ):         return new FontContext( *this, mxDxf->createFont() );
     146           0 :                 case XLS_TOKEN( border ):       return new BorderContext( *this, mxDxf->createBorder() );
     147           0 :                 case XLS_TOKEN( fill ):         return new FillContext( *this, mxDxf->createFill() );
     148             : 
     149          76 :                 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          76 :         break;
     156             :     }
     157          76 :     return 0;
     158             : }
     159             : 
     160         128 : StylesFragment::StylesFragment( const WorkbookHelper& rHelper, const OUString& rFragmentPath ) :
     161         128 :     WorkbookFragmentBase( rHelper, rFragmentPath )
     162             : {
     163         128 : }
     164             : 
     165        4478 : ContextHandlerRef StylesFragment::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs )
     166             : {
     167        4478 :     switch( getCurrentElement() )
     168             :     {
     169             :         case XML_ROOT_CONTEXT:
     170         128 :             if( nElement == XLS_TOKEN( styleSheet ) ) return this;
     171           0 :         break;
     172             : 
     173             :         case XLS_TOKEN( styleSheet ):
     174        1032 :             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         924 :                 case XLS_TOKEN( cellStyles ):   return this;
     185             :             }
     186         108 :         break;
     187             : 
     188             :         case XLS_TOKEN( colors ):
     189          18 :             if( nElement == XLS_TOKEN( indexedColors ) ) return new IndexedColorsContext( *this );
     190           0 :         break;
     191             :         case XLS_TOKEN( numFmts ):
     192         104 :             if( nElement == XLS_TOKEN( numFmt ) ) getStyles().importNumFmt( rAttribs );
     193         104 :         break;
     194             :         case XLS_TOKEN( fonts ):
     195         382 :             if( nElement == XLS_TOKEN( font ) ) return new FontContext( *this, getStyles().createFont() );
     196           0 :         break;
     197             :         case XLS_TOKEN( borders ):
     198         250 :             if( nElement == XLS_TOKEN( border ) ) return new BorderContext( *this, getStyles().createBorder() );
     199           0 :         break;
     200             :         case XLS_TOKEN( fills ):
     201         260 :             if( nElement == XLS_TOKEN( fill ) ) return new FillContext( *this, getStyles().createFill() );
     202           0 :         break;
     203             :         case XLS_TOKEN( cellXfs ):
     204         420 :             if( nElement == XLS_TOKEN( xf ) ) return new XfContext( *this, getStyles().createCellXf(), true );
     205           0 :         break;
     206             :         case XLS_TOKEN( cellStyleXfs ):
     207        1338 :             if( nElement == XLS_TOKEN( xf ) ) return new XfContext( *this, getStyles().createStyleXf(), false );
     208           0 :         break;
     209             :         case XLS_TOKEN( dxfs ):
     210          76 :             if( nElement == XLS_TOKEN( dxf ) ) return new DxfContext( *this, getStyles().createDxf() );
     211           0 :         break;
     212             :         case XLS_TOKEN( cellStyles ):
     213         470 :             if( nElement == XLS_TOKEN( cellStyle ) ) getStyles().importCellStyle( rAttribs );
     214         470 :         break;
     215             :     }
     216         682 :     return 0;
     217             : }
     218             : 
     219           0 : ContextHandlerRef StylesFragment::onCreateRecordContext( sal_Int32 nRecId, SequenceInputStream& rStrm )
     220             : {
     221           0 :     switch( getCurrentElement() )
     222             :     {
     223             :         case XML_ROOT_CONTEXT:
     224           0 :             if( nRecId == BIFF12_ID_STYLESHEET ) return this;
     225           0 :         break;
     226             : 
     227             :         case BIFF12_ID_STYLESHEET:
     228           0 :             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           0 :                 case BIFF12_ID_CELLSTYLES:      return this;
     239             :             }
     240           0 :         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           0 :             if( nRecId == BIFF12_ID_FONT ) getStyles().createFont()->importFont( rStrm );
     250           0 :         break;
     251             :         case BIFF12_ID_BORDERS:
     252           0 :             if( nRecId == BIFF12_ID_BORDER ) getStyles().createBorder()->importBorder( rStrm );
     253           0 :         break;
     254             :         case BIFF12_ID_FILLS:
     255           0 :             if( nRecId == BIFF12_ID_FILL ) getStyles().createFill()->importFill( rStrm );
     256           0 :         break;
     257             :         case BIFF12_ID_CELLXFS:
     258           0 :             if( nRecId == BIFF12_ID_XF ) getStyles().createCellXf()->importXf( rStrm, true );
     259           0 :         break;
     260             :         case BIFF12_ID_CELLSTYLEXFS:
     261           0 :             if( nRecId == BIFF12_ID_XF ) getStyles().createStyleXf()->importXf( rStrm, false );
     262           0 :         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           0 :             if( nRecId == BIFF12_ID_CELLSTYLE ) getStyles().importCellStyle( rStrm );
     268           0 :         break;
     269             :     }
     270           0 :     return 0;
     271             : }
     272             : 
     273           0 : 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           0 :     return spRecInfos;
     293             : }
     294             : 
     295         128 : void StylesFragment::finalizeImport()
     296             : {
     297         128 :     getStyles().finalizeImport();
     298         128 : }
     299             : 
     300             : } // namespace xls
     301          48 : } // namespace oox
     302             : 
     303             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10