chart2/qa/extras/chart2export.cxx         |   13 ++++++++++
 chart2/qa/extras/data/docx/tdf128794.docx |binary
 oox/source/drawingml/fillproperties.cxx   |   36 ++++++++++++++++++++----------
 3 files changed, 37 insertions(+), 12 deletions(-)

New commits:
commit 898e4ae1364e76af8be22183ac64d73b6a6d8d90
Author:     Balazs Varga <balazs.varga...@gmail.com>
AuthorDate: Tue May 5 16:58:23 2020 +0200
Commit:     László Németh <nem...@numbertext.org>
CommitDate: Tue May 12 16:50:45 2020 +0200

    tdf#128794 Chart: Fix OOXML import/export of Radial gradient
    
    Style should be radial at least when the horizontal/vertical
    center is not in the corner of a shape. Otherwise import
    as a linear gradient, because it is the most similar to the
    MSO radial style.
    
    Change-Id: I9bab7b787897bde51a06a950487de9843eb717a3
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/93497
    Tested-by: Jenkins
    Tested-by: László Németh <nem...@numbertext.org>
    Reviewed-by: Tünde Tóth <tund...@gmail.com>
    Reviewed-by: László Németh <nem...@numbertext.org>

diff --git a/chart2/qa/extras/chart2export.cxx 
b/chart2/qa/extras/chart2export.cxx
index 571a0da80132..5909bfd2c5db 100644
--- a/chart2/qa/extras/chart2export.cxx
+++ b/chart2/qa/extras/chart2export.cxx
@@ -96,6 +96,7 @@ public:
     void testColorGradientWithTransparancyDOCX();
     void testColorGradientWithTransparancyODS();
     void testColorGradientStopXLSX();
+    void testRadialColorGradientDOCX();
     void testBarChartDataPointPropDOCX();
     void testFdo83058dlblPos();
     void testAutoTitleDelXLSX();
@@ -225,6 +226,7 @@ public:
     CPPUNIT_TEST(testColorGradientWithTransparancyDOCX);
     CPPUNIT_TEST(testColorGradientWithTransparancyODS);
     CPPUNIT_TEST(testColorGradientStopXLSX);
+    CPPUNIT_TEST(testRadialColorGradientDOCX);
     CPPUNIT_TEST(testBarChartDataPointPropDOCX);
     CPPUNIT_TEST(testFdo83058dlblPos);
     CPPUNIT_TEST(testAutoTitleDelXLSX);
@@ -1347,6 +1349,17 @@ void Chart2ExportTest::testColorGradientStopXLSX()
     assertXPath(pXmlDoc, 
"/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser/c:spPr/a:gradFill/a:gsLst/a:gs[2]",
 "pos", "100000");
 }
 
+void Chart2ExportTest::testRadialColorGradientDOCX()
+{
+    load("/chart2/qa/extras/data/docx/", "tdf128794.docx");
+    xmlDocPtr pXmlDoc = parseExport("word/charts/chart", "Office Open XML 
Text");
+    CPPUNIT_ASSERT(pXmlDoc);
+    // Test the gradeint style (if there is no 'a:path' attribute, it is a 
linear gradient)
+    assertXPath(pXmlDoc, 
"/c:chartSpace/c:chart/c:plotArea/c:spPr/a:gradFill/a:path", 0);
+    // Test the linear gradeint angle
+    assertXPath(pXmlDoc, 
"/c:chartSpace/c:chart/c:plotArea/c:spPr/a:gradFill/a:lin", "ang", "13500000");
+}
+
 void Chart2ExportTest::testBarChartDataPointPropDOCX()
 {
     load("/chart2/qa/extras/data/docx/", "testBarChartDataPointPropDOCX.docx");
diff --git a/chart2/qa/extras/data/docx/tdf128794.docx 
b/chart2/qa/extras/data/docx/tdf128794.docx
new file mode 100644
index 000000000000..098c0a00e3cc
Binary files /dev/null and b/chart2/qa/extras/data/docx/tdf128794.docx differ
diff --git a/oox/source/drawingml/fillproperties.cxx 
b/oox/source/drawingml/fillproperties.cxx
index acc13271ebc1..023af3bc613f 100644
--- a/oox/source/drawingml/fillproperties.cxx
+++ b/oox/source/drawingml/fillproperties.cxx
@@ -374,23 +374,35 @@ void FillProperties::pushToPropMap( ShapePropertyMap& 
rPropMap,
 
                 if( maGradientProps.moGradientPath.has() )
                 {
-                    // position of gradient center (limited to [30%;100%], 
otherwise gradient is too hidden)
                     IntegerRectangle2D aFillToRect = 
maGradientProps.moFillToRect.get( IntegerRectangle2D( 0, 0, MAX_PERCENT, 
MAX_PERCENT ) );
                     sal_Int32 nCenterX = (MAX_PERCENT + aFillToRect.X1 - 
aFillToRect.X2) / 2;
                     aGradient.XOffset = getLimitedValue<sal_Int16, sal_Int32>(
-                        nCenterX / PER_PERCENT, 30, 100);
-
-                    // Style should be radial at least when the horizontal 
center is at 50%.
-                    awt::GradientStyle eCircle = aGradient.XOffset == 50
-                                                     ? 
awt::GradientStyle_RADIAL
-                                                     : 
awt::GradientStyle_ELLIPTICAL;
-                    aGradient.Style = (maGradientProps.moGradientPath.get() == 
XML_circle)
-                                          ? eCircle
-                                          : awt::GradientStyle_RECT;
-
+                        nCenterX / PER_PERCENT, 0, 100);
                     sal_Int32 nCenterY = (MAX_PERCENT + aFillToRect.Y1 - 
aFillToRect.Y2) / 2;
                     aGradient.YOffset = getLimitedValue<sal_Int16, sal_Int32>(
-                        nCenterY / PER_PERCENT, 30, 100);
+                        nCenterY / PER_PERCENT, 0, 100);
+
+                    if( maGradientProps.moGradientPath.get() == XML_circle )
+                    {
+                        // Style should be radial at least when the horizontal 
center is at 50%.
+                        // Otherwise import as a linear gradient, because it 
is the most similar to the MSO radial style.
+                        aGradient.Style = awt::GradientStyle_LINEAR;
+                        if( aGradient.XOffset == 100 && aGradient.YOffset == 
100 )
+                            aGradient.Angle = 450;
+                        else if( aGradient.XOffset == 0 && aGradient.YOffset 
== 100 )
+                            aGradient.Angle = 3150;
+                        else if( aGradient.XOffset == 100 && aGradient.YOffset 
== 0 )
+                            aGradient.Angle = 1350;
+                        else if( aGradient.XOffset == 0 && aGradient.YOffset 
== 0 )
+                            aGradient.Angle = 2250;
+                        else
+                            aGradient.Style = awt::GradientStyle_RADIAL;
+                    }
+                    else
+                    {
+                        aGradient.Style = awt::GradientStyle_RECT;
+                    }
+
                     ::std::swap( aGradient.StartColor, aGradient.EndColor );
                     ::std::swap( nStartTrans, nEndTrans );
 
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to