sw/qa/extras/rtfexport/data/tdf159824_axialGradient.odt |binary
 sw/qa/extras/rtfexport/rtfexport8.cxx                   |   34 ++++++++++++++++
 sw/source/filter/ww8/rtfattributeoutput.cxx             |    6 ++
 3 files changed, 40 insertions(+)

New commits:
commit 9ba68c769d41d1075152a22bf37e78fb9320317b
Author:     Justin Luth <jl...@mail.com>
AuthorDate: Wed Feb 21 11:52:36 2024 -0500
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Fri Feb 23 11:01:19 2024 +0100

    tdf#159824 MCGR rtf export: don't lose gradient's axial-ness
    
    This fixes alg's 7.6 regression from
    commit bb198176684c3d9377e26c04a29ec66deb811949
    
    Found when trying to import these strung-out-linears
    as real axials.
    
    make CppunitTest_sw_rtfexport \
        CPPUNIT_TEST_NAME=testTdf159824_axialGradient
    
    Change-Id: I220f1bf689b4b219bc0ae187e95aedb1a29a7233
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/163705
    Tested-by: Jenkins
    Reviewed-by: Justin Luth <jl...@mail.com>
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/sw/qa/extras/rtfexport/data/tdf159824_axialGradient.odt 
b/sw/qa/extras/rtfexport/data/tdf159824_axialGradient.odt
new file mode 100644
index 000000000000..c1ce5cd31d2a
Binary files /dev/null and 
b/sw/qa/extras/rtfexport/data/tdf159824_axialGradient.odt differ
diff --git a/sw/qa/extras/rtfexport/rtfexport8.cxx 
b/sw/qa/extras/rtfexport/rtfexport8.cxx
index c78298cdddd0..ab787919dfa9 100644
--- a/sw/qa/extras/rtfexport/rtfexport8.cxx
+++ b/sw/qa/extras/rtfexport/rtfexport8.cxx
@@ -10,6 +10,8 @@
 #include <swmodeltestbase.hxx>
 
 #include <com/sun/star/awt/FontWeight.hpp>
+#include <com/sun/star/awt/Gradient2.hpp>
+#include <com/sun/star/drawing/FillStyle.hpp>
 #include <com/sun/star/text/GraphicCrop.hpp>
 #include <com/sun/star/text/XFootnote.hpp>
 #include <com/sun/star/text/XFootnotesSupplier.hpp>
@@ -21,7 +23,9 @@
 #include <com/sun/star/style/ParagraphAdjust.hpp>
 #include <com/sun/star/style/TabStop.hpp>
 
+#include <basegfx/utils/gradienttools.hxx>
 #include <comphelper/sequenceashashmap.hxx>
+#include <docmodel/uno/UnoGradientTools.hxx>
 #include <tools/UnitConversion.hxx>
 #include <comphelper/propertyvalue.hxx>
 
@@ -178,6 +182,36 @@ DECLARE_RTFEXPORT_TEST(testTdf158826_extraCR, 
"tdf158826_extraCR.rtf")
     uno::Reference<text::XTextTable> xTable(getParagraphOrTable(1), 
uno::UNO_QUERY_THROW);
 }
 
+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 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()));
+}
+
 DECLARE_RTFEXPORT_TEST(testTdf158830, "tdf158830.rtf")
 {
     //check centered text in table
diff --git a/sw/source/filter/ww8/rtfattributeoutput.cxx 
b/sw/source/filter/ww8/rtfattributeoutput.cxx
index 6d9271417fda..cdf6d5ce9bd1 100644
--- a/sw/source/filter/ww8/rtfattributeoutput.cxx
+++ b/sw/source/filter/ww8/rtfattributeoutput.cxx
@@ -3751,6 +3751,12 @@ void RtfAttributeOutput::FormatFillGradient(const 
XFillGradientItem& rFillGradie
         const Color aEndColor(rColorStops.back().getStopColor());
         m_aFlyProperties.push_back(std::make_pair<OString, OString>(
             "fillBackColor"_ostr, 
OString::number(wwUtility::RGBToBGR(aEndColor))));
+
+        if (rGradient.GetGradientStyle() == awt::GradientStyle_AXIAL)
+        {
+            m_aFlyProperties.push_back(
+                std::make_pair<OString, OString>("fillFocus"_ostr, 
OString::number(50)));
+        }
     }
     else
     {

Reply via email to