oox/source/export/drawingml.cxx |   61 ++++++++++++++++++++++++++--------------
 svx/source/xoutdev/xattr.cxx    |    7 ++++
 2 files changed, 48 insertions(+), 20 deletions(-)

New commits:
commit e6ad415037b0b0bc77cd742af8260d99c1610c11
Author:     Armin Le Grand (allotropia) <armin.le.grand.ext...@allotropia.de>
AuthorDate: Mon May 22 12:13:25 2023 +0200
Commit:     Armin Le Grand <armin.le.gr...@me.com>
CommitDate: Tue May 23 10:11:48 2023 +0200

    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.gr...@me.com>

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<XPropertySet>& 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);
diff --git a/svx/source/xoutdev/xattr.cxx b/svx/source/xoutdev/xattr.cxx
index 9a3567430278..4860373836a8 100644
--- a/svx/source/xoutdev/xattr.cxx
+++ b/svx/source/xoutdev/xattr.cxx
@@ -2434,6 +2434,13 @@ XFillFloatTransparenceItem* 
XFillFloatTransparenceItem::Clone( SfxItemPool* /*pP
 
 bool XFillFloatTransparenceItem::QueryValue( css::uno::Any& rVal, sal_uInt8 
nMemberId ) const
 {
+    if (!IsEnabled() && nMemberId == MID_NAME)
+    {
+        // make sure that we return empty string in case of query for
+        // "FillTransparenceGradientName" if the item is disabled
+        rVal <<= OUString();
+    }
+
     return XFillGradientItem::QueryValue( rVal, nMemberId );
 }
 

Reply via email to