summaryrefslogtreecommitdiff
path: root/svx
diff options
context:
space:
mode:
authorArmin Le Grand (allotropia) <armin.le.grand.extern@allotropia.de>2023-03-13 19:39:34 +0100
committerArmin Le Grand <Armin.Le.Grand@me.com>2023-03-19 17:38:38 +0000
commit01d0019c851b9e942f9a3b94d6dd554fb1adb40c (patch)
tree201cb6d13f57f8fa06128785c1ddb330eeacc349 /svx
parentfd299d209d82495eb6528fb444e0b68f41c8ae0d (diff)
MCGR: Model data changes for ColorSteps
Added tooling replaceStart/EndColor to allow simple transition for code that does not immediately adapt to multi color gradients. Also added createColorStepsFromStartEndColor for the same purpose. Adapted XGradient to no longer have Start/EndColor at all, but only use ColorSteps. Adapted all usages of XGradient to no longer use Get/Set/Start/EndColor, but access the ColorSteps instead. Replaced quite some XGradient constructors that used XGradient() as Start/EndColor since this is already the default. Adapted ColorBlending to black AKA Start/EndIntens in XGradient to work now on all ColorSteps in the required linearly-scaled manner. UNO API changes: Added com::sun::star::awt::ColorStep as basic data element that holds a pair of Offset and Color. Added com::sun::star::awt::ColorStepSequence to handle an array of sorted entries. Added com::sun::star::awt::Gradient2 derived from com::sun::star::awt::Gradient, extended by the needed com::sun::star::awt::ColorStepSequence. Added MID_GRADIENT_COLORSTEPSEQUENCE to UNO API to provide access to ColorSteps directly. Adapted XFillGradientItem::QueryValue/PutValue to make use of new UNO API data structures. To do so, added tooling methods for data transition: - fillColorStepSequenceFromColorSteps - fillGradient2FromXGradient - fillColorStepsFromAny - fillXGradientFromAny and adapted - case '0' (all data) - MID_FILLGRADIENT - MID_GRADIENT_COLORSTEPSEQUENCE - MID_GRADIENT_START/ENDCOLOR to make use of these. Tested usage of these in the office. Renamed from GradientStep to GradientStop after discussions with members on the list to make this closer related to other norms/definitions. Also renamed classes and class members to better reflect to GradientStop, so grepping/finding will be easier (e.g. 'Color' just exists pretty often, but 'StopColor' is more precise). Changed the used UNO API class for reprsenting the Color to better reflect to ranges [0.0 .. 1.0] and usage of RGB. Change-Id: I1eeb3e97e81d6785967615d1ff256551fc3b882d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148849 Tested-by: Jenkins Reviewed-by: Armin Le Grand <Armin.Le.Grand@me.com>
Diffstat (limited to 'svx')
-rw-r--r--svx/source/customshapes/EnhancedCustomShape2d.cxx21
-rw-r--r--svx/source/sdr/attribute/sdrallfillattributeshelper.cxx8
-rw-r--r--svx/source/sdr/primitive2d/sdrattributecreator.cxx113
-rw-r--r--svx/source/sidebar/area/AreaPropertyPanelBase.cxx21
-rw-r--r--svx/source/sidebar/area/AreaTransparencyGradientPopup.cxx17
-rw-r--r--svx/source/svdraw/gradtrns.cxx16
-rw-r--r--svx/source/svdraw/svdetc.cxx4
-rw-r--r--svx/source/svdraw/svdfmtf.cxx17
-rw-r--r--svx/source/svdraw/svdoashp.cxx10
-rw-r--r--svx/source/unodraw/XPropertyTable.cxx11
-rw-r--r--svx/source/unodraw/unobrushitemhelper.cxx8
-rw-r--r--svx/source/xoutdev/xattr.cxx227
-rw-r--r--svx/source/xoutdev/xpool.cxx14
-rw-r--r--svx/source/xoutdev/xtabgrdt.cxx25
14 files changed, 288 insertions, 224 deletions
diff --git a/svx/source/customshapes/EnhancedCustomShape2d.cxx b/svx/source/customshapes/EnhancedCustomShape2d.cxx
index d93dbee142a3..e6b0173c5bc2 100644
--- a/svx/source/customshapes/EnhancedCustomShape2d.cxx
+++ b/svx/source/customshapes/EnhancedCustomShape2d.cxx
@@ -2804,16 +2804,17 @@ void EnhancedCustomShape2d::AdaptObjColor(
if ( nColorCount || 0.0 != dBrightness )
{
- aXGradient.SetStartColor(
- GetColorData(
- aXGradient.GetStartColor(),
- std::min(nColorIndex, nColorCount-1),
- dBrightness ));
- aXGradient.SetEndColor(
- GetColorData(
- aXGradient.GetEndColor(),
- std::min(nColorIndex, nColorCount-1),
- dBrightness ));
+ basegfx::ColorStops aColorStops(aXGradient.GetColorStops());
+ for (auto& candidate : aColorStops)
+ {
+ candidate = basegfx::ColorStop(
+ candidate.getStopOffset(),
+ GetColorData(
+ Color(candidate.getStopColor()),
+ std::min(nColorIndex, nColorCount-1),
+ dBrightness ).getBColor());
+ }
+ aXGradient.SetColorStops(aColorStops);
}
rObj.SetMergedItem( XFillGradientItem( "", aXGradient ) );
diff --git a/svx/source/sdr/attribute/sdrallfillattributeshelper.cxx b/svx/source/sdr/attribute/sdrallfillattributeshelper.cxx
index 720adcf26a78..6a96870a4b79 100644
--- a/svx/source/sdr/attribute/sdrallfillattributeshelper.cxx
+++ b/svx/source/sdr/attribute/sdrallfillattributeshelper.cxx
@@ -152,8 +152,8 @@ namespace drawinglayer::attribute
if(!rFillTransparenceGradientAttribute.isDefault())
{
- const double fTransA(rFillTransparenceGradientAttribute.getColorSteps().front().getColor().luminance());
- const double fTransB(rFillTransparenceGradientAttribute.getColorSteps().back().getColor().luminance());
+ const double fTransA(rFillTransparenceGradientAttribute.getColorStops().front().getStopColor().luminance());
+ const double fTransB(rFillTransparenceGradientAttribute.getColorStops().back().getStopColor().luminance());
fTransparence = (fTransA + fTransB) * 0.5;
}
@@ -161,8 +161,8 @@ namespace drawinglayer::attribute
if(!rFillGradientAttribute.isDefault())
{
// gradient fill
- const basegfx::BColor aStart(rFillGradientAttribute.getColorSteps().front().getColor());
- const basegfx::BColor aEnd(rFillGradientAttribute.getColorSteps().back().getColor());
+ const basegfx::BColor aStart(rFillGradientAttribute.getColorStops().front().getStopColor());
+ const basegfx::BColor aEnd(rFillGradientAttribute.getColorStops().back().getStopColor());
aRetval = basegfx::interpolate(aStart, aEnd, 0.5);
}
diff --git a/svx/source/sdr/primitive2d/sdrattributecreator.cxx b/svx/source/sdr/primitive2d/sdrattributecreator.cxx
index 0e0369b08a43..7409c4017202 100644
--- a/svx/source/sdr/primitive2d/sdrattributecreator.cxx
+++ b/svx/source/sdr/primitive2d/sdrattributecreator.cxx
@@ -444,8 +444,8 @@ namespace drawinglayer::primitive2d
&& pGradientItem->IsEnabled())
{
const XGradient& rGradient = pGradientItem->GetGradientValue();
- const sal_uInt8 nStartLuminance(rGradient.GetStartColor().GetLuminance());
- const sal_uInt8 nEndLuminance(rGradient.GetEndColor().GetLuminance());
+ const sal_uInt8 nStartLuminance(Color(rGradient.GetColorStops().front().getStopColor()).GetLuminance());
+ const sal_uInt8 nEndLuminance(Color(rGradient.GetColorStops().back().getStopColor()).GetLuminance());
const bool bCompletelyTransparent(0xff == nStartLuminance && 0xff == nEndLuminance);
if(bCompletelyTransparent)
@@ -472,62 +472,36 @@ namespace drawinglayer::primitive2d
case drawing::FillStyle_GRADIENT :
{
XGradient aXGradient(rSet.Get(XATTR_FILLGRADIENT).GetGradientValue());
-
- const Color aStartColor(aXGradient.GetStartColor());
- const sal_uInt16 nStartIntens(aXGradient.GetStartIntens());
- basegfx::BColor aStart(aStartColor.getBColor());
-
- if(nStartIntens != 100)
- {
- const basegfx::BColor aBlack;
- aStart = interpolate(aBlack, aStart, static_cast<double>(nStartIntens) * 0.01);
- }
-
- const Color aEndColor(aXGradient.GetEndColor());
- const sal_uInt16 nEndIntens(aXGradient.GetEndIntens());
- basegfx::BColor aEnd(aEndColor.getBColor());
-
- if(nEndIntens != 100)
- {
- const basegfx::BColor aBlack;
- aEnd = interpolate(aBlack, aEnd, static_cast<double>(nEndIntens) * 0.01);
- }
-
- // prepare ColorSteps
- // currently always two (Start/EndColor) to stay compatible
- // for now, but that will change. It already gets manipulated
- // by the test cases below
- basegfx::ColorSteps aColorSteps {
- basegfx::ColorStep(0.0, aStart),
- basegfx::ColorStep(1.0, aEnd) };
+ basegfx::ColorStops aColorStops(aXGradient.GetColorStops());
// test code here, can/will be removed later
static sal_uInt32 nUseGradientSteps(0);
+
switch(nUseGradientSteps)
{
case 1:
{
// just test a nice valid gradient
- aColorSteps.clear();
- aColorSteps.emplace_back(0.0, basegfx::BColor(1.0, 0.0, 0.0)); // red
- aColorSteps.emplace_back(0.25, basegfx::BColor(0.0, 1.0, 0.0)); // green@25%
- aColorSteps.emplace_back(0.50, basegfx::BColor(1.0, 1.0, 0.0)); // yellow@50%
- aColorSteps.emplace_back(0.75, basegfx::BColor(1.0, 0.0, 1.0)); // pink@75%
- aColorSteps.emplace_back(1.0, basegfx::BColor(0.0, 0.0, 1.0)); // blue
+ aColorStops.clear();
+ aColorStops.emplace_back(0.0, basegfx::BColor(1.0, 0.0, 0.0)); // red
+ aColorStops.emplace_back(0.25, basegfx::BColor(0.0, 1.0, 0.0)); // green@25%
+ aColorStops.emplace_back(0.50, basegfx::BColor(1.0, 1.0, 0.0)); // yellow@50%
+ aColorStops.emplace_back(0.75, basegfx::BColor(1.0, 0.0, 1.0)); // pink@75%
+ aColorStops.emplace_back(1.0, basegfx::BColor(0.0, 0.0, 1.0)); // blue
break;
}
case 2:
{
// single added in-between, no change of start/end
- aColorSteps.emplace_back(0.5, basegfx::BColor(1.0, 1.0, 0.0)); // yellow@50%
+ aColorStops.emplace_back(0.5, basegfx::BColor(1.0, 1.0, 0.0)); // yellow@50%
break;
}
case 3:
{
// check additional StartColor, the one given directly has to win
- aColorSteps.emplace_back(0.0, basegfx::BColor(1.0, 1.0, 0.0)); // yellow@50%
+ aColorStops.emplace_back(0.0, basegfx::BColor(1.0, 1.0, 0.0)); // yellow@50%
break;
}
@@ -535,63 +509,63 @@ namespace drawinglayer::primitive2d
{
// check additional EndColor, the one given directly has to win
// due this one being added *after* the original one
- aColorSteps.emplace_back(1.0, basegfx::BColor(1.0, 1.0, 0.0)); // yellow@50%
+ aColorStops.emplace_back(1.0, basegfx::BColor(1.0, 1.0, 0.0)); // yellow@50%
break;
}
case 5:
{
// check invalid color (too low index), has to be ignored
- aColorSteps.emplace_back(-1.0, basegfx::BColor(1.0, 1.0, 0.0)); // yellow@50%
+ aColorStops.emplace_back(-1.0, basegfx::BColor(1.0, 1.0, 0.0)); // yellow@50%
break;
}
case 6:
{
// check invalid color (too high index), has to be ignored
- aColorSteps.emplace_back(2.0, basegfx::BColor(1.0, 1.0, 0.0)); // yellow@50%
+ aColorStops.emplace_back(2.0, basegfx::BColor(1.0, 1.0, 0.0)); // yellow@50%
break;
}
case 7:
{
// check in-between single-color section
- aColorSteps.emplace_back(0.3, basegfx::BColor(1.0, 1.0, 0.0)); // yellow@50%
- aColorSteps.emplace_back(0.7, basegfx::BColor(1.0, 1.0, 0.0)); // yellow@50%
+ aColorStops.emplace_back(0.3, basegfx::BColor(1.0, 1.0, 0.0)); // yellow@50%
+ aColorStops.emplace_back(0.7, basegfx::BColor(1.0, 1.0, 0.0)); // yellow@50%
break;
}
case 8:
{
// check in-between single-color sections
- aColorSteps.emplace_back(0.2, basegfx::BColor(1.0, 1.0, 0.0)); // yellow@50%
- aColorSteps.emplace_back(0.4, basegfx::BColor(1.0, 1.0, 0.0)); // yellow@50%
- aColorSteps.emplace_back(0.5, aStart);
- aColorSteps.emplace_back(0.6, basegfx::BColor(1.0, 1.0, 0.0)); // yellow@50%
- aColorSteps.emplace_back(0.8, basegfx::BColor(1.0, 1.0, 0.0)); // yellow@50%
+ aColorStops.emplace_back(0.2, basegfx::BColor(1.0, 1.0, 0.0)); // yellow@50%
+ aColorStops.emplace_back(0.4, basegfx::BColor(1.0, 1.0, 0.0)); // yellow@50%
+ aColorStops.emplace_back(0.5, aXGradient.GetColorStops().front().getStopColor());
+ aColorStops.emplace_back(0.6, basegfx::BColor(1.0, 1.0, 0.0)); // yellow@50%
+ aColorStops.emplace_back(0.8, basegfx::BColor(1.0, 1.0, 0.0)); // yellow@50%
break;
}
case 9:
{
// check single-color start area
- aColorSteps.emplace_back(0.6, aStart);
+ aColorStops.emplace_back(0.6, aXGradient.GetColorStops().front().getStopColor());
break;
}
case 10:
{
// check single-color end area
- aColorSteps.emplace_back(0.4, aEnd);
+ aColorStops.emplace_back(0.4, aXGradient.GetColorStops().back().getStopColor());
break;
}
case 11:
{
// check case without direct Start/EndColor
- aColorSteps.clear();
- aColorSteps.emplace_back(0.4, aEnd);
- aColorSteps.emplace_back(0.6, aStart);
+ aColorStops.clear();
+ aColorStops.emplace_back(0.4, aXGradient.GetColorStops().back().getStopColor());
+ aColorStops.emplace_back(0.6, aXGradient.GetColorStops().front().getStopColor());
break;
}
@@ -601,13 +575,32 @@ namespace drawinglayer::primitive2d
}
}
+ if(aXGradient.GetStartIntens() != 100 || aXGradient.GetEndIntens() != 100)
+ {
+ // Need to do the (old, crazy) blend against black for a
+ // used intensity, but now for all ColorStops relative to their
+ // offsets, where 0 means black and 100 means original color
+ const double fStartIntensity(aXGradient.GetStartIntens() * 0.01);
+ const double fEndIntensity(aXGradient.GetEndIntens() * 0.01);
+ const basegfx::BColor aBlack;
+
+ for (auto& candidate : aColorStops)
+ {
+ const double fOffset(candidate.getStopOffset());
+ const double fIntensity((fStartIntensity * (1.0 - fOffset)) + (fEndIntensity * fOffset));
+ candidate = basegfx::ColorStop(
+ fOffset,
+ basegfx::interpolate(aBlack, candidate.getStopColor(), fIntensity));
+ }
+ }
+
aGradient = attribute::FillGradientAttribute(
XGradientStyleToGradientStyle(aXGradient.GetGradientStyle()),
static_cast<double>(aXGradient.GetBorder()) * 0.01,
static_cast<double>(aXGradient.GetXOffset()) * 0.01,
static_cast<double>(aXGradient.GetYOffset()) * 0.01,
toRadians(aXGradient.GetAngle()),
- aColorSteps,
+ aColorStops,
rSet.Get(XATTR_GRADIENTSTEPCOUNT).GetValue());
break;
@@ -747,8 +740,8 @@ namespace drawinglayer::primitive2d
{
// test if float transparence is completely transparent
const XGradient& rGradient = pGradientItem->GetGradientValue();
- const sal_uInt8 nStartLuminance(rGradient.GetStartColor().GetLuminance());
- const sal_uInt8 nEndLuminance(rGradient.GetEndColor().GetLuminance());
+ const sal_uInt8 nStartLuminance(Color(rGradient.GetColorStops().front().getStopColor()).GetLuminance());
+ const sal_uInt8 nEndLuminance(Color(rGradient.GetColorStops().back().getStopColor()).GetLuminance());
const bool bCompletelyTransparent(0xff == nStartLuminance && 0xff == nEndLuminance);
const bool bNotTransparent(0x00 == nStartLuminance && 0x00 == nEndLuminance);
@@ -761,17 +754,15 @@ namespace drawinglayer::primitive2d
const double fStartLum(nStartLuminance / 255.0);
const double fEndLum(nEndLuminance / 255.0);
- const basegfx::ColorSteps aColorSteps {
- basegfx::ColorStep(0.0, basegfx::BColor(fStartLum, fStartLum, fStartLum)),
- basegfx::ColorStep(1.0, basegfx::BColor(fEndLum, fEndLum, fEndLum)) };
-
return attribute::FillGradientAttribute(
XGradientStyleToGradientStyle(rGradient.GetGradientStyle()),
static_cast<double>(rGradient.GetBorder()) * 0.01,
static_cast<double>(rGradient.GetXOffset()) * 0.01,
static_cast<double>(rGradient.GetYOffset()) * 0.01,
toRadians(rGradient.GetAngle()),
- aColorSteps);
+ basegfx::utils::createColorStopsFromStartEndColor(
+ basegfx::BColor(fStartLum, fStartLum, fStartLum),
+ basegfx::BColor(fEndLum, fEndLum, fEndLum)));
}
}
diff --git a/svx/source/sidebar/area/AreaPropertyPanelBase.cxx b/svx/source/sidebar/area/AreaPropertyPanelBase.cxx
index e54002ef9589..33c5382d805b 100644
--- a/svx/source/sidebar/area/AreaPropertyPanelBase.cxx
+++ b/svx/source/sidebar/area/AreaPropertyPanelBase.cxx
@@ -127,8 +127,10 @@ void AreaPropertyPanelBase::Initialize()
maGradientLinear.SetXOffset(DEFAULT_CENTERX);
maGradientLinear.SetYOffset(DEFAULT_CENTERY);
maGradientLinear.SetAngle(Degree10(DEFAULT_ANGLE));
- maGradientLinear.SetStartColor(Color(DEFAULT_STARTVALUE));
- maGradientLinear.SetEndColor(Color(DEFAULT_ENDVALUE));
+ maGradientLinear.SetColorStops(
+ basegfx::utils::createColorStopsFromStartEndColor(
+ Color(DEFAULT_STARTVALUE).getBColor(),
+ Color(DEFAULT_ENDVALUE).getBColor()));
maGradientLinear.SetBorder(DEFAULT_BORDER);
maGradientLinear.SetGradientStyle(css::awt::GradientStyle_LINEAR);
@@ -295,11 +297,12 @@ void AreaPropertyPanelBase::SelectFillAttrHdl_Impl()
if (pSh && pSh->GetItem(SID_COLOR_TABLE))
{
- XGradient aGradient;
+ XGradient aGradient(
+ basegfx::utils::createColorStopsFromStartEndColor(
+ mxLbFillGradFrom->GetSelectEntryColor().getBColor(),
+ mxLbFillGradTo->GetSelectEntryColor().getBColor()));
aGradient.SetAngle(Degree10(mxMTRAngle->get_value(FieldUnit::DEGREE) * 10));
aGradient.SetGradientStyle(static_cast<css::awt::GradientStyle>(mxGradientStyle->get_active()));
- aGradient.SetStartColor(mxLbFillGradFrom->GetSelectEntryColor());
- aGradient.SetEndColor(mxLbFillGradTo->GetSelectEntryColor());
const XFillGradientItem aXFillGradientItem(mxLbFillAttr->get_active_text(), aGradient);
@@ -485,8 +488,8 @@ void AreaPropertyPanelBase::FillStyleChanged(bool bUpdateModel)
// #i122676# change FillStyle and Gradient in one call
XFillStyleItem aXFillStyleItem(drawing::FillStyle_GRADIENT);
setFillStyleAndGradient(&aXFillStyleItem, aXFillGradientItem);
- mxLbFillGradFrom->SelectEntry(aGradient.GetStartColor());
- mxLbFillGradTo->SelectEntry(aGradient.GetEndColor());
+ mxLbFillGradFrom->SelectEntry(Color(aGradient.GetColorStops().front().getStopColor()));
+ mxLbFillGradTo->SelectEntry(Color(aGradient.GetColorStops().back().getStopColor()));
mxMTRAngle->set_value(toDegrees(aGradient.GetAngle()), FieldUnit::DEGREE);
css::awt::GradientStyle eXGS = aGradient.GetGradientStyle();
@@ -506,8 +509,8 @@ void AreaPropertyPanelBase::FillStyleChanged(bool bUpdateModel)
const OUString aString(mpFillGradientItem->GetName());
mxLbFillAttr->set_active_text(aString);
const XGradient aGradient = mpFillGradientItem->GetGradientValue();
- mxLbFillGradFrom->SelectEntry(aGradient.GetStartColor());
- mxLbFillGradTo->SelectEntry(aGradient.GetEndColor());
+ mxLbFillGradFrom->SelectEntry(Color(aGradient.GetColorStops().front().getStopColor()));
+ mxLbFillGradTo->SelectEntry(Color(aGradient.GetColorStops().back().getStopColor()));
mxGradientStyle->set_active(
sal::static_int_cast<sal_Int32>(aGradient.GetGradientStyle()));
if (mxGradientStyle->get_active() == sal_Int32(GradientStyle::Radial))
diff --git a/svx/source/sidebar/area/AreaTransparencyGradientPopup.cxx b/svx/source/sidebar/area/AreaTransparencyGradientPopup.cxx
index 2d92b6b4b3b8..4cbfa7b3581e 100644
--- a/svx/source/sidebar/area/AreaTransparencyGradientPopup.cxx
+++ b/svx/source/sidebar/area/AreaTransparencyGradientPopup.cxx
@@ -59,13 +59,15 @@ void AreaTransparencyGradientPopup::InitStatus(XFillFloatTransparenceItem const
const XGradient& rGradient = pGradientItem->GetGradientValue();
XGradient aGradient;
+ Color aStart(rGradient.GetColorStops().front().getStopColor());
+ Color aEnd(rGradient.GetColorStops().back().getStopColor());
if (rGradient.GetXOffset() == AreaPropertyPanelBase::DEFAULT_CENTERX
&& rGradient.GetYOffset() == AreaPropertyPanelBase::DEFAULT_CENTERY
&& static_cast<sal_Int32>(toDegrees(rGradient.GetAngle())) == AreaPropertyPanelBase::DEFAULT_ANGLE
- && static_cast<sal_uInt16>(((static_cast<sal_uInt16>(rGradient.GetStartColor().GetRed()) + 1) * 100) / 255)
+ && static_cast<sal_uInt16>(((static_cast<sal_uInt16>(aStart.GetRed()) + 1) * 100) / 255)
== AreaPropertyPanelBase::DEFAULT_STARTVALUE
- && static_cast<sal_uInt16>(((static_cast<sal_uInt16>(rGradient.GetEndColor().GetRed()) + 1) * 100) / 255)
+ && static_cast<sal_uInt16>(((static_cast<sal_uInt16>(aEnd.GetRed()) + 1) * 100) / 255)
== AreaPropertyPanelBase::DEFAULT_ENDVALUE
&& rGradient.GetBorder() == AreaPropertyPanelBase::DEFAULT_BORDER)
{
@@ -78,8 +80,10 @@ void AreaTransparencyGradientPopup::InitStatus(XFillFloatTransparenceItem const
mxMtrTrgrCenterX->set_value(aGradient.GetXOffset(), FieldUnit::PERCENT);
mxMtrTrgrCenterY->set_value(aGradient.GetYOffset(), FieldUnit::PERCENT);
mxMtrTrgrAngle->set_value(toDegrees(aGradient.GetAngle()), FieldUnit::DEGREE);
- mxMtrTrgrStartValue->set_value(static_cast<sal_uInt16>(((static_cast<sal_uInt16>(aGradient.GetStartColor().GetRed()) + 1) * 100) / 255), FieldUnit::PERCENT);
- mxMtrTrgrEndValue->set_value(static_cast<sal_uInt16>(((static_cast<sal_uInt16>(aGradient.GetEndColor().GetRed()) + 1) * 100) / 255), FieldUnit::PERCENT);
+ aStart = Color(aGradient.GetColorStops().front().getStopColor());
+ aEnd = Color(aGradient.GetColorStops().back().getStopColor());
+ mxMtrTrgrStartValue->set_value(static_cast<sal_uInt16>(((static_cast<sal_uInt16>(aStart.GetRed()) + 1) * 100) / 255), FieldUnit::PERCENT);
+ mxMtrTrgrEndValue->set_value(static_cast<sal_uInt16>(((static_cast<sal_uInt16>(aEnd.GetRed()) + 1) * 100) / 255), FieldUnit::PERCENT);
mxMtrTrgrBorder->set_value(aGradient.GetBorder(), FieldUnit::PERCENT);
}
@@ -122,8 +126,9 @@ void AreaTransparencyGradientPopup::ExecuteValueModify(sal_uInt8 nStartCol, sal_
mxMtrTrgrAngle->set_value(nVal, FieldUnit::DEGREE);
//End of new code
XGradient aTmpGradient(
- Color(nStartCol, nStartCol, nStartCol),
- Color(nEndCol, nEndCol, nEndCol),
+ basegfx::utils::createColorStopsFromStartEndColor(
+ Color(nStartCol, nStartCol, nStartCol).getBColor(),
+ Color(nEndCol, nEndCol, nEndCol).getBColor()),
static_cast<css::awt::GradientStyle>(mrAreaPropertyPanel.GetSelectedTransparencyTypeIndex()-2),
Degree10(static_cast<sal_Int16>(mxMtrTrgrAngle->get_value(FieldUnit::DEGREE)) * 10),
static_cast<sal_uInt16>(mxMtrTrgrCenterX->get_value(FieldUnit::PERCENT)),
diff --git a/svx/source/svdraw/gradtrns.cxx b/svx/source/svdraw/gradtrns.cxx
index d665cd48ce16..c559e580cf67 100644
--- a/svx/source/svdraw/gradtrns.cxx
+++ b/svx/source/svdraw/gradtrns.cxx
@@ -30,7 +30,7 @@
void GradTransformer::GradToVec(GradTransGradient const & rG, GradTransVector& rV, const SdrObject* pObj)
{
// handle start color
- rV.aCol1 = rG.aGradient.GetStartColor();
+ rV.aCol1 = Color(rG.aGradient.GetColorStops().front().getStopColor());
if(100 != rG.aGradient.GetStartIntens())
{
const double fFact(static_cast<double>(rG.aGradient.GetStartIntens()) / 100.0);
@@ -38,7 +38,7 @@ void GradTransformer::GradToVec(GradTransGradient const & rG, GradTransVector& r
}
// handle end color
- rV.aCol2 = rG.aGradient.GetEndColor();
+ rV.aCol2 = Color(rG.aGradient.GetColorStops().back().getStopColor());
if(100 != rG.aGradient.GetEndIntens())
{
const double fFact(static_cast<double>(rG.aGradient.GetEndIntens()) / 100.0);
@@ -186,14 +186,18 @@ void GradTransformer::VecToGrad(GradTransVector const & rV, GradTransGradient& r
rG = rGOld;
// handle color changes
- if(rV.aCol1 != rGOld.aGradient.GetStartColor())
+ if(rV.aCol1 != Color(rGOld.aGradient.GetColorStops().front().getStopColor()))
{
- rG.aGradient.SetStartColor(rV.aCol1);
+ basegfx::ColorStops aNewColorStops(rG.aGradient.GetColorStops());
+ basegfx::utils::replaceStartColor(aNewColorStops, rV.aCol1.getBColor());
+ rG.aGradient.SetColorStops(aNewColorStops);
rG.aGradient.SetStartIntens(100);
}
- if(rV.aCol2 != rGOld.aGradient.GetEndColor())
+ if(rV.aCol2 != Color(rGOld.aGradient.GetColorStops().back().getStopColor()))
{
- rG.aGradient.SetEndColor(rV.aCol2);
+ basegfx::ColorStops aNewColorStops(rG.aGradient.GetColorStops());
+ basegfx::utils::replaceEndColor(aNewColorStops, rV.aCol2.getBColor());
+ rG.aGradient.SetColorStops(aNewColorStops);
rG.aGradient.SetEndIntens(100);
}
diff --git a/svx/source/svdraw/svdetc.cxx b/svx/source/svdraw/svdetc.cxx
index 41639002a143..97da36957306 100644
--- a/svx/source/svdraw/svdetc.cxx
+++ b/svx/source/svdraw/svdetc.cxx
@@ -272,8 +272,8 @@ bool GetDraftFillColor(const SfxItemSet& rSet, Color& rCol)
}
case drawing::FillStyle_GRADIENT: {
const XGradient& rGrad=rSet.Get(XATTR_FILLGRADIENT).GetGradientValue();
- Color aCol1(rGrad.GetStartColor());
- Color aCol2(rGrad.GetEndColor());
+ Color aCol1(Color(rGrad.GetColorStops().front().getStopColor()));
+ Color aCol2(Color(rGrad.GetColorStops().back().getStopColor()));
const basegfx::BColor aAverageColor(basegfx::average(aCol1.getBColor(), aCol2.getBColor()));
rCol = Color(aAverageColor);
bRetval = true;
diff --git a/svx/source/svdraw/svdfmtf.cxx b/svx/source/svdraw/svdfmtf.cxx
index eb1c9648b127..86cb829119ec 100644
--- a/svx/source/svdraw/svdfmtf.cxx
+++ b/svx/source/svdraw/svdfmtf.cxx
@@ -1245,11 +1245,12 @@ void ImpSdrGDIMetaFileImport::DoAction( MetaCommentAction const & rAct, GDIMetaF
std::move(aSource));
// #i125211# Use the ranges from the SdrObject to create a new empty SfxItemSet
SfxItemSet aGradAttr(mpModel->GetItemPool(), pPath->GetMergedItemSet().GetRanges());
- XGradient aXGradient;
+ XGradient aXGradient(
+ basegfx::utils::createColorStopsFromStartEndColor(
+ rGrad.GetStartColor().getBColor(),
+ rGrad.GetEndColor().getBColor()));
aXGradient.SetGradientStyle(static_cast<css::awt::GradientStyle>(rGrad.GetStyle()));
- aXGradient.SetStartColor(rGrad.GetStartColor());
- aXGradient.SetEndColor(rGrad.GetEndColor());
aXGradient.SetAngle(rGrad.GetAngle());
aXGradient.SetBorder(rGrad.GetBorder());
aXGradient.SetXOffset(rGrad.GetOfsX());
@@ -1442,8 +1443,9 @@ void ImpSdrGDIMetaFileImport::DoAction(MetaGradientAction const & rAct)
const css::awt::GradientStyle aXGradientStyle(getXGradientStyleFromGradientStyle(rGradient.GetStyle()));
const XFillGradientItem aXFillGradientItem(
XGradient(
- rGradient.GetStartColor(),
- rGradient.GetEndColor(),
+ basegfx::utils::createColorStopsFromStartEndColor(
+ rGradient.GetStartColor().getBColor(),
+ rGradient.GetEndColor().getBColor()),
aXGradientStyle,
rGradient.GetAngle(),
rGradient.GetOfsX(),
@@ -1504,8 +1506,9 @@ void ImpSdrGDIMetaFileImport::DoAction(MetaGradientExAction const & rAct)
const css::awt::GradientStyle aXGradientStyle(getXGradientStyleFromGradientStyle(rGradient.GetStyle()));
const XFillGradientItem aXFillGradientItem(
XGradient(
- rGradient.GetStartColor(),
- rGradient.GetEndColor(),
+ basegfx::utils::createColorStopsFromStartEndColor(
+ rGradient.GetStartColor().getBColor(),
+ rGradient.GetEndColor().getBColor()),
aXGradientStyle,
rGradient.GetAngle(),
rGradient.GetOfsX(),
diff --git a/svx/source/svdraw/svdoashp.cxx b/svx/source/svdraw/svdoashp.cxx
index 63a987e172ff..a2db44a795c6 100644
--- a/svx/source/svdraw/svdoashp.cxx
+++ b/svx/source/svdraw/svdoashp.cxx
@@ -303,8 +303,8 @@ static rtl::Reference<SdrObject> ImpCreateShadowObjectClone(const SdrObject& rOr
if(bGradientFillUsed)
{
XGradient aGradient(rOriginalSet.Get(XATTR_FILLGRADIENT).GetGradientValue());
- sal_uInt8 nStartLuminance(aGradient.GetStartColor().GetLuminance());
- sal_uInt8 nEndLuminance(aGradient.GetEndColor().GetLuminance());
+ sal_uInt8 nStartLuminance(Color(aGradient.GetColorStops().front().getStopColor()).GetLuminance());
+ sal_uInt8 nEndLuminance(Color(aGradient.GetColorStops().back().getStopColor()).GetLuminance());
if(aGradient.GetStartIntens() != 100)
{
@@ -326,8 +326,10 @@ static rtl::Reference<SdrObject> ImpCreateShadowObjectClone(const SdrObject& rOr
static_cast<sal_uInt8>((nEndLuminance * aShadowColor.GetGreen()) / 256),
static_cast<sal_uInt8>((nEndLuminance * aShadowColor.GetBlue()) / 256));
- aGradient.SetStartColor(aStartColor);
- aGradient.SetEndColor(aEndColor);
+ aGradient.SetColorStops(
+ basegfx::utils::createColorStopsFromStartEndColor(
+ aStartColor.getBColor(),
+ aEndColor.getBColor()));
aTempSet.Put(XFillGradientItem(aGradient));
aTempSet.Put(XFillTransparenceItem(nShadowTransparence));
}
diff --git a/svx/source/unodraw/XPropertyTable.cxx b/svx/source/unodraw/XPropertyTable.cxx
index c1105335ae84..586bba387699 100644
--- a/svx/source/unodraw/XPropertyTable.cxx
+++ b/svx/source/unodraw/XPropertyTable.cxx
@@ -536,8 +536,8 @@ uno::Any SvxUnoXGradientTable::getAny( const XPropertyEntry* pEntry ) const noex
awt::Gradient aGradient;
aGradient.Style = aXGradient.GetGradientStyle();
- aGradient.StartColor = static_cast<sal_Int32>(aXGradient.GetStartColor());
- aGradient.EndColor = static_cast<sal_Int32>(aXGradient.GetEndColor());
+ aGradient.StartColor = static_cast<sal_Int32>(Color(aXGradient.GetColorStops().front().getStopColor()));
+ aGradient.EndColor = static_cast<sal_Int32>(Color(aXGradient.GetColorStops().back().getStopColor()));
aGradient.Angle = static_cast<short>(aXGradient.GetAngle());
aGradient.Border = aXGradient.GetBorder();
aGradient.XOffset = aXGradient.GetXOffset();
@@ -555,11 +555,12 @@ std::unique_ptr<XPropertyEntry> SvxUnoXGradientTable::createEntry(const OUString
if(!(rAny >>= aGradient))
return std::unique_ptr<XPropertyEntry>();
- XGradient aXGradient;
+ XGradient aXGradient(
+ basegfx::utils::createColorStopsFromStartEndColor(
+ Color(ColorTransparency, aGradient.StartColor).getBColor(),
+ Color(ColorTransparency, aGradient.EndColor).getBColor()));
aXGradient.SetGradientStyle( aGradient.Style );
- aXGradient.SetStartColor( Color(ColorTransparency, aGradient.StartColor) );
- aXGradient.SetEndColor( Color(ColorTransparency, aGradient.EndColor) );
aXGradient.SetAngle( Degree10(aGradient.Angle) );
aXGradient.SetBorder( aGradient.Border );
aXGradient.SetXOffset( aGradient.XOffset );
diff --git a/svx/source/unodraw/unobrushitemhelper.cxx b/svx/source/unodraw/unobrushitemhelper.cxx
index bc9d04747f9c..ba0924be803f 100644
--- a/svx/source/unodraw/unobrushitemhelper.cxx
+++ b/svx/source/unodraw/unobrushitemhelper.cxx
@@ -157,8 +157,8 @@ static sal_uInt16 getTransparenceForSvxBrushItem(const SfxItemSet& rSourceSet, b
&& pGradientItem->IsEnabled())
{
const XGradient& rGradient = pGradientItem->GetGradientValue();
- const sal_uInt16 nStartLuminance(rGradient.GetStartColor().GetLuminance());
- const sal_uInt16 nEndLuminance(rGradient.GetEndColor().GetLuminance());
+ const sal_uInt16 nStartLuminance(Color(rGradient.GetColorStops().front().getStopColor()).GetLuminance());
+ const sal_uInt16 nEndLuminance(Color(rGradient.GetColorStops().back().getStopColor()).GetLuminance());
// luminance is [0..255], transparence needs to be in [0..100].Maximum is 51200, thus sal_uInt16 is okay to use
nFillTransparence = static_cast< sal_uInt16 >(((nStartLuminance + nEndLuminance) * 100) / 512);
@@ -224,8 +224,8 @@ std::unique_ptr<SvxBrushItem> getSvxBrushItemFromSourceSet(const SfxItemSet& rSo
{
// cannot be directly supported, but do the best possible
const XGradient aXGradient(rSourceSet.Get(XATTR_FILLGRADIENT).GetGradientValue());
- const basegfx::BColor aStartColor(aXGradient.GetStartColor().getBColor() * (aXGradient.GetStartIntens() * 0.01));
- const basegfx::BColor aEndColor(aXGradient.GetEndColor().getBColor() * (aXGradient.GetEndIntens() * 0.01));
+ const basegfx::BColor aStartColor(aXGradient.GetColorStops().front().getStopColor() * (aXGradient.GetStartIntens() * 0.01));
+ const basegfx::BColor aEndColor(aXGradient.GetColorStops().back().getStopColor() * (aXGradient.GetEndIntens() * 0.01));
// use half/half mixed color from gradient start and end
Color aMixedColor((aStartColor + aEndColor) * 0.5);
diff --git a/svx/source/xoutdev/xattr.cxx b/svx/source/xoutdev/xattr.cxx
index f0d17dbc0b14..64df04216530 100644
--- a/svx/source/xoutdev/xattr.cxx
+++ b/svx/source/xoutdev/xattr.cxx
@@ -27,7 +27,7 @@
#include <com/sun/star/drawing/LineDash.hpp>
#include <com/sun/star/drawing/DashStyle.hpp>
#include <com/sun/star/drawing/FillStyle.hpp>
-#include <com/sun/star/awt/Gradient.hpp>
+#include <com/sun/star/awt/Gradient2.hpp>
#include <com/sun/star/uno/Sequence.hxx>
#include <com/sun/star/beans/PropertyValue.hpp>
@@ -2159,10 +2159,11 @@ namespace
XGradient lcl_buildGradientFromStringMap(StringMap& rMap)
{
- XGradient aGradient;
+ XGradient aGradient(
+ basegfx::utils::createColorStopsFromStartEndColor(
+ Color(ColorTransparency, rMap["startcolor"].toInt32(16)).getBColor(),
+ Color(ColorTransparency, rMap["endcolor"].toInt32(16)).getBColor()));
- aGradient.SetStartColor(Color(ColorTransparency, rMap["startcolor"].toInt32(16)));
- aGradient.SetEndColor(Color(ColorTransparency, rMap["endcolor"].toInt32(16)));
aGradient.SetGradientStyle(lcl_getStyleFromString(rMap["style"]));
aGradient.SetAngle(Degree10(rMap["angle"].toInt32()));
@@ -2176,28 +2177,43 @@ XGradient XGradient::fromJSON(std::u16string_view rJSON)
return lcl_buildGradientFromStringMap(aMap);
}
-css::awt::Gradient XGradient::toGradientUNO() const
+namespace
{
- css::awt::Gradient aGradient;
+ void fillGradient2FromXGradient(css::awt::Gradient2& rGradient2, const XGradient& rXGradient)
+ {
+ // standard values
+ rGradient2.Style = rXGradient.GetGradientStyle();
+ rGradient2.Angle = static_cast<short>(rXGradient.GetAngle());
+ rGradient2.Border = rXGradient.GetBorder();
+ rGradient2.XOffset = rXGradient.GetXOffset();
+ rGradient2.YOffset = rXGradient.GetYOffset();
+ rGradient2.StartIntensity = rXGradient.GetStartIntens();
+ rGradient2.EndIntensity = rXGradient.GetEndIntens();
+ rGradient2.StepCount = rXGradient.GetSteps();
+
+ // for compatibility, still set StartColor/EndColor
+ const basegfx::ColorStops& rColorStops(rXGradient.GetColorStops());
+ rGradient2.StartColor = static_cast<sal_Int32>(Color(rColorStops.front().getStopColor()));
+ rGradient2.EndColor = static_cast<sal_Int32>(Color(rColorStops.back().getStopColor()));
+
+ // fill ColorStops to extended Gradient2
+ basegfx::utils::fillColorStopSequenceFromColorStops(rGradient2.ColorStops, rColorStops);
+ }
+}
- aGradient.Style = this->GetGradientStyle();
- aGradient.StartColor = static_cast<sal_Int32>(this->GetStartColor());
- aGradient.EndColor = static_cast<sal_Int32>(this->GetEndColor());
- aGradient.Angle = static_cast<short>(this->GetAngle());
- aGradient.Border = this->GetBorder();
- aGradient.XOffset = this->GetXOffset();
- aGradient.YOffset = this->GetYOffset();
- aGradient.StartIntensity = this->GetStartIntens();
- aGradient.EndIntensity = this->GetEndIntens();
- aGradient.StepCount = this->GetSteps();
+css::awt::Gradient2 XGradient::toGradientUNO() const
+{
+ css::awt::Gradient2 aGradient2;
- return aGradient;
+ // fill values
+ fillGradient2FromXGradient(aGradient2, *this);
+
+ return aGradient2;
}
XGradient::XGradient() :
eStyle( css::awt::GradientStyle_LINEAR ),
- aStartColor( COL_BLACK ),
- aEndColor( COL_WHITE ),
+ aColorStops(),
nAngle( 0 ),
nBorder( 0 ),
nOfsX( 50 ),
@@ -2206,16 +2222,17 @@ XGradient::XGradient() :
nIntensEnd( 100 ),
nStepCount( 0 )
{
+ aColorStops.emplace_back(0.0, COL_BLACK.getBColor());
+ aColorStops.emplace_back(1.0, COL_WHITE.getBColor());
}
-XGradient::XGradient(const Color& rStart, const Color& rEnd,
+XGradient::XGradient(const basegfx::ColorStops& rColorStops,
css::awt::GradientStyle eTheStyle, Degree10 nTheAngle, sal_uInt16 nXOfs,
sal_uInt16 nYOfs, sal_uInt16 nTheBorder,
sal_uInt16 nStartIntens, sal_uInt16 nEndIntens,
sal_uInt16 nSteps) :
eStyle(eTheStyle),
- aStartColor(rStart),
- aEndColor(rEnd),
+ aColorStops(rColorStops),
nAngle(nTheAngle),
nBorder(nTheBorder),
nOfsX(nXOfs),
@@ -2224,13 +2241,13 @@ XGradient::XGradient(const Color& rStart, const Color& rEnd,
nIntensEnd(nEndIntens),
nStepCount(nSteps)
{
+ SetColorStops(aColorStops);
}
bool XGradient::operator==(const XGradient& rGradient) const
{
return ( eStyle == rGradient.eStyle &&
- aStartColor == rGradient.aStartColor &&
- aEndColor == rGradient.aEndColor &&
+ aColorStops == rGradient.aColorStops &&
nAngle == rGradient.nAngle &&
nBorder == rGradient.nBorder &&
nOfsX == rGradient.nOfsX &&
@@ -2240,13 +2257,21 @@ bool XGradient::operator==(const XGradient& rGradient) const
nStepCount == rGradient.nStepCount );
}
+void XGradient::SetColorStops(const basegfx::ColorStops& rSteps)
+{
+ aColorStops = rSteps;
+ basegfx::utils::sortAndCorrectColorStops(aColorStops);
+ if (aColorStops.empty())
+ aColorStops.emplace_back(0.0, basegfx::BColor());
+}
+
boost::property_tree::ptree XGradient::dumpAsJSON() const
{
boost::property_tree::ptree aTree;
aTree.put("style", XGradient::GradientStyleToString(eStyle));
- aTree.put("startcolor",aStartColor.AsRGBHexString());
- aTree.put("endcolor", aEndColor.AsRGBHexString());
+ aTree.put("startcolor", Color(GetColorStops().front().getStopColor()).AsRGBHexString());
+ aTree.put("endcolor", Color(GetColorStops().back().getStopColor()).AsRGBHexString());
aTree.put("angle", std::to_string(nAngle.get()));
aTree.put("border", std::to_string(nBorder));
aTree.put("x", std::to_string(nOfsX));
@@ -2318,6 +2343,37 @@ bool XFillGradientItem::GetPresentation
return true;
}
+namespace
+{
+ void fillXGradientFromAny(XGradient& rXGradient, const css::uno::Any& rVal)
+ {
+ css::awt::Gradient aGradient;
+ if (!(rVal >>= aGradient))
+ return;
+
+ // for compatibility, read and set StartColor/EndColor
+ rXGradient.SetColorStops(basegfx::utils::createColorStopsFromStartEndColor(
+ Color(ColorTransparency, aGradient.StartColor).getBColor(),
+ Color(ColorTransparency, aGradient.EndColor).getBColor()));
+
+ // set values
+ rXGradient.SetGradientStyle( aGradient.Style );
+ rXGradient.SetAngle( Degree10(aGradient.Angle) );
+ rXGradient.SetBorder( aGradient.Border );
+ rXGradient.SetXOffset( aGradient.XOffset );
+ rXGradient.SetYOffset( aGradient.YOffset );
+ rXGradient.SetStartIntens( aGradient.StartIntensity );
+ rXGradient.SetEndIntens( aGradient.EndIntensity );
+ rXGradient.SetSteps( aGradient.StepCount );
+
+ // check if we have a awt::Gradient2 with a ColorStopSequence
+ basegfx::ColorStops aColorStops;
+ basegfx::utils::fillColorStopsFromAny(aColorStops, rVal);
+ if (!aColorStops.empty())
+ rXGradient.SetColorStops(aColorStops);
+ }
+}
+
bool XFillGradientItem::QueryValue( css::uno::Any& rVal, sal_uInt8 nMemberId ) const
{
nMemberId &= ~CONVERT_TWIPS;
@@ -2325,20 +2381,12 @@ bool XFillGradientItem::QueryValue( css::uno::Any& rVal, sal_uInt8 nMemberId ) c
{
case 0:
{
- css::awt::Gradient aGradient2;
+ css::awt::Gradient2 aGradient2;
- const XGradient& aXGradient = GetGradientValue();
- aGradient2.Style = aXGradient.GetGradientStyle();
- aGradient2.StartColor = static_cast<sal_Int32>(aXGradient.GetStartColor());
- aGradient2.EndColor = static_cast<sal_Int32>(aXGradient.GetEndColor());
- aGradient2.Angle = static_cast<short>(aXGradient.GetAngle());
- aGradient2.Border = aXGradient.GetBorder();
- aGradient2.XOffset = aXGradient.GetXOffset();
- aGradient2.YOffset = aXGradient.GetYOffset();
- aGradient2.StartIntensity = aXGradient.GetStartIntens();
- aGradient2.EndIntensity = aXGradient.GetEndIntens();
- aGradient2.StepCount = aXGradient.GetSteps();
+ // fill values
+ fillGradient2FromXGradient(aGradient2, GetGradientValue());
+ // create sequence
uno::Sequence< beans::PropertyValue > aPropSeq{
comphelper::makePropertyValue("Name", SvxUnogetApiNameForItem(Which(), GetName())),
comphelper::makePropertyValue("FillGradient", aGradient2)
@@ -2349,20 +2397,12 @@ bool XFillGradientItem::QueryValue( css::uno::Any& rVal, sal_uInt8 nMemberId ) c
case MID_FILLGRADIENT:
{
- const XGradient& aXGradient = GetGradientValue();
- css::awt::Gradient aGradient2;
+ css::awt::Gradient2 aGradient2;
- aGradient2.Style = aXGradient.GetGradientStyle();
- aGradient2.StartColor = static_cast<sal_Int32>(aXGradient.GetStartColor());
- aGradient2.EndColor = static_cast<sal_Int32>(aXGradient.GetEndColor());
- aGradient2.Angle = static_cast<short>(aXGradient.GetAngle());
- aGradient2.Border = aXGradient.GetBorder();
- aGradient2.XOffset = aXGradient.GetXOffset();
- aGradient2.YOffset = aXGradient.GetYOffset();
- aGradient2.StartIntensity = aXGradient.GetStartIntens();
- aGradient2.EndIntensity = aXGradient.GetEndIntens();
- aGradient2.StepCount = aXGradient.GetSteps();
+ // fill values
+ fillGradient2FromXGradient(aGradient2, GetGradientValue());
+ // create sequence
rVal <<= aGradient2;
break;
}
@@ -2373,9 +2413,21 @@ bool XFillGradientItem::QueryValue( css::uno::Any& rVal, sal_uInt8 nMemberId ) c
break;
}
+ case MID_GRADIENT_COLORSTOPSEQUENCE:
+ {
+ css::awt::ColorStopSequence aColorStopSequence;
+
+ // fill values
+ basegfx::utils::fillColorStopSequenceFromColorStops(aColorStopSequence, GetGradientValue().GetColorStops());
+
+ // create sequence
+ rVal <<= aColorStopSequence;
+ break;
+ }
+
case MID_GRADIENT_STYLE: rVal <<= static_cast<sal_Int16>(GetGradientValue().GetGradientStyle()); break;
- case MID_GRADIENT_STARTCOLOR: rVal <<= GetGradientValue().GetStartColor(); break;
- case MID_GRADIENT_ENDCOLOR: rVal <<= GetGradientValue().GetEndColor(); break;
+ case MID_GRADIENT_STARTCOLOR: rVal <<= Color(GetGradientValue().GetColorStops().front().getStopColor()); break;
+ case MID_GRADIENT_ENDCOLOR: rVal <<= Color(GetGradientValue().GetColorStops().back().getStopColor()); break;
case MID_GRADIENT_ANGLE: rVal <<= static_cast<sal_Int16>(GetGradientValue().GetAngle()); break;
case MID_GRADIENT_BORDER: rVal <<= GetGradientValue().GetBorder(); break;
case MID_GRADIENT_XOFFSET: rVal <<= GetGradientValue().GetXOffset(); break;
@@ -2399,40 +2451,27 @@ bool XFillGradientItem::PutValue( const css::uno::Any& rVal, sal_uInt8 nMemberId
case 0:
{
uno::Sequence< beans::PropertyValue > aPropSeq;
+ css::uno::Any aGradientAny;
if ( rVal >>= aPropSeq )
{
- css::awt::Gradient aGradient2;
OUString aName;
- bool bGradient( false );
+
for ( const auto& rProp : std::as_const(aPropSeq) )
{
if ( rProp.Name == "Name" )
rProp.Value >>= aName;
else if ( rProp.Name == "FillGradient" )
- {
- if ( rProp.Value >>= aGradient2 )
- bGradient = true;
- }
+ aGradientAny = rProp.Value;
}
SetName( aName );
- if ( bGradient )
+
+ if ( aGradientAny.hasValue() )
{
XGradient aXGradient;
-
- aXGradient.SetGradientStyle( aGradient2.Style );
- aXGradient.SetStartColor( Color(ColorTransparency, aGradient2.StartColor) );
- aXGradient.SetEndColor( Color(ColorTransparency, aGradient2.EndColor) );
- aXGradient.SetAngle( Degree10(aGradient2.Angle) );
- aXGradient.SetBorder( aGradient2.Border );
- aXGradient.SetXOffset( aGradient2.XOffset );
- aXGradient.SetYOffset( aGradient2.YOffset );
- aXGradient.SetStartIntens( aGradient2.StartIntensity );
- aXGradient.SetEndIntens( aGradient2.EndIntensity );
- aXGradient.SetSteps( aGradient2.StepCount );
-
- SetGradientValue( aXGradient );
+ fillXGradientFromAny(aXGradient, aGradientAny);
+ SetGradientValue(aXGradient);
}
return true;
@@ -2452,24 +2491,23 @@ bool XFillGradientItem::PutValue( const css::uno::Any& rVal, sal_uInt8 nMemberId
case MID_FILLGRADIENT:
{
- css::awt::Gradient aGradient2;
- if(!(rVal >>= aGradient2))
- return false;
-
XGradient aXGradient;
+ fillXGradientFromAny(aXGradient, rVal);
+ SetGradientValue(aXGradient);
+ break;
+ }
- aXGradient.SetGradientStyle( aGradient2.Style );
- aXGradient.SetStartColor( Color(ColorTransparency, aGradient2.StartColor) );
- aXGradient.SetEndColor( Color(ColorTransparency, aGradient2.EndColor) );
- aXGradient.SetAngle( Degree10(aGradient2.Angle) );
- aXGradient.SetBorder( aGradient2.Border );
- aXGradient.SetXOffset( aGradient2.XOffset );
- aXGradient.SetYOffset( aGradient2.YOffset );
- aXGradient.SetStartIntens( aGradient2.StartIntensity );
- aXGradient.SetEndIntens( aGradient2.EndIntensity );
- aXGradient.SetSteps( aGradient2.StepCount );
-
- SetGradientValue( aXGradient );
+ case MID_GRADIENT_COLORSTOPSEQUENCE:
+ {
+ // check if we have a awt::Gradient2 with a ColorStopSequence
+ basegfx::ColorStops aColorStops;
+ basegfx::utils::fillColorStopsFromAny(aColorStops, rVal);
+ if (!aColorStops.empty())
+ {
+ XGradient aXGradient(GetGradientValue());
+ aXGradient.SetColorStops(aColorStops);
+ SetGradientValue(aXGradient);
+ }
break;
}
@@ -2480,12 +2518,19 @@ bool XFillGradientItem::PutValue( const css::uno::Any& rVal, sal_uInt8 nMemberId
if(!(rVal >>= nVal ))
return false;
- XGradient aXGradient = GetGradientValue();
+ XGradient aXGradient(GetGradientValue());
+ basegfx::ColorStops aNewColorStops(aXGradient.GetColorStops());
if ( nMemberId == MID_GRADIENT_STARTCOLOR )
- aXGradient.SetStartColor( nVal );
+ {
+ basegfx::utils::replaceStartColor(aNewColorStops, nVal.getBColor());
+ }
else
- aXGradient.SetEndColor( nVal );
+ {
+ basegfx::utils::replaceEndColor(aNewColorStops, nVal.getBColor());
+ }
+
+ aXGradient.SetColorStops(aNewColorStops);
SetGradientValue( aXGradient );
break;
}
diff --git a/svx/source/xoutdev/xpool.cxx b/svx/source/xoutdev/xpool.cxx
index 65a096de3910..5294092a3183 100644
--- a/svx/source/xoutdev/xpool.cxx
+++ b/svx/source/xoutdev/xpool.cxx
@@ -108,7 +108,10 @@ XOutdevItemPool::XOutdevItemPool(SfxItemPool* _pMaster)
rPoolDefaults[XATTR_LINECAP -XATTR_START] = new XLineCapItem;
rPoolDefaults[XATTR_FILLSTYLE -XATTR_START] = new XFillStyleItem;
rPoolDefaults[XATTR_FILLCOLOR -XATTR_START] = new XFillColorItem (aNullStr,aNullFillCol);
- rPoolDefaults[XATTR_FILLGRADIENT -XATTR_START] = new XFillGradientItem(XGradient(COL_BLACK, COL_WHITE));
+
+ // XGradient() default already creates [COL_BLACK, COL_WHITE] as defaults
+ rPoolDefaults[XATTR_FILLGRADIENT -XATTR_START] = new XFillGradientItem(XGradient());
+
rPoolDefaults[XATTR_FILLHATCH -XATTR_START] = new XFillHatchItem (aNullHatch);
rPoolDefaults[XATTR_FILLBITMAP -XATTR_START] = new XFillBitmapItem (Graphic());
rPoolDefaults[XATTR_FILLTRANSPARENCE -XATTR_START] = new XFillTransparenceItem;
@@ -123,7 +126,14 @@ XOutdevItemPool::XOutdevItemPool(SfxItemPool* _pMaster)
rPoolDefaults[XATTR_FILLBMP_STRETCH -XATTR_START] = new XFillBmpStretchItem;
rPoolDefaults[XATTR_FILLBMP_POSOFFSETX -XATTR_START] = new XFillBmpPosOffsetXItem;
rPoolDefaults[XATTR_FILLBMP_POSOFFSETY -XATTR_START] = new XFillBmpPosOffsetYItem;
- rPoolDefaults[XATTR_FILLFLOATTRANSPARENCE -XATTR_START] = new XFillFloatTransparenceItem( XGradient(COL_BLACK, COL_BLACK), false );
+
+ rPoolDefaults[XATTR_FILLFLOATTRANSPARENCE -XATTR_START] = new XFillFloatTransparenceItem(
+ XGradient(
+ basegfx::utils::createColorStopsFromStartEndColor(
+ COL_BLACK.getBColor(),
+ COL_BLACK.getBColor())),
+ false);
+
rPoolDefaults[XATTR_SECONDARYFILLCOLOR -XATTR_START] = new XSecondaryFillColorItem(aNullStr, aNullFillCol);
rPoolDefaults[XATTR_FILLBACKGROUND -XATTR_START] = new XFillBackgroundItem;
rPoolDefaults[XATTR_FILLUSESLIDEBACKGROUND -XATTR_START] = new XFillUseSlideBackgroundItem;
diff --git a/svx/source/xoutdev/xtabgrdt.cxx b/svx/source/xoutdev/xtabgrdt.cxx
index 219ee2801d69..e44141d45428 100644
--- a/svx/source/xoutdev/xtabgrdt.cxx
+++ b/svx/source/xoutdev/xtabgrdt.cxx
@@ -69,17 +69,20 @@ bool XGradientList::Create()
OUStringBuffer aStr(SvxResId(RID_SVXSTR_GRADIENT));
aStr.append(" 1");
sal_Int32 nLen = aStr.getLength() - 1;
- Insert(std::make_unique<XGradientEntry>(XGradient(COL_BLACK, COL_WHITE, css::awt::GradientStyle_LINEAR , 0_deg10,10,10, 0,100,100),aStr.toString()));
+
+ // XGradient() default already creates [COL_BLACK, COL_WHITE] as defaults
+ Insert(std::make_unique<XGradientEntry>(XGradient(),aStr.toString()));
+
aStr[nLen] = '2';
- Insert(std::make_unique<XGradientEntry>(XGradient(COL_BLUE, COL_RED, css::awt::GradientStyle_AXIAL , 300_deg10,20,20,10,100,100),aStr.toString()));
+ Insert(std::make_unique<XGradientEntry>(XGradient(basegfx::utils::createColorStopsFromStartEndColor(COL_BLUE.getBColor(), COL_RED.getBColor()), css::awt::GradientStyle_AXIAL , 300_deg10,20,20,10,100,100),aStr.toString()));
aStr[nLen] = '3';
- Insert(std::make_unique<XGradientEntry>(XGradient(COL_RED, COL_YELLOW,css::awt::GradientStyle_RADIAL , 600_deg10,30,30,20,100,100),aStr.toString()));
+ Insert(std::make_unique<XGradientEntry>(XGradient(basegfx::utils::createColorStopsFromStartEndColor(COL_RED.getBColor(), COL_YELLOW.getBColor()), css::awt::GradientStyle_RADIAL , 600_deg10,30,30,20,100,100),aStr.toString()));
aStr[nLen] = '4';
- Insert(std::make_unique<XGradientEntry>(XGradient(COL_YELLOW , COL_GREEN, css::awt::GradientStyle_ELLIPTICAL, 900_deg10,40,40,30,100,100),aStr.toString()));
+ Insert(std::make_unique<XGradientEntry>(XGradient(basegfx::utils::createColorStopsFromStartEndColor(COL_YELLOW.getBColor(), COL_GREEN.getBColor()), css::awt::GradientStyle_ELLIPTICAL, 900_deg10,40,40,30,100,100),aStr.toString()));
aStr[nLen] = '5';
- Insert(std::make_unique<XGradientEntry>(XGradient(COL_GREEN , COL_MAGENTA,css::awt::GradientStyle_SQUARE , 1200_deg10,50,50,40,100,100),aStr.toString()));
+ Insert(std::make_unique<XGradientEntry>(XGradient(basegfx::utils::createColorStopsFromStartEndColor(COL_GREEN.getBColor(), COL_MAGENTA.getBColor()), css::awt::GradientStyle_SQUARE , 1200_deg10,50,50,40,100,100),aStr.toString()));
aStr[nLen] = '6';
- Insert(std::make_unique<XGradientEntry>(XGradient(COL_MAGENTA, COL_YELLOW ,css::awt::GradientStyle_RECT , 1900_deg10,60,60,50,100,100),aStr.toString()));
+ Insert(std::make_unique<XGradientEntry>(XGradient(basegfx::utils::createColorStopsFromStartEndColor(COL_MAGENTA.getBColor(), COL_YELLOW.getBColor()), css::awt::GradientStyle_RECT , 1900_deg10,60,60,50,100,100),aStr.toString()));
return true;
}
@@ -100,7 +103,7 @@ BitmapEx XGradientList::CreateBitmap( tools::Long nIndex, const Size& rSize ) co
const XGradient& rGradient = GetGradient(nIndex)->GetGradient();
const sal_uInt16 nStartIntens(rGradient.GetStartIntens());
- basegfx::BColor aStart(rGradient.GetStartColor().getBColor());
+ basegfx::BColor aStart(rGradient.GetColorStops().front().getStopColor());
if(nStartIntens != 100)
{
@@ -109,7 +112,7 @@ BitmapEx XGradientList::CreateBitmap( tools::Long nIndex, const Size& rSize ) co
}
const sal_uInt16 nEndIntens(rGradient.GetEndIntens());
- basegfx::BColor aEnd(rGradient.GetEndColor().getBColor());
+ basegfx::BColor aEnd(rGradient.GetColorStops().back().getStopColor());
if(nEndIntens != 100)
{
@@ -153,17 +156,13 @@ BitmapEx XGradientList::CreateBitmap( tools::Long nIndex, const Size& rSize ) co
}
}
- const basegfx::ColorSteps aColorSteps {
- basegfx::ColorStep(0.0, aStart),
- basegfx::ColorStep(1.0, aEnd) };
-
drawinglayer::attribute::FillGradientAttribute aFillGradient(
aGradientStyle,
static_cast<double>(rGradient.GetBorder()) * 0.01,
static_cast<double>(rGradient.GetXOffset()) * 0.01,
static_cast<double>(rGradient.GetYOffset()) * 0.01,
toRadians(rGradient.GetAngle()),
- aColorSteps);
+ basegfx::utils::createColorStopsFromStartEndColor(aStart, aEnd));
const drawinglayer::primitive2d::Primitive2DReference aGradientPrimitive(
new drawinglayer::primitive2d::PolyPolygonGradientPrimitive2D(