Add a comment to clarify what kind of inputs the class handles
[LibreOffice.git] / starmath / source / mathml / attribute.cxx
blobca4a86290d05807c93d2348242d4a17ea7e91770
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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 */
10 #include <mathml/attribute.hxx>
12 void SmMlAttribute::clearPreviousAttributeValue()
14 switch (m_aSmMlAttributeValueType)
16 case SmMlAttributeValueType::NMlEmpty:
17 break;
18 case SmMlAttributeValueType::MlHref:
19 if (m_aAttributeValue.m_aHref.m_aLnk)
20 delete m_aAttributeValue.m_aHref.m_aLnk;
21 break;
22 case SmMlAttributeValueType::MlLspace:
23 if (m_aAttributeValue.m_aLspace.m_aLengthValue.m_aOriginalText)
24 delete m_aAttributeValue.m_aLspace.m_aLengthValue.m_aOriginalText;
25 break;
26 case SmMlAttributeValueType::MlMathsize:
27 if (m_aAttributeValue.m_aMathsize.m_aLengthValue.m_aOriginalText)
28 delete m_aAttributeValue.m_aMathsize.m_aLengthValue.m_aOriginalText;
29 break;
30 case SmMlAttributeValueType::MlMaxsize:
31 if (m_aAttributeValue.m_aMaxsize.m_aLengthValue.m_aOriginalText)
32 delete m_aAttributeValue.m_aMaxsize.m_aLengthValue.m_aOriginalText;
33 break;
34 case SmMlAttributeValueType::MlMinsize:
35 if (m_aAttributeValue.m_aMinsize.m_aLengthValue.m_aOriginalText)
36 delete m_aAttributeValue.m_aMinsize.m_aLengthValue.m_aOriginalText;
37 break;
38 case SmMlAttributeValueType::MlRspace:
39 if (m_aAttributeValue.m_aRspace.m_aLengthValue.m_aOriginalText)
40 delete m_aAttributeValue.m_aRspace.m_aLengthValue.m_aOriginalText;
41 break;
42 default:
43 break;
47 void SmMlAttribute::setDefaultAttributeValue()
49 switch (m_aSmMlAttributeValueType)
51 case SmMlAttributeValueType::NMlEmpty:
52 break;
53 case SmMlAttributeValueType::MlAccent:
54 m_aAttributeValue.m_aAccent.m_aAccent = SmMlAttributeValueAccent::MlFalse;
55 break;
56 case SmMlAttributeValueType::MlDir:
57 m_aAttributeValue.m_aDir.m_aDir = SmMlAttributeValueDir::MlLtr;
58 break;
59 case SmMlAttributeValueType::MlDisplaystyle:
60 m_aAttributeValue.m_aDisplaystyle.m_aDisplaystyle
61 = SmMlAttributeValueDisplaystyle::MlFalse;
62 break;
63 case SmMlAttributeValueType::MlFence:
64 m_aAttributeValue.m_aFence.m_aFence = SmMlAttributeValueFence::MlFalse;
65 break;
66 case SmMlAttributeValueType::MlForm:
67 m_aAttributeValue.m_aForm.m_aForm = SmMlAttributeValueForm::MlInfix;
68 break;
69 case SmMlAttributeValueType::MlHref:
70 m_aAttributeValue.m_aHref.m_aHref = SmMlAttributeValueHref::NMlEmpty;
71 m_aAttributeValue.m_aHref.m_aLnk = new OUString(u""_ustr);
72 break;
73 case SmMlAttributeValueType::MlLspace:
74 m_aAttributeValue.m_aLspace.m_aLengthValue.m_aLengthUnit = SmLengthUnit::MlEm;
75 m_aAttributeValue.m_aLspace.m_aLengthValue.m_aLengthValue = 5.0 / 18;
76 m_aAttributeValue.m_aLspace.m_aLengthValue.m_aOriginalText
77 = new OUString(u"5/18em"_ustr);
78 break;
79 case SmMlAttributeValueType::MlMathbackground:
80 m_aAttributeValue.m_aMathbackground.m_aMathbackground
81 = SmMlAttributeValueMathbackground::MlTransparent;
82 break;
83 case SmMlAttributeValueType::MlMathcolor:
84 m_aAttributeValue.m_aMathcolor.m_aMathcolor = SmMlAttributeValueMathcolor::MlDefault;
85 break;
86 case SmMlAttributeValueType::MlMathsize:
87 m_aAttributeValue.m_aMathsize.m_aLengthValue.m_aLengthUnit = SmLengthUnit::MlP;
88 m_aAttributeValue.m_aMathsize.m_aLengthValue.m_aLengthValue = 100;
89 m_aAttributeValue.m_aMathsize.m_aLengthValue.m_aOriginalText
90 = new OUString(u"100%"_ustr);
91 break;
92 case SmMlAttributeValueType::MlMathvariant:
93 m_aAttributeValue.m_aMathvariant.m_aMathvariant = SmMlAttributeValueMathvariant::normal;
94 break;
95 case SmMlAttributeValueType::MlMaxsize:
96 m_aAttributeValue.m_aMaxsize.m_aMaxsize = SmMlAttributeValueMaxsize::MlInfinity;
97 m_aAttributeValue.m_aMaxsize.m_aLengthValue.m_aLengthUnit = SmLengthUnit::MlP;
98 m_aAttributeValue.m_aMaxsize.m_aLengthValue.m_aLengthValue = 10000;
99 m_aAttributeValue.m_aMaxsize.m_aLengthValue.m_aOriginalText
100 = new OUString(u"10000%"_ustr);
101 break;
102 case SmMlAttributeValueType::MlMinsize:
103 m_aAttributeValue.m_aMinsize.m_aLengthValue.m_aLengthUnit = SmLengthUnit::MlP;
104 m_aAttributeValue.m_aMinsize.m_aLengthValue.m_aLengthValue = 1;
105 m_aAttributeValue.m_aMinsize.m_aLengthValue.m_aOriginalText = new OUString(u"1%"_ustr);
106 break;
107 case SmMlAttributeValueType::MlMovablelimits:
108 m_aAttributeValue.m_aMovablelimits.m_aMovablelimits
109 = SmMlAttributeValueMovablelimits::MlFalse;
110 break;
111 case SmMlAttributeValueType::MlRspace:
112 m_aAttributeValue.m_aRspace.m_aLengthValue.m_aLengthUnit = SmLengthUnit::MlEm;
113 m_aAttributeValue.m_aRspace.m_aLengthValue.m_aLengthValue = 5.0 / 18;
114 m_aAttributeValue.m_aRspace.m_aLengthValue.m_aOriginalText
115 = new OUString(u"5/18em"_ustr);
116 break;
117 case SmMlAttributeValueType::MlSeparator:
118 m_aAttributeValue.m_aSeparator.m_aSeparator = SmMlAttributeValueSeparator::MlFalse;
119 break;
120 case SmMlAttributeValueType::MlStretchy:
121 m_aAttributeValue.m_aStretchy.m_aStretchy = SmMlAttributeValueStretchy::MlFalse;
122 break;
123 case SmMlAttributeValueType::MlSymmetric:
124 m_aAttributeValue.m_aSymmetric.m_aSymmetric = SmMlAttributeValueSymmetric::MlFalse;
125 break;
129 void SmMlAttribute::setAttributeValue(const SmMlAttribute* aAttribute)
131 switch (aAttribute->getMlAttributeValueType())
133 case SmMlAttributeValueType::NMlEmpty:
134 clearPreviousAttributeValue();
135 m_aSmMlAttributeValueType = SmMlAttributeValueType::NMlEmpty;
136 break;
137 case SmMlAttributeValueType::MlAccent:
138 setMlAccent(aAttribute->getMlAccent());
139 break;
140 case SmMlAttributeValueType::MlDir:
141 setMlDir(aAttribute->getMlDir());
142 break;
143 case SmMlAttributeValueType::MlDisplaystyle:
144 setMlDisplaystyle(aAttribute->getMlDisplaystyle());
145 break;
146 case SmMlAttributeValueType::MlFence:
147 setMlFence(aAttribute->getMlFence());
148 break;
149 case SmMlAttributeValueType::MlForm:
150 setMlForm(aAttribute->getMlForm());
151 break;
152 case SmMlAttributeValueType::MlHref:
153 setMlHref(aAttribute->getMlHref());
154 break;
155 case SmMlAttributeValueType::MlLspace:
156 setMlLspace(aAttribute->getMlLspace());
157 break;
158 case SmMlAttributeValueType::MlMathbackground:
159 setMlMathbackground(aAttribute->getMlMathbackground());
160 break;
161 case SmMlAttributeValueType::MlMathcolor:
162 setMlMathcolor(aAttribute->getMlMathcolor());
163 break;
164 case SmMlAttributeValueType::MlMathsize:
165 setMlMathsize(aAttribute->getMlMathsize());
166 break;
167 case SmMlAttributeValueType::MlMathvariant:
168 setMlMathvariant(aAttribute->getMlMathvariant());
169 break;
170 case SmMlAttributeValueType::MlMaxsize:
171 setMlMaxsize(aAttribute->getMlMaxsize());
172 break;
173 case SmMlAttributeValueType::MlMinsize:
174 setMlMinsize(aAttribute->getMlMinsize());
175 break;
176 case SmMlAttributeValueType::MlMovablelimits:
177 setMlMovablelimits(aAttribute->getMlMovablelimits());
178 break;
179 case SmMlAttributeValueType::MlRspace:
180 setMlRspace(aAttribute->getMlRspace());
181 break;
182 case SmMlAttributeValueType::MlSeparator:
183 setMlSeparator(aAttribute->getMlSeparator());
184 break;
185 case SmMlAttributeValueType::MlStretchy:
186 setMlStretchy(aAttribute->getMlStretchy());
187 break;
188 case SmMlAttributeValueType::MlSymmetric:
189 setMlSymmetric(aAttribute->getMlSymmetric());
190 break;
194 /* get values */
195 /*************************************************************************************************/
197 const struct SmMlAccent* SmMlAttribute::getMlAccent() const
199 if (m_aSmMlAttributeValueType == SmMlAttributeValueType::MlAccent)
200 return &m_aAttributeValue.m_aAccent;
201 return nullptr;
204 const struct SmMlDir* SmMlAttribute::getMlDir() const
206 if (m_aSmMlAttributeValueType == SmMlAttributeValueType::MlDir)
207 return &m_aAttributeValue.m_aDir;
208 return nullptr;
211 const struct SmMlDisplaystyle* SmMlAttribute::getMlDisplaystyle() const
213 if (m_aSmMlAttributeValueType == SmMlAttributeValueType::MlDisplaystyle)
214 return &m_aAttributeValue.m_aDisplaystyle;
215 return nullptr;
218 const struct SmMlFence* SmMlAttribute::getMlFence() const
220 if (m_aSmMlAttributeValueType == SmMlAttributeValueType::MlFence)
221 return &m_aAttributeValue.m_aFence;
222 return nullptr;
225 const struct SmMlForm* SmMlAttribute::getMlForm() const
227 if (m_aSmMlAttributeValueType == SmMlAttributeValueType::MlForm)
228 return &m_aAttributeValue.m_aForm;
229 return nullptr;
232 const struct SmMlHref* SmMlAttribute::getMlHref() const
234 if (m_aSmMlAttributeValueType == SmMlAttributeValueType::MlHref)
235 return &m_aAttributeValue.m_aHref;
236 return nullptr;
239 const struct SmMlLspace* SmMlAttribute::getMlLspace() const
241 if (m_aSmMlAttributeValueType == SmMlAttributeValueType::MlLspace)
242 return &m_aAttributeValue.m_aLspace;
243 return nullptr;
246 const struct SmMlMathbackground* SmMlAttribute::getMlMathbackground() const
248 if (m_aSmMlAttributeValueType == SmMlAttributeValueType::MlMathbackground)
249 return &m_aAttributeValue.m_aMathbackground;
250 return nullptr;
253 const struct SmMlMathcolor* SmMlAttribute::getMlMathcolor() const
255 if (m_aSmMlAttributeValueType == SmMlAttributeValueType::MlMathcolor)
256 return &m_aAttributeValue.m_aMathcolor;
257 return nullptr;
260 const struct SmMlMathsize* SmMlAttribute::getMlMathsize() const
262 if (m_aSmMlAttributeValueType == SmMlAttributeValueType::MlAccent)
263 return &m_aAttributeValue.m_aMathsize;
264 return nullptr;
267 const struct SmMlMathvariant* SmMlAttribute::getMlMathvariant() const
269 if (m_aSmMlAttributeValueType == SmMlAttributeValueType::MlMathvariant)
270 return &m_aAttributeValue.m_aMathvariant;
271 return nullptr;
274 const struct SmMlMaxsize* SmMlAttribute::getMlMaxsize() const
276 if (m_aSmMlAttributeValueType == SmMlAttributeValueType::MlMaxsize)
277 return &m_aAttributeValue.m_aMaxsize;
278 return nullptr;
281 const struct SmMlMinsize* SmMlAttribute::getMlMinsize() const
283 if (m_aSmMlAttributeValueType == SmMlAttributeValueType::MlMinsize)
284 return &m_aAttributeValue.m_aMinsize;
285 return nullptr;
288 const struct SmMlMovablelimits* SmMlAttribute::getMlMovablelimits() const
290 if (m_aSmMlAttributeValueType == SmMlAttributeValueType::MlMovablelimits)
291 return &m_aAttributeValue.m_aMovablelimits;
292 return nullptr;
295 const struct SmMlRspace* SmMlAttribute::getMlRspace() const
297 if (m_aSmMlAttributeValueType == SmMlAttributeValueType::MlRspace)
298 return &m_aAttributeValue.m_aRspace;
299 return nullptr;
302 const struct SmMlSeparator* SmMlAttribute::getMlSeparator() const
304 if (m_aSmMlAttributeValueType == SmMlAttributeValueType::MlSeparator)
305 return &m_aAttributeValue.m_aSeparator;
306 return nullptr;
309 const struct SmMlStretchy* SmMlAttribute::getMlStretchy() const
311 if (m_aSmMlAttributeValueType == SmMlAttributeValueType::MlStretchy)
312 return &m_aAttributeValue.m_aStretchy;
313 return nullptr;
316 const struct SmMlSymmetric* SmMlAttribute::getMlSymmetric() const
318 if (m_aSmMlAttributeValueType == SmMlAttributeValueType::MlSymmetric)
319 return &m_aAttributeValue.m_aSymmetric;
320 return nullptr;
323 /* set values */
324 /*************************************************************************************************/
326 void SmMlAttribute::setMlAccent(const SmMlAccent* aAccent)
328 m_bSet = true;
329 clearPreviousAttributeValue();
330 m_aAttributeValue.m_aAccent.m_aAccent = aAccent->m_aAccent;
333 void SmMlAttribute::setMlDir(const SmMlDir* aDir)
335 m_bSet = true;
336 clearPreviousAttributeValue();
337 m_aAttributeValue.m_aDir.m_aDir = aDir->m_aDir;
340 void SmMlAttribute::setMlDisplaystyle(const SmMlDisplaystyle* aDisplaystyle)
342 m_bSet = true;
343 clearPreviousAttributeValue();
344 m_aAttributeValue.m_aDisplaystyle.m_aDisplaystyle = aDisplaystyle->m_aDisplaystyle;
347 void SmMlAttribute::setMlFence(const SmMlFence* aFence)
349 m_bSet = true;
350 clearPreviousAttributeValue();
351 m_aAttributeValue.m_aFence.m_aFence = aFence->m_aFence;
354 void SmMlAttribute::setMlForm(const SmMlForm* aForm)
356 m_bSet = true;
357 clearPreviousAttributeValue();
358 m_aAttributeValue.m_aForm.m_aForm = aForm->m_aForm;
361 void SmMlAttribute::setMlHref(const SmMlHref* aHref)
363 m_bSet = true;
364 clearPreviousAttributeValue();
365 m_aAttributeValue.m_aHref.m_aHref = aHref->m_aHref;
366 m_aAttributeValue.m_aHref.m_aLnk = new OUString(*aHref->m_aLnk);
369 void SmMlAttribute::setMlLspace(const SmMlLspace* aLspace)
371 m_bSet = true;
372 clearPreviousAttributeValue();
373 m_aAttributeValue.m_aLspace.m_aLengthValue.m_aLengthUnit
374 = aLspace->m_aLengthValue.m_aLengthUnit;
375 m_aAttributeValue.m_aLspace.m_aLengthValue.m_aLengthValue
376 = aLspace->m_aLengthValue.m_aLengthValue;
377 m_aAttributeValue.m_aLspace.m_aLengthValue.m_aOriginalText
378 = new OUString(*aLspace->m_aLengthValue.m_aOriginalText);
381 void SmMlAttribute::setMlMathbackground(const SmMlMathbackground* aMathbackground)
383 m_bSet = true;
384 clearPreviousAttributeValue();
385 m_aAttributeValue.m_aMathbackground.m_aMathbackground = aMathbackground->m_aMathbackground;
388 void SmMlAttribute::setMlMathcolor(const SmMlMathcolor* aMathcolor)
390 m_bSet = true;
391 clearPreviousAttributeValue();
392 m_aAttributeValue.m_aMathcolor.m_aMathcolor = aMathcolor->m_aMathcolor;
395 void SmMlAttribute::setMlMathsize(const SmMlMathsize* aMathsize)
397 m_bSet = true;
398 clearPreviousAttributeValue();
399 m_aAttributeValue.m_aMathsize.m_aLengthValue.m_aLengthUnit
400 = aMathsize->m_aLengthValue.m_aLengthUnit;
401 m_aAttributeValue.m_aMathsize.m_aLengthValue.m_aLengthValue
402 = aMathsize->m_aLengthValue.m_aLengthValue;
403 m_aAttributeValue.m_aMathsize.m_aLengthValue.m_aOriginalText
404 = new OUString(*aMathsize->m_aLengthValue.m_aOriginalText);
407 void SmMlAttribute::setMlMathvariant(const SmMlMathvariant* aMathvariant)
409 m_bSet = true;
410 clearPreviousAttributeValue();
411 m_aAttributeValue.m_aMathvariant.m_aMathvariant = aMathvariant->m_aMathvariant;
414 void SmMlAttribute::setMlMaxsize(const SmMlMaxsize* aMaxsize)
416 m_bSet = true;
417 clearPreviousAttributeValue();
418 m_aAttributeValue.m_aMaxsize.m_aMaxsize = aMaxsize->m_aMaxsize;
419 m_aAttributeValue.m_aMaxsize.m_aLengthValue.m_aLengthUnit
420 = aMaxsize->m_aLengthValue.m_aLengthUnit;
421 m_aAttributeValue.m_aMaxsize.m_aLengthValue.m_aLengthValue
422 = aMaxsize->m_aLengthValue.m_aLengthValue;
423 m_aAttributeValue.m_aMaxsize.m_aLengthValue.m_aOriginalText
424 = new OUString(*aMaxsize->m_aLengthValue.m_aOriginalText);
427 void SmMlAttribute::setMlMinsize(const SmMlMinsize* aMinsize)
429 m_bSet = true;
430 clearPreviousAttributeValue();
431 m_aAttributeValue.m_aMinsize.m_aLengthValue.m_aLengthUnit
432 = aMinsize->m_aLengthValue.m_aLengthUnit;
433 m_aAttributeValue.m_aMinsize.m_aLengthValue.m_aLengthValue
434 = aMinsize->m_aLengthValue.m_aLengthValue;
435 m_aAttributeValue.m_aMinsize.m_aLengthValue.m_aOriginalText
436 = new OUString(*aMinsize->m_aLengthValue.m_aOriginalText);
439 void SmMlAttribute::setMlMovablelimits(const SmMlMovablelimits* aMovablelimits)
441 m_bSet = true;
442 clearPreviousAttributeValue();
443 m_aAttributeValue.m_aMovablelimits.m_aMovablelimits = aMovablelimits->m_aMovablelimits;
446 void SmMlAttribute::setMlRspace(const SmMlRspace* aRspace)
448 m_bSet = true;
449 clearPreviousAttributeValue();
450 m_aAttributeValue.m_aRspace.m_aLengthValue.m_aLengthUnit
451 = aRspace->m_aLengthValue.m_aLengthUnit;
452 m_aAttributeValue.m_aRspace.m_aLengthValue.m_aLengthValue
453 = aRspace->m_aLengthValue.m_aLengthValue;
454 m_aAttributeValue.m_aRspace.m_aLengthValue.m_aOriginalText
455 = new OUString(*aRspace->m_aLengthValue.m_aOriginalText);
458 void SmMlAttribute::setMlSeparator(const SmMlSeparator* aSeparator)
460 m_bSet = true;
461 clearPreviousAttributeValue();
462 m_aAttributeValue.m_aSeparator.m_aSeparator = aSeparator->m_aSeparator;
465 void SmMlAttribute::setMlStretchy(const SmMlStretchy* aStretchy)
467 m_bSet = true;
468 clearPreviousAttributeValue();
469 m_aAttributeValue.m_aStretchy.m_aStretchy = aStretchy->m_aStretchy;
472 void SmMlAttribute::setMlSymmetric(const SmMlSymmetric* aSymmetric)
474 m_bSet = true;
475 clearPreviousAttributeValue();
476 m_aAttributeValue.m_aSymmetric.m_aSymmetric = aSymmetric->m_aSymmetric;
479 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */