summaryrefslogtreecommitdiff
path: root/basegfx
diff options
context:
space:
mode:
authorArmin Le Grand (allotropia) <armin.le.grand.extern@allotropia.de>2023-05-16 15:59:42 +0200
committerArmin Le Grand <Armin.Le.Grand@me.com>2023-05-19 10:09:11 +0200
commit428b8a8d23e473fecf2916591615ff38611b93c9 (patch)
treeed883778d6094cb6d24a30a8fd73df16ae2a17cd /basegfx
parent286a1c03fa10acf60f076a0af987112d24cb2ff5 (diff)
MCGR: Adaptions to WriteGradientFill and BGradient
Added code to make WriteGradientFill directly use the available BGradient implementation. The goal is to never directly work on awt::Gradient2, but use BGradient & it's tooling methods. Added constructors and tooling to BGradient and BColorStops to make that easier (single line conversions between uno::Any, basesgfx classes and awt:: incarnations). Directly handle uno::Any and awt:: classes, changed stuff to make use of this. Change-Id: I083a323b9efee8ca4f3becb2966aac0a294b9a60 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151842 Tested-by: Jenkins Reviewed-by: Armin Le Grand <Armin.Le.Grand@me.com>
Diffstat (limited to 'basegfx')
-rw-r--r--basegfx/source/tools/bgradient.cxx42
-rw-r--r--basegfx/source/tools/gradienttools.cxx57
2 files changed, 31 insertions, 68 deletions
diff --git a/basegfx/source/tools/bgradient.cxx b/basegfx/source/tools/bgradient.cxx
index 134fda548ece..52aa721f36a6 100644
--- a/basegfx/source/tools/bgradient.cxx
+++ b/basegfx/source/tools/bgradient.cxx
@@ -94,10 +94,12 @@ BColorStops::BColorStops(const css::awt::ColorStopSequence& rColorStops)
BColorStops::BColorStops(const css::uno::Any& rVal)
{
- css::awt::Gradient2 aGradient2;
- if (rVal >>= aGradient2)
+ if (rVal.has<css::awt::ColorStopSequence>())
{
- setColorStopSequence(aGradient2.ColorStops);
+ // we can use awt::ColorStopSequence
+ css::awt::ColorStopSequence aColorStopSequence;
+ rVal >>= aColorStopSequence;
+ setColorStopSequence(aColorStopSequence);
}
}
@@ -627,7 +629,7 @@ BGradient::BGradient(const basegfx::BColorStops& rColorStops, css::awt::Gradient
SetColorStops(aColorStops);
}
-BGradient::BGradient(const css::awt::Gradient2& rGradient2)
+void BGradient::setGradient2(const css::awt::Gradient2& rGradient2)
{
// set values
SetGradientStyle(rGradient2.Style);
@@ -640,10 +642,24 @@ BGradient::BGradient(const css::awt::Gradient2& rGradient2)
SetSteps(rGradient2.StepCount);
// set ColorStops
- aColorStops = BColorStops(rGradient2.ColorStops);
- aColorStops.sortAndCorrect();
+ 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()
{
@@ -653,19 +669,7 @@ BGradient::BGradient(const css::uno::Any& rVal)
css::awt::Gradient2 aGradient2;
rVal >>= aGradient2;
- // set values
- SetGradientStyle(aGradient2.Style);
- SetAngle(Degree10(aGradient2.Angle));
- SetBorder(aGradient2.Border);
- SetXOffset(aGradient2.XOffset);
- SetYOffset(aGradient2.YOffset);
- SetStartIntens(aGradient2.StartIntensity);
- SetEndIntens(aGradient2.EndIntensity);
- SetSteps(aGradient2.StepCount);
-
- // set ColorStops
- aColorStops = BColorStops(aGradient2.ColorStops);
- aColorStops.sortAndCorrect();
+ setGradient2(aGradient2);
}
else if (rVal.has<css::awt::Gradient>())
{
diff --git a/basegfx/source/tools/gradienttools.cxx b/basegfx/source/tools/gradienttools.cxx
index c778a5237676..d7b1bb167613 100644
--- a/basegfx/source/tools/gradienttools.cxx
+++ b/basegfx/source/tools/gradienttools.cxx
@@ -265,47 +265,6 @@ namespace basegfx
namespace utils
{
- /// Tooling method to fill awt::Gradient2 from data contained in the given Any
- bool fillGradient2FromAny(css::awt::Gradient2& rGradient, const css::uno::Any& rVal)
- {
- bool bRetval(false);
-
- if (rVal.has< css::awt::Gradient2 >())
- {
- // we can use awt::Gradient2 directly
- bRetval = (rVal >>= rGradient);
- }
- else if (rVal.has< css::awt::Gradient >())
- {
- // 1st get awt::Gradient
- css::awt::Gradient aTmp;
-
- if (rVal >>= aTmp)
- {
- // copy all awt::Gradient data to awt::Gradient2
- rGradient.Style = aTmp.Style;
- rGradient.StartColor = aTmp.StartColor;
- rGradient.EndColor = aTmp.EndColor;
- rGradient.Angle = aTmp.Angle;
- rGradient.Border = aTmp.Border;
- rGradient.XOffset = aTmp.XOffset;
- rGradient.YOffset = aTmp.YOffset;
- rGradient.StartIntensity = aTmp.StartIntensity;
- rGradient.EndIntensity = aTmp.EndIntensity;
- rGradient.StepCount = aTmp.StepCount;
-
- // complete data by creating ColorStops for awt::Gradient2
- const BColorStops aTempColorStops {
- BColorStop(0.0, ColorToBColorConverter(aTmp.StartColor).getBColor()),
- BColorStop(1.0, ColorToBColorConverter(aTmp.EndColor).getBColor()) };
- rGradient.ColorStops = aTempColorStops.getAsColorStopSequence();
- bRetval = true;
- }
- }
-
- return bRetval;
- }
-
/* Tooling method to extract data from given awt::Gradient2
to ColorStops, doing some corrections, partially based
on given SingleColor.
@@ -321,11 +280,11 @@ namespace basegfx
directly
*/
void prepareColorStops(
- const com::sun::star::awt::Gradient2& rGradient,
+ const basegfx::BGradient& rGradient,
BColorStops& rColorStops,
BColor& rSingleColor)
{
- rColorStops = BColorStops(rGradient.ColorStops);
+ rColorStops = rGradient.GetColorStops();
if (rColorStops.isSingleColor(rSingleColor))
{
@@ -335,12 +294,12 @@ namespace basegfx
return;
}
- if (rGradient.StartIntensity != 100 || rGradient.EndIntensity != 100)
+ if (100 != rGradient.GetStartIntens() || 100 != rGradient.GetEndIntens())
{
// apply 'old' blend stuff, blend against black
rColorStops.blendToIntensity(
- rGradient.StartIntensity * 0.01,
- rGradient.EndIntensity * 0.01,
+ rGradient.GetStartIntens() * 0.01,
+ rGradient.GetEndIntens() * 0.01,
basegfx::BColor()); // COL_BLACK
// can lead to single color (e.g. both zero, so all black),
@@ -352,18 +311,18 @@ namespace basegfx
}
}
- if (rGradient.Border != 0)
+ if (0 != rGradient.GetBorder())
{
// apply Border if set
// NOTE: no new start node is added. The new ColorStop
// mechanism does not need entries at 0.0 and 1.0.
// In case this is needed, do that in the caller
- const double fFactor(rGradient.Border * 0.01);
+ const double fFactor(rGradient.GetBorder() * 0.01);
BColorStops aNewStops;
for (const auto& candidate : rColorStops)
{
- if (css::awt::GradientStyle_AXIAL == rGradient.Style)
+ if (css::awt::GradientStyle_AXIAL == rGradient.GetGradientStyle())
{
// for axial add the 'gap' at the start due to reverse used gradient
aNewStops.emplace_back((1.0 - fFactor) * candidate.getStopOffset(), candidate.getStopColor());