summaryrefslogtreecommitdiff
path: root/include/docmodel
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2022-12-28 09:43:46 +0900
committerTomaž Vajngerl <quikee@gmail.com>2023-01-20 07:13:13 +0000
commit8402470ae0eb3a2040dab4121b9b0032618b7010 (patch)
treefef5f7eeeb9b58f3f262d8da40803e7e2eeb959d /include/docmodel
parent299270cadfde2376494d939521c58b5b0797acd5 (diff)
introduce docmodel comp., model::ThemeColor, use it in SvxColorItem
Added a new component docmodel, that has the document model types, which only depend on other basic components. This is needed so the types can be used in every relevant component - xmloff, oox, svx, editeng,... Introduces model::ThemeColor, which is a class used to store the theme color data, including transformations (svx::Transformation). For UNO use XThemeColor is added, and the implementation UnoThemeColor which wraps svx::ThemeColor, so it can be tranported around. Reactor all the code and tests to accomodate for this change. Change-Id: I7ce6752cdfaf5e4d3b8e4d90314afa469dd65cfc Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144847 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com> (cherry picked from commit bd0f526f2d3e1ffe43a74672485815768eee6e9e) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145844 Tested-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'include/docmodel')
-rw-r--r--include/docmodel/dllapi.h21
-rw-r--r--include/docmodel/theme/ThemeColor.hxx146
-rw-r--r--include/docmodel/theme/ThemeColorType.hxx42
-rw-r--r--include/docmodel/uno/UnoThemeColor.hxx55
4 files changed, 264 insertions, 0 deletions
diff --git a/include/docmodel/dllapi.h b/include/docmodel/dllapi.h
new file mode 100644
index 000000000000..f90b7cc4c08e
--- /dev/null
+++ b/include/docmodel/dllapi.h
@@ -0,0 +1,21 @@
+/* -*- 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/.
+ */
+
+#pragma once
+
+#include <sal/types.h>
+
+#if defined(DOCMODEL_DLLIMPLEMENTATION)
+#define DOCMODEL_DLLPUBLIC SAL_DLLPUBLIC_EXPORT
+#else
+#define DOCMODEL_DLLPUBLIC SAL_DLLPUBLIC_IMPORT
+#endif
+#define DOCMODEL_DLLPRIVATE SAL_DLLPRIVATE
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/docmodel/theme/ThemeColor.hxx b/include/docmodel/theme/ThemeColor.hxx
new file mode 100644
index 000000000000..2069594713d8
--- /dev/null
+++ b/include/docmodel/theme/ThemeColor.hxx
@@ -0,0 +1,146 @@
+/* -*- 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/.
+ *
+ */
+
+#pragma once
+
+#include <docmodel/dllapi.h>
+#include <vector>
+#include <docmodel/theme/ThemeColorType.hxx>
+#include <tools/color.hxx>
+
+namespace model
+{
+/** Color transfomation type */
+enum class TransformationType
+{
+ Undefined,
+ Red,
+ RedMod,
+ RedOff,
+ Green,
+ GreenMod,
+ GreenOff,
+ Blue,
+ BlueMod,
+ BlueOff,
+ Alpha,
+ AlphaMod,
+ AlphaOff,
+ Hue,
+ HueMod,
+ HueOff,
+ Sat,
+ SatMod,
+ SatOff,
+ Lum,
+ LumMod,
+ LumOff,
+ Shade,
+ Tint,
+ Gray,
+ Comp,
+ Inv,
+ Gamma,
+ InvGamma
+};
+
+/** Definition of a color transformation.
+ *
+ * This just defines how a color should be transformed (changed). The
+ * type defines what kind of transformation should occur and the value
+ * defines by how much.
+ */
+struct DOCMODEL_DLLPUBLIC Transformation
+{
+ TransformationType meType = TransformationType::Undefined;
+ sal_Int16 mnValue = 0; /// percentage value -10000 to +10000
+
+ bool operator==(const Transformation& rTransformation) const
+ {
+ return meType == rTransformation.meType && mnValue == rTransformation.mnValue;
+ }
+};
+
+/** Definition of a theme color
+ *
+ * A theme color is defined by the type of theme color and a set of
+ * transformations that in addition manipulate the resulting color
+ * (i.e. tints, shades).
+ */
+class DOCMODEL_DLLPUBLIC ThemeColor
+{
+ ThemeColorType meType = ThemeColorType::Unknown;
+ std::vector<Transformation> maTransformations;
+
+public:
+ ThemeColor() = default;
+
+ ThemeColorType getType() const { return meType; }
+
+ void setType(ThemeColorType eType) { meType = eType; }
+
+ void clearTransformations() { maTransformations.clear(); }
+
+ void addTransformation(Transformation const& rTransform)
+ {
+ maTransformations.push_back(rTransform);
+ }
+
+ void removeTransformations(TransformationType eType)
+ {
+ maTransformations.erase(std::remove_if(maTransformations.begin(), maTransformations.end(),
+ [eType](Transformation const& rTransform) {
+ return rTransform.meType == eType;
+ }),
+ maTransformations.end());
+ }
+
+ std::vector<Transformation> const& getTransformations() const { return maTransformations; }
+
+ /** Applies the defined trasformations to the input color */
+ Color applyTransformations(Color const& rColor) const
+ {
+ Color aColor(rColor);
+
+ for (auto const& rTransform : maTransformations)
+ {
+ switch (rTransform.meType)
+ {
+ case TransformationType::Tint:
+ aColor.ApplyTintOrShade(rTransform.mnValue);
+ break;
+ case TransformationType::Shade:
+ aColor.ApplyTintOrShade(-rTransform.mnValue);
+ break;
+ case TransformationType::LumMod:
+ aColor.ApplyLumModOff(rTransform.mnValue, 0);
+ break;
+ case TransformationType::LumOff:
+ aColor.ApplyLumModOff(10000, rTransform.mnValue);
+ break;
+ default:
+ break;
+ }
+ }
+ return aColor;
+ }
+
+ bool operator==(const ThemeColor& rThemeColor) const
+ {
+ return meType == rThemeColor.meType
+ && maTransformations.size() == rThemeColor.maTransformations.size()
+ && std::equal(maTransformations.begin(), maTransformations.end(),
+ rThemeColor.maTransformations.begin());
+ }
+};
+
+} // end of namespace model
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/docmodel/theme/ThemeColorType.hxx b/include/docmodel/theme/ThemeColorType.hxx
new file mode 100644
index 000000000000..a8ed9a56a6dc
--- /dev/null
+++ b/include/docmodel/theme/ThemeColorType.hxx
@@ -0,0 +1,42 @@
+/* -*- 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/.
+ *
+ */
+
+#pragma once
+
+namespace model
+{
+/// Offsets into the color list of a theme.
+enum class ThemeColorType : sal_Int32
+{
+ Unknown = -1,
+ Dark1 = 0,
+ Light1 = 1,
+ Dark2 = 2,
+ Light2 = 3,
+ Accent1 = 4,
+ Accent2 = 5,
+ Accent3 = 6,
+ Accent4 = 7,
+ Accent5 = 8,
+ Accent6 = 9,
+ Hyperlink = 10,
+ FollowedHyperlink = 11,
+ LAST = FollowedHyperlink
+};
+
+constexpr ThemeColorType convertToThemeColorType(sal_Int32 nIndex)
+{
+ if (nIndex < 0 || nIndex > 11)
+ return ThemeColorType::Unknown;
+ return static_cast<ThemeColorType>(nIndex);
+}
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/docmodel/uno/UnoThemeColor.hxx b/include/docmodel/uno/UnoThemeColor.hxx
new file mode 100644
index 000000000000..50063ab981dd
--- /dev/null
+++ b/include/docmodel/uno/UnoThemeColor.hxx
@@ -0,0 +1,55 @@
+/* -*- 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/.
+ */
+
+#pragma once
+
+#include <cppuhelper/implbase.hxx>
+#include <cppuhelper/supportsservice.hxx>
+#include <comphelper/servicehelper.hxx>
+
+#include <com/sun/star/util/Color.hpp>
+#include <com/sun/star/util/XThemeColor.hpp>
+#include <com/sun/star/lang/XUnoTunnel.hpp>
+#include <com/sun/star/uno/XComponentContext.hpp>
+
+#include <utility>
+#include <docmodel/dllapi.h>
+#include <docmodel/theme/ThemeColor.hxx>
+
+class DOCMODEL_DLLPUBLIC UnoThemeColor final
+ : public cppu::WeakImplHelper<css::util::XThemeColor, css::lang::XUnoTunnel>
+{
+private:
+ model::ThemeColor maThemeColor;
+
+public:
+ UnoThemeColor(model::ThemeColor const& rThemeColor)
+ : maThemeColor(rThemeColor)
+ {
+ }
+
+ model::ThemeColor const& getThemeColor() const { return maThemeColor; }
+
+ // XThemeColor
+ sal_Int16 SAL_CALL getType() override;
+
+ UNO3_GETIMPLEMENTATION_DECL(UnoThemeColor)
+};
+
+namespace model::theme
+{
+DOCMODEL_DLLPUBLIC css::uno::Reference<css::util::XThemeColor>
+createXThemeColor(model::ThemeColor const& rThemeColor);
+
+DOCMODEL_DLLPUBLIC void
+setFromXThemeColor(model::ThemeColor& rThemeColor,
+ css::uno::Reference<css::util::XThemeColor> const& rxThemeColor);
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */