oox/source/drawingml/fillproperties.cxx   |    2 +
 sw/qa/extras/ooxmlexport/ooxmlexport2.cxx |   30 +++----------------
 sw/qa/extras/ooxmlexport/ooxmlexport7.cxx |   26 +++-------------
 sw/qa/extras/rtfexport/rtfexport.cxx      |   47 +++++++++++++++---------------
 sw/qa/extras/rtfexport/rtfexport8.cxx     |   15 +--------
 5 files changed, 42 insertions(+), 78 deletions(-)

New commits:
commit 38083e4c0b5638d69162593c3fbf599da6cd499f
Author:     Justin Luth <jl...@mail.com>
AuthorDate: Tue Feb 20 16:11:08 2024 -0500
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Tue Feb 27 08:40:50 2024 +0100

    related tdf#126533 dml/vml import: import radials as radials
    
    ... and not as symmetrical linear gradients.
    
    The benefit is that our export code
    will be able to intelligently export it.
    
    Apparently RTF export code does not intelligently export axials,
    (now fixed - tdf#159824)
    but VML and DML (and doc) do it well.
    
    Unfortunately charts can be badly affected,
    (avoided by ignoring when transparent)
    and unit tests are implementation-tested...
    
    This affects existing unit tests:
    -tdf128345_Legend_CS_TG_axial.pptx: label imports fine:
        lost on export (no change)
    -tdf128345_ChartWall_CS_TG.pptx: wall gradient now looks axial:
        lost on export (no change)
    -textframe-gradient.docx: still round-trips OK: no change
    -textframe-gradient.rtf: round-trips as linear: lost axial-ness
     (now fixed: tdf#159824)
    -fdo78663.docx: textbox font fill: still exports as solid: no change
    
    I ran the assert check against chart2, oox, and sw
    
    Change-Id: Ib16e9488a76b006bf335ff01a38acf7cde69cccb
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/163675
    Tested-by: Jenkins
    Reviewed-by: Justin Luth <jl...@mail.com>
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/oox/source/drawingml/fillproperties.cxx 
b/oox/source/drawingml/fillproperties.cxx
index dec9ab9672cc..f24208722cb5 100644
--- a/oox/source/drawingml/fillproperties.cxx
+++ b/oox/source/drawingml/fillproperties.cxx
@@ -543,6 +543,8 @@ void FillProperties::pushToPropMap(ShapePropertyMap& 
rPropMap, const GraphicHelp
 
                     // convert DrawingML angle (in 1/60000 degrees) to API 
angle (in 1/10 degrees)
                     aGradient.SetAngle(Degree10(static_cast< sal_Int16 >( 
(8100 - (nDmlAngle / (PER_DEGREE / 10))) % 3600 )));
+                    if (!bContainsTransparency)
+                        aGradient.tryToConvertToAxial();
                 }
 
                 if (awt::GradientStyle_RECT == aGradient.GetGradientStyle())
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport2.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport2.cxx
index f8defa15d1a2..72072bc5bb03 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport2.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport2.cxx
@@ -577,34 +577,16 @@ DECLARE_OOXMLEXPORT_TEST(testTextframeGradient, 
"textframe-gradient.docx")
     uno::Reference<beans::XPropertySet> xFrame(getShape(1), uno::UNO_QUERY);
     CPPUNIT_ASSERT_EQUAL(drawing::FillStyle_GRADIENT, 
getProperty<drawing::FillStyle>(xFrame, "FillStyle"));
     awt::Gradient2 aGradient(getProperty<awt::Gradient2>(xFrame, 
"FillGradient"));
-
-    // MCGR: Use the completely imported transparency gradient to check for 
correctness
-    basegfx::BColorStops aColorStops = 
model::gradient::getColorStopsFromUno(aGradient.ColorStops);
-
-    CPPUNIT_ASSERT_EQUAL(size_t(3), aColorStops.size());
-    CPPUNIT_ASSERT(basegfx::fTools::equal(aColorStops[0].getStopOffset(), 
0.0));
-    CPPUNIT_ASSERT_EQUAL(Color(0xd99594), 
Color(aColorStops[0].getStopColor()));
-    CPPUNIT_ASSERT(basegfx::fTools::equal(aColorStops[1].getStopOffset(), 
0.5));
-    CPPUNIT_ASSERT_EQUAL(Color(0xc0504d), 
Color(aColorStops[1].getStopColor()));
-    CPPUNIT_ASSERT(basegfx::fTools::equal(aColorStops[2].getStopOffset(), 
1.0));
-    CPPUNIT_ASSERT_EQUAL(Color(0xd99594), 
Color(aColorStops[2].getStopColor()));
-    CPPUNIT_ASSERT_EQUAL(awt::GradientStyle_LINEAR, aGradient.Style);
+    CPPUNIT_ASSERT_EQUAL(Color(0xC0504D), Color(ColorTransparency, 
aGradient.StartColor));
+    CPPUNIT_ASSERT_EQUAL(Color(0xD99594), Color(ColorTransparency, 
aGradient.EndColor));
+    CPPUNIT_ASSERT_EQUAL(awt::GradientStyle_AXIAL, aGradient.Style);;
 
     xFrame.set(getShape(2), uno::UNO_QUERY);
     CPPUNIT_ASSERT_EQUAL(drawing::FillStyle_GRADIENT, 
getProperty<drawing::FillStyle>(xFrame, "FillStyle"));
     aGradient = getProperty<awt::Gradient2>(xFrame, "FillGradient");
-
-    // MCGR: Use the completely imported transparency gradient to check for 
correctness
-    aColorStops = model::gradient::getColorStopsFromUno(aGradient.ColorStops);
-
-    CPPUNIT_ASSERT_EQUAL(size_t(3), aColorStops.size());
-    CPPUNIT_ASSERT(basegfx::fTools::equal(aColorStops[0].getStopOffset(), 
0.0));
-    CPPUNIT_ASSERT_EQUAL(Color(0x666666), 
Color(aColorStops[0].getStopColor()));
-    CPPUNIT_ASSERT(basegfx::fTools::equal(aColorStops[1].getStopOffset(), 
0.5));
-    CPPUNIT_ASSERT_EQUAL(Color(0x000000), 
Color(aColorStops[1].getStopColor()));
-    CPPUNIT_ASSERT(basegfx::fTools::equal(aColorStops[2].getStopOffset(), 
1.0));
-    CPPUNIT_ASSERT_EQUAL(Color(0x666666), 
Color(aColorStops[2].getStopColor()));
-    CPPUNIT_ASSERT_EQUAL(awt::GradientStyle_LINEAR, aGradient.Style);
+    CPPUNIT_ASSERT_EQUAL(COL_BLACK, Color(ColorTransparency, 
aGradient.StartColor));
+    CPPUNIT_ASSERT_EQUAL(Color(0x666666), Color(ColorTransparency, 
aGradient.EndColor));
+    CPPUNIT_ASSERT_EQUAL(awt::GradientStyle_AXIAL, aGradient.Style);
 
     // Left / right margin was incorrect: the attribute was missing and we
     // didn't have the right default (had 0 instead of the below one).
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport7.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport7.cxx
index 020b9196cc72..771912c2e503 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport7.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport7.cxx
@@ -648,18 +648,11 @@ DECLARE_OOXMLEXPORT_TEST(testTdf126533_axialAngle, 
"tdf126533_axialAngle.docx")
     CPPUNIT_ASSERT_EQUAL(drawing::FillStyle_GRADIENT, 
getProperty<drawing::FillStyle>(xPageStyle, "FillStyle"));
     awt::Gradient2 aGradient = getProperty<awt::Gradient2>(xPageStyle, 
"FillGradient");
 
-    basegfx::BColorStops aColorStops = 
model::gradient::getColorStopsFromUno(aGradient.ColorStops);
-
-    CPPUNIT_ASSERT_EQUAL(size_t(3), aColorStops.size());
-    CPPUNIT_ASSERT(basegfx::fTools::equal(aColorStops[0].getStopOffset(), 
0.0));
-    CPPUNIT_ASSERT_EQUAL(COL_LIGHTMAGENTA, 
Color(aColorStops[0].getStopColor()));
-    CPPUNIT_ASSERT(basegfx::fTools::equal(aColorStops[1].getStopOffset(), 
0.5));
-    CPPUNIT_ASSERT_EQUAL(COL_LIGHTGREEN, Color(aColorStops[1].getStopColor()));
-    CPPUNIT_ASSERT(basegfx::fTools::equal(aColorStops[2].getStopOffset(), 
1.0));
-    CPPUNIT_ASSERT_EQUAL(COL_LIGHTMAGENTA, 
Color(aColorStops[2].getStopColor()));
     // without the fix, this was 1350 (visually the colors were reversed)
     CPPUNIT_ASSERT_EQUAL(sal_Int16(2250), aGradient.Angle);
-    CPPUNIT_ASSERT_EQUAL(awt::GradientStyle_LINEAR, aGradient.Style);
+    CPPUNIT_ASSERT_EQUAL(awt::GradientStyle_AXIAL, aGradient.Style);
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(COL_LIGHTGREEN), aGradient.StartColor);
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(COL_LIGHTMAGENTA), aGradient.EndColor);
 }
 
 DECLARE_OOXMLEXPORT_TEST(testTdf126533_axialAngle2, 
"tdf126533_axialAngle2.docx")
@@ -670,17 +663,10 @@ DECLARE_OOXMLEXPORT_TEST(testTdf126533_axialAngle2, 
"tdf126533_axialAngle2.docx"
     CPPUNIT_ASSERT_EQUAL(drawing::FillStyle_GRADIENT, 
getProperty<drawing::FillStyle>(xPageStyle, "FillStyle"));
     awt::Gradient2 aGradient = getProperty<awt::Gradient2>(xPageStyle, 
"FillGradient");
 
-    basegfx::BColorStops aColorStops = 
model::gradient::getColorStopsFromUno(aGradient.ColorStops);
-
-    CPPUNIT_ASSERT_EQUAL(size_t(3), aColorStops.size());
-    CPPUNIT_ASSERT(basegfx::fTools::equal(aColorStops[0].getStopOffset(), 
0.0));
-    CPPUNIT_ASSERT_EQUAL(COL_LIGHTMAGENTA, 
Color(aColorStops[0].getStopColor()));
-    CPPUNIT_ASSERT(basegfx::fTools::equal(aColorStops[1].getStopOffset(), 
0.5));
-    CPPUNIT_ASSERT_EQUAL(COL_LIGHTGREEN, Color(aColorStops[1].getStopColor()));
-    CPPUNIT_ASSERT(basegfx::fTools::equal(aColorStops[2].getStopOffset(), 
1.0));
-    CPPUNIT_ASSERT_EQUAL(COL_LIGHTMAGENTA, 
Color(aColorStops[2].getStopColor()));
+    CPPUNIT_ASSERT_EQUAL(awt::GradientStyle_AXIAL, aGradient.Style);
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(COL_LIGHTGREEN), aGradient.StartColor);
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(COL_LIGHTMAGENTA), aGradient.EndColor);
     CPPUNIT_ASSERT_EQUAL(sal_Int16(1350), aGradient.Angle);
-    CPPUNIT_ASSERT_EQUAL(awt::GradientStyle_LINEAR, aGradient.Style);
 }
 
 DECLARE_OOXMLEXPORT_TEST(testTdf77219_foregroundShape, 
"tdf77219_foregroundShape.docx")
diff --git a/sw/qa/extras/rtfexport/rtfexport.cxx 
b/sw/qa/extras/rtfexport/rtfexport.cxx
index f10270927e00..4ef9ebc9e8f3 100644
--- a/sw/qa/extras/rtfexport/rtfexport.cxx
+++ b/sw/qa/extras/rtfexport/rtfexport.cxx
@@ -634,34 +634,37 @@ DECLARE_RTFEXPORT_TEST(testTextframeGradient, 
"textframe-gradient.rtf")
     const Color aColC(0x666666);
     const Color aColD(0x000000);
 
-    // MCGR: Use the completely imported transparency gradient to check for 
correctness
-    basegfx::BColorStops aColorStops = 
model::gradient::getColorStopsFromUno(aGradient.ColorStops);
-
-    CPPUNIT_ASSERT_EQUAL(size_t(3), aColorStops.size());
-    CPPUNIT_ASSERT_EQUAL(awt::GradientStyle_LINEAR, aGradient.Style);
-    CPPUNIT_ASSERT(basegfx::fTools::equal(aColorStops[0].getStopOffset(), 
0.0));
-    CPPUNIT_ASSERT_EQUAL(aColA, Color(aColorStops[0].getStopColor()));
-    CPPUNIT_ASSERT(basegfx::fTools::equal(aColorStops[1].getStopOffset(), 
0.5));
-    CPPUNIT_ASSERT_EQUAL(aColB, Color(aColorStops[1].getStopColor()));
-    CPPUNIT_ASSERT(basegfx::fTools::equal(aColorStops[2].getStopOffset(), 
1.0));
-    CPPUNIT_ASSERT_EQUAL(aColA, Color(aColorStops[2].getStopColor()));
+    CPPUNIT_ASSERT_EQUAL(awt::GradientStyle_AXIAL, aGradient.Style);
+    CPPUNIT_ASSERT_EQUAL(aColB, Color(ColorTransparency, 
aGradient.StartColor));
+    CPPUNIT_ASSERT_EQUAL(aColA, Color(ColorTransparency, aGradient.EndColor));
 
     xFrame.set(xIndexAccess->getByIndex(1), uno::UNO_QUERY);
     CPPUNIT_ASSERT_EQUAL(drawing::FillStyle_GRADIENT,
                          getProperty<drawing::FillStyle>(xFrame, "FillStyle"));
     aGradient = getProperty<awt::Gradient2>(xFrame, "FillGradient");
 
-    // MCGR: Use the completely imported transparency gradient to check for 
correctness
-    aColorStops = model::gradient::getColorStopsFromUno(aGradient.ColorStops);
-
-    CPPUNIT_ASSERT_EQUAL(size_t(3), aColorStops.size());
-    CPPUNIT_ASSERT_EQUAL(awt::GradientStyle_LINEAR, aGradient.Style);
-    CPPUNIT_ASSERT(basegfx::fTools::equal(aColorStops[0].getStopOffset(), 
0.0));
-    CPPUNIT_ASSERT_EQUAL(aColC, Color(aColorStops[0].getStopColor()));
-    CPPUNIT_ASSERT(basegfx::fTools::equal(aColorStops[1].getStopOffset(), 
0.5));
-    CPPUNIT_ASSERT_EQUAL(aColD, Color(aColorStops[1].getStopColor()));
-    CPPUNIT_ASSERT(basegfx::fTools::equal(aColorStops[2].getStopOffset(), 
1.0));
-    CPPUNIT_ASSERT_EQUAL(aColC, Color(aColorStops[2].getStopColor()));
+    CPPUNIT_ASSERT_EQUAL(awt::GradientStyle_AXIAL, aGradient.Style);
+    CPPUNIT_ASSERT_EQUAL(aColD, Color(ColorTransparency, 
aGradient.StartColor));
+    CPPUNIT_ASSERT_EQUAL(aColC, Color(ColorTransparency, aGradient.EndColor));
+}
+
+CPPUNIT_TEST_FIXTURE(Test, testTdf159824_axialGradient)
+{
+    // given a frame with an axial gradient (white - green - white)
+    loadAndReload("tdf159824_axialGradient.odt");
+
+    uno::Reference<text::XTextFramesSupplier> xTextFramesSupplier(mxComponent, 
uno::UNO_QUERY);
+    uno::Reference<container::XIndexAccess> 
xIndexAccess(xTextFramesSupplier->getTextFrames(),
+                                                         uno::UNO_QUERY);
+    uno::Reference<beans::XPropertySet> xFrame(xIndexAccess->getByIndex(0), 
uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL(drawing::FillStyle_GRADIENT,
+                         getProperty<drawing::FillStyle>(xFrame, "FillStyle"));
+    awt::Gradient2 aGradient = getProperty<awt::Gradient2>(xFrame, 
"FillGradient");
+
+    const Color aColorGreen(0x127622); // green
+    CPPUNIT_ASSERT_EQUAL(awt::GradientStyle_AXIAL, aGradient.Style);
+    CPPUNIT_ASSERT_EQUAL(aColorGreen, Color(ColorTransparency, 
aGradient.StartColor));
+    CPPUNIT_ASSERT_EQUAL(COL_WHITE, Color(ColorTransparency, 
aGradient.EndColor));
 }
 
 DECLARE_RTFEXPORT_TEST(testRecordChanges, "record-changes.rtf")
diff --git a/sw/qa/extras/rtfexport/rtfexport8.cxx 
b/sw/qa/extras/rtfexport/rtfexport8.cxx
index 7b303f3fd3da..61a0ac2a13e2 100644
--- a/sw/qa/extras/rtfexport/rtfexport8.cxx
+++ b/sw/qa/extras/rtfexport/rtfexport8.cxx
@@ -198,18 +198,9 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf159824_axialGradient)
     const Color aColA(0x127622); // green
     const Color aColB(0xffffff); // white
 
