summaryrefslogtreecommitdiff
path: root/svx/source
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 /svx/source
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 'svx/source')
-rw-r--r--svx/source/unodraw/XPropertyTable.cxx23
-rw-r--r--svx/source/xoutdev/xattr.cxx62
2 files changed, 20 insertions, 65 deletions
diff --git a/svx/source/unodraw/XPropertyTable.cxx b/svx/source/unodraw/XPropertyTable.cxx
index d88a37c4462d..4d47a1290281 100644
--- a/svx/source/unodraw/XPropertyTable.cxx
+++ b/svx/source/unodraw/XPropertyTable.cxx
@@ -559,29 +559,10 @@ uno::Any SvxUnoXGradientTable::getAny( const XPropertyEntry* pEntry ) const noex
std::unique_ptr<XPropertyEntry> SvxUnoXGradientTable::createEntry(const OUString& rName, const uno::Any& rAny) const
{
- awt::Gradient aGradient;
- if(!(rAny >>= aGradient))
+ if (!rAny.has<css::awt::Gradient>() || !rAny.has<css::awt::Gradient2>())
return std::unique_ptr<XPropertyEntry>();
- basegfx::BGradient aBGradient(
- basegfx::BColorStops(
- Color(ColorTransparency, aGradient.StartColor).getBColor(),
- Color(ColorTransparency, aGradient.EndColor).getBColor()));
-
- 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 );
-
- // check if we have a awt::Gradient2 with a ColorStopSequence
- const basegfx::BColorStops aColorStops(rAny);
- if (!aColorStops.empty())
- aBGradient.SetColorStops(aColorStops);
-
+ const basegfx::BGradient aBGradient(rAny);
return std::make_unique<XGradientEntry>(aBGradient, rName);
}
diff --git a/svx/source/xoutdev/xattr.cxx b/svx/source/xoutdev/xattr.cxx
index 8c4c7af9eb11..9a3567430278 100644
--- a/svx/source/xoutdev/xattr.cxx
+++ b/svx/source/xoutdev/xattr.cxx
@@ -2152,37 +2152,6 @@ bool XFillGradientItem::GetPresentation
return true;
}
-namespace
-{
- void fillXGradientFromAny(basegfx::BGradient& rBGradient, const css::uno::Any& rVal)
- {
- css::awt::Gradient aGradient;
- if (!(rVal >>= aGradient))
- return;
-
- // for compatibility, read and set StartColor/EndColor
- rBGradient.SetColorStops(
- basegfx::BColorStops(
- Color(ColorTransparency, aGradient.StartColor).getBColor(),
- Color(ColorTransparency, aGradient.EndColor).getBColor()));
-
- // set values
- rBGradient.SetGradientStyle( aGradient.Style );
- rBGradient.SetAngle( Degree10(aGradient.Angle) );
- rBGradient.SetBorder( aGradient.Border );
- rBGradient.SetXOffset( aGradient.XOffset );
- rBGradient.SetYOffset( aGradient.YOffset );
- rBGradient.SetStartIntens( aGradient.StartIntensity );
- rBGradient.SetEndIntens( aGradient.EndIntensity );
- rBGradient.SetSteps( aGradient.StepCount );
-
- // check if we have a awt::Gradient2 with a ColorStopSequence
- const basegfx::BColorStops aColorStops(rVal);
- if (!aColorStops.empty())
- rBGradient.SetColorStops(aColorStops);
- }
-}
-
bool XFillGradientItem::QueryValue( css::uno::Any& rVal, sal_uInt8 nMemberId ) const
{
nMemberId &= ~CONVERT_TWIPS;
@@ -2271,10 +2240,9 @@ bool XFillGradientItem::PutValue( const css::uno::Any& rVal, sal_uInt8 nMemberId
SetName( aName );
- if ( aGradientAny.hasValue() )
+ if (aGradientAny.hasValue() && (aGradientAny.has<css::awt::Gradient>() || aGradientAny.has<css::awt::Gradient2>()))
{
- basegfx::BGradient aBGradient;
- fillXGradientFromAny(aBGradient, aGradientAny);
+ const basegfx::BGradient aBGradient(aGradientAny);
SetGradientValue(aBGradient);
}
@@ -2295,22 +2263,28 @@ bool XFillGradientItem::PutValue( const css::uno::Any& rVal, sal_uInt8 nMemberId
case MID_FILLGRADIENT:
{
- basegfx::BGradient aBGradient;
- fillXGradientFromAny(aBGradient, rVal);
- SetGradientValue(aBGradient);
+ if (rVal.hasValue() && (rVal.has<css::awt::Gradient>() || rVal.has<css::awt::Gradient2>()))
+ {
+ const basegfx::BGradient aBGradient(rVal);
+ SetGradientValue(aBGradient);
+ }
+
break;
}
case MID_GRADIENT_COLORSTOPSEQUENCE:
{
- // check if we have a awt::Gradient2 with a ColorStopSequence
- const basegfx::BColorStops aColorStops(rVal);
-
- if (!aColorStops.empty())
+ // check if we have a awt::ColorStopSequence
+ if (rVal.hasValue() && rVal.has<css::awt::ColorStopSequence>())
{
- basegfx::BGradient aBGradient(GetGradientValue());
- aBGradient.SetColorStops(aColorStops);
- SetGradientValue(aBGradient);
+ const basegfx::BColorStops aColorStops(rVal);
+
+ if (!aColorStops.empty())
+ {
+ basegfx::BGradient aBGradient(GetGradientValue());
+ aBGradient.SetColorStops(aColorStops);
+ SetGradientValue(aBGradient);
+ }
}
break;
}