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

Generated by: LCOV version 1.10