LCOV - code coverage report
Current view: top level - starmath/source - wordexportbase.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 74 82 90.2 %
Date: 2014-04-11 Functions: 9 10 90.0 %
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          99 : SmWordExportBase::SmWordExportBase(const SmNode* pIn)
      16          99 :     : m_pTree(pIn)
      17             : {
      18          99 : }
      19             : 
      20          99 : SmWordExportBase::~SmWordExportBase()
      21             : {
      22          99 : }
      23             : 
      24        1290 : void SmWordExportBase::HandleNode(const SmNode* pNode, int nLevel)
      25             : {
      26             :     SAL_INFO("starmath.wordbase", "Node: " << nLevel << " " << int(pNode->GetType()) << " " << pNode->GetNumSubNodes());
      27        1290 :     switch (pNode->GetType())
      28             :     {
      29             :     case NATTRIBUT:
      30          28 :         HandleAttribute(static_cast< const SmAttributNode* >(pNode), nLevel);
      31          28 :         break;
      32             :     case NTEXT:
      33         540 :         HandleText(pNode,nLevel);
      34         540 :         break;
      35             :     case NVERTICAL_BRACE:
      36           4 :         HandleVerticalBrace(static_cast< const SmVerticalBraceNode* >(pNode), nLevel);
      37           4 :         break;
      38             :     case NBRACE:
      39          57 :         HandleBrace(static_cast< const SmBraceNode* >(pNode), nLevel);
      40          57 :         break;
      41             :     case NOPER:
      42          20 :         HandleOperator(static_cast< const SmOperNode* >(pNode), nLevel);
      43          20 :         break;
      44             :     case NUNHOR:
      45           9 :         HandleUnaryOperation(static_cast< const SmUnHorNode* >(pNode), nLevel);
      46           9 :         break;
      47             :     case NBINHOR:
      48          98 :         HandleBinaryOperation(static_cast< const SmBinHorNode* >(pNode), nLevel);
      49          98 :         break;
      50             :     case NBINVER:
      51          32 :         HandleFractions(pNode,nLevel);
      52          32 :         break;
      53             :     case NROOT:
      54          10 :         HandleRoot(static_cast< const SmRootNode* >(pNode), nLevel);
      55          10 :         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 it's a mathchar
      61           0 :         if (pText->GetText() == 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         110 :         HandleMath(pNode,nLevel);
      70         110 :         break;
      71             :     case NSUBSUP:
      72          75 :         HandleSubSupScript(static_cast< const SmSubSupNode* >(pNode), nLevel);
      73          75 :         break;
      74             :     case NEXPRESSION:
      75          82 :         HandleAllSubNodes(pNode, nLevel);
      76          82 :         break;
      77             :     case NTABLE:
      78             :         //Root Node, PILE equivalent, i.e. vertical stack
      79         111 :         HandleTable(pNode,nLevel);
      80         111 :         break;
      81             :     case NMATRIX:
      82           2 :         HandleMatrix(static_cast< const SmMatrixNode* >(pNode), nLevel);
      83           2 :         break;
      84             :     case NLINE:
      85             :     {
      86             : // TODO
      87          99 :         HandleAllSubNodes(pNode, nLevel);
      88             :     }
      89          99 :     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           3 :         HandleAllSubNodes(pNode, nLevel);
     103           3 :         break;
     104             :     }
     105        1290 : }
     106             : 
     107             : //Root Node, PILE equivalent, i.e. vertical stack
     108         111 : 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         111 :     if (nLevel || pNode->GetNumSubNodes() > 1)
     117          12 :         HandleVerticalStack(pNode, nLevel);
     118             :     else
     119          99 :         HandleAllSubNodes(pNode, nLevel);
     120         111 : }
     121             : 
     122         388 : void SmWordExportBase::HandleAllSubNodes(const SmNode* pNode, int nLevel)
     123             : {
     124         388 :     int size = pNode->GetNumSubNodes();
     125        1148 :     for (int i = 0;
     126             :             i < size;
     127             :             ++i)
     128             :     {
     129             : // TODO remove when all types of nodes are handled properly
     130         760 :         if (pNode->GetSubNode(i) == NULL)
     131             :         {
     132             :             SAL_WARN("starmath.wordbase", "Subnode is NULL, parent node not handled properly");
     133           0 :             continue;
     134             :         }
     135         760 :         HandleNode(pNode->GetSubNode(i), nLevel + 1);
     136             :     }
     137         388 : }
     138             : 
     139           9 : 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           9 :     HandleAllSubNodes(pNode, nLevel);
     149             : //            break;
     150             : //    }
     151           9 : }
     152             : 
     153          98 : 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          98 :     switch (pNode->Symbol()->GetToken().eType)
     158             :     {
     159             :     case TDIVIDEBY:
     160         100 :         return HandleFractions(pNode, nLevel, "lin");
     161             :     default:
     162          96 :         HandleAllSubNodes(pNode, nLevel);
     163          96 :         break;
     164             :     }
     165             : }
     166             : 
     167         110 : void SmWordExportBase::HandleMath(const SmNode* pNode, int nLevel)
     168             : {
     169             :     SAL_INFO("starmath.wordbase", "Math: " << int(pNode->GetToken().eType));
     170         110 :     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         110 :         HandleText(pNode, nLevel);
     178         110 :         break;
     179             :     }
     180         110 : }
     181             : 
     182          75 : void SmWordExportBase::HandleSubSupScript(const SmSubSupNode* pNode, int nLevel)
     183             : {
     184             :     // set flags to a bitfield of which sub/sup items exists
     185          75 :     int flags = (pNode->GetSubSup(CSUB) != NULL ? (1 << CSUB) : 0)
     186          75 :                 | (pNode->GetSubSup(CSUP) != NULL ? (1 << CSUP) : 0)
     187          75 :                 | (pNode->GetSubSup(RSUB) != NULL ? (1 << RSUB) : 0)
     188          75 :                 | (pNode->GetSubSup(RSUP) != NULL ? (1 << RSUP) : 0)
     189          75 :                 | (pNode->GetSubSup(LSUB) != NULL ? (1 << LSUB) : 0)
     190          75 :                 | (pNode->GetSubSup(LSUP) != NULL ? (1 << LSUP) : 0);
     191          75 :     HandleSubSupScriptInternal(pNode, nLevel, flags);
     192          75 : }
     193             : 
     194             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10