svx/source/svdraw/svdetc.cxx | 42 +++++++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-)
New commits: commit f8c87d617fc684e8e204a17cbd119c179a7e86e3 Author: Pranam Lashkari <lpra...@collabora.com> AuthorDate: Fri Oct 25 10:56:37 2024 +0530 Commit: Caolán McNamara <caolan.mcnam...@collabora.com> CommitDate: Sun Oct 27 13:34:00 2024 +0100 svx: calculate fill color with transperency calculate absoulutly visible color based on transperency against the doc background TODO: calculate this color based on the object in the background to increase visibility more Change-Id: I56076c29f10c58c6ee13e1358da92a4685ea01e5 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/175621 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Tested-by: Caolán McNamara <caolan.mcnam...@collabora.com> Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com> diff --git a/svx/source/svdraw/svdetc.cxx b/svx/source/svdraw/svdetc.cxx index e5f99a8f8f01..6ae1eb3b1e5c 100644 --- a/svx/source/svdraw/svdetc.cxx +++ b/svx/source/svdraw/svdetc.cxx @@ -37,6 +37,7 @@ #include <svx/xbtmpit.hxx> #include <svx/xflgrit.hxx> #include <svx/svdoole2.hxx> +#include <svx/xfltrit.hxx> #include <svl/itempool.hxx> #include <unotools/configmgr.hxx> #include <unotools/localedatawrapper.hxx> @@ -240,12 +241,13 @@ bool OLEObjCache::UnloadObj(SdrOle2Obj& rObj) std::optional<Color> GetDraftFillColor(const SfxItemSet& rSet) { drawing::FillStyle eFill=rSet.Get(XATTR_FILLSTYLE).GetValue(); - + Color aResult; switch(eFill) { case drawing::FillStyle_SOLID: { - return rSet.Get(XATTR_FILLCOLOR).GetColorValue(); + aResult = rSet.Get(XATTR_FILLCOLOR).GetColorValue(); + break; } case drawing::FillStyle_HATCH: { @@ -260,14 +262,16 @@ std::optional<Color> GetDraftFillColor(const SfxItemSet& rSet) } const basegfx::BColor aAverageColor(basegfx::average(aCol1.getBColor(), aCol2.getBColor())); - return Color(aAverageColor); + aResult = Color(aAverageColor); + break; } case drawing::FillStyle_GRADIENT: { const basegfx::BGradient& rGrad=rSet.Get(XATTR_FILLGRADIENT).GetGradientValue(); Color aCol1(Color(rGrad.GetColorStops().front().getStopColor())); Color aCol2(Color(rGrad.GetColorStops().back().getStopColor())); const basegfx::BColor aAverageColor(basegfx::average(aCol1.getBColor(), aCol2.getBColor())); - return Color(aAverageColor); + aResult = Color(aAverageColor); + break; } case drawing::FillStyle_BITMAP: { @@ -307,14 +311,38 @@ std::optional<Color> GetDraftFillColor(const SfxItemSet& rSet) nGn /= nCount; nBl /= nCount; - return Color(sal_uInt8(nRt), sal_uInt8(nGn), sal_uInt8(nBl)); + aResult = Color(sal_uInt8(nRt), sal_uInt8(nGn), sal_uInt8(nBl)); } break; } - default: break; + default: + return {}; } - return {}; + sal_uInt16 nTransparencyPercentage = rSet.Get(XATTR_FILLTRANSPARENCE).GetValue(); + if (!nTransparencyPercentage) + return aResult; + + auto nTransparency = nTransparencyPercentage / 100.0; + auto nOpacity = 1 - nTransparency; + + svtools::ColorConfig aColorConfig; + Color aBackground(aColorConfig.GetColorValue(svtools::DOCCOLOR).nColor); + + // https://en.wikipedia.org/wiki/Alpha_compositing + // We are here calculating transperency fill color against background with + // To put it is simple words with example + // I.E: fill is Red (FF0000) and background is pure white (FFFFFF) + // If we add 50% transperency to fill color will look like Pink(ff7777) + + // TODO: calculate this colors based on object in background and not just the doc color + aResult.SetRed( + std::min(aResult.GetRed() * nOpacity + aBackground.GetRed() * nTransparency, 255.0)); + aResult.SetGreen( + std::min(aResult.GetGreen() * nOpacity + aBackground.GetGreen() * nTransparency, 255.0)); + aResult.SetBlue( + std::min(aResult.GetBlue() * nOpacity + aBackground.GetBlue() * nTransparency, 255.0)); + return aResult; } std::unique_ptr<SdrOutliner> SdrMakeOutliner(OutlinerMode nOutlinerMode, SdrModel& rModel)