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 "mathmlattr.hxx"
13 #include <unordered_map>
15 sal_Int32
ParseMathMLUnsignedNumber(const OUString
&rStr
, Fraction
& rUN
)
17 auto nLen
= rStr
.getLength();
18 sal_Int32 nDecimalPoint
= -1;
20 for (nIdx
= 0; nIdx
< nLen
; nIdx
++)
25 if (nDecimalPoint
>= 0)
30 if (cD
< u
'0' || u
'9' < cD
)
33 if (nIdx
== 0 || (nIdx
== 1 && nDecimalPoint
== 0))
36 rUN
= Fraction(rStr
.copy(0, nIdx
).toDouble());
41 sal_Int32
ParseMathMLNumber(const OUString
&rStr
, Fraction
& rN
)
45 bool bNegative
= (rStr
[0] == '-');
46 sal_Int32 nOffset
= bNegative
? 1 : 0;
47 auto nIdx
= ParseMathMLUnsignedNumber(rStr
.copy(nOffset
), rN
);
48 if (nIdx
<= 0 || !rN
.IsValid())
52 return nOffset
+ nIdx
;
55 sal_Int32
ParseMathMLAttributeLengthValue(const OUString
&rStr
, MathMLAttributeLengthValue
& rV
)
57 auto nIdx
= ParseMathMLNumber(rStr
, rV
.aNumber
);
60 OUString sRest
= rStr
.copy(nIdx
);
63 rV
.eUnit
= MathMLLengthUnit::None
;
66 if (sRest
.startsWith("em"))
68 rV
.eUnit
= MathMLLengthUnit::Em
;
71 if (sRest
.startsWith("ex"))
73 rV
.eUnit
= MathMLLengthUnit::Ex
;
76 if (sRest
.startsWith("px"))
78 rV
.eUnit
= MathMLLengthUnit::Px
;
81 if (sRest
.startsWith("in"))
83 rV
.eUnit
= MathMLLengthUnit::In
;
86 if (sRest
.startsWith("cm"))
88 rV
.eUnit
= MathMLLengthUnit::Cm
;
91 if (sRest
.startsWith("mm"))
93 rV
.eUnit
= MathMLLengthUnit::Mm
;
96 if (sRest
.startsWith("pt"))
98 rV
.eUnit
= MathMLLengthUnit::Pt
;
101 if (sRest
.startsWith("pc"))
103 rV
.eUnit
= MathMLLengthUnit::Pc
;
106 if (sRest
[0] == u
'%')
108 rV
.eUnit
= MathMLLengthUnit::Percent
;
114 bool GetMathMLMathvariantValue(const OUString
&rStr
, MathMLMathvariantValue
& rV
)
116 static const std::unordered_map
<OUString
, MathMLMathvariantValue
> aMap
{
117 {"normal", MathMLMathvariantValue::Normal
},
118 {"bold", MathMLMathvariantValue::Bold
},
119 {"italic", MathMLMathvariantValue::Italic
},
120 {"bold-italic", MathMLMathvariantValue::BoldItalic
},
121 {"double-struck", MathMLMathvariantValue::DoubleStruck
},
122 {"bold-fraktur", MathMLMathvariantValue::BoldFraktur
},
123 {"script", MathMLMathvariantValue::Script
},
124 {"bold-script", MathMLMathvariantValue::BoldScript
},
125 {"fraktur", MathMLMathvariantValue::Fraktur
},
126 {"sans-serif", MathMLMathvariantValue::SansSerif
},
127 {"bold-sans-serif", MathMLMathvariantValue::BoldSansSerif
},
128 {"sans-serif-italic", MathMLMathvariantValue::SansSerifItalic
},
129 {"sans-serif-bold-italic", MathMLMathvariantValue::SansSerifBoldItalic
},
130 {"monospace", MathMLMathvariantValue::Monospace
},
131 {"initial", MathMLMathvariantValue::Initial
},
132 {"tailed", MathMLMathvariantValue::Tailed
},
133 {"looped", MathMLMathvariantValue::Looped
},
134 {"stretched", MathMLMathvariantValue::Stretched
}
137 auto it
= aMap
.find(rStr
);
138 if (it
!= aMap
.end())
146 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */