diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 05:54:39 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 05:54:39 +0000 |
commit | 267c6f2ac71f92999e969232431ba04678e7437e (patch) | |
tree | 358c9467650e1d0a1d7227a21dac2e3d08b622b2 /docmodel | |
parent | Initial commit. (diff) | |
download | libreoffice-267c6f2ac71f92999e969232431ba04678e7437e.tar.xz libreoffice-267c6f2ac71f92999e969232431ba04678e7437e.zip |
Adding upstream version 4:24.2.0.upstream/4%24.2.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'docmodel')
-rw-r--r-- | docmodel/Library_docmodel.mk | 48 | ||||
-rw-r--r-- | docmodel/Makefile | 7 | ||||
-rw-r--r-- | docmodel/Module_docmodel.mk | 18 | ||||
-rw-r--r-- | docmodel/README.md | 5 | ||||
-rw-r--r-- | docmodel/inc/pch/precompiled_docmodel.cxx | 12 | ||||
-rw-r--r-- | docmodel/inc/pch/precompiled_docmodel.hxx | 34 | ||||
-rw-r--r-- | docmodel/source/color/ComplexColorJSON.cxx | 109 | ||||
-rw-r--r-- | docmodel/source/theme/ColorSet.cxx | 74 | ||||
-rw-r--r-- | docmodel/source/theme/Theme.cxx | 157 | ||||
-rw-r--r-- | docmodel/source/uno/UnoComplexColor.cxx | 43 | ||||
-rw-r--r-- | docmodel/source/uno/UnoGradientTools.cxx | 200 | ||||
-rw-r--r-- | docmodel/source/uno/UnoTheme.cxx | 51 |
12 files changed, 758 insertions, 0 deletions
diff --git a/docmodel/Library_docmodel.mk b/docmodel/Library_docmodel.mk new file mode 100644 index 0000000000..d5f4531602 --- /dev/null +++ b/docmodel/Library_docmodel.mk @@ -0,0 +1,48 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t; fill-column: 100 -*- +# +# 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/. +# + +$(eval $(call gb_Library_Library,docmodel)) + +$(eval $(call gb_Library_add_exception_objects,docmodel,\ + docmodel/source/uno/UnoComplexColor \ + docmodel/source/uno/UnoGradientTools \ + docmodel/source/uno/UnoTheme \ + docmodel/source/theme/ColorSet \ + docmodel/source/theme/Theme \ + docmodel/source/color/ComplexColorJSON \ +)) + +$(eval $(call gb_Library_set_include,docmodel,\ + $$(INCLUDE) \ + -I$(SRCDIR)/docmodel/inc \ +)) + +$(eval $(call gb_Library_use_externals,docmodel,\ + libxml2 \ + boost_headers \ +)) + +$(eval $(call gb_Library_add_defs,docmodel,\ + -DDOCMODEL_DLLIMPLEMENTATION \ +)) + +$(eval $(call gb_Library_set_precompiled_header,docmodel,docmodel/inc/pch/precompiled_docmodel)) + +$(eval $(call gb_Library_use_sdk_api,docmodel)) + +$(eval $(call gb_Library_use_libraries,docmodel,\ + basegfx \ + comphelper \ + cppuhelper \ + cppu \ + sal \ + tl \ +)) + +# vim: set noet sw=4 ts=4: diff --git a/docmodel/Makefile b/docmodel/Makefile new file mode 100644 index 0000000000..ccb1c85a04 --- /dev/null +++ b/docmodel/Makefile @@ -0,0 +1,7 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- + +module_directory:=$(dir $(realpath $(firstword $(MAKEFILE_LIST)))) + +include $(module_directory)/../solenv/gbuild/partial_build.mk + +# vim: set noet sw=4 ts=4: diff --git a/docmodel/Module_docmodel.mk b/docmodel/Module_docmodel.mk new file mode 100644 index 0000000000..7e55ff74ad --- /dev/null +++ b/docmodel/Module_docmodel.mk @@ -0,0 +1,18 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +# +# 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/. +# + +$(eval $(call gb_Module_Module,docmodel)) + +$(eval $(call gb_Module_add_targets,docmodel,\ + Library_docmodel \ +)) + + + +# vim: set noet sw=4 ts=4: diff --git a/docmodel/README.md b/docmodel/README.md new file mode 100644 index 0000000000..85464fb5be --- /dev/null +++ b/docmodel/README.md @@ -0,0 +1,5 @@ +# Document Model Types and Objects + +Contains document model types, that don't require many dependencies except +basic types found in basegfx and tools. The purpose of this types and +objects is to be available in all common components. diff --git a/docmodel/inc/pch/precompiled_docmodel.cxx b/docmodel/inc/pch/precompiled_docmodel.cxx new file mode 100644 index 0000000000..f8a84e17d6 --- /dev/null +++ b/docmodel/inc/pch/precompiled_docmodel.cxx @@ -0,0 +1,12 @@ +/* -*- 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 "precompiled_docmodel.hxx" + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/docmodel/inc/pch/precompiled_docmodel.hxx b/docmodel/inc/pch/precompiled_docmodel.hxx new file mode 100644 index 0000000000..1942b8737a --- /dev/null +++ b/docmodel/inc/pch/precompiled_docmodel.hxx @@ -0,0 +1,34 @@ +/* -*- 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/. + */ + +/* + This file has been autogenerated by update_pch.sh. It is possible to edit it + manually (such as when an include file has been moved/renamed/removed). All such + manual changes will be rewritten by the next run of update_pch.sh (which presumably + also fixes all possible problems, so it's usually better to use it). + + Generated on 2023-01-10 23:20:14 using: + bin/update_pch docmodel docmodel --cutoff=3 --exclude:system --exclude:module --include:local + + If after updating build fails, use the following command to locate conflicting headers: + ./bin/update_pch_bisect ./docmodel/inc/pch/precompiled_docmodel.hxx "make docmodel.build" --find-conflicts +*/ + +#include <sal/config.h> +#if PCH_LEVEL >= 1 +#endif // PCH_LEVEL >= 1 +#if PCH_LEVEL >= 2 +#include <sal/types.h> +#endif // PCH_LEVEL >= 2 +#if PCH_LEVEL >= 3 +#endif // PCH_LEVEL >= 3 +#if PCH_LEVEL >= 4 +#endif // PCH_LEVEL >= 4 + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/docmodel/source/color/ComplexColorJSON.cxx b/docmodel/source/color/ComplexColorJSON.cxx new file mode 100644 index 0000000000..7c09a1e822 --- /dev/null +++ b/docmodel/source/color/ComplexColorJSON.cxx @@ -0,0 +1,109 @@ +/* -*- 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/color/ComplexColorJSON.hxx> +#include <boost/property_tree/json_parser.hpp> +#include <sstream> +#include <utility> +#include <sal/log.hxx> + +namespace model::color +{ +bool convertFromJSON(OString const& rJsonString, model::ComplexColor& rComplexColor) +{ + model::ComplexColor aComplexColor; + + try + { + std::stringstream aStream((std::string(rJsonString))); + boost::property_tree::ptree aRootTree; + boost::property_tree::read_json(aStream, aRootTree); + + sal_Int32 nThemeType = aRootTree.get<sal_Int32>("ThemeIndex", -1); + aComplexColor.setThemeColor(model::convertToThemeColorType(nThemeType)); + boost::property_tree::ptree aTransformTree = aRootTree.get_child("Transformations"); + for (const auto& rEachTransformationNode : + boost::make_iterator_range(aTransformTree.equal_range(""))) + { + auto const& rTransformationTree = rEachTransformationNode.second; + std::string sType = rTransformationTree.get<std::string>("Type", ""); + sal_Int16 nValue = rTransformationTree.get<sal_Int16>("Value", 0); + + auto eType = model::TransformationType::Undefined; + if (sType == "LumOff") + eType = model::TransformationType::LumOff; + else if (sType == "LumMod") + eType = model::TransformationType::LumMod; + else if (sType == "Tint") + eType = model::TransformationType::Tint; + else if (sType == "Shade") + eType = model::TransformationType::Shade; + + if (eType != model::TransformationType::Undefined) + aComplexColor.addTransformation({ eType, nValue }); + } + } + catch (const boost::property_tree::json_parser_error& /*exception*/) + { + return false; + } + + rComplexColor = aComplexColor; + return true; +} + +void convertToJSONTree(boost::property_tree::ptree& rTree, model::ComplexColor const& rComplexColor) +{ + rTree.put("ThemeIndex", sal_Int16(rComplexColor.getThemeColorType())); + + boost::property_tree::ptree aTransformationsList; + for (auto const& rTransformation : rComplexColor.getTransformations()) + { + std::string aType; + switch (rTransformation.meType) + { + case model::TransformationType::LumMod: + aType = "LumMod"; + break; + case model::TransformationType::LumOff: + aType = "LumOff"; + break; + case model::TransformationType::Tint: + aType = "Tint"; + break; + case model::TransformationType::Shade: + aType = "Shade"; + break; + default: + break; + } + if (!aType.empty()) + { + boost::property_tree::ptree aChild; + aChild.put("Type", aType); + aChild.put("Value", rTransformation.mnValue); + aTransformationsList.push_back(std::make_pair("", aChild)); + } + } + rTree.add_child("Transformations", aTransformationsList); +} + +OString convertToJSON(model::ComplexColor const& rComplexColor) +{ + boost::property_tree::ptree aTree; + convertToJSONTree(aTree, rComplexColor); + std::stringstream aStream; + boost::property_tree::write_json(aStream, aTree); + return OString(aStream.str()); +} + +} // end model::theme + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/docmodel/source/theme/ColorSet.cxx b/docmodel/source/theme/ColorSet.cxx new file mode 100644 index 0000000000..df7cf18f61 --- /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::ComplexColor const& rComplexColor) const +{ + auto eThemeType = rComplexColor.getThemeColorType(); + if (eThemeType == model::ThemeColorType::Unknown) + { + SAL_WARN("svx", "ColorSet::resolveColor with ThemeColorType::Unknown"); + return COL_AUTO; + } + Color aColor = getColor(eThemeType); + return rComplexColor.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: */ diff --git a/docmodel/source/theme/Theme.cxx b/docmodel/source/theme/Theme.cxx new file mode 100644 index 0000000000..d4095eeb3e --- /dev/null +++ b/docmodel/source/theme/Theme.cxx @@ -0,0 +1,157 @@ +/* -*- 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/Theme.hxx> + +#include <utility> +#include <libxml/xmlwriter.h> +#include <comphelper/sequenceashashmap.hxx> +#include <comphelper/sequence.hxx> +#include <sal/log.hxx> +#include <sal/types.h> +#include <o3tl/enumrange.hxx> +#include <com/sun/star/util/Color.hpp> +#include <com/sun/star/beans/PropertyValue.hpp> + +using namespace com::sun::star; + +namespace model +{ +Theme::Theme() = default; + +Theme::Theme(OUString const& rName) + : maName(rName) +{ +} + +Theme::Theme(Theme const& rTheme) + : maName(rTheme.maName) + , mpColorSet(new ColorSet(*rTheme.getColorSet())) + , maFontScheme(rTheme.maFontScheme) +{ +} + +void Theme::SetName(const OUString& rName) { maName = rName; } + +const OUString& Theme::GetName() const { return maName; } + +void Theme::dumpAsXml(xmlTextWriterPtr pWriter) const +{ + (void)xmlTextWriterStartElement(pWriter, BAD_CAST("Theme")); + (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", this); + (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("maName"), + BAD_CAST(maName.toUtf8().getStr())); + + if (mpColorSet) + { + mpColorSet->dumpAsXml(pWriter); + } + + (void)xmlTextWriterEndElement(pWriter); +} + +void Theme::ToAny(uno::Any& rVal) const +{ + comphelper::SequenceAsHashMap aMap; + aMap["Name"] <<= maName; + + if (mpColorSet) + { + std::vector<util::Color> aColorScheme; + for (auto eThemeColorType : o3tl::enumrange<model::ThemeColorType>()) + { + if (eThemeColorType != model::ThemeColorType::Unknown) + { + Color aColor = mpColorSet->getColor(eThemeColorType); + aColorScheme.push_back(sal_Int32(aColor)); + } + } + + aMap["ColorSchemeName"] <<= mpColorSet->getName(); + aMap["ColorScheme"] <<= comphelper::containerToSequence(aColorScheme); + } + + rVal <<= aMap.getAsConstPropertyValueList(); +} + +std::unique_ptr<Theme> Theme::FromAny(const uno::Any& rVal) +{ + comphelper::SequenceAsHashMap aMap(rVal); + std::unique_ptr<Theme> pTheme; + std::shared_ptr<model::ColorSet> pColorSet; + + auto it = aMap.find("Name"); + if (it != aMap.end()) + { + OUString aName; + it->second >>= aName; + pTheme = std::make_unique<Theme>(aName); + } + + it = aMap.find("ColorSchemeName"); + if (it != aMap.end() && pTheme) + { + OUString aName; + it->second >>= aName; + pColorSet = std::make_shared<model::ColorSet>(aName); + pTheme->setColorSet(pColorSet); + } + + it = aMap.find("ColorScheme"); + if (it != aMap.end() && pColorSet) + { + uno::Sequence<util::Color> aColors; + it->second >>= aColors; + + SAL_WARN_IF(aColors.size() > 12, "svx", + "Theme::FromAny: number of colors greater than max theme colors supported"); + + for (auto eThemeColorType : o3tl::enumrange<model::ThemeColorType>()) + { + if (eThemeColorType != model::ThemeColorType::Unknown) + { + size_t nIndex(static_cast<sal_Int16>(eThemeColorType)); + if (nIndex < aColors.size()) + { + Color aColor(ColorTransparency, aColors[nIndex]); + pColorSet->add(eThemeColorType, aColor); + } + } + } + } + + return pTheme; +} + +std::vector<Color> Theme::GetColors() const +{ + if (!mpColorSet) + return {}; + + std::vector<Color> aColors; + for (auto eThemeColorType : o3tl::enumrange<model::ThemeColorType>()) + { + if (eThemeColorType != model::ThemeColorType::Unknown) + aColors.push_back(mpColorSet->getColor(eThemeColorType)); + } + return aColors; +} + +Color Theme::GetColor(model::ThemeColorType eType) const +{ + if (!mpColorSet) + return {}; + + return mpColorSet->getColor(eType); +} + +} // end of namespace model + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/docmodel/source/uno/UnoComplexColor.cxx b/docmodel/source/uno/UnoComplexColor.cxx new file mode 100644 index 0000000000..f419543ca0 --- /dev/null +++ b/docmodel/source/uno/UnoComplexColor.cxx @@ -0,0 +1,43 @@ +/* -*- 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/uno/UnoComplexColor.hxx> +#include <cppuhelper/queryinterface.hxx> + +using namespace css; + +sal_Int32 UnoComplexColor::getType() { return sal_Int32(maColor.getType()); } + +sal_Int32 UnoComplexColor::getThemeColorType() { return sal_Int32(maColor.getThemeColorType()); } + +util::Color UnoComplexColor::resolveColor(uno::Reference<util::XTheme> const& /*xTheme*/) +{ + return util::Color(maColor.getRGBColor()); +} + +namespace model::color +{ +uno::Reference<util::XComplexColor> createXComplexColor(model::ComplexColor const& rColor) +{ + return new UnoComplexColor(rColor); +} + +model::ComplexColor getFromXComplexColor(uno::Reference<util::XComplexColor> const& rxColor) +{ + model::ComplexColor aComplexColor; + UnoComplexColor const* pUnoComplexColor = static_cast<UnoComplexColor const*>(rxColor.get()); + if (pUnoComplexColor) + aComplexColor = pUnoComplexColor->getComplexColor(); + return aComplexColor; +} + +} // end model::color + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/docmodel/source/uno/UnoGradientTools.cxx b/docmodel/source/uno/UnoGradientTools.cxx new file mode 100644 index 0000000000..0f05e398de --- /dev/null +++ b/docmodel/source/uno/UnoGradientTools.cxx @@ -0,0 +1,200 @@ +/* -*- 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/uno/UnoGradientTools.hxx> +#include <com/sun/star/awt/Gradient.hpp> +#include <com/sun/star/awt/Gradient2.hpp> +#include <com/sun/star/rendering/RGBColor.hpp> +#include <basegfx/utils/bgradient.hxx> +#include <tools/color.hxx> + +using namespace css; + +namespace model::gradient +{ +css::awt::ColorStopSequence createColorStopSequence(basegfx::BColorStops const& rColorStops) +{ + // Fill color stops + css::awt::ColorStopSequence aSequence(rColorStops.size()); + css::awt::ColorStop* pSequence(aSequence.getArray()); + + for (const auto& rStop : rColorStops) + { + auto rBColor = rStop.getStopColor(); + pSequence->StopOffset = rStop.getStopOffset(); + pSequence->StopColor + = css::rendering::RGBColor(rBColor.getRed(), rBColor.getGreen(), rBColor.getBlue()); + pSequence++; + } + + return aSequence; +} + +css::awt::Gradient2 createUnoGradient2(basegfx::BGradient const& rGradient) +{ + css::awt::Gradient2 aGradient2; + + // standard values + aGradient2.Style = rGradient.GetGradientStyle(); + aGradient2.Angle = static_cast<short>(rGradient.GetAngle()); + aGradient2.Border = rGradient.GetBorder(); + aGradient2.XOffset = rGradient.GetXOffset(); + aGradient2.YOffset = rGradient.GetYOffset(); + aGradient2.StartIntensity = rGradient.GetStartIntens(); + aGradient2.EndIntensity = rGradient.GetEndIntens(); + aGradient2.StepCount = rGradient.GetSteps(); + + // for compatibility, still set StartColor/EndColor + // NOTE: All code after adapting to multi color gradients works + // using the ColorSteps, so in principle Start/EndColor might + // be either + // (a) ignored consequently everywhere or + // (b) be set/added consequently everywhere + // since this is - in principle - redundant data. + // Be aware that e.g. cases like DrawingML::EqualGradients + // and others would have to be identified and adapted (!) + // Since awt::Gradient2 is UNO API data there might + // be cases where just awt::Gradient is transferred, so (b) + // is far better backwards compatible and thus more safe, so + // all changes will make use of additionally using/setting + // these additionally, but will only make use of the given + // ColorSteps if these are not empty, assuming that these + // already contain Start/EndColor. + // In principle that redundancy and that it is conflict-free + // could even be checked and asserted, but consequently using + // (b) methodically should be safe. + const basegfx::BColorStops& rColorStops = rGradient.GetColorStops(); + aGradient2.StartColor = static_cast<sal_Int32>(::Color(rColorStops.front().getStopColor())); + aGradient2.EndColor = static_cast<sal_Int32>(::Color(rColorStops.back().getStopColor())); + + aGradient2.ColorStops = createColorStopSequence(rColorStops); + + return aGradient2; +} + +namespace +{ +void fillFromColorStopSequence(basegfx::BColorStops& rColorStops, + css::awt::ColorStopSequence const& rUnoColorStopSequence) +{ + const auto nLength = rUnoColorStopSequence.getLength(); + if (0 != nLength) + { + rColorStops.clear(); + rColorStops.reserve(nLength); + + for (css::awt::ColorStop const& rSourceStop : rUnoColorStopSequence) + { + rColorStops.emplace_back(rSourceStop.StopOffset, + basegfx::BColor(rSourceStop.StopColor.Red, + rSourceStop.StopColor.Green, + rSourceStop.StopColor.Blue)); + } + } +} + +void fillFromGradient2(basegfx::BGradient& rBGradient, css::awt::Gradient2 const& rGradient2) +{ + rBGradient.SetGradientStyle(rGradient2.Style); + rBGradient.SetAngle(Degree10(rGradient2.Angle)); + rBGradient.SetBorder(rGradient2.Border); + rBGradient.SetXOffset(rGradient2.XOffset); + rBGradient.SetYOffset(rGradient2.YOffset); + rBGradient.SetStartIntens(rGradient2.StartIntensity); + rBGradient.SetEndIntens(rGradient2.EndIntensity); + rBGradient.SetSteps(rGradient2.StepCount); + + // set ColorStops + if (rGradient2.ColorStops.hasElements()) + { + basegfx::BColorStops aColorStops; + fillFromColorStopSequence(aColorStops, rGradient2.ColorStops); + rBGradient.SetColorStops(aColorStops); + } + else + { + // if not, for compatibility, use StartColor/EndColor + basegfx::BColorStops aColorStops{ + basegfx::BColorStop(0.0, ::Color(ColorTransparency, rGradient2.StartColor).getBColor()), + basegfx::BColorStop(1.0, ::Color(ColorTransparency, rGradient2.EndColor).getBColor()) + }; + rBGradient.SetColorStops(aColorStops); + } +} + +} // end anonymous + +basegfx::BColorStops getColorStopsFromUno(css::awt::ColorStopSequence const& rColorStopSequence) +{ + basegfx::BColorStops aColorStops; + fillFromColorStopSequence(aColorStops, rColorStopSequence); + return aColorStops; +} + +basegfx::BColorStops getColorStopsFromAny(css::uno::Any const& rAny) +{ + basegfx::BColorStops aColorStops; + if (!rAny.has<css::awt::ColorStopSequence>()) + return aColorStops; + + auto aSequence = rAny.get<css::awt::ColorStopSequence>(); + fillFromColorStopSequence(aColorStops, aSequence); + return aColorStops; +} + +basegfx::BGradient getFromUnoGradient2(css::awt::Gradient2 const& rGradient2) +{ + basegfx::BGradient aBGradient; + fillFromGradient2(aBGradient, rGradient2); + return aBGradient; +} + +basegfx::BGradient getFromAny(css::uno::Any const& rAny) +{ + basegfx::BGradient aBGradient; + + if (rAny.has<css::awt::Gradient2>()) + { + // we can use awt::Gradient2 directly + css::awt::Gradient2 aGradient2; + rAny >>= aGradient2; + + fillFromGradient2(aBGradient, aGradient2); + } + else if (rAny.has<css::awt::Gradient>()) + { + // use awt::Gradient + css::awt::Gradient aGradient; + rAny >>= aGradient; + + // set values + aBGradient.SetGradientStyle(aGradient.Style); + aBGradient.SetAngle(Degree10(aGradient.Angle)); + aBGradient.SetBorder(aGradient.Border); + aBGradient.SetXOffset(aGradient.XOffset); + aBGradient.SetYOffset(aGradient.YOffset); + aBGradient.SetStartIntens(aGradient.StartIntensity); + aBGradient.SetEndIntens(aGradient.EndIntensity); + aBGradient.SetSteps(aGradient.StepCount); + + basegfx::BColorStops aColorStops{ + basegfx::BColorStop(0.0, ::Color(ColorTransparency, aGradient.StartColor).getBColor()), + basegfx::BColorStop(1.0, ::Color(ColorTransparency, aGradient.EndColor).getBColor()) + }; + + aBGradient.SetColorStops(aColorStops); + } + + return aBGradient; +} + +} // end model::gradient + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/docmodel/source/uno/UnoTheme.cxx b/docmodel/source/uno/UnoTheme.cxx new file mode 100644 index 0000000000..a7eac05cbd --- /dev/null +++ b/docmodel/source/uno/UnoTheme.cxx @@ -0,0 +1,51 @@ +/* -*- 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/uno/UnoTheme.hxx> +#include <docmodel/theme/ThemeColorType.hxx> +#include <cppuhelper/queryinterface.hxx> +#include <o3tl/enumrange.hxx> +#include <comphelper/sequence.hxx> +#include <docmodel/theme/Theme.hxx> + +using namespace css; + +OUString UnoTheme::getName() { return mpTheme->GetName(); } + +css::uno::Sequence<sal_Int32> UnoTheme::getColorSet() +{ + std::vector<sal_Int32> aColorScheme(12); + auto pColorSet = mpTheme->getColorSet(); + if (pColorSet) + { + size_t i = 0; + + for (auto eThemeColorType : o3tl::enumrange<model::ThemeColorType>()) + { + if (eThemeColorType == model::ThemeColorType::Unknown) + continue; + Color aColor = pColorSet->getColor(eThemeColorType); + aColorScheme[i] = sal_Int32(aColor); + i++; + } + } + return comphelper::containerToSequence(aColorScheme); +} + +namespace model::theme +{ +uno::Reference<util::XTheme> createXTheme(std::shared_ptr<model::Theme> const& pTheme) +{ + return new UnoTheme(pTheme); +} + +} // end model::theme + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |