LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/starmath/source - wordexportbase.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 72 82 87.8 %
Date: 2013-07-09 Functions: 11 12 91.7 %
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             : 
      10             : 
      11             : #include "wordexportbase.hxx"
      12             : 
      13             : #include <rtl/ustring.hxx>
      14             : 
      15          73 : SmWordExportBase::SmWordExportBase( const SmNode* pIn )
      16          73 : : m_pTree( pIn )
      17             : {
      18          73 : }
      19             : 
      20          73 : SmWordExportBase::~SmWordExportBase()
      21             : {
      22          73 : }
      23             : 
      24        1010 : void SmWordExportBase::HandleNode( const SmNode* pNode, int nLevel )
      25             : {
      26             :     SAL_INFO( "starmath.wordbase", "Node: " << nLevel << " " << int( pNode->GetType()) << " " << pNode->GetNumSubNodes());
      27        1010 :     switch(pNode->GetType())
      28             :     {
      29             :         case NATTRIBUT:
      30          28 :             HandleAttribute( static_cast< const SmAttributNode* >( pNode ), nLevel );
      31          28 :             break;
      32             :         case NTEXT:
      33         432 :             HandleText(pNode,nLevel);
      34         432 :             break;
      35             :         case NVERTICAL_BRACE:
      36           4 :             HandleVerticalBrace( static_cast< const SmVerticalBraceNode* >( pNode ), nLevel );
      37           4 :             break;
      38             :         case NBRACE:
      39          45 :             HandleBrace( static_cast< const SmBraceNode* >( pNode ), nLevel );
      40          45 :             break;
      41             :         case NOPER:
      42          18 :             HandleOperator( static_cast< const SmOperNode* >( pNode ), nLevel );
      43          18 :             break;
      44             :         case NUNHOR:
      45           2 :             HandleUnaryOperation( static_cast< const SmUnHorNode* >( pNode ), nLevel );
      46           2 :             break;
      47             :         case NBINHOR:
      48          80 :             HandleBinaryOperation( static_cast< const SmBinHorNode* >( pNode ), nLevel );
      49          80 :             break;
      50             :         case NBINVER:
      51          28 :             HandleFractions(pNode,nLevel);
      52          28 :             break;
      53             :         case NROOT:
      54           6 :             HandleRoot( static_cast< const SmRootNode* >( pNode ), nLevel );
      55           6 :             break;
      56             :         case NSPECIAL:
      57             :         {
      58           0 :             const SmTextNode* pText= static_cast< const SmTextNode* >( pNode );
      59             :             //if the token str and the result text are the same then this
      60             :             //is to be seen as text, else assume its a mathchar
      61           0 :             if (pText->GetText() == OUString(pText->GetToken().aText))
      62           0 :                 HandleText(pText,nLevel);
      63             :             else
      64           0 :                 HandleMath(pText,nLevel);
      65           0 :             break;
      66             :         }
      67             :         case NMATH:
      68             :         case NMATHIDENT:
      69          85 :             HandleMath(pNode,nLevel);
      70          85 :             break;
      71             :         case NSUBSUP:
      72          51 :             HandleSubSupScript( static_cast< const SmSubSupNode* >( pNode ), nLevel );
      73          51 :             break;
      74             :         case NEXPRESSION:
      75          64 :             HandleAllSubNodes( pNode, nLevel );
      76          64 :             break;
      77             :         case NTABLE:
      78             :             //Root Node, PILE equivalent, i.e. vertical stack
      79          82 :             HandleTable(pNode,nLevel);
      80          82 :             break;
      81             :         case NMATRIX:
      82           2 :             HandleMatrix( static_cast< const SmMatrixNode* >( pNode ), nLevel );
      83           2 :             break;
      84             :         case NLINE:
      85             :             {
      86             : // TODO
      87          73 :             HandleAllSubNodes( pNode, nLevel );
      88             :             }
      89          73 :             break;
      90             : #if 0
      91             :         case NALIGN:
      92             :             HandleMAlign(pNode,nLevel);
      93             :             break;
      94             : #endif
      95             :         case NPLACE:
      96             :             // explicitly do nothing, MSOffice treats that as a placeholder if item is missing
      97          10 :             break;
      98             :         case NBLANK:
      99           0 :             HandleBlank();
     100           0 :             break;
     101             :         default:
     102           0 :             HandleAllSubNodes( pNode, nLevel );
     103           0 :             break;
     104             :     }
     105        1010 : }
     106             : 
     107             : //Root Node, PILE equivalent, i.e. vertical stack
     108          82 : void SmWordExportBase::HandleTable( const SmNode* pNode, int nLevel )
     109             : {
     110             :     //The root of the starmath is a table, if
     111             :     //we convert this them each iteration of
     112             :     //conversion from starmath to Word will
     113             :     //add an extra unnecessary level to the
     114             :     //Word output stack which would grow
     115             :     //without bound in a multi step conversion
     116          82 :     if( nLevel || pNode->GetNumSubNodes() > 1 )
     117           9 :         HandleVerticalStack( pNode, nLevel );
     118             :     else
     119          73 :         HandleAllSubNodes( pNode, nLevel );
     120          82 : }
     121             : 
     122         290 : void SmWordExportBase::HandleAllSubNodes( const SmNode* pNode, int nLevel )
     123             : {
     124         290 :     int size = pNode->GetNumSubNodes();
     125         887 :     for( int i = 0;
     126             :          i < size;
     127             :          ++i )
     128             :     {
     129             : // TODO remove when all types of nodes are handled properly
     130         597 :         if( pNode->GetSubNode( i ) == NULL )
     131             :         {
     132             :             OSL_FAIL( "Subnode is NULL, parent node not handled properly" );
     133           0 :             continue;
     134             :         }
     135         597 :         HandleNode( pNode->GetSubNode( i ), nLevel + 1 );
     136             :     }
     137         290 : }
     138             : 
     139           2 : void SmWordExportBase::HandleUnaryOperation( const SmUnHorNode* pNode, int nLevel )
     140             : {
     141             :     // update HandleMath() when adding new items
     142             :     SAL_INFO( "starmath.wordbase", "Unary: " << int( pNode->GetToken().eType ));
     143             : 
     144             : // Avoid MSVC warning C4065: switch statement contains 'default' but no 'case' labels
     145             : //    switch( pNode->GetToken().eType )
     146             : //    {
     147             : //        default:
     148           2 :             HandleAllSubNodes( pNode, nLevel );
     149             : //            break;
     150             : //    }
     151           2 : }
     152             : 
     153          80 : void SmWordExportBase::HandleBinaryOperation( const SmBinHorNode* pNode, int nLevel )
     154             : {
     155             :     SAL_INFO( "starmath.wordbase", "Binary: " << int( pNode->Symbol()->GetToken().eType ));
     156             :     // update HandleMath() when adding new items
     157          80 :     switch( pNode->Symbol()->GetToken().eType )
     158             :     {
     159             :         case TDIVIDEBY:
     160          82 :             return HandleFractions( pNode, nLevel, "lin" );
     161             :         default:
     162          78 :             HandleAllSubNodes( pNode, nLevel );
     163          78 :             break;
     164             :     }
     165             : }
     166             : 
     167          85 : void SmWordExportBase::HandleMath( const SmNode* pNode, int nLevel )
     168             : {
     169             :     SAL_INFO( "starmath.wordbase", "Math: " << int( pNode->GetToken().eType ));
     170          85 :     switch( pNode->GetToken().eType )
     171             :     {
     172             :         case TDIVIDEBY:
     173             :         case TACUTE:
     174             :         // these are handled elsewhere, e.g. when handling BINHOR
     175             :             OSL_ASSERT( false );
     176             :         default:
     177          85 :             HandleText( pNode, nLevel );
     178          85 :             break;
     179             :     }
     180          85 : }
     181             : 
     182          51 : void SmWordExportBase::HandleSubSupScript( const SmSubSupNode* pNode, int nLevel )
     183             : {
     184             :     // set flags to a bitfield of which sub/sup items exists
     185          51 :     int flags = ( pNode->GetSubSup( CSUB ) != NULL ? ( 1 << CSUB ) : 0 )
     186          51 :             | ( pNode->GetSubSup( CSUP ) != NULL ? ( 1 << CSUP ) : 0 )
     187          51 :             | ( pNode->GetSubSup( RSUB ) != NULL ? ( 1 << RSUB ) : 0 )
     188          51 :             | ( pNode->GetSubSup( RSUP ) != NULL ? ( 1 << RSUP ) : 0 )
     189          51 :             | ( pNode->GetSubSup( LSUB ) != NULL ? ( 1 << LSUB ) : 0 )
     190          51 :             | ( pNode->GetSubSup( LSUP ) != NULL ? ( 1 << LSUP ) : 0 );
     191          51 :     HandleSubSupScriptInternal( pNode, nLevel, flags );
     192          72 : }
     193             : 
     194             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10