summaryrefslogtreecommitdiff
path: root/svx
diff options
context:
space:
mode:
authorPranam Lashkari <lpranam@collabora.com>2024-10-25 10:56:37 +0530
committerPranam Lashkari <lpranam@collabora.com>2024-10-28 14:21:03 +0100
commit65fea94ac08fa9f428250098aa527ab072a378f3 (patch)
treed5d812581d02bd35bedb0d17de7a178058690009 /svx
parentc31a897f33fdce43b3392909feb0d8b82131e268 (diff)
tdf#163467 svx: calculate fill color with transparency
calculate absolutely visible color based on transparency 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 <jenkinscollaboraoffice@gmail.com> Tested-by: Caolán McNamara <caolan.mcnamara@collabora.com> Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com> (cherry picked from commit f8c87d617fc684e8e204a17cbd119c179a7e86e3) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/175616 Tested-by: Jenkins Reviewed-by: Pranam Lashkari <lpranam@collabora.com>
Diffstat (limited to 'svx')
-rw-r--r--svx/source/svdraw/svdetc.cxx42
1 files changed, 35 insertions, 7 deletions
diff --git a/svx/source/svdraw/svdetc.cxx b/svx/source/svdraw/svdetc.cxx
index f6b79cb4b5b7..e3dcb280e92f 100644
--- a/svx/source/svdraw/svdetc.cxx
+++ b/svx/source/svdraw/svdetc.cxx
@@ -39,6 +39,7 @@
#include <svx/xbtmpit.hxx>
#include <svx/xflgrit.hxx>
#include <svx/svdoole2.hxx>
+#include <svx/xfltrit.hxx>
#include <svl/itempool.hxx>
#include <comphelper/configuration.hxx>
#include <unotools/localedatawrapper.hxx>
@@ -242,12 +243,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:
{
@@ -262,14 +264,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:
{
@@ -309,14 +313,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)