1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <sal/config.h>
12 #include <sal/log.hxx>
13 #include <sax/tools/converter.hxx>
14 #include <xmloff/xmluconv.hxx>
15 #include <xmloff/namespacemap.hxx>
16 #include <xmloff/xmlnamespace.hxx>
17 #include <xmloff/xmlimp.hxx>
18 #include <xmloff/xmltoken.hxx>
19 #include <xmloff/xmlement.hxx>
20 #include <xmloff/xmlprhdl.hxx>
21 #include <xmloff/XMLComplexColorContext.hxx>
22 #include <docmodel/uno/UnoComplexColor.hxx>
25 using namespace xmloff::token
;
27 SvXMLEnumMapEntry
<sal_Int16
> const pXML_ThemeColor_Enum
[] = { { XML_NONE
, -1 },
38 { XML_HYPERLINK
, 10 },
39 { XML_FOLLOWED_HYPERLINK
, 11 },
40 { XML_TOKEN_INVALID
, 0 } };
42 XMLComplexColorImport::XMLComplexColorImport(model::ComplexColor
& rComplexColor
)
43 : mrComplexColor(rComplexColor
)
47 void XMLComplexColorImport::fillAttributes(
48 const uno::Reference
<xml::sax::XFastAttributeList
>& xAttrList
)
50 for (auto& aIter
: sax_fastparser::castToFastAttributeList(xAttrList
))
52 switch (aIter
.getToken())
54 case XML_ELEMENT(LO_EXT
, XML_THEME_TYPE
):
56 sal_Int16 nValue
= -1;
57 if (SvXMLUnitConverter::convertEnum(nValue
, aIter
.toView(), pXML_ThemeColor_Enum
))
59 mrComplexColor
.setThemeColor(model::convertToThemeColorType(nValue
));
63 case XML_ELEMENT(LO_EXT
, XML_COLOR_TYPE
):
65 const OUString aValue
= aIter
.toString();
66 if (aValue
== u
"theme")
67 mrComplexColor
.setType(model::ColorType::Theme
);
68 // TODO - handle other color types
72 XMLOFF_WARN_UNKNOWN("xmloff", aIter
);
78 bool XMLComplexColorImport::handleTransformContext(
79 sal_Int32 nElement
, const css::uno::Reference
<css::xml::sax::XFastAttributeList
>& xAttrList
)
81 if (nElement
== XML_ELEMENT(LO_EXT
, XML_TRANSFORMATION
))
83 auto eTransformationType
= model::TransformationType::Undefined
;
84 sal_Int16 nTransformationValue
= 0;
85 for (auto& aIter
: sax_fastparser::castToFastAttributeList(xAttrList
))
87 switch (aIter
.getToken())
89 case XML_ELEMENT(LO_EXT
, XML_TYPE
):
91 const OUString aValue
= aIter
.toString();
92 if (aValue
== u
"tint")
93 eTransformationType
= model::TransformationType::Tint
;
94 else if (aValue
== u
"shade")
95 eTransformationType
= model::TransformationType::Shade
;
96 else if (aValue
== u
"lumoff")
97 eTransformationType
= model::TransformationType::LumOff
;
98 else if (aValue
== u
"lummod")
99 eTransformationType
= model::TransformationType::LumMod
;
102 case XML_ELEMENT(LO_EXT
, XML_VALUE
):
105 if (::sax::Converter::convertNumber(nValue
, aIter
.toView(), SHRT_MIN
, SHRT_MAX
))
106 nTransformationValue
= static_cast<sal_Int16
>(nValue
);
110 XMLOFF_WARN_UNKNOWN("xmloff", aIter
);
114 mrComplexColor
.addTransformation({ eTransformationType
, nTransformationValue
});
117 XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement
);
121 XMLPropertyComplexColorContext::XMLPropertyComplexColorContext(
122 SvXMLImport
& rImport
, sal_Int32 nElement
,
123 const uno::Reference
<xml::sax::XFastAttributeList
>& xAttrList
, const XMLPropertyState
& rProp
,
124 std::vector
<XMLPropertyState
>& rProps
)
125 : XMLElementPropertyContext(rImport
, nElement
, rProp
, rProps
)
126 , mnRootElement(nElement
)
127 , maComplexColorImport(maComplexColor
)
129 maComplexColorImport
.fillAttributes(xAttrList
);
132 css::uno::Reference
<css::xml::sax::XFastContextHandler
>
133 XMLPropertyComplexColorContext::createFastChildContext(
134 sal_Int32 nElement
, const css::uno::Reference
<css::xml::sax::XFastAttributeList
>& xAttrList
)
136 if (maComplexColorImport
.handleTransformContext(nElement
, xAttrList
))
141 void XMLPropertyComplexColorContext::endFastElement(sal_Int32 nElement
)
143 if (nElement
== mnRootElement
)
145 if (getComplexColor().getThemeColorType() != model::ThemeColorType::Unknown
)
147 aProp
.maValue
<<= model::color::createXComplexColor(getComplexColor());
151 XMLElementPropertyContext::endFastElement(nElement
);
154 XMLComplexColorContext::XMLComplexColorContext(
155 SvXMLImport
& rImport
, model::ComplexColor
& rComplexColor
,
156 const uno::Reference
<xml::sax::XFastAttributeList
>& xAttrList
)
157 : SvXMLImportContext(rImport
)
158 , maComplexColorImport(rComplexColor
)
160 maComplexColorImport
.fillAttributes(xAttrList
);
163 css::uno::Reference
<css::xml::sax::XFastContextHandler
>
164 XMLComplexColorContext::createFastChildContext(
165 sal_Int32 nElement
, const css::uno::Reference
<css::xml::sax::XFastAttributeList
>& xAttrList
)
167 if (maComplexColorImport
.handleTransformContext(nElement
, xAttrList
))
172 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */