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
"");
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
= new OUString(u
"5/18em");
78 case SmMlAttributeValueType::MlMathbackground
:
79 m_aAttributeValue
.m_aMathbackground
.m_aMathbackground
80 = SmMlAttributeValueMathbackground::MlTransparent
;
82 case SmMlAttributeValueType::MlMathcolor
:
83 m_aAttributeValue
.m_aMathcolor
.m_aMathcolor
= SmMlAttributeValueMathcolor::MlDefault
;
85 case SmMlAttributeValueType::MlMathsize
:
86 m_aAttributeValue
.m_aMathsize
.m_aLengthValue
.m_aLengthUnit
= SmLengthUnit::MlP
;
87 m_aAttributeValue
.m_aMathsize
.m_aLengthValue
.m_aLengthValue
= 100;
88 m_aAttributeValue
.m_aMathsize
.m_aLengthValue
.m_aOriginalText
= new OUString(u
"100%");
90 case SmMlAttributeValueType::MlMathvariant
:
91 m_aAttributeValue
.m_aMathvariant
.m_aMathvariant
= SmMlAttributeValueMathvariant::normal
;
93 case SmMlAttributeValueType::MlMaxsize
:
94 m_aAttributeValue
.m_aMaxsize
.m_aMaxsize
= SmMlAttributeValueMaxsize::MlInfinity
;
95 m_aAttributeValue
.m_aMaxsize
.m_aLengthValue
.m_aLengthUnit
= SmLengthUnit::MlP
;
96 m_aAttributeValue
.m_aMaxsize
.m_aLengthValue
.m_aLengthValue
= 10000;
97 m_aAttributeValue
.m_aMaxsize
.m_aLengthValue
.m_aOriginalText
= new OUString(u
"10000%");
99 case SmMlAttributeValueType::MlMinsize
:
100 m_aAttributeValue
.m_aMinsize
.m_aLengthValue
.m_aLengthUnit
= SmLengthUnit::MlP
;
101 m_aAttributeValue
.m_aMinsize
.m_aLengthValue
.m_aLengthValue
= 1;
102 m_aAttributeValue
.m_aMinsize
.m_aLengthValue
.m_aOriginalText
= new OUString(u
"1%");
104 case SmMlAttributeValueType::MlMovablelimits
:
105 m_aAttributeValue
.m_aMovablelimits
.m_aMovablelimits
106 = SmMlAttributeValueMovablelimits::MlFalse
;
108 case SmMlAttributeValueType::MlRspace
:
109 m_aAttributeValue
.m_aRspace
.m_aLengthValue
.m_aLengthUnit
= SmLengthUnit::MlEm
;
110 m_aAttributeValue
.m_aRspace
.m_aLengthValue
.m_aLengthValue
= 5.0 / 18;
111 m_aAttributeValue
.m_aRspace
.m_aLengthValue
.m_aOriginalText
= new OUString(u
"5/18em");
113 case SmMlAttributeValueType::MlSeparator
:
114 m_aAttributeValue
.m_aSeparator
.m_aSeparator
= SmMlAttributeValueSeparator::MlFalse
;
116 case SmMlAttributeValueType::MlStretchy
:
117 m_aAttributeValue
.m_aStretchy
.m_aStretchy
= SmMlAttributeValueStretchy::MlFalse
;
119 case SmMlAttributeValueType::MlSymmetric
:
120 m_aAttributeValue
.m_aSymmetric
.m_aSymmetric
= SmMlAttributeValueSymmetric::MlFalse
;
125 void SmMlAttribute::setAttributeValue(const SmMlAttribute
* aAttribute
)
127 switch (aAttribute
->getMlAttributeValueType())
129 case SmMlAttributeValueType::NMlEmpty
:
130 clearPreviousAttributeValue();
131 m_aSmMlAttributeValueType
= SmMlAttributeValueType::NMlEmpty
;
133 case SmMlAttributeValueType::MlAccent
:
134 setMlAccent(aAttribute
->getMlAccent());
136 case SmMlAttributeValueType::MlDir
:
137 setMlDir(aAttribute
->getMlDir());
139 case SmMlAttributeValueType::MlDisplaystyle
:
140 setMlDisplaystyle(aAttribute
->getMlDisplaystyle());
142 case SmMlAttributeValueType::MlFence
:
143 setMlFence(aAttribute
->getMlFence());
145 case SmMlAttributeValueType::MlForm
:
146 setMlForm(aAttribute
->getMlForm());
148 case SmMlAttributeValueType::MlHref
:
149 setMlHref(aAttribute
->getMlHref());
151 case SmMlAttributeValueType::MlLspace
:
152 setMlLspace(aAttribute
->getMlLspace());
154 case SmMlAttributeValueType::MlMathbackground
:
155 setMlMathbackground(aAttribute
->getMlMathbackground());
157 case SmMlAttributeValueType::MlMathcolor
:
158 setMlMathcolor(aAttribute
->getMlMathcolor());
160 case SmMlAttributeValueType::MlMathsize
:
161 setMlMathsize(aAttribute
->getMlMathsize());
163 case SmMlAttributeValueType::MlMathvariant
:
164 setMlMathvariant(aAttribute
->getMlMathvariant());
166 case SmMlAttributeValueType::MlMaxsize
:
167 setMlMaxsize(aAttribute
->getMlMaxsize());
169 case SmMlAttributeValueType::MlMinsize
:
170 setMlMinsize(aAttribute
->getMlMinsize());
172 case SmMlAttributeValueType::MlMovablelimits
:
173 setMlMovablelimits(aAttribute
->getMlMovablelimits());
175 case SmMlAttributeValueType::MlRspace
:
176 setMlRspace(aAttribute
->getMlRspace());
178 case SmMlAttributeValueType::MlSeparator
:
179 setMlSeparator(aAttribute
->getMlSeparator());
181 case SmMlAttributeValueType::MlStretchy
:
182 setMlStretchy(aAttribute
->getMlStretchy());
184 case SmMlAttributeValueType::MlSymmetric
:
185 setMlSymmetric(aAttribute
->getMlSymmetric());
191 /*************************************************************************************************/
193 const struct SmMlAccent
* SmMlAttribute::getMlAccent() const
195 if (m_aSmMlAttributeValueType
== SmMlAttributeValueType::MlAccent
)
196 return &m_aAttributeValue
.m_aAccent
;
200 const struct SmMlDir
* SmMlAttribute::getMlDir() const
202 if (m_aSmMlAttributeValueType
== SmMlAttributeValueType::MlDir
)
203 return &m_aAttributeValue
.m_aDir
;
207 const struct SmMlDisplaystyle
* SmMlAttribute::getMlDisplaystyle() const
209 if (m_aSmMlAttributeValueType
== SmMlAttributeValueType::MlDisplaystyle
)
210 return &m_aAttributeValue
.m_aDisplaystyle
;
214 const struct SmMlFence
* SmMlAttribute::getMlFence() const
216 if (m_aSmMlAttributeValueType
== SmMlAttributeValueType::MlFence
)
217 return &m_aAttributeValue
.m_aFence
;
221 const struct SmMlForm
* SmMlAttribute::getMlForm() const
223 if (m_aSmMlAttributeValueType
== SmMlAttributeValueType::MlForm
)
224 return &m_aAttributeValue
.m_aForm
;
228 const struct SmMlHref
* SmMlAttribute::getMlHref() const
230 if (m_aSmMlAttributeValueType
== SmMlAttributeValueType::MlHref
)
231 return &m_aAttributeValue
.m_aHref
;
235 const struct SmMlLspace
* SmMlAttribute::getMlLspace() const
237 if (m_aSmMlAttributeValueType
== SmMlAttributeValueType::MlLspace
)
238 return &m_aAttributeValue
.m_aLspace
;
242 const struct SmMlMathbackground
* SmMlAttribute::getMlMathbackground() const
244 if (m_aSmMlAttributeValueType
== SmMlAttributeValueType::MlMathbackground
)
245 return &m_aAttributeValue
.m_aMathbackground
;
249 const struct SmMlMathcolor
* SmMlAttribute::getMlMathcolor() const
251 if (m_aSmMlAttributeValueType
== SmMlAttributeValueType::MlMathcolor
)
252 return &m_aAttributeValue
.m_aMathcolor
;
256 const struct SmMlMathsize
* SmMlAttribute::getMlMathsize() const
258 if (m_aSmMlAttributeValueType
== SmMlAttributeValueType::MlAccent
)
259 return &m_aAttributeValue
.m_aMathsize
;
263 const struct SmMlMathvariant
* SmMlAttribute::getMlMathvariant() const
265 if (m_aSmMlAttributeValueType
== SmMlAttributeValueType::MlMathvariant
)
266 return &m_aAttributeValue
.m_aMathvariant
;
270 const struct SmMlMaxsize
* SmMlAttribute::getMlMaxsize() const
272 if (m_aSmMlAttributeValueType
== SmMlAttributeValueType::MlMaxsize
)
273 return &m_aAttributeValue
.m_aMaxsize
;
277 const struct SmMlMinsize
* SmMlAttribute::getMlMinsize() const
279 if (m_aSmMlAttributeValueType
== SmMlAttributeValueType::MlMinsize
)
280 return &m_aAttributeValue
.m_aMinsize
;
284 const struct SmMlMovablelimits
* SmMlAttribute::getMlMovablelimits() const
286 if (m_aSmMlAttributeValueType
== SmMlAttributeValueType::MlMovablelimits
)
287 return &m_aAttributeValue
.m_aMovablelimits
;
291 const struct SmMlRspace
* SmMlAttribute::getMlRspace() const
293 if (m_aSmMlAttributeValueType
== SmMlAttributeValueType::MlRspace
)
294 return &m_aAttributeValue
.m_aRspace
;
298 const struct SmMlSeparator
* SmMlAttribute::getMlSeparator() const
300 if (m_aSmMlAttributeValueType
== SmMlAttributeValueType::MlSeparator
)
301 return &m_aAttributeValue
.m_aSeparator
;
305 const struct SmMlStretchy
* SmMlAttribute::getMlStretchy() const
307 if (m_aSmMlAttributeValueType
== SmMlAttributeValueType::MlStretchy
)
308 return &m_aAttributeValue
.m_aStretchy
;
312 const struct SmMlSymmetric
* SmMlAttribute::getMlSymmetric() const
314 if (m_aSmMlAttributeValueType
== SmMlAttributeValueType::MlSymmetric
)
315 return &m_aAttributeValue
.m_aSymmetric
;
320 /*************************************************************************************************/
322 void SmMlAttribute::setMlAccent(const SmMlAccent
* aAccent
)
325 clearPreviousAttributeValue();
326 m_aAttributeValue
.m_aAccent
.m_aAccent
= aAccent
->m_aAccent
;
329 void SmMlAttribute::setMlDir(const SmMlDir
* aDir
)
332 clearPreviousAttributeValue();
333 m_aAttributeValue
.m_aDir
.m_aDir
= aDir
->m_aDir
;
336 void SmMlAttribute::setMlDisplaystyle(const SmMlDisplaystyle
* aDisplaystyle
)
339 clearPreviousAttributeValue();
340 m_aAttributeValue
.m_aDisplaystyle
.m_aDisplaystyle
= aDisplaystyle
->m_aDisplaystyle
;
343 void SmMlAttribute::setMlFence(const SmMlFence
* aFence
)
346 clearPreviousAttributeValue();
347 m_aAttributeValue
.m_aFence
.m_aFence
= aFence
->m_aFence
;
350 void SmMlAttribute::setMlForm(const SmMlForm
* aForm
)
353 clearPreviousAttributeValue();
354 m_aAttributeValue
.m_aForm
.m_aForm
= aForm
->m_aForm
;
357 void SmMlAttribute::setMlHref(const SmMlHref
* aHref
)
360 clearPreviousAttributeValue();
361 m_aAttributeValue
.m_aHref
.m_aHref
= aHref
->m_aHref
;
362 m_aAttributeValue
.m_aHref
.m_aLnk
= new OUString(*aHref
->m_aLnk
);
365 void SmMlAttribute::setMlLspace(const SmMlLspace
* aLspace
)
368 clearPreviousAttributeValue();
369 m_aAttributeValue
.m_aLspace
.m_aLengthValue
.m_aLengthUnit
370 = aLspace
->m_aLengthValue
.m_aLengthUnit
;
371 m_aAttributeValue
.m_aLspace
.m_aLengthValue
.m_aLengthValue
372 = aLspace
->m_aLengthValue
.m_aLengthValue
;
373 m_aAttributeValue
.m_aLspace
.m_aLengthValue
.m_aOriginalText
374 = new OUString(*aLspace
->m_aLengthValue
.m_aOriginalText
);
377 void SmMlAttribute::setMlMathbackground(const SmMlMathbackground
* aMathbackground
)
380 clearPreviousAttributeValue();
381 m_aAttributeValue
.m_aMathbackground
.m_aMathbackground
= aMathbackground
->m_aMathbackground
;
384 void SmMlAttribute::setMlMathcolor(const SmMlMathcolor
* aMathcolor
)
387 clearPreviousAttributeValue();
388 m_aAttributeValue
.m_aMathcolor
.m_aMathcolor
= aMathcolor
->m_aMathcolor
;
391 void SmMlAttribute::setMlMathsize(const SmMlMathsize
* aMathsize
)
394 clearPreviousAttributeValue();
395 m_aAttributeValue
.m_aMathsize
.m_aLengthValue
.m_aLengthUnit
396 = aMathsize
->m_aLengthValue
.m_aLengthUnit
;
397 m_aAttributeValue
.m_aMathsize
.m_aLengthValue
.m_aLengthValue
398 = aMathsize
->m_aLengthValue
.m_aLengthValue
;
399 m_aAttributeValue
.m_aMathsize
.m_aLengthValue
.m_aOriginalText
400 = new OUString(*aMathsize
->m_aLengthValue
.m_aOriginalText
);
403 void SmMlAttribute::setMlMathvariant(const SmMlMathvariant
* aMathvariant
)
406 clearPreviousAttributeValue();
407 m_aAttributeValue
.m_aMathvariant
.m_aMathvariant
= aMathvariant
->m_aMathvariant
;
410 void SmMlAttribute::setMlMaxsize(const SmMlMaxsize
* aMaxsize
)
413 clearPreviousAttributeValue();
414 m_aAttributeValue
.m_aMaxsize
.m_aMaxsize
= aMaxsize
->m_aMaxsize
;
415 m_aAttributeValue
.m_aMaxsize
.m_aLengthValue
.m_aLengthUnit
416 = aMaxsize
->m_aLengthValue
.m_aLengthUnit
;
417 m_aAttributeValue
.m_aMaxsize
.m_aLengthValue
.m_aLengthValue
418 = aMaxsize
->m_aLengthValue
.m_aLengthValue
;
419 m_aAttributeValue
.m_aMaxsize
.m_aLengthValue
.m_aOriginalText
420 = new OUString(*aMaxsize
->m_aLengthValue
.m_aOriginalText
);
423 void SmMlAttribute::setMlMinsize(const SmMlMinsize
* aMinsize
)
426 clearPreviousAttributeValue();
427 m_aAttributeValue
.m_aMinsize
.m_aLengthValue
.m_aLengthUnit
428 = aMinsize
->m_aLengthValue
.m_aLengthUnit
;
429 m_aAttributeValue
.m_aMinsize
.m_aLengthValue
.m_aLengthValue
430 = aMinsize
->m_aLengthValue
.m_aLengthValue
;
431 m_aAttributeValue
.m_aMinsize
.m_aLengthValue
.m_aOriginalText
432 = new OUString(*aMinsize
->m_aLengthValue
.m_aOriginalText
);
435 void SmMlAttribute::setMlMovablelimits(const SmMlMovablelimits
* aMovablelimits
)
438 clearPreviousAttributeValue();
439 m_aAttributeValue
.m_aMovablelimits
.m_aMovablelimits
= aMovablelimits
->m_aMovablelimits
;
442 void SmMlAttribute::setMlRspace(const SmMlRspace
* aRspace
)
445 clearPreviousAttributeValue();
446 m_aAttributeValue
.m_aRspace
.m_aLengthValue
.m_aLengthUnit
447 = aRspace
->m_aLengthValue
.m_aLengthUnit
;
448 m_aAttributeValue
.m_aRspace
.m_aLengthValue
.m_aLengthValue
449 = aRspace
->m_aLengthValue
.m_aLengthValue
;
450 m_aAttributeValue
.m_aRspace
.m_aLengthValue
.m_aOriginalText
451 = new OUString(*aRspace
->m_aLengthValue
.m_aOriginalText
);
454 void SmMlAttribute::setMlSeparator(const SmMlSeparator
* aSeparator
)
457 clearPreviousAttributeValue();
458 m_aAttributeValue
.m_aSeparator
.m_aSeparator
= aSeparator
->m_aSeparator
;
461 void SmMlAttribute::setMlStretchy(const SmMlStretchy
* aStretchy
)
464 clearPreviousAttributeValue();
465 m_aAttributeValue
.m_aStretchy
.m_aStretchy
= aStretchy
->m_aStretchy
;
468 void SmMlAttribute::setMlSymmetric(const SmMlSymmetric
* aSymmetric
)
471 clearPreviousAttributeValue();
472 m_aAttributeValue
.m_aSymmetric
.m_aSymmetric
= aSymmetric
->m_aSymmetric
;
475 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */