diff options
author | Armin Le Grand (allotropia) <armin.le.grand.extern@allotropia.de> | 2023-05-22 12:13:25 +0200 |
---|---|---|
committer | Andras Timar <andras.timar@collabora.com> | 2023-06-04 16:34:11 +0200 |
commit | c6b90b83ad6bfaf1e95ca600ef4c5559a2a864fe (patch) | |
tree | 8383f14d841b7fc7bd7108eaee631ced9c0503a1 /oox | |
parent | 08de3d302faf13cd7ff6a1927d07428651cafabf (diff) |
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 <Armin.Le.Grand@me.com>
Diffstat (limited to 'oox')
-rw-r--r-- | oox/source/export/drawingml.cxx | 61 |
1 files changed, 41 insertions, 20 deletions
diff --git a/oox/source/export/drawingml.cxx b/oox/source/export/drawingml.cxx index 65798fa36cf6..7771caa7c92f 100644 --- a/oox/source/export/drawingml.cxx +++ b/oox/source/export/drawingml.cxx @@ -470,15 +470,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); @@ -625,13 +632,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")) @@ -5176,19 +5181,35 @@ void DrawingML::WriteFill( const Reference< XPropertySet >& xPropSet ) 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); |