diff options
author | A_GAN <ganzouri97@gmail.com> | 2020-06-08 21:36:34 +0200 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2020-06-15 11:55:53 +0200 |
commit | b435c4fe82e77a82fde6464d6722281e5fc4f394 (patch) | |
tree | c19cffeaae1ed9e17663f908e29020adbd1696f8 | |
parent | 5d8f2c1eda5583dd89dcd1d03cbd38ddb68ad273 (diff) |
Add process function to create the blur shadow
Create processShadowPrimitive2D function which uses the blur radius
from the shadow primitive to generate mask for the shadow bitmap.
Change-Id: Iba86bdbe1728153d866dd559a1b12eb5570ced51
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95859
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
-rw-r--r-- | drawinglayer/source/processor2d/vclpixelprocessor2d.cxx | 53 | ||||
-rw-r--r-- | drawinglayer/source/processor2d/vclpixelprocessor2d.hxx | 2 |
2 files changed, 55 insertions, 0 deletions
diff --git a/drawinglayer/source/processor2d/vclpixelprocessor2d.cxx b/drawinglayer/source/processor2d/vclpixelprocessor2d.cxx index 3a57695f81e0..864f5ca107b6 100644 --- a/drawinglayer/source/processor2d/vclpixelprocessor2d.cxx +++ b/drawinglayer/source/processor2d/vclpixelprocessor2d.cxx @@ -61,6 +61,7 @@ #include <drawinglayer/primitive2d/fillhatchprimitive2d.hxx> #include <drawinglayer/primitive2d/epsprimitive2d.hxx> #include <drawinglayer/primitive2d/softedgeprimitive2d.hxx> +#include <drawinglayer/primitive2d/shadowprimitive2d.hxx> #include <com/sun/star/awt/XWindow2.hpp> #include <com/sun/star/awt/XControl.hpp> @@ -392,6 +393,12 @@ void VclPixelProcessor2D::processBasePrimitive2D(const primitive2d::BasePrimitiv static_cast<const drawinglayer::primitive2d::SoftEdgePrimitive2D&>(rCandidate)); break; } + case PRIMITIVE2D_ID_SHADOWPRIMITIVE2D: + { + processShadowPrimitive2D( + static_cast<const drawinglayer::primitive2d::ShadowPrimitive2D&>(rCandidate)); + break; + } default: { SAL_INFO("drawinglayer", "default case for " << drawinglayer::primitive2d::idToString( @@ -1067,6 +1074,52 @@ void VclPixelProcessor2D::processSoftEdgePrimitive2D( SAL_WARN("drawinglayer", "Temporary buffered virtual device is not visible"); } +void VclPixelProcessor2D::processShadowPrimitive2D(const primitive2d::ShadowPrimitive2D& rCandidate) +{ + if (rCandidate.getShadowBlur() == 0) + { + process(rCandidate); + return; + } + + basegfx::B2DRange aRange(rCandidate.getB2DRange(getViewInformation2D())); + aRange.transform(maCurrentTransformation); + basegfx::B2DVector aBlurRadiusVector(rCandidate.getShadowBlur(), 0); + aBlurRadiusVector *= maCurrentTransformation; + const double fBlurRadius = aBlurRadiusVector.getLength(); + + impBufferDevice aBufferDevice(*mpOutputDevice, aRange, true); + if (aBufferDevice.isVisible()) + { + OutputDevice* pLastOutputDevice = mpOutputDevice; + mpOutputDevice = &aBufferDevice.getContent(); + mpOutputDevice->Erase(); + + process(rCandidate); + + const tools::Rectangle aRect(static_cast<long>(std::floor(aRange.getMinX())), + static_cast<long>(std::floor(aRange.getMinY())), + static_cast<long>(std::ceil(aRange.getMaxX())), + static_cast<long>(std::ceil(aRange.getMaxY()))); + + BitmapEx bitmapEx = mpOutputDevice->GetBitmapEx(aRect.TopLeft(), aRect.GetSize()); + + AlphaMask mask = ProcessAndBlurAlphaMask(bitmapEx.GetAlpha(), 0, fBlurRadius, 0); + + const basegfx::BColor aShadowColor( + maBColorModifierStack.getModifiedColor(rCandidate.getShadowColor())); + + Bitmap bitmap = bitmapEx.GetBitmap(); + bitmap.Erase(Color(aShadowColor)); + BitmapEx result(bitmap, mask); + + mpOutputDevice = pLastOutputDevice; + mpOutputDevice->DrawBitmapEx(aRect.TopLeft(), result); + } + else + SAL_WARN("drawinglayer", "Temporary buffered virtual device is not visible"); +} + } // end of namespace /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/drawinglayer/source/processor2d/vclpixelprocessor2d.hxx b/drawinglayer/source/processor2d/vclpixelprocessor2d.hxx index e78d1f08225a..5a23499f9a9b 100644 --- a/drawinglayer/source/processor2d/vclpixelprocessor2d.hxx +++ b/drawinglayer/source/processor2d/vclpixelprocessor2d.hxx @@ -40,6 +40,7 @@ class FillHatchPrimitive2D; class BackgroundColorPrimitive2D; class BorderLinePrimitive2D; class GlowPrimitive2D; +class ShadowPrimitive2D; class SoftEdgePrimitive2D; } @@ -97,6 +98,7 @@ class VclPixelProcessor2D final : public VclProcessor2D void processMetaFilePrimitive2D(const primitive2d::BasePrimitive2D& rCandidate); void processGlowPrimitive2D(const primitive2d::GlowPrimitive2D& rCandidate); void processSoftEdgePrimitive2D(const primitive2d::SoftEdgePrimitive2D& rCandidate); + void processShadowPrimitive2D(const primitive2d::ShadowPrimitive2D& rCandidate); public: /// constructor/destructor |