From a745ca096e100a4d2cbff3665112f7cba7291876 Mon Sep 17 00:00:00 2001 From: Tomaž Vajngerl Date: Thu, 26 Jan 2023 23:43:00 +0900 Subject: move ColorSet class to own file inside docmodel MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 (cherry picked from commit 69c6f7bccec838b7288a25a29a83b7f782ba7586) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/146229 Tested-by: Tomaž Vajngerl --- docmodel/Library_docmodel.mk | 5 +++ docmodel/source/theme/ColorSet.cxx | 74 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 docmodel/source/theme/ColorSet.cxx (limited to 'docmodel') 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 +#include +#include +#include +#include + +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: */ -- cgit