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 <xmloff/XMLComplexColorExport.hxx>
12 #include <sal/config.h>
14 #include <docmodel/uno/UnoComplexColor.hxx>
15 #include <xmloff/xmlnamespace.hxx>
16 #include <xmloff/xmluconv.hxx>
17 #include <xmloff/xmlexp.hxx>
21 using namespace ::xmloff::token
;
23 XMLComplexColorExport::XMLComplexColorExport(SvXMLExport
& rExport
)
30 constexpr const std::array
<XMLTokenEnum
, 12> constThemeColorTypeToToken
{
31 XML_DARK1
, XML_LIGHT1
, XML_DARK2
, XML_LIGHT2
, XML_ACCENT1
, XML_ACCENT2
,
32 XML_ACCENT3
, XML_ACCENT4
, XML_ACCENT5
, XML_ACCENT6
, XML_HYPERLINK
, XML_FOLLOWED_HYPERLINK
36 void XMLComplexColorExport::doExport(model::ComplexColor
const& rComplexColor
, sal_uInt16 nPrefix
,
37 const OUString
& rLocalName
)
39 auto eThemeType
= rComplexColor
.getThemeColorType();
40 if (eThemeType
== model::ThemeColorType::Unknown
)
43 XMLTokenEnum nToken
= constThemeColorTypeToToken
[sal_Int16(eThemeType
)];
44 mrExport
.AddAttribute(XML_NAMESPACE_LO_EXT
, XML_THEME_TYPE
, nToken
);
45 mrExport
.AddAttribute(XML_NAMESPACE_LO_EXT
, XML_COLOR_TYPE
, "theme");
46 SvXMLElementExport
aComplexColorElement(mrExport
, nPrefix
, rLocalName
, true, true);
48 for (auto const& rTransform
: rComplexColor
.getTransformations())
51 switch (rTransform
.meType
)
53 case model::TransformationType::Tint
:
56 case model::TransformationType::Shade
:
59 case model::TransformationType::LumMod
:
62 case model::TransformationType::LumOff
:
70 mrExport
.AddAttribute(XML_NAMESPACE_LO_EXT
, XML_TYPE
, aType
);
71 mrExport
.AddAttribute(XML_NAMESPACE_LO_EXT
, XML_VALUE
,
72 OUString::number(rTransform
.mnValue
));
73 SvXMLElementExport
aTransformElement(mrExport
, XML_NAMESPACE_LO_EXT
, XML_TRANSFORMATION
,
79 void XMLComplexColorExport::exportComplexColor(model::ComplexColor
const& rComplexColor
,
80 sal_uInt16 nPrefix
, XMLTokenEnum nToken
)
82 doExport(rComplexColor
, nPrefix
, GetXMLToken(nToken
));
85 void XMLComplexColorExport::exportXML(const uno::Any
& rAny
, sal_uInt16 nPrefix
,
86 const OUString
& rLocalName
)
88 uno::Reference
<util::XComplexColor
> xComplexColor
;
89 rAny
>>= xComplexColor
;
90 if (!xComplexColor
.is())
93 model::ComplexColor aComplexColor
= model::color::getFromXComplexColor(xComplexColor
);
94 doExport(aComplexColor
, nPrefix
, rLocalName
);
97 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */