Avoid potential negative array index access to cached text.
[LibreOffice.git] / xmloff / source / text / XMLComplexColorExport.cxx
blobfeac9d0d6e3debdde510f16061806afa2bf4ce17
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
8 */
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>
18 #include <array>
20 using namespace css;
21 using namespace ::xmloff::token;
23 XMLComplexColorExport::XMLComplexColorExport(SvXMLExport& rExport)
24 : mrExport(rExport)
28 namespace
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)
41 return;
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())
50 OUString aType;
51 switch (rTransform.meType)
53 case model::TransformationType::Tint:
54 aType = "tint";
55 break;
56 case model::TransformationType::Shade:
57 aType = "shade";
58 break;
59 case model::TransformationType::LumMod:
60 aType = "lummod";
61 break;
62 case model::TransformationType::LumOff:
63 aType = "lumoff";
64 break;
65 default:
66 break;
68 if (!aType.isEmpty())
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,
74 true, true);
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())
91 return;
93 model::ComplexColor aComplexColor = model::color::getFromXComplexColor(xComplexColor);
94 doExport(aComplexColor, nPrefix, rLocalName);
97 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */