cid#1640468 Dereference after null check
[LibreOffice.git] / xmloff / source / text / XMLComplexColorExport.cxx
blob2a4170d498fd44dd790146a76ce95bda933cd64a
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/xmlexp.hxx>
17 #include <array>
19 using namespace css;
20 using namespace ::xmloff::token;
22 XMLComplexColorExport::XMLComplexColorExport(SvXMLExport& rExport)
23 : mrExport(rExport)
27 namespace
29 constexpr const std::array<XMLTokenEnum, 12> constThemeColorTypeToToken{
30 XML_DARK1, XML_LIGHT1, XML_DARK2, XML_LIGHT2, XML_ACCENT1, XML_ACCENT2,
31 XML_ACCENT3, XML_ACCENT4, XML_ACCENT5, XML_ACCENT6, XML_HYPERLINK, XML_FOLLOWED_HYPERLINK
35 void XMLComplexColorExport::doExport(model::ComplexColor const& rComplexColor, sal_uInt16 nPrefix,
36 const OUString& rLocalName)
38 auto eThemeType = rComplexColor.getThemeColorType();
39 if (eThemeType == model::ThemeColorType::Unknown)
40 return;
42 XMLTokenEnum nToken = constThemeColorTypeToToken[sal_Int16(eThemeType)];
43 mrExport.AddAttribute(XML_NAMESPACE_LO_EXT, XML_THEME_TYPE, nToken);
44 mrExport.AddAttribute(XML_NAMESPACE_LO_EXT, XML_COLOR_TYPE, u"theme"_ustr);
45 SvXMLElementExport aComplexColorElement(mrExport, nPrefix, rLocalName, true, true);
47 for (auto const& rTransform : rComplexColor.getTransformations())
49 OUString aType;
50 switch (rTransform.meType)
52 case model::TransformationType::Tint:
53 aType = "tint";
54 break;
55 case model::TransformationType::Shade:
56 aType = "shade";
57 break;
58 case model::TransformationType::LumMod:
59 aType = "lummod";
60 break;
61 case model::TransformationType::LumOff:
62 aType = "lumoff";
63 break;
64 default:
65 break;
67 if (!aType.isEmpty())
69 mrExport.AddAttribute(XML_NAMESPACE_LO_EXT, XML_TYPE, aType);
70 mrExport.AddAttribute(XML_NAMESPACE_LO_EXT, XML_VALUE,
71 OUString::number(rTransform.mnValue));
72 SvXMLElementExport aTransformElement(mrExport, XML_NAMESPACE_LO_EXT, XML_TRANSFORMATION,
73 true, true);
78 void XMLComplexColorExport::exportComplexColor(model::ComplexColor const& rComplexColor,
79 sal_uInt16 nPrefix, XMLTokenEnum nToken)
81 doExport(rComplexColor, nPrefix, GetXMLToken(nToken));
84 void XMLComplexColorExport::exportXML(const uno::Any& rAny, sal_uInt16 nPrefix,
85 const OUString& rLocalName)
87 uno::Reference<util::XComplexColor> xComplexColor;
88 rAny >>= xComplexColor;
89 if (!xComplexColor.is())
90 return;
92 model::ComplexColor aComplexColor = model::color::getFromXComplexColor(xComplexColor);
93 doExport(aComplexColor, nPrefix, rLocalName);
96 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */