Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * Version: MPL 1.1 / GPLv3+ / LGPLv3+
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License or as specified alternatively below. You may obtain a copy of
8 : * the License at http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * Major Contributor(s):
16 : * Copyright (C) 2011 Lubos Lunak <l.lunak@suse.cz> (initial developer)
17 : *
18 : * All Rights Reserved.
19 : *
20 : * For minor contributions see the git repository.
21 : *
22 : * Alternatively, the contents of this file may be used under the terms of
23 : * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
24 : * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
25 : * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
26 : * instead of those above.
27 : */
28 :
29 :
30 : #include "wordexportbase.hxx"
31 :
32 : #include <rtl/ustring.hxx>
33 :
34 142 : SmWordExportBase::SmWordExportBase( const SmNode* pIn )
35 142 : : m_pTree( pIn )
36 : {
37 142 : }
38 :
39 142 : SmWordExportBase::~SmWordExportBase()
40 : {
41 142 : }
42 :
43 2644 : void SmWordExportBase::HandleNode( const SmNode* pNode, int nLevel )
44 : {
45 : SAL_INFO( "starmath.wordbase", "Node: " << nLevel << " " << int( pNode->GetType()) << " " << pNode->GetNumSubNodes());
46 2644 : switch(pNode->GetType())
47 : {
48 : case NATTRIBUT:
49 56 : HandleAttribute( static_cast< const SmAttributNode* >( pNode ), nLevel );
50 56 : break;
51 : case NTEXT:
52 830 : HandleText(pNode,nLevel);
53 830 : break;
54 : case NVERTICAL_BRACE:
55 8 : HandleVerticalBrace( static_cast< const SmVerticalBraceNode* >( pNode ), nLevel );
56 8 : break;
57 : case NBRACE:
58 90 : HandleBrace( static_cast< const SmBraceNode* >( pNode ), nLevel );
59 90 : break;
60 : case NOPER:
61 28 : HandleOperator( static_cast< const SmOperNode* >( pNode ), nLevel );
62 28 : break;
63 : case NUNHOR:
64 4 : HandleUnaryOperation( static_cast< const SmUnHorNode* >( pNode ), nLevel );
65 4 : break;
66 : case NBINHOR:
67 156 : HandleBinaryOperation( static_cast< const SmBinHorNode* >( pNode ), nLevel );
68 156 : break;
69 : case NBINVER:
70 56 : HandleFractions(pNode,nLevel);
71 56 : break;
72 : case NROOT:
73 12 : HandleRoot( static_cast< const SmRootNode* >( pNode ), nLevel );
74 12 : break;
75 : case NSPECIAL:
76 : {
77 0 : const SmTextNode* pText= static_cast< const SmTextNode* >( pNode );
78 : //if the token str and the result text are the same then this
79 : //is to be seen as text, else assume its a mathchar
80 0 : if (pText->GetText() == OUString(pText->GetToken().aText))
81 0 : HandleText(pText,nLevel);
82 : else
83 0 : HandleMath(pText,nLevel);
84 0 : break;
85 : }
86 : case NMATH:
87 166 : HandleMath(pNode,nLevel);
88 166 : break;
89 : case NSUBSUP:
90 102 : HandleSubSupScript( static_cast< const SmSubSupNode* >( pNode ), nLevel );
91 102 : break;
92 : case NEXPRESSION:
93 818 : HandleAllSubNodes( pNode, nLevel );
94 818 : break;
95 : case NTABLE:
96 : //Root Node, PILE equivalent, i.e. vertical stack
97 160 : HandleTable(pNode,nLevel);
98 160 : break;
99 : case NMATRIX:
100 4 : HandleMatrix( static_cast< const SmMatrixNode* >( pNode ), nLevel );
101 4 : break;
102 : case NLINE:
103 : {
104 : // TODO
105 142 : HandleAllSubNodes( pNode, nLevel );
106 : }
107 142 : break;
108 : #if 0
109 : case NALIGN:
110 : HandleMAlign(pNode,nLevel);
111 : break;
112 : #endif
113 : case NPLACE:
114 : // explicitly do nothing, MSOffice treats that as a placeholder if item is missing
115 12 : break;
116 : case NBLANK:
117 0 : HandleBlank();
118 0 : break;
119 : default:
120 0 : HandleAllSubNodes( pNode, nLevel );
121 0 : break;
122 : }
123 2644 : }
124 :
125 : //Root Node, PILE equivalent, i.e. vertical stack
126 160 : void SmWordExportBase::HandleTable( const SmNode* pNode, int nLevel )
127 : {
128 : //The root of the starmath is a table, if
129 : //we convert this them each iteration of
130 : //conversion from starmath to Word will
131 : //add an extra unnecessary level to the
132 : //Word output stack which would grow
133 : //without bound in a multi step conversion
134 160 : if( nLevel || pNode->GetNumSubNodes() > 1 )
135 18 : HandleVerticalStack( pNode, nLevel );
136 : else
137 142 : HandleAllSubNodes( pNode, nLevel );
138 160 : }
139 :
140 1258 : void SmWordExportBase::HandleAllSubNodes( const SmNode* pNode, int nLevel )
141 : {
142 1258 : int size = pNode->GetNumSubNodes();
143 3104 : for( int i = 0;
144 : i < size;
145 : ++i )
146 : {
147 : // TODO remove when all types of nodes are handled properly
148 1846 : if( pNode->GetSubNode( i ) == NULL )
149 : {
150 : OSL_FAIL( "Subnode is NULL, parent node not handled properly" );
151 0 : continue;
152 : }
153 1846 : HandleNode( pNode->GetSubNode( i ), nLevel + 1 );
154 : }
155 1258 : }
156 :
157 4 : void SmWordExportBase::HandleUnaryOperation( const SmUnHorNode* pNode, int nLevel )
158 : {
159 : // update HandleMath() when adding new items
160 : SAL_INFO( "starmath.wordbase", "Unary: " << int( pNode->GetToken().eType ));
161 :
162 : // Avoid MSVC warning C4065: switch statement contains 'default' but no 'case' labels
163 : // switch( pNode->GetToken().eType )
164 : // {
165 : // default:
166 4 : HandleAllSubNodes( pNode, nLevel );
167 : // break;
168 : // }
169 4 : }
170 :
171 156 : void SmWordExportBase::HandleBinaryOperation( const SmBinHorNode* pNode, int nLevel )
172 : {
173 : SAL_INFO( "starmath.wordbase", "Binary: " << int( pNode->Symbol()->GetToken().eType ));
174 : // update HandleMath() when adding new items
175 156 : switch( pNode->Symbol()->GetToken().eType )
176 : {
177 : case TDIVIDEBY:
178 160 : return HandleFractions( pNode, nLevel, "lin" );
179 : default:
180 152 : HandleAllSubNodes( pNode, nLevel );
181 152 : break;
182 : }
183 : }
184 :
185 166 : void SmWordExportBase::HandleMath( const SmNode* pNode, int nLevel )
186 : {
187 : SAL_INFO( "starmath.wordbase", "Math: " << int( pNode->GetToken().eType ));
188 166 : switch( pNode->GetToken().eType )
189 : {
190 : case TDIVIDEBY:
191 : case TACUTE:
192 : // these are handled elsewhere, e.g. when handling BINHOR
193 : OSL_ASSERT( false );
194 : default:
195 166 : HandleText( pNode, nLevel );
196 166 : break;
197 : }
198 166 : }
199 :
200 102 : void SmWordExportBase::HandleSubSupScript( const SmSubSupNode* pNode, int nLevel )
201 : {
202 : // set flags to a bitfield of which sub/sup items exists
203 102 : int flags = ( pNode->GetSubSup( CSUB ) != NULL ? ( 1 << CSUB ) : 0 )
204 102 : | ( pNode->GetSubSup( CSUP ) != NULL ? ( 1 << CSUP ) : 0 )
205 102 : | ( pNode->GetSubSup( RSUB ) != NULL ? ( 1 << RSUB ) : 0 )
206 102 : | ( pNode->GetSubSup( RSUP ) != NULL ? ( 1 << RSUP ) : 0 )
207 102 : | ( pNode->GetSubSup( LSUB ) != NULL ? ( 1 << LSUB ) : 0 )
208 510 : | ( pNode->GetSubSup( LSUP ) != NULL ? ( 1 << LSUP ) : 0 );
209 102 : HandleSubSupScriptInternal( pNode, nLevel, flags );
210 102 : }
211 :
212 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|