diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2023-01-26 23:43:00 +0900 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2023-01-27 01:41:22 +0000 |
commit | 69c6f7bccec838b7288a25a29a83b7f782ba7586 (patch) | |
tree | 0679998c8ff2af214365dd38a8997c4240871499 /docmodel | |
parent | 9cbc3a64492e0670427f17b753d0908657c8c5bd (diff) |
move ColorSet class to own file inside docmodel
Also move ColorSet from svx to model namespace so it is consistent
with other classes in docmodel.
Change-Id: Iacbdbdf5ece4015c628a0e45adf6a732b2d27777
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/146220
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'docmodel')
-rw-r--r-- | docmodel/Library_docmodel.mk | 5 | ||||
-rw-r--r-- | docmodel/source/theme/ColorSet.cxx | 74 |
2 files changed, 79 insertions, 0 deletions
diff --git a/docmodel/Library_docmodel.mk b/docmodel/Library_docmodel.mk index 3e0d28dfda28..22ecdfa59ac4 100644 --- a/docmodel/Library_docmodel.mk +++ b/docmodel/Library_docmodel.mk @@ -11,6 +11,7 @@ $(eval $(call gb_Library_Library,docmodel)) $(eval $(call gb_Library_add_exception_objects,docmodel,\ docmodel/source/uno/UnoThemeColor \ + docmodel/source/theme/ColorSet \ )) $(eval $(call gb_Library_set_include,docmodel,\ @@ -18,6 +19,10 @@ $(eval $(call gb_Library_set_include,docmodel,\ -I$(SRCDIR)/docmodel/inc \ )) +$(eval $(call gb_Library_use_externals,docmodel,\ + libxml2 \ +)) + $(eval $(call gb_Library_add_defs,docmodel,\ -DDOCMODEL_DLLIMPLEMENTATION \ )) diff --git a/docmodel/source/theme/ColorSet.cxx b/docmodel/source/theme/ColorSet.cxx new file mode 100644 index 000000000000..55c03dadba8c --- /dev/null +++ b/docmodel/source/theme/ColorSet.cxx @@ -0,0 +1,74 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + */ + +#include <docmodel/theme/ColorSet.hxx> +#include <sstream> +#include <utility> +#include <libxml/xmlwriter.h> +#include <sal/log.hxx> + +namespace model +{ +ColorSet::ColorSet(OUString const& rName) + : maName(rName) +{ +} + +void ColorSet::add(model::ThemeColorType eType, Color aColorData) +{ + if (eType == model::ThemeColorType::Unknown) + return; + maColors[sal_Int16(eType)] = aColorData; +} + +Color ColorSet::getColor(model::ThemeColorType eType) const +{ + if (eType == model::ThemeColorType::Unknown) + { + SAL_WARN("svx", "ColorSet::getColor with ThemeColorType::Unknown"); + return COL_AUTO; + } + return maColors[size_t(eType)]; +} + +Color ColorSet::resolveColor(model::ThemeColor const& rThemeColor) const +{ + auto eType = rThemeColor.getType(); + if (eType == model::ThemeColorType::Unknown) + { + SAL_WARN("svx", "ColorSet::resolveColor with ThemeColorType::Unknown"); + return COL_AUTO; + } + Color aColor = getColor(eType); + return rThemeColor.applyTransformations(aColor); +} + +void ColorSet::dumpAsXml(xmlTextWriterPtr pWriter) const +{ + (void)xmlTextWriterStartElement(pWriter, BAD_CAST("ColorSet")); + (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", this); + (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("maName"), + BAD_CAST(maName.toUtf8().getStr())); + + for (const auto& rColor : maColors) + { + (void)xmlTextWriterStartElement(pWriter, BAD_CAST("Color")); + std::stringstream ss; + ss << rColor; + (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("value"), BAD_CAST(ss.str().c_str())); + (void)xmlTextWriterEndElement(pWriter); + } + + (void)xmlTextWriterEndElement(pWriter); +} + +} // end of namespace svx + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |