tdf#130857 qt weld: Implement QtInstanceWidget::get_text_height
[LibreOffice.git] / docmodel / source / theme / ColorSet.cxx
blobdf7cf18f61b6dfbd9ba7f8a3b52b4488ab78a9e6
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/.
9 */
11 #include <docmodel/theme/ColorSet.hxx>
12 #include <sstream>
13 #include <utility>
14 #include <libxml/xmlwriter.h>
15 #include <sal/log.hxx>
17 namespace model
19 ColorSet::ColorSet(OUString const& rName)
20 : maName(rName)
24 void ColorSet::add(model::ThemeColorType eType, Color aColorData)
26 if (eType == model::ThemeColorType::Unknown)
27 return;
28 maColors[sal_Int16(eType)] = aColorData;
31 Color ColorSet::getColor(model::ThemeColorType eType) const
33 if (eType == model::ThemeColorType::Unknown)
35 SAL_WARN("svx", "ColorSet::getColor with ThemeColorType::Unknown");
36 return COL_AUTO;
38 return maColors[size_t(eType)];
41 Color ColorSet::resolveColor(model::ComplexColor const& rComplexColor) const
43 auto eThemeType = rComplexColor.getThemeColorType();
44 if (eThemeType == model::ThemeColorType::Unknown)
46 SAL_WARN("svx", "ColorSet::resolveColor with ThemeColorType::Unknown");
47 return COL_AUTO;
49 Color aColor = getColor(eThemeType);
50 return rComplexColor.applyTransformations(aColor);
53 void ColorSet::dumpAsXml(xmlTextWriterPtr pWriter) const
55 (void)xmlTextWriterStartElement(pWriter, BAD_CAST("ColorSet"));
56 (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", this);
57 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("maName"),
58 BAD_CAST(maName.toUtf8().getStr()));
60 for (const auto& rColor : maColors)
62 (void)xmlTextWriterStartElement(pWriter, BAD_CAST("Color"));
63 std::stringstream ss;
64 ss << rColor;
65 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("value"), BAD_CAST(ss.str().c_str()));
66 (void)xmlTextWriterEndElement(pWriter);
69 (void)xmlTextWriterEndElement(pWriter);
72 } // end of namespace svx
74 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */