[Libreoffice-commits] core.git: chart2/qa include/oox oox/source

Balazs Varga (via logerrit) logerrit at kemper.freedesktop.org
Tue Nov 5 14:56:52 UTC 2019


 chart2/qa/extras/chart2export.cxx                                 |   28 +++++
 chart2/qa/extras/data/docx/testColorGradientWithTransparancy.docx |binary
 chart2/qa/extras/data/ods/testColorGradientWithTransparancy.ods   |binary
 include/oox/export/drawingml.hxx                                  |    6 -
 oox/source/export/chartexport.cxx                                 |   20 ++-
 oox/source/export/drawingml.cxx                                   |   55 ++++++----
 6 files changed, 83 insertions(+), 26 deletions(-)

New commits:
commit ef43ee69a355c0eda49d2f62540fbcf1299a59d2
Author:     Balazs Varga <balazs.varga991 at gmail.com>
AuthorDate: Tue Oct 22 09:43:29 2019 +0200
Commit:     László Németh <nemeth at numbertext.org>
CommitDate: Tue Nov 5 15:55:34 2019 +0100

    tdf#108065 tdf#128609 OOXML chart export: fix transparent color gradient
    
    Linear and axial color gradients keep their solid or gradient
    transparencies.
    
    Change-Id: I37dfe016864bded49c767cea5c8c865455281de0
    Reviewed-on: https://gerrit.libreoffice.org/81308
    Reviewed-by: László Németh <nemeth at numbertext.org>
    Tested-by: László Németh <nemeth at numbertext.org>

diff --git a/chart2/qa/extras/chart2export.cxx b/chart2/qa/extras/chart2export.cxx
index 694ba5501043..5f2b9ee6825b 100644
--- a/chart2/qa/extras/chart2export.cxx
+++ b/chart2/qa/extras/chart2export.cxx
@@ -89,6 +89,8 @@ public:
     void testChartTitlePropertiesColorFillDOCX();
     void testChartTitlePropertiesGradientFillDOCX();
     void testChartTitlePropertiesBitmapFillDOCX();
+    void testColorGradientWithTransparancyDOCX();
+    void testColorGradientWithTransparancyODS();
     void testBarChartDataPointPropDOCX();
     void testFdo83058dlblPos();
     void testAutoTitleDelXLSX();
@@ -195,6 +197,8 @@ public:
     CPPUNIT_TEST(testChartTitlePropertiesColorFillDOCX);
     CPPUNIT_TEST(testChartTitlePropertiesGradientFillDOCX);
     CPPUNIT_TEST(testChartTitlePropertiesBitmapFillDOCX);
+    CPPUNIT_TEST(testColorGradientWithTransparancyDOCX);
+    CPPUNIT_TEST(testColorGradientWithTransparancyODS);
     CPPUNIT_TEST(testBarChartDataPointPropDOCX);
     CPPUNIT_TEST(testFdo83058dlblPos);
     CPPUNIT_TEST(testAutoTitleDelXLSX);
@@ -1219,6 +1223,30 @@ void Chart2ExportTest::testChartTitlePropertiesBitmapFillDOCX()
     assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:title/c:spPr/a:ln/a:noFill", 1);
 }
 
+void Chart2ExportTest::testColorGradientWithTransparancyDOCX()
+{
+    // Test color gradient (two color) with gradient transparency
+    load("/chart2/qa/extras/data/docx/", "testColorGradientWithTransparancy.docx");
+    xmlDocPtr pXmlDoc = parseExport("word/charts/chart", "Office Open XML Text");
+    CPPUNIT_ASSERT(pXmlDoc);
+    // Test the transparency of the first color
+    assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser/c:spPr/a:gradFill/a:gsLst/a:gs[1]/a:srgbClr/a:alpha", "val", "60000");
+    // Test the transparency of the second color
+    assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser/c:spPr/a:gradFill/a:gsLst/a:gs[2]/a:srgbClr/a:alpha", "val", "90196");
+}
+
+void Chart2ExportTest::testColorGradientWithTransparancyODS()
+{
+    // Test color gradient (two color) with simple transparency
+    load("/chart2/qa/extras/data/ods/", "testColorGradientWithTransparancy.ods");
+    xmlDocPtr pXmlDoc = parseExport("xl/charts/chart", "Calc Office Open XML");
+    CPPUNIT_ASSERT(pXmlDoc);
+    // Test the transparency of the first color
+    assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser/c:spPr/a:gradFill/a:gsLst/a:gs[1]/a:srgbClr/a:alpha", "val", "60000");
+    // Test the transparency of the second color
+    assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser/c:spPr/a:gradFill/a:gsLst/a:gs[2]/a:srgbClr/a:alpha", "val", "60000");
+}
+
 void Chart2ExportTest::testBarChartDataPointPropDOCX()
 {
     load("/chart2/qa/extras/data/docx/", "testBarChartDataPointPropDOCX.docx");
diff --git a/chart2/qa/extras/data/docx/testColorGradientWithTransparancy.docx b/chart2/qa/extras/data/docx/testColorGradientWithTransparancy.docx
new file mode 100644
index 000000000000..adc2aff042bf
Binary files /dev/null and b/chart2/qa/extras/data/docx/testColorGradientWithTransparancy.docx differ
diff --git a/chart2/qa/extras/data/ods/testColorGradientWithTransparancy.ods b/chart2/qa/extras/data/ods/testColorGradientWithTransparancy.ods
new file mode 100644
index 000000000000..d8a41c02c186
Binary files /dev/null and b/chart2/qa/extras/data/ods/testColorGradientWithTransparancy.ods differ
diff --git a/include/oox/export/drawingml.hxx b/include/oox/export/drawingml.hxx
index c0d451fdf0f4..a3da6a3cb442 100644
--- a/include/oox/export/drawingml.hxx
+++ b/include/oox/export/drawingml.hxx
@@ -193,10 +193,8 @@ public:
     void WriteSolidFill( const css::uno::Reference< css::beans::XPropertySet >& rXPropSet );
     void WriteGradientFill( const css::uno::Reference< css::beans::XPropertySet >& rXPropSet );
 
-    /// In case rXPropSet is set, it may serve as a source of gradient transparency information.
-    void WriteGradientFill(css::awt::Gradient rGradient,
-                           const css::uno::Reference<css::beans::XPropertySet>& rXPropSet
-                           = css::uno::Reference<css::beans::XPropertySet>());
+    void WriteGradientFill( css::awt::Gradient rGradient, css::awt::Gradient rTransparenceGradient,
+                            const css::uno::Reference<css::beans::XPropertySet>& rXPropSet = css::uno::Reference<css::beans::XPropertySet>());
 
     void WriteGrabBagGradientFill( const css::uno::Sequence< css::beans::PropertyValue >& aGradientStops, css::awt::Gradient rGradient);
 
diff --git a/oox/source/export/chartexport.cxx b/oox/source/export/chartexport.cxx
index 4eb82d71805e..c4bf38eff9ef 100644
--- a/oox/source/export/chartexport.cxx
+++ b/oox/source/export/chartexport.cxx
@@ -1543,16 +1543,28 @@ void ChartExport::exportGradientFill( const Reference< XPropertySet >& xPropSet
         xPropSet->getPropertyValue("FillGradientName") >>= sFillGradientName;
 
         awt::Gradient aGradient;
+        awt::Gradient aTransparenceGradient;
         uno::Reference< lang::XMultiServiceFactory > xFact( getModel(), uno::UNO_QUERY );
         try
         {
             uno::Reference< container::XNameAccess > xGradient( xFact->createInstance("com.sun.star.drawing.GradientTable"), uno::UNO_QUERY );
-            uno::Any rValue = xGradient->getByName( sFillGradientName );
-            if( rValue >>= aGradient )
+            uno::Any rGradientValue = xGradient->getByName( sFillGradientName );
+            if( rGradientValue >>= aGradient )
             {
                 mpFS->startElementNS(XML_a, XML_gradFill);
-                WriteGradientFill( aGradient );
-                mpFS->endElementNS( XML_a, XML_gradFill );
+                OUString sFillTransparenceGradientName;
+                if( (xPropSet->getPropertyValue("FillTransparenceGradientName") >>= sFillTransparenceGradientName) && !sFillTransparenceGradientName.isEmpty())
+                {
+                    uno::Reference< container::XNameAccess > xTransparenceGradient(xFact->createInstance("com.sun.star.drawing.TransparencyGradientTable"), uno::UNO_QUERY);
+                    uno::Any rTransparenceValue = xTransparenceGradient->getByName(sFillTransparenceGradientName);
+                    rTransparenceValue >>= aTransparenceGradient;;
+                    WriteGradientFill(aGradient, aTransparenceGradient);
+                }
+                else
+                {
+                    WriteGradientFill(aGradient, aTransparenceGradient, xPropSet);
+                }
+                mpFS->endElementNS(XML_a, XML_gradFill);
             }
         }
         catch (const uno::Exception &)
diff --git a/oox/source/export/drawingml.cxx b/oox/source/export/drawingml.cxx
index fb5f6ed7a4cd..a5c152dcf6d1 100644
--- a/oox/source/export/drawingml.cxx
+++ b/oox/source/export/drawingml.cxx
@@ -481,6 +481,7 @@ bool DrawingML::EqualGradients( awt::Gradient aGradient1, awt::Gradient aGradien
 void DrawingML::WriteGradientFill( const Reference< XPropertySet >& rXPropSet )
 {
     awt::Gradient aGradient;
+    awt::Gradient aTransparenceGradient;
     if (GetProperty(rXPropSet, "FillGradient"))
     {
         aGradient = *o3tl::doAccess<awt::Gradient>(mAny);
@@ -515,7 +516,9 @@ void DrawingML::WriteGradientFill( const Reference< XPropertySet >& rXPropSet )
         else
         {
             mpFS->startElementNS(XML_a, XML_gradFill, XML_rotWithShape, "0");
-            WriteGradientFill(aGradient, rXPropSet);
+            if( GetProperty(rXPropSet, "FillTransparenceGradient") )
+                aTransparenceGradient = *o3tl::doAccess<awt::Gradient>(mAny);
+            WriteGradientFill(aGradient, aTransparenceGradient);
             mpFS->endElementNS( XML_a, XML_gradFill );
         }
     }
@@ -580,7 +583,7 @@ void DrawingML::WriteGrabBagGradientFill( const Sequence< PropertyValue >& aGrad
     }
 }
 
-void DrawingML::WriteGradientFill(awt::Gradient rGradient,
+void DrawingML::WriteGradientFill(awt::Gradient rGradient, awt::Gradient rTransparenceGradient,
                                   const uno::Reference<beans::XPropertySet>& rXPropSet)
 {
     switch( rGradient.Style )
@@ -588,21 +591,19 @@ void DrawingML::WriteGradientFill(awt::Gradient rGradient,
         default:
         case awt::GradientStyle_LINEAR:
         {
-            awt::Gradient aTransparenceGradient;
-            bool bTransparent = false;
-            if (rXPropSet.is() && GetProperty(rXPropSet, "FillTransparenceGradient"))
+            mpFS->startElementNS(XML_a, XML_gsLst);
+            sal_Int32 nStartAlpha;
+            sal_Int32 nEndAlpha;
+            if( rXPropSet.is() && GetProperty(rXPropSet, "FillTransparence") )
             {
-                aTransparenceGradient = *o3tl::doAccess<awt::Gradient>(mAny);
-                bTransparent = true;
+                sal_Int32 nTransparency = 0;
+                mAny >>= nTransparency;
+                nStartAlpha = nEndAlpha = (MAX_PERCENT - (PER_PERCENT * nTransparency));
             }
-
-            mpFS->startElementNS(XML_a, XML_gsLst);
-            sal_Int32 nStartAlpha = MAX_PERCENT;
-            sal_Int32 nEndAlpha = MAX_PERCENT;
-            if (bTransparent)
+            else
             {
-                nStartAlpha = GetAlphaFromTransparenceGradient(aTransparenceGradient, true);
-                nEndAlpha = GetAlphaFromTransparenceGradient(aTransparenceGradient, false);
+                nStartAlpha = GetAlphaFromTransparenceGradient(rTransparenceGradient, true);
+                nEndAlpha = GetAlphaFromTransparenceGradient(rTransparenceGradient, false);
             }
             WriteGradientStop(0, ColorWithIntensity(rGradient.StartColor, rGradient.StartIntensity),
                               nStartAlpha);
@@ -616,15 +617,33 @@ void DrawingML::WriteGradientFill(awt::Gradient rGradient,
         }
 
         case awt::GradientStyle_AXIAL:
+        {
             mpFS->startElementNS(XML_a, XML_gsLst);
-            WriteGradientStop( 0, ColorWithIntensity( rGradient.EndColor, rGradient.EndIntensity ) );
-            WriteGradientStop( 50, ColorWithIntensity( rGradient.StartColor, rGradient.StartIntensity ) );
-            WriteGradientStop( 100, ColorWithIntensity( rGradient.EndColor, rGradient.EndIntensity ) );
-            mpFS->endElementNS( XML_a, XML_gsLst );
+            sal_Int32 nStartAlpha;
+            sal_Int32 nEndAlpha;
+            if (rXPropSet.is() && GetProperty(rXPropSet, "FillTransparence"))
+            {
+                sal_Int32 nTransparency = 0;
+                mAny >>= nTransparency;
+                nStartAlpha = nEndAlpha = (MAX_PERCENT - (PER_PERCENT * nTransparency));
+            }
+            else
+            {
+                nStartAlpha = GetAlphaFromTransparenceGradient(rTransparenceGradient, true);
+                nEndAlpha = GetAlphaFromTransparenceGradient(rTransparenceGradient, false);
+            }
+            WriteGradientStop(0, ColorWithIntensity(rGradient.EndColor, rGradient.EndIntensity),
+                              nEndAlpha);
+            WriteGradientStop(50, ColorWithIntensity(rGradient.StartColor, rGradient.StartIntensity),
+                              nStartAlpha);
+            WriteGradientStop(100, ColorWithIntensity(rGradient.EndColor, rGradient.EndIntensity),
+                              nEndAlpha);
+            mpFS->endElementNS(XML_a, XML_gsLst);
             mpFS->singleElementNS(
                 XML_a, XML_lin, XML_ang,
                 OString::number((((3600 - rGradient.Angle + 900) * 6000) % 21600000)));
             break;
+        }
 
         case awt::GradientStyle_RADIAL:
         {


More information about the Libreoffice-commits mailing list