update credits
[LibreOffice.git] / starmath / source / wordexportbase.cxx
blob0a7a6b866c98c267cc2c639596a2774e7b7a5b41
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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 */
11 #include "wordexportbase.hxx"
13 #include <rtl/ustring.hxx>
15 SmWordExportBase::SmWordExportBase( const SmNode* pIn )
16 : m_pTree( pIn )
20 SmWordExportBase::~SmWordExportBase()
24 void SmWordExportBase::HandleNode( const SmNode* pNode, int nLevel )
26 SAL_INFO( "starmath.wordbase", "Node: " << nLevel << " " << int( pNode->GetType()) << " " << pNode->GetNumSubNodes());
27 switch(pNode->GetType())
29 case NATTRIBUT:
30 HandleAttribute( static_cast< const SmAttributNode* >( pNode ), nLevel );
31 break;
32 case NTEXT:
33 HandleText(pNode,nLevel);
34 break;
35 case NVERTICAL_BRACE:
36 HandleVerticalBrace( static_cast< const SmVerticalBraceNode* >( pNode ), nLevel );
37 break;
38 case NBRACE:
39 HandleBrace( static_cast< const SmBraceNode* >( pNode ), nLevel );
40 break;
41 case NOPER:
42 HandleOperator( static_cast< const SmOperNode* >( pNode ), nLevel );
43 break;
44 case NUNHOR:
45 HandleUnaryOperation( static_cast< const SmUnHorNode* >( pNode ), nLevel );
46 break;
47 case NBINHOR:
48 HandleBinaryOperation( static_cast< const SmBinHorNode* >( pNode ), nLevel );
49 break;
50 case NBINVER:
51 HandleFractions(pNode,nLevel);
52 break;
53 case NROOT:
54 HandleRoot( static_cast< const SmRootNode* >( pNode ), nLevel );
55 break;
56 case NSPECIAL:
58 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 if (pText->GetText() == OUString(pText->GetToken().aText))
62 HandleText(pText,nLevel);
63 else
64 HandleMath(pText,nLevel);
65 break;
67 case NMATH:
68 HandleMath(pNode,nLevel);
69 break;
70 case NSUBSUP:
71 HandleSubSupScript( static_cast< const SmSubSupNode* >( pNode ), nLevel );
72 break;
73 case NEXPRESSION:
74 HandleAllSubNodes( pNode, nLevel );
75 break;
76 case NTABLE:
77 //Root Node, PILE equivalent, i.e. vertical stack
78 HandleTable(pNode,nLevel);
79 break;
80 case NMATRIX:
81 HandleMatrix( static_cast< const SmMatrixNode* >( pNode ), nLevel );
82 break;
83 case NLINE:
85 // TODO
86 HandleAllSubNodes( pNode, nLevel );
88 break;
89 #if 0
90 case NALIGN:
91 HandleMAlign(pNode,nLevel);
92 break;
93 #endif
94 case NPLACE:
95 // explicitly do nothing, MSOffice treats that as a placeholder if item is missing
96 break;
97 case NBLANK:
98 HandleBlank();
99 break;
100 default:
101 HandleAllSubNodes( pNode, nLevel );
102 break;
106 //Root Node, PILE equivalent, i.e. vertical stack
107 void SmWordExportBase::HandleTable( const SmNode* pNode, int nLevel )
109 //The root of the starmath is a table, if
110 //we convert this them each iteration of
111 //conversion from starmath to Word will
112 //add an extra unnecessary level to the
113 //Word output stack which would grow
114 //without bound in a multi step conversion
115 if( nLevel || pNode->GetNumSubNodes() > 1 )
116 HandleVerticalStack( pNode, nLevel );
117 else
118 HandleAllSubNodes( pNode, nLevel );
121 void SmWordExportBase::HandleAllSubNodes( const SmNode* pNode, int nLevel )
123 int size = pNode->GetNumSubNodes();
124 for( int i = 0;
125 i < size;
126 ++i )
128 // TODO remove when all types of nodes are handled properly
129 if( pNode->GetSubNode( i ) == NULL )
131 OSL_FAIL( "Subnode is NULL, parent node not handled properly" );
132 continue;
134 HandleNode( pNode->GetSubNode( i ), nLevel + 1 );
138 void SmWordExportBase::HandleUnaryOperation( const SmUnHorNode* pNode, int nLevel )
140 // update HandleMath() when adding new items
141 SAL_INFO( "starmath.wordbase", "Unary: " << int( pNode->GetToken().eType ));
143 // Avoid MSVC warning C4065: switch statement contains 'default' but no 'case' labels
144 // switch( pNode->GetToken().eType )
145 // {
146 // default:
147 HandleAllSubNodes( pNode, nLevel );
148 // break;
149 // }
152 void SmWordExportBase::HandleBinaryOperation( const SmBinHorNode* pNode, int nLevel )
154 SAL_INFO( "starmath.wordbase", "Binary: " << int( pNode->Symbol()->GetToken().eType ));
155 // update HandleMath() when adding new items
156 switch( pNode->Symbol()->GetToken().eType )
158 case TDIVIDEBY:
159 return HandleFractions( pNode, nLevel, "lin" );
160 default:
161 HandleAllSubNodes( pNode, nLevel );
162 break;
166 void SmWordExportBase::HandleMath( const SmNode* pNode, int nLevel )
168 SAL_INFO( "starmath.wordbase", "Math: " << int( pNode->GetToken().eType ));
169 switch( pNode->GetToken().eType )
171 case TDIVIDEBY:
172 case TACUTE:
173 // these are handled elsewhere, e.g. when handling BINHOR
174 OSL_ASSERT( false );
175 default:
176 HandleText( pNode, nLevel );
177 break;
181 void SmWordExportBase::HandleSubSupScript( const SmSubSupNode* pNode, int nLevel )
183 // set flags to a bitfield of which sub/sup items exists
184 int flags = ( pNode->GetSubSup( CSUB ) != NULL ? ( 1 << CSUB ) : 0 )
185 | ( pNode->GetSubSup( CSUP ) != NULL ? ( 1 << CSUP ) : 0 )
186 | ( pNode->GetSubSup( RSUB ) != NULL ? ( 1 << RSUB ) : 0 )
187 | ( pNode->GetSubSup( RSUP ) != NULL ? ( 1 << RSUP ) : 0 )
188 | ( pNode->GetSubSup( LSUB ) != NULL ? ( 1 << LSUB ) : 0 )
189 | ( pNode->GetSubSup( LSUP ) != NULL ? ( 1 << LSUP ) : 0 );
190 HandleSubSupScriptInternal( pNode, nLevel, flags );
193 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */