Branch data 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/oustringostreaminserter.hxx>
33 : :
34 : 213 : SmWordExportBase::SmWordExportBase( const SmNode* pIn )
35 : 213 : : m_pTree( pIn )
36 : : {
37 : 213 : }
38 : :
39 : 213 : SmWordExportBase::~SmWordExportBase()
40 : : {
41 [ - + ]: 213 : }
42 : :
43 : 3966 : void SmWordExportBase::HandleNode( const SmNode* pNode, int nLevel )
44 : : {
45 : : SAL_INFO( "starmath.wordbase", "Node: " << nLevel << " " << int( pNode->GetType()) << " " << pNode->GetNumSubNodes());
46 [ + + + + : 3966 : switch(pNode->GetType())
+ + + + +
- + + + +
+ + + -
- ]
47 : : {
48 : : case NATTRIBUT:
49 : 84 : HandleAttribute( static_cast< const SmAttributNode* >( pNode ), nLevel );
50 : 84 : break;
51 : : case NTEXT:
52 : 1245 : HandleText(pNode,nLevel);
53 : 1245 : break;
54 : : case NVERTICAL_BRACE:
55 : 12 : HandleVerticalBrace( static_cast< const SmVerticalBraceNode* >( pNode ), nLevel );
56 : 12 : break;
57 : : case NBRACE:
58 : 135 : HandleBrace( static_cast< const SmBraceNode* >( pNode ), nLevel );
59 : 135 : break;
60 : : case NOPER:
61 : 42 : HandleOperator( static_cast< const SmOperNode* >( pNode ), nLevel );
62 : 42 : break;
63 : : case NUNHOR:
64 : 6 : HandleUnaryOperation( static_cast< const SmUnHorNode* >( pNode ), nLevel );
65 : 6 : break;
66 : : case NBINHOR:
67 : 234 : HandleBinaryOperation( static_cast< const SmBinHorNode* >( pNode ), nLevel );
68 : 234 : break;
69 : : case NBINVER:
70 : 84 : HandleFractions(pNode,nLevel);
71 : 84 : break;
72 : : case NROOT:
73 : 18 : HandleRoot( static_cast< const SmRootNode* >( pNode ), nLevel );
74 : 18 : 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() == pText->GetToken().aText)
81 : 0 : HandleText(pText,nLevel);
82 : : else
83 : 0 : HandleMath(pText,nLevel);
84 : 0 : break;
85 : : }
86 : : case NMATH:
87 : 249 : HandleMath(pNode,nLevel);
88 : 249 : break;
89 : : case NSUBSUP:
90 : 153 : HandleSubSupScript( static_cast< const SmSubSupNode* >( pNode ), nLevel );
91 : 153 : break;
92 : : case NEXPRESSION:
93 : 1227 : HandleAllSubNodes( pNode, nLevel );
94 : 1227 : break;
95 : : case NTABLE:
96 : : //Root Node, PILE equivalent, i.e. vertical stack
97 : 240 : HandleTable(pNode,nLevel);
98 : 240 : break;
99 : : case NMATRIX:
100 : 6 : HandleMatrix( static_cast< const SmMatrixNode* >( pNode ), nLevel );
101 : 6 : break;
102 : : case NLINE:
103 : : {
104 : : // TODO
105 : 213 : HandleAllSubNodes( pNode, nLevel );
106 : : }
107 : 213 : 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 : 18 : break;
116 : : case NBLANK:
117 : 0 : HandleBlank();
118 : 0 : break;
119 : : default:
120 : 0 : HandleAllSubNodes( pNode, nLevel );
121 : 0 : break;
122 : : }
123 : 3966 : }
124 : :
125 : : //Root Node, PILE equivalent, i.e. vertical stack
126 : 240 : 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 [ + + ][ - + ]: 240 : if( nLevel || pNode->GetNumSubNodes() > 1 )
[ + + ]
135 : 27 : HandleVerticalStack( pNode, nLevel );
136 : : else
137 : 213 : HandleAllSubNodes( pNode, nLevel );
138 : 240 : }
139 : :
140 : 1887 : void SmWordExportBase::HandleAllSubNodes( const SmNode* pNode, int nLevel )
141 : : {
142 : 1887 : int size = pNode->GetNumSubNodes();
143 [ + + ]: 4656 : for( int i = 0;
144 : : i < size;
145 : : ++i )
146 : : {
147 : : // TODO remove when all types of nodes are handled properly
148 [ - + ]: 2769 : if( pNode->GetSubNode( i ) == NULL )
149 : : {
150 : : OSL_FAIL( "Subnode is NULL, parent node not handled properly" );
151 : 0 : continue;
152 : : }
153 : 2769 : HandleNode( pNode->GetSubNode( i ), nLevel + 1 );
154 : : }
155 : 1887 : }
156 : :
157 : 6 : 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 : 6 : HandleAllSubNodes( pNode, nLevel );
167 : : // break;
168 : : // }
169 : 6 : }
170 : :
171 : 234 : 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 [ + + ]: 234 : switch( pNode->Symbol()->GetToken().eType )
176 : : {
177 : : case TDIVIDEBY:
178 : 234 : return HandleFractions( pNode, nLevel, "lin" );
179 : : default:
180 : 228 : HandleAllSubNodes( pNode, nLevel );
181 : 228 : break;
182 : : }
183 : : }
184 : :
185 : 249 : void SmWordExportBase::HandleMath( const SmNode* pNode, int nLevel )
186 : : {
187 : : SAL_INFO( "starmath.wordbase", "Math: " << int( pNode->GetToken().eType ));
188 : 249 : 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 : 249 : HandleText( pNode, nLevel );
196 : 249 : break;
197 : : }
198 : 249 : }
199 : :
200 : 153 : void SmWordExportBase::HandleSubSupScript( const SmSubSupNode* pNode, int nLevel )
201 : : {
202 : : // set flags to a bitfield of which sub/sup items exists
203 : 153 : int flags = ( pNode->GetSubSup( CSUB ) != NULL ? ( 1 << CSUB ) : 0 )
204 : 153 : | ( pNode->GetSubSup( CSUP ) != NULL ? ( 1 << CSUP ) : 0 )
205 : 153 : | ( pNode->GetSubSup( RSUB ) != NULL ? ( 1 << RSUB ) : 0 )
206 : 153 : | ( pNode->GetSubSup( RSUP ) != NULL ? ( 1 << RSUP ) : 0 )
207 : 153 : | ( pNode->GetSubSup( LSUB ) != NULL ? ( 1 << LSUB ) : 0 )
208 [ + + ][ + + ]: 765 : | ( pNode->GetSubSup( LSUP ) != NULL ? ( 1 << LSUP ) : 0 );
[ + + ][ + + ]
[ + + ][ + + ]
209 : 153 : HandleSubSupScriptInternal( pNode, nLevel, flags );
210 : 153 : }
211 : :
212 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|