1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
11 #include "wordexportbase.hxx"
13 #include <rtl/ustring.hxx>
15 SmWordExportBase::SmWordExportBase( const SmNode
* 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())
30 HandleAttribute( static_cast< const SmAttributNode
* >( pNode
), nLevel
);
33 HandleText(pNode
,nLevel
);
36 HandleVerticalBrace( static_cast< const SmVerticalBraceNode
* >( pNode
), nLevel
);
39 HandleBrace( static_cast< const SmBraceNode
* >( pNode
), nLevel
);
42 HandleOperator( static_cast< const SmOperNode
* >( pNode
), nLevel
);
45 HandleUnaryOperation( static_cast< const SmUnHorNode
* >( pNode
), nLevel
);
48 HandleBinaryOperation( static_cast< const SmBinHorNode
* >( pNode
), nLevel
);
51 HandleFractions(pNode
,nLevel
);
54 HandleRoot( static_cast< const SmRootNode
* >( pNode
), nLevel
);
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
);
64 HandleMath(pText
,nLevel
);
68 HandleMath(pNode
,nLevel
);
71 HandleSubSupScript( static_cast< const SmSubSupNode
* >( pNode
), nLevel
);
74 HandleAllSubNodes( pNode
, nLevel
);
77 //Root Node, PILE equivalent, i.e. vertical stack
78 HandleTable(pNode
,nLevel
);
81 HandleMatrix( static_cast< const SmMatrixNode
* >( pNode
), nLevel
);
86 HandleAllSubNodes( pNode
, nLevel
);
91 HandleMAlign(pNode
,nLevel
);
95 // explicitly do nothing, MSOffice treats that as a placeholder if item is missing
101 HandleAllSubNodes( pNode
, nLevel
);
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
);
118 HandleAllSubNodes( pNode
, nLevel
);
121 void SmWordExportBase::HandleAllSubNodes( const SmNode
* pNode
, int nLevel
)
123 int size
= pNode
->GetNumSubNodes();
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" );
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 )
147 HandleAllSubNodes( pNode
, nLevel
);
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
)
159 return HandleFractions( pNode
, nLevel
, "lin" );
161 HandleAllSubNodes( pNode
, nLevel
);
166 void SmWordExportBase::HandleMath( const SmNode
* pNode
, int nLevel
)
168 SAL_INFO( "starmath.wordbase", "Math: " << int( pNode
->GetToken().eType
));
169 switch( pNode
->GetToken().eType
)
173 // these are handled elsewhere, e.g. when handling BINHOR
176 HandleText( pNode
, nLevel
);
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: */