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

Generated by: LCOV version 1.10