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