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"
12 #include <unordered_map>
14 static sal_Int32
ParseMathMLUnsignedNumber(const OUString
& rStr
, Fraction
& rUN
)
16 auto nLen
= rStr
.getLength();
17 sal_Int32 nDecimalPoint
= -1;
19 for (nIdx
= 0; nIdx
< nLen
; nIdx
++)
24 if (nDecimalPoint
>= 0)
29 if (cD
< u
'0' || u
'9' < cD
)
32 if (nIdx
== 0 || (nIdx
== 1 && nDecimalPoint
== 0))
35 rUN
= Fraction(rStr
.copy(0, nIdx
).toDouble());
40 static sal_Int32
ParseMathMLNumber(const OUString
& rStr
, Fraction
& rN
)
44 bool bNegative
= (rStr
[0] == '-');
45 sal_Int32 nOffset
= bNegative
? 1 : 0;
46 auto nIdx
= ParseMathMLUnsignedNumber(rStr
.copy(nOffset
), rN
);
47 if (nIdx
<= 0 || !rN
.IsValid())
51 return nOffset
+ nIdx
;
54 sal_Int32
ParseMathMLAttributeLengthValue(const OUString
& rStr
, MathMLAttributeLengthValue
& rV
)
56 auto nIdx
= ParseMathMLNumber(rStr
, rV
.aNumber
);
59 OUString sRest
= rStr
.copy(nIdx
);
62 rV
.eUnit
= MathMLLengthUnit::None
;
65 if (sRest
.startsWith("em"))
67 rV
.eUnit
= MathMLLengthUnit::Em
;
70 if (sRest
.startsWith("ex"))
72 rV
.eUnit
= MathMLLengthUnit::Ex
;
75 if (sRest
.startsWith("px"))
77 rV
.eUnit
= MathMLLengthUnit::Px
;
80 if (sRest
.startsWith("in"))
82 rV
.eUnit
= MathMLLengthUnit::In
;
85 if (sRest
.startsWith("cm"))
87 rV
.eUnit
= MathMLLengthUnit::Cm
;
90 if (sRest
.startsWith("mm"))
92 rV
.eUnit
= MathMLLengthUnit::Mm
;
95 if (sRest
.startsWith("pt"))
97 rV
.eUnit
= MathMLLengthUnit::Pt
;
100 if (sRest
.startsWith("pc"))
102 rV
.eUnit
= MathMLLengthUnit::Pc
;
105 if (sRest
[0] == u
'%')
107 rV
.eUnit
= MathMLLengthUnit::Percent
;
113 bool GetMathMLMathvariantValue(const OUString
& rStr
, MathMLMathvariantValue
& rV
)
115 static const std::unordered_map
<OUString
, MathMLMathvariantValue
> aMap
{
116 { "normal", MathMLMathvariantValue::Normal
},
117 { "bold", MathMLMathvariantValue::Bold
},
118 { "italic", MathMLMathvariantValue::Italic
},
119 { "bold-italic", MathMLMathvariantValue::BoldItalic
},
120 { "double-struck", MathMLMathvariantValue::DoubleStruck
},
121 { "bold-fraktur", MathMLMathvariantValue::BoldFraktur
},
122 { "script", MathMLMathvariantValue::Script
},
123 { "bold-script", MathMLMathvariantValue::BoldScript
},
124 { "fraktur", MathMLMathvariantValue::Fraktur
},
125 { "sans-serif", MathMLMathvariantValue::SansSerif
},
126 { "bold-sans-serif", MathMLMathvariantValue::BoldSansSerif
},
127 { "sans-serif-italic", MathMLMathvariantValue::SansSerifItalic
},
128 { "sans-serif-bold-italic", MathMLMathvariantValue::SansSerifBoldItalic
},
129 { "monospace", MathMLMathvariantValue::Monospace
},
130 { "initial", MathMLMathvariantValue::Initial
},
131 { "tailed", MathMLMathvariantValue::Tailed
},
132 { "looped", MathMLMathvariantValue::Looped
},
133 { "stretched", MathMLMathvariantValue::Stretched
}
136 auto it
= aMap
.find(rStr
);
137 if (it
!= aMap
.end())
145 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */