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/xmlnamespace.hxx>
16 #include <xmloff/xmlimp.hxx>
17 #include <xmloff/xmltoken.hxx>
18 #include <xmloff/xmlement.hxx>
19 #include <xmloff/XMLComplexColorContext.hxx>
20 #include <docmodel/uno/UnoComplexColor.hxx>
23 using namespace xmloff::token
;
25 SvXMLEnumMapEntry
<sal_Int16
> const pXML_ThemeColor_Enum
[] = { { XML_NONE
, -1 },
36 { XML_HYPERLINK
, 10 },
37 { XML_FOLLOWED_HYPERLINK
, 11 },
38 { XML_TOKEN_INVALID
, 0 } };
40 XMLComplexColorImport::XMLComplexColorImport(model::ComplexColor
& rComplexColor
)
41 : mrComplexColor(rComplexColor
)
45 void XMLComplexColorImport::fillAttributes(
46 const uno::Reference
<xml::sax::XFastAttributeList
>& xAttrList
)
48 for (auto& aIter
: sax_fastparser::castToFastAttributeList(xAttrList
))
50 switch (aIter
.getToken())
52 case XML_ELEMENT(LO_EXT
, XML_THEME_TYPE
):
54 sal_Int16 nValue
= -1;
55 if (SvXMLUnitConverter::convertEnum(nValue
, aIter
.toView(), pXML_ThemeColor_Enum
))
57 mrComplexColor
.setThemeColor(model::convertToThemeColorType(nValue
));
61 case XML_ELEMENT(LO_EXT
, XML_COLOR_TYPE
):
63 const OUString aValue
= aIter
.toString();
64 if (aValue
== u
"theme")
65 mrComplexColor
.setType(model::ColorType::Theme
);
66 // TODO - handle other color types
70 XMLOFF_WARN_UNKNOWN("xmloff", aIter
);
76 bool XMLComplexColorImport::handleTransformContext(
77 sal_Int32 nElement
, const css::uno::Reference
<css::xml::sax::XFastAttributeList
>& xAttrList
)
79 if (nElement
== XML_ELEMENT(LO_EXT
, XML_TRANSFORMATION
))
81 auto eTransformationType
= model::TransformationType::Undefined
;
82 sal_Int16 nTransformationValue
= 0;
83 for (auto& aIter
: sax_fastparser::castToFastAttributeList(xAttrList
))
85 switch (aIter
.getToken())
87 case XML_ELEMENT(LO_EXT
, XML_TYPE
):
89 const OUString aValue
= aIter
.toString();
90 if (aValue
== u
"tint")
91 eTransformationType
= model::TransformationType::Tint
;
92 else if (aValue
== u
"shade")
93 eTransformationType
= model::TransformationType::Shade
;
94 else if (aValue
== u
"lumoff")
95 eTransformationType
= model::TransformationType::LumOff
;
96 else if (aValue
== u
"lummod")
97 eTransformationType
= model::TransformationType::LumMod
;
100 case XML_ELEMENT(LO_EXT
, XML_VALUE
):
103 if (::sax::Converter::convertNumber(nValue
, aIter
.toView(), SHRT_MIN
, SHRT_MAX
))
104 nTransformationValue
= static_cast<sal_Int16
>(nValue
);
108 XMLOFF_WARN_UNKNOWN("xmloff", aIter
);
112 mrComplexColor
.addTransformation({ eTransformationType
, nTransformationValue
});
115 XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement
);
119 XMLPropertyComplexColorContext::XMLPropertyComplexColorContext(
120 SvXMLImport
& rImport
, sal_Int32 nElement
,
121 const uno::Reference
<xml::sax::XFastAttributeList
>& xAttrList
, const XMLPropertyState
& rProp
,
122 std::vector
<XMLPropertyState
>& rProps
)
123 : XMLElementPropertyContext(rImport
, nElement
, rProp
, rProps
)
124 , mnRootElement(nElement
)
125 , maComplexColorImport(maComplexColor
)
127 maComplexColorImport
.fillAttributes(xAttrList
);
130 css::uno::Reference
<css::xml::sax::XFastContextHandler
>
131 XMLPropertyComplexColorContext::createFastChildContext(
132 sal_Int32 nElement
, const css::uno::Reference
<css::xml::sax::XFastAttributeList
>& xAttrList
)
134 if (maComplexColorImport
.handleTransformContext(nElement
, xAttrList
))
139 void XMLPropertyComplexColorContext::endFastElement(sal_Int32 nElement
)
141 if (nElement
== mnRootElement
)
143 if (getComplexColor().getThemeColorType() != model::ThemeColorType::Unknown
)
145 aProp
.maValue
<<= model::color::createXComplexColor(getComplexColor());
149 XMLElementPropertyContext::endFastElement(nElement
);
152 XMLComplexColorContext::XMLComplexColorContext(
153 SvXMLImport
& rImport
, model::ComplexColor
& rComplexColor
,
154 const uno::Reference
<xml::sax::XFastAttributeList
>& xAttrList
)
155 : SvXMLImportContext(rImport
)
156 , maComplexColorImport(rComplexColor
)
158 maComplexColorImport
.fillAttributes(xAttrList
);
161 css::uno::Reference
<css::xml::sax::XFastContextHandler
>
162 XMLComplexColorContext::createFastChildContext(
163 sal_Int32 nElement
, const css::uno::Reference
<css::xml::sax::XFastAttributeList
>& xAttrList
)
165 if (maComplexColorImport
.handleTransformContext(nElement
, xAttrList
))
170 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */