diff options
author | Regina Henschel <rb.henschel@t-online.de> | 2023-06-21 15:01:20 +0200 |
---|---|---|
committer | Regina Henschel <rb.henschel@t-online.de> | 2023-06-23 10:54:24 +0200 |
commit | bb19bda1dc620f0f8662776d9818aedf45486994 (patch) | |
tree | b3642e60db311287a935b54d46fd7b440e2d36f0 /cui | |
parent | 8ec8d592e31aebe19075e9f89c4c2c7abcf8d420 (diff) |
tdf#155901 MCGR: preserve first and last gradient stop too
Error was, that only the in-between gradient stops were preserve. First
stop was set with fixed offset 0, last stop with fixed offset 1. The
offsets of first and last gradient stop of the original gradient were
lost. Now in all cases (hopefully) the complete gradient stops vector is
preserved and the original offset is used, if e.g. the user changes the
color.
For calculating transparence the indirect way over Color is removed.
Instead percent is directly transformed to the 0..1 values of BColor.
That avoids rounding errors.
Change-Id: Icdf699a6c2e9c6289d2f77033858448e58396a60
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153395
Tested-by: Jenkins
Reviewed-by: Regina Henschel <rb.henschel@t-online.de>
Diffstat (limited to 'cui')
-rw-r--r-- | cui/source/inc/cuitabarea.hxx | 8 | ||||
-rw-r--r-- | cui/source/tabpages/tpgradnt.cxx | 25 | ||||
-rw-r--r-- | cui/source/tabpages/tptrans.cxx | 28 |
3 files changed, 37 insertions, 24 deletions
diff --git a/cui/source/inc/cuitabarea.hxx b/cui/source/inc/cuitabarea.hxx index 2d6c713236da..4e766c76e57d 100644 --- a/cui/source/inc/cuitabarea.hxx +++ b/cui/source/inc/cuitabarea.hxx @@ -169,7 +169,7 @@ class SvxTransparenceTabPage : public SfxTabPage std::unique_ptr<weld::CustomWeld> m_xCtlBitmapPreview; std::unique_ptr<weld::CustomWeld> m_xCtlXRectPreview; - // MCGR: Preserve in-between ColorStops until we have an UI to edit these + // MCGR: Preserve ColorStops until we have a UI to edit these basegfx::BColorStops maColorStops; DECL_LINK(ClickTransOffHdl_Impl, weld::Toggleable&, void); @@ -187,7 +187,7 @@ class SvxTransparenceTabPage : public SfxTabPage bool InitPreview ( const SfxItemSet& rSet ); void InvalidatePreview (bool bEnable = true ); - // MCGR: Preserve in-between ColorStops until we have an UI to edit these + // MCGR: Preserve ColorStops until we have a UI to edit these basegfx::BColorStops createColorStops(); public: @@ -367,7 +367,7 @@ private: XFillAttrSetItem m_aXFillAttr; SfxItemSet& m_rXFSet; - // MCGR: Preserve in-between ColorStops until we have an UI to edit these + // MCGR: Preserve ColorStops until we have a UI to edit these basegfx::BColorStops m_aColorStops; SvxXRectPreview m_aCtlPreview; @@ -409,7 +409,7 @@ private: void SetControlState_Impl( css::awt::GradientStyle eXGS ); sal_Int32 SearchGradientList(std::u16string_view rGradientName); - // MCGR: Preserve in-between ColorStops until we have an UI to edit these + // MCGR: Preserve ColorStops until we have a UI to edit these basegfx::BColorStops createColorStops(); public: diff --git a/cui/source/tabpages/tpgradnt.cxx b/cui/source/tabpages/tpgradnt.cxx index 7f6630747a42..d3d066236ae1 100644 --- a/cui/source/tabpages/tpgradnt.cxx +++ b/cui/source/tabpages/tpgradnt.cxx @@ -548,9 +548,11 @@ void SvxGradientTabPage::ChangeGradientHdl_Impl() m_xLbColorTo->SetNoSelection(); m_xLbColorTo->SelectEntry(Color(pGradient->GetColorStops().back().getStopColor())); - // MCGR: preserve in-between ColorStops if given - if (pGradient->GetColorStops().size() > 2) - m_aColorStops = basegfx::BColorStops(pGradient->GetColorStops().begin() + 1, pGradient->GetColorStops().end() - 1); + // MCGR: preserve ColorStops if given. + // tdf#155901 We need offset of first and last stop, so include them. + if (pGradient->GetColorStops().size() >= 2) + m_aColorStops = basegfx::BColorStops(pGradient->GetColorStops().begin(), + pGradient->GetColorStops().end()); else m_aColorStops.clear(); @@ -641,14 +643,19 @@ basegfx::BColorStops SvxGradientTabPage::createColorStops() { basegfx::BColorStops aColorStops; - aColorStops.emplace_back(0.0, m_xLbColorFrom->GetSelectEntryColor().getBColor()); - - if(!m_aColorStops.empty()) + if(m_aColorStops.size() >= 2) { - aColorStops.insert(aColorStops.begin(), m_aColorStops.begin(), m_aColorStops.end()); + aColorStops.emplace_back(m_aColorStops.front().getStopOffset(), + m_xLbColorFrom->GetSelectEntryColor().getBColor()); + aColorStops.insert(aColorStops.begin(), m_aColorStops.begin() + 1, m_aColorStops.end() - 1); + aColorStops.emplace_back(m_aColorStops.back().getStopOffset(), + m_xLbColorTo->GetSelectEntryColor().getBColor()); + } + else + { + aColorStops.emplace_back(0.0, m_xLbColorFrom->GetSelectEntryColor().getBColor()); + aColorStops.emplace_back(1.0, m_xLbColorTo->GetSelectEntryColor().getBColor()); } - - aColorStops.emplace_back(1.0, m_xLbColorTo->GetSelectEntryColor().getBColor()); return aColorStops; } diff --git a/cui/source/tabpages/tptrans.cxx b/cui/source/tabpages/tptrans.cxx index 1dc675613d12..3d157850a526 100644 --- a/cui/source/tabpages/tptrans.cxx +++ b/cui/source/tabpages/tptrans.cxx @@ -367,9 +367,10 @@ void SvxTransparenceTabPage::Reset(const SfxItemSet* rAttrs) m_xMtrTrgrStartValue->set_value(static_cast<sal_uInt16>(((static_cast<sal_uInt16>(aStart.GetRed()) + 1) * 100) / 255), FieldUnit::PERCENT); m_xMtrTrgrEndValue->set_value(static_cast<sal_uInt16>(((static_cast<sal_uInt16>(aEnd.GetRed()) + 1) * 100) / 255), FieldUnit::PERCENT); - // MCGR: preserve in-between ColorStops if given - if (rGradient.GetColorStops().size() > 2) - maColorStops = basegfx::BColorStops(rGradient.GetColorStops().begin() + 1, rGradient.GetColorStops().end() - 1); + // MCGR: preserve ColorStops if given + // tdf#155901 We need offset of first and last stop, so include them. + if (rGradient.GetColorStops().size() >= 2) + maColorStops = basegfx::BColorStops(rGradient.GetColorStops().begin(), rGradient.GetColorStops().end()); else maColorStops.clear(); @@ -511,17 +512,22 @@ void SvxTransparenceTabPage::InvalidatePreview (bool bEnable) basegfx::BColorStops SvxTransparenceTabPage::createColorStops() { basegfx::BColorStops aColorStops; - const sal_uInt8 nStartCol(static_cast<sal_uInt8>((static_cast<sal_uInt16>(m_xMtrTrgrStartValue->get_value(FieldUnit::PERCENT)) * 255) / 100)); - const sal_uInt8 nEndCol(static_cast<sal_uInt8>((static_cast<sal_uInt16>(m_xMtrTrgrEndValue->get_value(FieldUnit::PERCENT)) * 255) / 100)); + basegfx::BColor aStartBColor(m_xMtrTrgrStartValue->get_value(FieldUnit::PERCENT) / 100.0); + aStartBColor.clamp(); + basegfx::BColor aEndBColor(m_xMtrTrgrEndValue->get_value(FieldUnit::PERCENT) / 100.0); + aEndBColor.clamp(); - aColorStops.emplace_back(0.0, Color(nStartCol, nStartCol, nStartCol).getBColor()); - - if(!maColorStops.empty()) + if(maColorStops.size() >= 2) { - aColorStops.insert(aColorStops.begin(), maColorStops.begin(), maColorStops.end()); + aColorStops.emplace_back(maColorStops.front().getStopOffset(), aStartBColor); + aColorStops.insert(aColorStops.begin(), maColorStops.begin() + 1, maColorStops.end() - 1); + aColorStops.emplace_back(maColorStops.back().getStopOffset(), aEndBColor); + } + else + { + aColorStops.emplace_back(0.0, aStartBColor); + aColorStops.emplace_back(1.0, aEndBColor); } - - aColorStops.emplace_back(1.0, Color(nEndCol, nEndCol, nEndCol).getBColor()); return aColorStops; } |