build fix
[LibreOffice.git] / starmath / source / wordexportbase.cxx
blob61c1d973fbf449034346a3ddd0d93040ad48cb06
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 SmWordExportBase::SmWordExportBase(const SmNode* pIn)
14 : m_pTree(pIn)
18 SmWordExportBase::~SmWordExportBase() = default;
20 void SmWordExportBase::HandleNode(const SmNode* pNode, int nLevel)
22 SAL_INFO("starmath.wordbase", "Node: " << nLevel << " " << int(pNode->GetType()) << " " << pNode->GetNumSubNodes());
23 switch (pNode->GetType())
25 case NATTRIBUT:
26 HandleAttribute(static_cast< const SmAttributNode* >(pNode), nLevel);
27 break;
28 case NTEXT:
29 HandleText(pNode,nLevel);
30 break;
31 case NVERTICAL_BRACE:
32 HandleVerticalBrace(static_cast< const SmVerticalBraceNode* >(pNode), nLevel);
33 break;
34 case NBRACE:
35 HandleBrace(static_cast< const SmBraceNode* >(pNode), nLevel);
36 break;
37 case NOPER:
38 HandleOperator(static_cast< const SmOperNode* >(pNode), nLevel);
39 break;
40 case NUNHOR:
41 HandleUnaryOperation(static_cast< const SmUnHorNode* >(pNode), nLevel);
42 break;
43 case NBINHOR:
44 HandleBinaryOperation(static_cast< const SmBinHorNode* >(pNode), nLevel);
45 break;
46 case NBINVER:
47 HandleFractions(pNode,nLevel,nullptr);
48 break;
49 case NROOT:
50 HandleRoot(static_cast< const SmRootNode* >(pNode), nLevel);
51 break;
52 case NSPECIAL:
54 const SmTextNode* pText= static_cast< const SmTextNode* >(pNode);
55 //if the token str and the result text are the same then this
56 //is to be seen as text, else assume it's a mathchar
57 if (pText->GetText() == pText->GetToken().aText)
58 HandleText(pText,nLevel);
59 else
60 HandleMath(pText,nLevel);
61 break;
63 case NMATH:
64 case NMATHIDENT:
65 HandleMath(pNode,nLevel);
66 break;
67 case NSUBSUP:
68 HandleSubSupScript(static_cast< const SmSubSupNode* >(pNode), nLevel);
69 break;
70 case NEXPRESSION:
71 HandleAllSubNodes(pNode, nLevel);
72 break;
73 case NTABLE:
74 //Root Node, PILE equivalent, i.e. vertical stack
75 HandleTable(pNode,nLevel);
76 break;
77 case NMATRIX:
78 HandleMatrix(static_cast< const SmMatrixNode* >(pNode), nLevel);
79 break;
80 case NLINE:
82 // TODO
83 HandleAllSubNodes(pNode, nLevel);
85 break;
86 #if 0
87 case NALIGN:
88 HandleMAlign(pNode,nLevel);
89 break;
90 #endif
91 case NPLACE:
92 // explicitly do nothing, MSOffice treats that as a placeholder if item is missing
93 break;
94 case NBLANK:
95 HandleBlank();
96 break;
97 default:
98 HandleAllSubNodes(pNode, nLevel);
99 break;
103 //Root Node, PILE equivalent, i.e. vertical stack
104 void SmWordExportBase::HandleTable(const SmNode* pNode, int nLevel)
106 //The root of the starmath is a table, if
107 //we convert this them each iteration of
108 //conversion from starmath to Word will
109 //add an extra unnecessary level to the
110 //Word output stack which would grow
111 //without bound in a multi step conversion
112 if (nLevel || pNode->GetNumSubNodes() > 1)
113 HandleVerticalStack(pNode, nLevel);
114 else
115 HandleAllSubNodes(pNode, nLevel);
118 void SmWordExportBase::HandleAllSubNodes(const SmNode* pNode, int nLevel)
120 int size = pNode->GetNumSubNodes();
121 for (int i = 0;
122 i < size;
123 ++i)
125 // TODO remove when all types of nodes are handled properly
126 if (pNode->GetSubNode(i) == nullptr)
128 SAL_WARN("starmath.wordbase", "Subnode is NULL, parent node not handled properly");
129 continue;
131 HandleNode(pNode->GetSubNode(i), nLevel + 1);
135 void SmWordExportBase::HandleUnaryOperation(const SmUnHorNode* pNode, int nLevel)
137 // update HandleMath() when adding new items
138 SAL_INFO("starmath.wordbase", "Unary: " << int(pNode->GetToken().eType));
140 // Avoid MSVC warning C4065: switch statement contains 'default' but no 'case' labels
141 // switch( pNode->GetToken().eType )
142 // {
143 // default:
144 HandleAllSubNodes(pNode, nLevel);
145 // break;
146 // }
149 void SmWordExportBase::HandleBinaryOperation(const SmBinHorNode* pNode, int nLevel)
151 SAL_INFO("starmath.wordbase", "Binary: " << int(pNode->Symbol()->GetToken().eType));
152 // update HandleMath() when adding new items
153 switch (pNode->Symbol()->GetToken().eType)
155 case TDIVIDEBY:
156 return HandleFractions(pNode, nLevel, "lin");
157 default:
158 HandleAllSubNodes(pNode, nLevel);
159 break;
163 void SmWordExportBase::HandleMath(const SmNode* pNode, int nLevel)
165 SAL_INFO("starmath.wordbase", "Math: " << int(pNode->GetToken().eType));
166 switch (pNode->GetToken().eType)
168 case TDIVIDEBY:
169 case TACUTE:
170 OSL_ASSERT(false);
171 SAL_FALLTHROUGH; // the above are handled elsewhere, e.g. when handling BINHOR
172 default:
173 HandleText(pNode, nLevel);
174 break;
178 void SmWordExportBase::HandleSubSupScript(const SmSubSupNode* pNode, int nLevel)
180 // set flags to a bitfield of which sub/sup items exists
181 int flags = (pNode->GetSubSup(CSUB) != nullptr ? (1 << CSUB) : 0)
182 | (pNode->GetSubSup(CSUP) != nullptr ? (1 << CSUP) : 0)
183 | (pNode->GetSubSup(RSUB) != nullptr ? (1 << RSUB) : 0)
184 | (pNode->GetSubSup(RSUP) != nullptr ? (1 << RSUP) : 0)
185 | (pNode->GetSubSup(LSUB) != nullptr ? (1 << LSUB) : 0)
186 | (pNode->GetSubSup(LSUP) != nullptr ? (1 << LSUP) : 0);
187 HandleSubSupScriptInternal(pNode, nLevel, flags);
190 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */