diff options
author | Armin Le Grand (allotropia) <armin.le.grand.extern@allotropia.de> | 2023-03-13 19:39:34 +0100 |
---|---|---|
committer | Armin Le Grand <Armin.Le.Grand@me.com> | 2023-03-19 17:38:38 +0000 |
commit | 01d0019c851b9e942f9a3b94d6dd554fb1adb40c (patch) | |
tree | 201cb6d13f57f8fa06128785c1ddb330eeacc349 /sd | |
parent | fd299d209d82495eb6528fb444e0b68f41c8ae0d (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 'sd')
-rw-r--r-- | sd/qa/unit/uiimpress.cxx | 4 | ||||
-rw-r--r-- | sd/source/core/drawdoc4.cxx | 49 | ||||
-rw-r--r-- | sd/source/ui/sidebar/SlideBackground.cxx | 11 | ||||
-rw-r--r-- | sd/source/ui/view/drviews9.cxx | 41 |
4 files changed, 71 insertions, 34 deletions
diff --git a/sd/qa/unit/uiimpress.cxx b/sd/qa/unit/uiimpress.cxx index 5cf0de0a275f..d9f71fcbb7a1 100644 --- a/sd/qa/unit/uiimpress.cxx +++ b/sd/qa/unit/uiimpress.cxx @@ -764,8 +764,8 @@ CPPUNIT_TEST_FIXTURE(SdUiImpressTest, testPageFillGradient) CPPUNIT_ASSERT_EQUAL(drawing::FillStyle_GRADIENT, eXFS); XGradient aGradient = rPageAttr.GetItem(XATTR_FILLGRADIENT)->GetGradientValue(); - CPPUNIT_ASSERT_EQUAL(Color(0xff0000), aGradient.GetStartColor()); - CPPUNIT_ASSERT_EQUAL(Color(0x0000ff), aGradient.GetEndColor()); + CPPUNIT_ASSERT_EQUAL(Color(0xff0000), Color(aGradient.GetColorStops().front().getStopColor())); + CPPUNIT_ASSERT_EQUAL(Color(0x0000ff), Color(aGradient.GetColorStops().back().getStopColor())); } CPPUNIT_TEST_FIXTURE(SdUiImpressTest, testTdf134053) diff --git a/sd/source/core/drawdoc4.cxx b/sd/source/core/drawdoc4.cxx index c487c041c75a..b697be203095 100644 --- a/sd/source/core/drawdoc4.cxx +++ b/sd/source/core/drawdoc4.cxx @@ -154,7 +154,10 @@ void SdDrawDocument::CreateLayoutTemplates() Color aNullCol(COL_DEFAULT_SHAPE_STROKE); XDash aNullDash; - XGradient aNullGrad(aNullCol,COL_WHITE); + XGradient aNullGrad( + basegfx::utils::createColorStopsFromStartEndColor( + aNullCol.getBColor(), + COL_WHITE.getBColor())); aNullGrad.SetStartIntens( 100 ); aNullGrad.SetEndIntens( 100 ); XHatch aNullHatch(aNullCol); @@ -414,8 +417,12 @@ void SdDrawDocument::CreateLayoutTemplates() pISet->Put(XFillStyleItem(drawing::FillStyle_GRADIENT)); // fill with gradient aGradient.SetGradientStyle( ::awt::GradientStyle_RECT); // square type aGradient.SetAngle( 0_deg10 ); // 0° angle - aGradient.SetStartColor( Color(0xcccccc) ); // white - aGradient.SetEndColor( COL_WHITE ); // light gray 3 + + aGradient.SetColorStops( + basegfx::utils::createColorStopsFromStartEndColor( + Color(0xcccccc).getBColor(), // light gray 3 + COL_WHITE.getBColor())); // white + aFillGradient.SetName( aShapesName ); aFillGradient.SetGradientValue(aGradient); pISet->Put( aFillGradient ); @@ -434,8 +441,12 @@ void SdDrawDocument::CreateLayoutTemplates() aGradient.SetGradientStyle( ::awt::GradientStyle_LINEAR ); aGradient.SetAngle( 300_deg10 ); - aGradient.SetStartColor( COL_WHITE ); // white - aGradient.SetEndColor( Color(0xcccccc) ); // light gray 3 + + aGradient.SetColorStops( + basegfx::utils::createColorStopsFromStartEndColor( + COL_WHITE.getBColor(), // white + Color(0xcccccc).getBColor())); // light gray 3 + aFillGradient.SetName( aName ); aFillGradient.SetGradientValue(aGradient); pISet->Put( XFillStyleItem(drawing::FillStyle_GRADIENT) ); @@ -449,8 +460,11 @@ void SdDrawDocument::CreateLayoutTemplates() pSheet->SetHelpId( aHelpFile, HID_POOLSHEET_FILLED_BLUE ); pISet = &pSheet->GetItemSet(); - aGradient.SetStartColor( Color(0x00729fcf) ); // light blue 2 - aGradient.SetEndColor( Color(0x00355269) ); // dark blue 2 + aGradient.SetColorStops( + basegfx::utils::createColorStopsFromStartEndColor( + Color(0x00729fcf).getBColor(), // light blue 2 + Color(0x00355269).getBColor())); // dark blue 2 + aFillGradient.SetName( aName ); aFillGradient.SetGradientValue(aGradient); pISet->Put( aFillGradient ); @@ -464,8 +478,11 @@ void SdDrawDocument::CreateLayoutTemplates() pSheet->SetHelpId( aHelpFile, HID_POOLSHEET_FILLED_GREEN ); pISet = &pSheet->GetItemSet(); - aGradient.SetStartColor( Color(0x0077bc65) ); // light green 2 - aGradient.SetEndColor( Color(0x00127622) ); // dark green 2 + aGradient.SetColorStops( + basegfx::utils::createColorStopsFromStartEndColor( + Color(0x0077bc65).getBColor(), // light green 2 + Color(0x00127622).getBColor())); // dark green 2 + aFillGradient.SetName( aName ); aFillGradient.SetGradientValue(aGradient); pISet->Put( aFillGradient ); @@ -480,8 +497,11 @@ void SdDrawDocument::CreateLayoutTemplates() pSheet->SetHelpId( aHelpFile, HID_POOLSHEET_FILLED_RED ); pISet = &pSheet->GetItemSet(); - aGradient.SetStartColor( Color(0x00ff6d6d) ); // light red 2 - aGradient.SetEndColor( Color(0x00c9211e) ); // dark red 2 + aGradient.SetColorStops( + basegfx::utils::createColorStopsFromStartEndColor( + Color(0x00ff6d6d).getBColor(), // light red 2 + Color(0x00c9211e).getBColor())); // dark red 2 + aFillGradient.SetName( aName ); aFillGradient.SetGradientValue(aGradient); pISet->Put( aFillGradient ); @@ -495,8 +515,11 @@ void SdDrawDocument::CreateLayoutTemplates() pSheet->SetHelpId( aHelpFile, HID_POOLSHEET_FILLED_YELLOW ); pISet = &pSheet->GetItemSet(); - aGradient.SetStartColor( Color(0x00ffde59) ); // light gold 2 - aGradient.SetEndColor( Color(0x00b47804) ); // dark gold 2 + aGradient.SetColorStops( + basegfx::utils::createColorStopsFromStartEndColor( + Color(0x00ffde59).getBColor(), // light gold 2 + Color(0x00b47804).getBColor())); // dark gold 2 + aFillGradient.SetName( aName ); aFillGradient.SetGradientValue(aGradient); pISet->Put( aFillGradient ); diff --git a/sd/source/ui/sidebar/SlideBackground.cxx b/sd/source/ui/sidebar/SlideBackground.cxx index 5f8bcff886b7..101b8c6133a3 100644 --- a/sd/source/ui/sidebar/SlideBackground.cxx +++ b/sd/source/ui/sidebar/SlideBackground.cxx @@ -399,9 +399,9 @@ void SlideBackground::Update() mxFillGrad2->show(); const XGradient xGradient = GetGradientSetOrDefault(); - const Color aStartColor = xGradient.GetStartColor(); + const Color aStartColor(xGradient.GetColorStops().front().getStopColor()); mxFillGrad1->SelectEntry(aStartColor); - const Color aEndColor = xGradient.GetEndColor(); + const Color aEndColor(xGradient.GetColorStops().back().getStopColor()); mxFillGrad2->SelectEntry(aEndColor); } break; @@ -1127,9 +1127,10 @@ IMPL_LINK_NOARG(SlideBackground, FillColorHdl, ColorListBox&, void) break; case drawing::FillStyle_GRADIENT: { - XGradient aGradient; - aGradient.SetStartColor(mxFillGrad1->GetSelectEntryColor()); - aGradient.SetEndColor(mxFillGrad2->GetSelectEntryColor()); + XGradient aGradient( + basegfx::utils::createColorStopsFromStartEndColor( + mxFillGrad1->GetSelectEntryColor().getBColor(), + mxFillGrad2->GetSelectEntryColor().getBColor())); // the name doesn't really matter, it'll be converted to unique one eventually, // but it has to be non-empty diff --git a/sd/source/ui/view/drviews9.cxx b/sd/source/ui/view/drviews9.cxx index 274fdaf01789..f0a6cae461a5 100644 --- a/sd/source/ui/view/drviews9.cxx +++ b/sd/source/ui/view/drviews9.cxx @@ -347,9 +347,18 @@ void DrawViewShell::AttrExec (SfxRequest &rReq) if (pEntry->GetName () == pName->GetValue ()) { XGradient aGradient(pEntry->GetGradient()); + basegfx::ColorStops aNewColorStops(aGradient.GetColorStops()); - if (rReq.GetSlot () == SID_SETGRADSTARTCOLOR) aGradient.SetStartColor (aColor); - else aGradient.SetEndColor (aColor); + if (SID_SETGRADSTARTCOLOR == rReq.GetSlot ()) + { + basegfx::utils::replaceStartColor(aNewColorStops, aColor.getBColor()); + } + else + { + basegfx::utils::replaceEndColor(aNewColorStops, aColor.getBColor()); + } + + aGradient.SetColorStops(aNewColorStops); XFillStyleItem aStyleItem(drawing::FillStyle_GRADIENT); aStyleItem.SetWhich(XATTR_FILLSTYLE); @@ -364,12 +373,14 @@ void DrawViewShell::AttrExec (SfxRequest &rReq) if (i >= nCounts) { Color aBlack (0, 0, 0); - XGradient aGradient ((rReq.GetSlot () == SID_SETGRADSTARTCOLOR) - ? aColor - : aBlack, - (rReq.GetSlot () == SID_SETGRADENDCOLOR) - ? aColor - : aBlack); + XGradient aGradient ( + basegfx::utils::createColorStopsFromStartEndColor( + (rReq.GetSlot () == SID_SETGRADSTARTCOLOR) + ? aColor.getBColor() + : aBlack.getBColor(), + (rReq.GetSlot () == SID_SETGRADENDCOLOR) + ? aColor.getBColor() + : aBlack.getBColor())); GetDoc()->GetGradientList()->Insert(std::make_unique<XGradientEntry>(aGradient, pName->GetValue())); @@ -568,10 +579,12 @@ void DrawViewShell::AttrExec (SfxRequest &rReq) if (i >= nCounts) { Color aBlack (0, 0, 0); - XGradient aGradient (aBlack, aBlack, static_cast<css::awt::GradientStyle>(pStyle->GetValue ()), - Degree10(pAngle->GetValue () * 10), static_cast<short>(pCenterX->GetValue ()), - static_cast<short>(pCenterY->GetValue ()), static_cast<short>(pBorder->GetValue ()), - static_cast<short>(pStart->GetValue ()), static_cast<short>(pEnd->GetValue ())); + XGradient aGradient ( + basegfx::utils::createColorStopsFromStartEndColor(aBlack.getBColor(), aBlack.getBColor()), + static_cast<css::awt::GradientStyle>(pStyle->GetValue ()), + Degree10(pAngle->GetValue () * 10), static_cast<short>(pCenterX->GetValue ()), + static_cast<short>(pCenterY->GetValue ()), static_cast<short>(pBorder->GetValue ()), + static_cast<short>(pStart->GetValue ()), static_cast<short>(pEnd->GetValue ())); pGradientList->Insert(std::make_unique<XGradientEntry>(aGradient, pName->GetValue())); XFillStyleItem aStyleItem(drawing::FillStyle_GRADIENT); @@ -854,8 +867,8 @@ void DrawViewShell::AttrState (SfxItemSet& rSet) const XGradient &rGradient = rFillGradientItem.GetGradientValue (); aColor = (rWhatKind.GetValue () == 3) - ? rGradient.GetStartColor () - : rGradient.GetEndColor (); + ? Color(rGradient.GetColorStops().front().getStopColor()) + : Color(rGradient.GetColorStops().back().getStopColor()); break; } |