1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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/.
10 #include <mathml/attribute.hxx>
12 void SmMlAttribute::clearPreviousAttributeValue()
14 switch (m_aSmMlAttributeValueType
)
16 case SmMlAttributeValueType::NMlEmpty
:
18 case SmMlAttributeValueType::MlHref
:
19 if (m_aAttributeValue
.m_aHref
.m_aLnk
)
20 delete m_aAttributeValue
.m_aHref
.m_aLnk
;
22 case SmMlAttributeValueType::MlLspace
:
23 if (m_aAttributeValue
.m_aLspace
.m_aLengthValue
.m_aOriginalText
)
24 delete m_aAttributeValue
.m_aLspace
.m_aLengthValue
.m_aOriginalText
;
26 case SmMlAttributeValueType::MlMathsize
:
27 if (m_aAttributeValue
.m_aMathsize
.m_aLengthValue
.m_aOriginalText
)
28 delete m_aAttributeValue
.m_aMathsize
.m_aLengthValue
.m_aOriginalText
;
30 case SmMlAttributeValueType::MlMaxsize
:
31 if (m_aAttributeValue
.m_aMaxsize
.m_aLengthValue
.m_aOriginalText
)
32 delete m_aAttributeValue
.m_aMaxsize
.m_aLengthValue
.m_aOriginalText
;
34 case SmMlAttributeValueType::MlMinsize
:
35 if (m_aAttributeValue
.m_aMinsize
.m_aLengthValue
.m_aOriginalText
)
36 delete m_aAttributeValue
.m_aMinsize
.m_aLengthValue
.m_aOriginalText
;
38 case SmMlAttributeValueType::MlRspace
:
39 if (m_aAttributeValue
.m_aRspace
.m_aLengthValue
.m_aOriginalText
)
40 delete m_aAttributeValue
.m_aRspace
.m_aLengthValue
.m_aOriginalText
;
47 void SmMlAttribute::setDefaultAttributeValue()
49 switch (m_aSmMlAttributeValueType
)
51 case SmMlAttributeValueType::NMlEmpty
:
53 case SmMlAttributeValueType::MlAccent
:
54 m_aAttributeValue
.m_aAccent
.m_aAccent
= SmMlAttributeValueAccent::MlFalse
;
56 case SmMlAttributeValueType::MlDir
:
57 m_aAttributeValue
.m_aDir
.m_aDir
= SmMlAttributeValueDir::MlLtr
;
59 case SmMlAttributeValueType::MlDisplaystyle
:
60 m_aAttributeValue
.m_aDisplaystyle
.m_aDisplaystyle
61 = SmMlAttributeValueDisplaystyle::MlFalse
;
63 case SmMlAttributeValueType::MlFence
:
64 m_aAttributeValue
.m_aFence
.m_aFence
= SmMlAttributeValueFence::MlFalse
;
66 case SmMlAttributeValueType::MlForm
:
67 m_aAttributeValue
.m_aForm
.m_aForm
= SmMlAttributeValueForm::MlInfix
;
69 case SmMlAttributeValueType::MlHref
:
70 m_aAttributeValue
.m_aHref
.m_aHref
= SmMlAttributeValueHref::NMlEmpty
;
71 m_aAttributeValue
.m_aHref
.m_aLnk
= new OUString(u
""_ustr
);
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
);
79 case SmMlAttributeValueType::MlMathbackground
:
80 m_aAttributeValue
.m_aMathbackground
.m_aMathbackground
81 = SmMlAttributeValueMathbackground::MlTransparent
;
83 case SmMlAttributeValueType::MlMathcolor
:
84 m_aAttributeValue
.m_aMathcolor
.m_aMathcolor
= SmMlAttributeValueMathcolor::MlDefault
;
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
);
92 case SmMlAttributeValueType::MlMathvariant
:
93 m_aAttributeValue
.m_aMathvariant
.m_aMathvariant
= SmMlAttributeValueMathvariant::normal
;
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
);
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
);
107 case SmMlAttributeValueType::MlMovablelimits
:
108 m_aAttributeValue
.m_aMovablelimits
.m_aMovablelimits
109 = SmMlAttributeValueMovablelimits::MlFalse
;
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
);
117 case SmMlAttributeValueType::MlSeparator
:
118 m_aAttributeValue
.m_aSeparator
.m_aSeparator
= SmMlAttributeValueSeparator::MlFalse
;
120 case SmMlAttributeValueType::MlStretchy
:
121 m_aAttributeValue
.m_aStretchy
.m_aStretchy
= SmMlAttributeValueStretchy::MlFalse
;
123 case SmMlAttributeValueType::MlSymmetric
:
124 m_aAttributeValue
.m_aSymmetric
.m_aSymmetric
= SmMlAttributeValueSymmetric::MlFalse
;
129 void SmMlAttribute::setAttributeValue(const SmMlAttribute
* aAttribute
)
131 switch (aAttribute
->getMlAttributeValueType())
133 case SmMlAttributeValueType::NMlEmpty
:
134 clearPreviousAttributeValue();
135 m_aSmMlAttributeValueType
= SmMlAttributeValueType::NMlEmpty
;
137 case SmMlAttributeValueType::MlAccent
:
138 setMlAccent(aAttribute
->getMlAccent());
140 case SmMlAttributeValueType::MlDir
:
141 setMlDir(aAttribute
->getMlDir());
143 case SmMlAttributeValueType::MlDisplaystyle
:
144 setMlDisplaystyle(aAttribute
->getMlDisplaystyle());
146 case SmMlAttributeValueType::MlFence
:
147 setMlFence(aAttribute
->getMlFence());
149 case SmMlAttributeValueType::MlForm
:
150 setMlForm(aAttribute
->getMlForm());
152 case SmMlAttributeValueType::MlHref
:
153 setMlHref(aAttribute
->getMlHref());
155 case SmMlAttributeValueType::MlLspace
:
156 setMlLspace(aAttribute
->getMlLspace());
158 case SmMlAttributeValueType::MlMathbackground
:
159 setMlMathbackground(aAttribute
->getMlMathbackground());
161 case SmMlAttributeValueType::MlMathcolor
:
162 setMlMathcolor(aAttribute
->getMlMathcolor());
164 case SmMlAttributeValueType::MlMathsize
:
165 setMlMathsize(aAttribute
->getMlMathsize());
167 case SmMlAttributeValueType::MlMathvariant
:
168 setMlMathvariant(aAttribute
->getMlMathvariant());
170 case SmMlAttributeValueType::MlMaxsize
:
171 setMlMaxsize(aAttribute
->getMlMaxsize());
173 case SmMlAttributeValueType::MlMinsize
:
174 setMlMinsize(aAttribute
->getMlMinsize());
176 case SmMlAttributeValueType::MlMovablelimits
:
177 setMlMovablelimits(aAttribute
->getMlMovablelimits());
179 case SmMlAttributeValueType::MlRspace
:
180 setMlRspace(aAttribute
->getMlRspace());
182 case SmMlAttributeValueType::MlSeparator
:
183 setMlSeparator(aAttribute
->getMlSeparator());
185 case SmMlAttributeValueType::MlStretchy
:
186 setMlStretchy(aAttribute
->getMlStretchy());
188 case SmMlAttributeValueType::MlSymmetric
:
189 setMlSymmetric(aAttribute
->getMlSymmetric());
195 /*************************************************************************************************/
197 const struct SmMlAccent
* SmMlAttribute::getMlAccent() const
199 if (m_aSmMlAttributeValueType
== SmMlAttributeValueType::MlAccent
)
200 return &m_aAttributeValue
.m_aAccent
;
204 const struct SmMlDir
* SmMlAttribute::getMlDir() const
206 if (m_aSmMlAttributeValueType
== SmMlAttributeValueType::MlDir
)
207 return &m_aAttributeValue
.m_aDir
;
211 const struct SmMlDisplaystyle
* SmMlAttribute::getMlDisplaystyle() const
213 if (m_aSmMlAttributeValueType
== SmMlAttributeValueType::MlDisplaystyle
)
214 return &m_aAttributeValue
.m_aDisplaystyle
;
218 const struct SmMlFence
* SmMlAttribute::getMlFence() const
220 if (m_aSmMlAttributeValueType
== SmMlAttributeValueType::MlFence
)
221 return &m_aAttributeValue
.m_aFence
;
225 const struct SmMlForm
* SmMlAttribute::getMlForm() const
227 if (m_aSmMlAttributeValueType
== SmMlAttributeValueType::MlForm
)
228 return &m_aAttributeValue
.m_aForm
;
232 const struct SmMlHref
* SmMlAttribute::getMlHref() const
234 if (m_aSmMlAttributeValueType
== SmMlAttributeValueType::MlHref
)
235 return &m_aAttributeValue
.m_aHref
;
239 const struct SmMlLspace
* SmMlAttribute::getMlLspace() const
241 if (m_aSmMlAttributeValueType
== SmMlAttributeValueType::MlLspace
)
242 return &m_aAttributeValue
.m_aLspace
;
246 const struct SmMlMathbackground
* SmMlAttribute::getMlMathbackground() const
248 if (m_aSmMlAttributeValueType
== SmMlAttributeValueType::MlMathbackground
)
249 return &m_aAttributeValue
.m_aMathbackground
;
253 const struct SmMlMathcolor
* SmMlAttribute::getMlMathcolor() const
255 if (m_aSmMlAttributeValueType
== SmMlAttributeValueType::MlMathcolor
)
256 return &m_aAttributeValue
.m_aMathcolor
;
260 const struct SmMlMathsize
* SmMlAttribute::getMlMathsize() const
262 if (m_aSmMlAttributeValueType
== SmMlAttributeValueType::MlAccent
)
263 return &m_aAttributeValue
.m_aMathsize
;
267 const struct SmMlMathvariant
* SmMlAttribute::getMlMathvariant() const
269 if (m_aSmMlAttributeValueType
== SmMlAttributeValueType::MlMathvariant
)
270 return &m_aAttributeValue
.m_aMathvariant
;
274 const struct SmMlMaxsize
* SmMlAttribute::getMlMaxsize() const
276 if (m_aSmMlAttributeValueType
== SmMlAttributeValueType::MlMaxsize
)
277 return &m_aAttributeValue
.m_aMaxsize
;
281 const struct SmMlMinsize
* SmMlAttribute::getMlMinsize() const
283 if (m_aSmMlAttributeValueType
== SmMlAttributeValueType::MlMinsize
)
284 return &m_aAttributeValue
.m_aMinsize
;
288 const struct SmMlMovablelimits
* SmMlAttribute::getMlMovablelimits() const
290 if (m_aSmMlAttributeValueType
== SmMlAttributeValueType::MlMovablelimits
)
291 return &m_aAttributeValue
.m_aMovablelimits
;
295 const struct SmMlRspace
* SmMlAttribute::getMlRspace() const
297 if (m_aSmMlAttributeValueType
== SmMlAttributeValueType::MlRspace
)
298 return &m_aAttributeValue
.m_aRspace
;
302 const struct SmMlSeparator
* SmMlAttribute::getMlSeparator() const
304 if (m_aSmMlAttributeValueType
== SmMlAttributeValueType::MlSeparator
)
305 return &m_aAttributeValue
.m_aSeparator
;
309 const struct SmMlStretchy
* SmMlAttribute::getMlStretchy() const
311 if (m_aSmMlAttributeValueType
== SmMlAttributeValueType::MlStretchy
)
312 return &m_aAttributeValue
.m_aStretchy
;
316 const struct SmMlSymmetric
* SmMlAttribute::getMlSymmetric() const
318 if (m_aSmMlAttributeValueType
== SmMlAttributeValueType::MlSymmetric
)
319 return &m_aAttributeValue
.m_aSymmetric
;
324 /*************************************************************************************************/
326 void SmMlAttribute::setMlAccent(const SmMlAccent
* aAccent
)
329 clearPreviousAttributeValue();
330 m_aAttributeValue
.m_aAccent
.m_aAccent
= aAccent
->m_aAccent
;
333 void SmMlAttribute::setMlDir(const SmMlDir
* aDir
)
336 clearPreviousAttributeValue();
337 m_aAttributeValue
.m_aDir
.m_aDir
= aDir
->m_aDir
;
340 void SmMlAttribute::setMlDisplaystyle(const SmMlDisplaystyle
* aDisplaystyle
)
343 clearPreviousAttributeValue();
344 m_aAttributeValue
.m_aDisplaystyle
.m_aDisplaystyle
= aDisplaystyle
->m_aDisplaystyle
;
347 void SmMlAttribute::setMlFence(const SmMlFence
* aFence
)
350 clearPreviousAttributeValue();
351 m_aAttributeValue
.m_aFence
.m_aFence
= aFence
->m_aFence
;
354 void SmMlAttribute::setMlForm(const SmMlForm
* aForm
)
357 clearPreviousAttributeValue();
358 m_aAttributeValue
.m_aForm
.m_aForm
= aForm
->m_aForm
;
361 void SmMlAttribute::setMlHref(const SmMlHref
* aHref
)
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
)
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
)
384 clearPreviousAttributeValue();
385 m_aAttributeValue
.m_aMathbackground
.m_aMathbackground
= aMathbackground
->m_aMathbackground
;
388 void SmMlAttribute::setMlMathcolor(const SmMlMathcolor
* aMathcolor
)
391 clearPreviousAttributeValue();
392 m_aAttributeValue
.m_aMathcolor
.m_aMathcolor
= aMathcolor
->m_aMathcolor
;
395 void SmMlAttribute::setMlMathsize(const SmMlMathsize
* aMathsize
)
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
)
410 clearPreviousAttributeValue();
411 m_aAttributeValue
.m_aMathvariant
.m_aMathvariant
= aMathvariant
->m_aMathvariant
;
414 void SmMlAttribute::setMlMaxsize(const SmMlMaxsize
* aMaxsize
)
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
)
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
)
442 clearPreviousAttributeValue();
443 m_aAttributeValue
.m_aMovablelimits
.m_aMovablelimits
= aMovablelimits
->m_aMovablelimits
;
446 void SmMlAttribute::setMlRspace(const SmMlRspace
* aRspace
)
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
)
461 clearPreviousAttributeValue();
462 m_aAttributeValue
.m_aSeparator
.m_aSeparator
= aSeparator
->m_aSeparator
;
465 void SmMlAttribute::setMlStretchy(const SmMlStretchy
* aStretchy
)
468 clearPreviousAttributeValue();
469 m_aAttributeValue
.m_aStretchy
.m_aStretchy
= aStretchy
->m_aStretchy
;
472 void SmMlAttribute::setMlSymmetric(const SmMlSymmetric
* aSymmetric
)
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: */