diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2023-08-09 13:27:49 +0200 |
---|---|---|
committer | Xisco Fauli <xiscofauli@libreoffice.org> | 2023-09-06 16:56:27 +0200 |
commit | eee4b3f8e46b85b3bb4f7cbe83b8af552594be89 (patch) | |
tree | acfe160d74d0a0622ea439d40b0e96d13c295a18 /basegfx | |
parent | 850015d1e59490546018f07742f798ecf97bc50d (diff) |
move BGradient to awt::Gradient2 UNO conversion into docmodel
This is needed because the module dependencies are an issues if
the conversion is done in basegfx. The bigger issue will come when
the ComplexColor conversion will be done as basegfx can't depend on
docmodel because of circular dependencies.
The BGradient is also more suitable for docmodel anyway as the
previously it was part of the model and is not a basic (gfx)
type - however this doesn't move the whole BGradient into docmodel
yet.
Change-Id: Id91ce52232f89f00e09b451c13da36e2854ae14b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155674
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
(cherry picked from commit 242bb3fdda5be165bd00701518df47cc1276438f)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/156449
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
Diffstat (limited to 'basegfx')
-rw-r--r-- | basegfx/source/tools/bgradient.cxx | 167 |
1 files changed, 0 insertions, 167 deletions
diff --git a/basegfx/source/tools/bgradient.cxx b/basegfx/source/tools/bgradient.cxx index cd6f5492a595..88b1094f2445 100644 --- a/basegfx/source/tools/bgradient.cxx +++ b/basegfx/source/tools/bgradient.cxx @@ -68,41 +68,6 @@ basegfx::BGradient lcl_buildGradientFromStringMap(StringMap& rMap) namespace basegfx { -void BColorStops::setColorStopSequence(const css::awt::ColorStopSequence& rColorStops) -{ - const sal_Int32 nLen(rColorStops.getLength()); - - if (0 != nLen) - { - // we have ColorStops - reserve(nLen); - const css::awt::ColorStop* pSourceColorStop(rColorStops.getConstArray()); - - for (sal_Int32 a(0); a < nLen; a++, pSourceColorStop++) - { - emplace_back(pSourceColorStop->StopOffset, - BColor(pSourceColorStop->StopColor.Red, pSourceColorStop->StopColor.Green, - pSourceColorStop->StopColor.Blue)); - } - } -} - -BColorStops::BColorStops(const css::awt::ColorStopSequence& rColorStops) -{ - setColorStopSequence(rColorStops); -} - -BColorStops::BColorStops(const css::uno::Any& rVal) -{ - if (rVal.has<css::awt::ColorStopSequence>()) - { - // we can use awt::ColorStopSequence - css::awt::ColorStopSequence aColorStopSequence; - rVal >>= aColorStopSequence; - setColorStopSequence(aColorStopSequence); - } -} - // constructor with two colors to explicitly create a // BColorStops for a single StartColor @0.0 & EndColor @1.0 BColorStops::BColorStops(const BColor& rStart, const BColor& rEnd) @@ -498,28 +463,6 @@ bool BColorStops::checkPenultimate() const return true; } -/* Tooling method to fill a awt::ColorStopSequence with - the data from the given ColorStops. This is used in - UNO API implementations. - */ -css::awt::ColorStopSequence BColorStops::getAsColorStopSequence() const -{ - css::awt::ColorStopSequence aRetval(size()); - // rColorStopSequence.realloc(rColorStops.size()); - css::awt::ColorStop* pTargetColorStop(aRetval.getArray()); - - for (const auto& candidate : *this) - { - pTargetColorStop->StopOffset = candidate.getStopOffset(); - pTargetColorStop->StopColor = css::rendering::RGBColor(candidate.getStopColor().getRed(), - candidate.getStopColor().getGreen(), - candidate.getStopColor().getBlue()); - pTargetColorStop++; - } - - return aRetval; -} - /* Tooling method to check if a ColorStop vector is defined by a single color. It returns true if this is the case. If true is returned, rSingleColor contains that single @@ -856,72 +799,6 @@ BGradient::BGradient(const basegfx::BColorStops& rColorStops, css::awt::Gradient SetColorStops(aColorStops); } -void BGradient::setGradient2(const css::awt::Gradient2& rGradient2) -{ - // set values - SetGradientStyle(rGradient2.Style); - SetAngle(Degree10(rGradient2.Angle)); - SetBorder(rGradient2.Border); - SetXOffset(rGradient2.XOffset); - SetYOffset(rGradient2.YOffset); - SetStartIntens(rGradient2.StartIntensity); - SetEndIntens(rGradient2.EndIntensity); - SetSteps(rGradient2.StepCount); - - // set ColorStops - if (rGradient2.ColorStops.hasElements()) - { - // if we have a awt::ColorStopSequence, use it - aColorStops = BColorStops(rGradient2.ColorStops); - aColorStops.sortAndCorrect(); - } - else - { - // if not, for compatibility, use StartColor/EndColor - aColorStops = BColorStops{ - BColorStop(0.0, ColorToBColorConverter(rGradient2.StartColor).getBColor()), - BColorStop(1.0, ColorToBColorConverter(rGradient2.EndColor).getBColor()) - }; - } -} - -BGradient::BGradient(const css::awt::Gradient2& rGradient2) { setGradient2(rGradient2); } - -BGradient::BGradient(const css::uno::Any& rVal) - : BGradient() -{ - if (rVal.has<css::awt::Gradient2>()) - { - // we can use awt::Gradient2 directly - css::awt::Gradient2 aGradient2; - rVal >>= aGradient2; - - setGradient2(aGradient2); - } - else if (rVal.has<css::awt::Gradient>()) - { - // use awt::Gradient - css::awt::Gradient aGradient; - rVal >>= aGradient; - - // set values - SetGradientStyle(aGradient.Style); - SetAngle(Degree10(aGradient.Angle)); - SetBorder(aGradient.Border); - SetXOffset(aGradient.XOffset); - SetYOffset(aGradient.YOffset); - SetStartIntens(aGradient.StartIntensity); - SetEndIntens(aGradient.EndIntensity); - SetSteps(aGradient.StepCount); - - // complete data by creating ColorStops from fixed Start/EndColor - aColorStops = BColorStops{ - BColorStop(0.0, ColorToBColorConverter(aGradient.StartColor).getBColor()), - BColorStop(1.0, ColorToBColorConverter(aGradient.EndColor).getBColor()) - }; - } -} - bool BGradient::operator==(const BGradient& rGradient) const { return (eStyle == rGradient.eStyle && aColorStops == rGradient.aColorStops @@ -969,50 +846,6 @@ boost::property_tree::ptree BGradient::dumpAsJSON() const return aTree; } -css::awt::Gradient2 BGradient::getAsGradient2() const -{ - css::awt::Gradient2 aRetval; - - // standard values - aRetval.Style = GetGradientStyle(); - aRetval.Angle = static_cast<short>(GetAngle()); - aRetval.Border = GetBorder(); - aRetval.XOffset = GetXOffset(); - aRetval.YOffset = GetYOffset(); - aRetval.StartIntensity = GetStartIntens(); - aRetval.EndIntensity = GetEndIntens(); - aRetval.StepCount = 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. - aRetval.StartColor - = static_cast<sal_Int32>(ColorToBColorConverter(aColorStops.front().getStopColor())); - aRetval.EndColor - = static_cast<sal_Int32>(ColorToBColorConverter(aColorStops.back().getStopColor())); - - // fill ColorStops to extended Gradient2 - aRetval.ColorStops = aColorStops.getAsColorStopSequence(); - - return aRetval; -} - void BGradient::tryToRecreateBorder(basegfx::BColorStops* pAssociatedTransparencyStops) { // border already set, do not try to recreate |