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

Generated by: LCOV version 1.10