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

Generated by: LCOV version 1.10