-    // MCGR: Use the completely imported transparency gradient to check for 
correctness
-    basegfx::BColorStops aColorStops = 
model::gradient::getColorStopsFromUno(aGradient.ColorStops);
-
-    // expected: a 3-color linear gradient (or better yet a 2-color AXIAL 
gradient)
-    CPPUNIT_ASSERT_EQUAL(size_t(3), aColorStops.size());
-    CPPUNIT_ASSERT_EQUAL(awt::GradientStyle_LINEAR, aGradient.Style);
-    CPPUNIT_ASSERT(basegfx::fTools::equal(aColorStops[0].getStopOffset(), 
0.0));
-    CPPUNIT_ASSERT_EQUAL(aColB, Color(aColorStops[0].getStopColor()));
-    CPPUNIT_ASSERT(basegfx::fTools::equal(aColorStops[1].getStopOffset(), 
0.5));
-    CPPUNIT_ASSERT_EQUAL(aColA, Color(aColorStops[1].getStopColor()));
-    CPPUNIT_ASSERT(basegfx::fTools::equal(aColorStops[2].getStopOffset(), 
1.0));
-    CPPUNIT_ASSERT_EQUAL(aColB, Color(aColorStops[2].getStopColor()));
+    CPPUNIT_ASSERT_EQUAL(awt::GradientStyle_AXIAL, aGradient.Style);
+    CPPUNIT_ASSERT_EQUAL(aColA, Color(ColorTransparency, 
aGradient.StartColor));
+    CPPUNIT_ASSERT_EQUAL(aColB, Color(ColorTransparency, aGradient.EndColor));
 }
 
 DECLARE_RTFEXPORT_TEST(testTdf159824_gradientAngle1, 
"tdf159824_gradientAngle1.rtf")

Reply via email to