From e6ad415037b0b0bc77cd742af8260d99c1610c11 Mon Sep 17 00:00:00 2001 From: "Armin Le Grand (allotropia)" Date: Mon, 22 May 2023 12:13:25 +0200 Subject: MCGR: Check correctly for used FillTransparenceGradient To correctly check using UNO API if a FillTransparence- Gradient is used it is necessary to check if a Name for it is set. This corresponds to the IsEnabled() state of the XFillFloatTransparenceItem in the core. This was not consequently done that way and e.g. was done by checking if the FTG was 'default' in the sense that the StartColor was COL_BLACK. This was never sufficient and is not with MCGRs, too. Important in this case is the UnitTest checking for file fdo66688.docx - the re-export/roundtrip goes wrong when not doing this correctly. Change-Id: Iaf14c1e4481188124f044b4b3c8bcd6689c65aad Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152087 Tested-by: Jenkins Reviewed-by: Armin Le Grand --- oox/source/export/drawingml.cxx | 61 +++++++++++++++++++++++++++-------------- 1 file changed, 41 insertions(+), 20 deletions(-) (limited to 'oox/source/export') diff --git a/oox/source/export/drawingml.cxx b/oox/source/export/drawingml.cxx index 8bfcc8df5577..bd58cbf21249 100644 --- a/oox/source/export/drawingml.cxx +++ b/oox/source/export/drawingml.cxx @@ -473,15 +473,22 @@ void DrawingML::WriteSolidFill( const Reference< XPropertySet >& rXPropSet ) // OOXML has no separate transparence gradient but uses transparency in the gradient stops. // So we merge transparency and color and use gradient fill in such case. basegfx::BGradient aTransparenceGradient; + OUString sFillTransparenceGradientName; bool bNeedGradientFill(false); - if (GetProperty(rXPropSet, "FillTransparenceGradient")) + if (GetProperty(rXPropSet, "FillTransparenceGradientName") + && (mAny >>= sFillTransparenceGradientName) + && !sFillTransparenceGradientName.isEmpty() + && GetProperty(rXPropSet, "FillTransparenceGradient")) { aTransparenceGradient = basegfx::BGradient(mAny); basegfx::BColor aSingleColor; bNeedGradientFill = !aTransparenceGradient.GetColorStops().isSingleColor(aSingleColor); - if (!bNeedGradientFill && aSingleColor != basegfx::BColor()) + // we no longer need to 'guess' if FillTransparenceGradient is used by + // comparing it's 1st color to COL_BLACK after having tested that the + // FillTransparenceGradientName is set + if (!bNeedGradientFill) { // Our alpha is a gray color value. const sal_uInt8 nRed(aSingleColor.getRed() * 255.0); @@ -639,13 +646,11 @@ void DrawingML::WriteGradientFill( const Reference< XPropertySet >& rXPropSet ) if (GetProperty(rXPropSet, "FillTransparenceGradientName") && (mAny >>= sFillTransparenceGradientName) - && !sFillTransparenceGradientName.isEmpty()) + && !sFillTransparenceGradientName.isEmpty() + && GetProperty(rXPropSet, "FillTransparenceGradient")) { - if (GetProperty(rXPropSet, "FillTransparenceGradient")) - { - aTransparenceGradient = basegfx::BGradient(mAny); - } - + // TransparenceGradient is only used when name is not empty + aTransparenceGradient = basegfx::BGradient(mAny); pTransparenceGradient = &aTransparenceGradient; } else if (GetProperty(rXPropSet, "FillTransparence")) @@ -5314,19 +5319,35 @@ void DrawingML::WriteFill(const Reference& xPropSet, const awt::Si xPropSet->getPropertyValue( "FillStyle" ) >>= aFillStyle; // map full transparent background to no fill - if ( aFillStyle == FillStyle_SOLID && GetProperty( xPropSet, "FillTransparence" ) ) - { - sal_Int16 nVal = 0; - xPropSet->getPropertyValue( "FillTransparence" ) >>= nVal; - if ( nVal == 100 ) - aFillStyle = FillStyle_NONE; - } - if (aFillStyle == FillStyle_SOLID && GetProperty( xPropSet, "FillTransparenceGradient")) + if (aFillStyle == FillStyle_SOLID) { - awt::Gradient aTransparenceGradient; - mAny >>= aTransparenceGradient; - if (aTransparenceGradient.StartColor == 0xffffff && aTransparenceGradient.EndColor == 0xffffff) - aFillStyle = FillStyle_NONE; + OUString sFillTransparenceGradientName; + + if (GetProperty(xPropSet, "FillTransparenceGradientName") + && (mAny >>= sFillTransparenceGradientName) + && !sFillTransparenceGradientName.isEmpty() + && GetProperty(xPropSet, "FillTransparenceGradient")) + { + // check if a fully transparent TransparenceGradient is used + // use BGradient constructor & tooling here now + const basegfx::BGradient aTransparenceGradient(mAny); + basegfx::BColor aSingleColor; + const bool bSingleColor(aTransparenceGradient.GetColorStops().isSingleColor(aSingleColor)); + const bool bCompletelyTransparent(bSingleColor && basegfx::fTools::equal(aSingleColor.luminance(), 1.0)); + + if (bCompletelyTransparent) + { + aFillStyle = FillStyle_NONE; + } + } + else if ( GetProperty( xPropSet, "FillTransparence" ) ) + { + // check if a fully transparent FillTransparence is used + sal_Int16 nVal = 0; + xPropSet->getPropertyValue( "FillTransparence" ) >>= nVal; + if ( nVal == 100 ) + aFillStyle = FillStyle_NONE; + } } bool bUseBackground(false); -- cgit