include/basegfx/utils/bgradient.hxx   |    2 -
 xmloff/source/style/GradientStyle.cxx |   68 ++++++++++++++++++++++------------
 2 files changed, 46 insertions(+), 24 deletions(-)

New commits:
commit 8259a99f41367a1d8326c9157fe1902915715879
Author:     Armin Le Grand (allotropia) <armin.le.grand.ext...@allotropia.de>
AuthorDate: Tue May 30 16:48:38 2023 +0200
Commit:     Armin Le Grand <armin.le.gr...@me.com>
CommitDate: Wed May 31 11:03:34 2023 +0200

    MCGR: Use tryToRecreateBorder for better BW comp with LO
    
    For better compatibility with LO versions before MCGR, try
    to re-create a 'border' value based on the existing GradientSteps.
    
    With MCGR we do not need 'border' anymore in quite some cases since
    no Start/EndColor at 0.0 resp. 1.0 is explicitely needed. Since we
    (unfortunately need to) internally continue to support border
    anyways it does no harm to fallback to use the border value - if
    there is an equivalent representation as this helper checks for.
    
    For exports that do not support 'border' this will be adapted as
    needed (see tryToApplyBorder())
    
    Change-Id: If98c64039ff97143d4b5c92ac2a950e70f5bb70a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152395
    Tested-by: Jenkins
    Reviewed-by: Armin Le Grand <armin.le.gr...@me.com>

diff --git a/include/basegfx/utils/bgradient.hxx 
b/include/basegfx/utils/bgradient.hxx
index fa9591cdb266..49598c8266fa 100644
--- a/include/basegfx/utils/bgradient.hxx
+++ b/include/basegfx/utils/bgradient.hxx
@@ -335,7 +335,7 @@ public:
     css::awt::Gradient2 getAsGradient2() const;
 
     /// Tooling to handle border correction/integration and StartStopIntensity
-    void tryToRecreateBorder(basegfx::BColorStops* 
pAssociatedTransparencyStops);
+    void tryToRecreateBorder(basegfx::BColorStops* 
pAssociatedTransparencyStops = nullptr);
     void tryToApplyBorder();
     void tryToApplyStartEndIntensity();
 };
diff --git a/xmloff/source/style/GradientStyle.cxx 
b/xmloff/source/style/GradientStyle.cxx
index fcc371c89ffb..fb1fc68fb077 100644
--- a/xmloff/source/style/GradientStyle.cxx
+++ b/xmloff/source/style/GradientStyle.cxx
@@ -34,6 +34,7 @@
 #include <xmloff/xmltkmap.hxx>
 #include <xmloff/xmltoken.hxx>
 #include <xmloff/xmluconv.hxx>
+#include <basegfx/utils/bgradient.hxx>
 
 using namespace ::com::sun::star;
 using namespace ::xmloff::token;
@@ -219,19 +220,30 @@ void XMLGradientStyleExport::exportXML(
     const OUString& rStrName,
     const uno::Any& rValue )
 {
-    awt::Gradient2 aGradient;
-
     if( rStrName.isEmpty() )
         return;
 
-    if( !(rValue >>= aGradient) )
+    if (!rValue.has<css::awt::Gradient2>() && 
!rValue.has<css::awt::Gradient>())
         return;
 
+    basegfx::BGradient aGradient(rValue);
+
+    // MCGR: For better compatibility with LO versions before MCGR, try
+    // to re-create a 'border' value based on the existing gradient stops.
+    // With MCGR we do not need 'border' anymore in quite some cases since
+    // no Start/EndColor at 0.0 resp. 1.0 is explicitely needed. Since we
+    // (unfortunately need to) internally continue to support border
+    // anyways it does no harm to fallback to use the border value - if
+    // there is an equivalent representation as this helper checks for.
+    // For exports that do not support 'border' this will be adapted as
+    // needed (see tryToApplyBorder()).
+    aGradient.tryToRecreateBorder(nullptr);
+
     OUString aStrValue;
     OUStringBuffer aOut;
 
     // Style
-    if( !SvXMLUnitConverter::convertEnum( aOut, aGradient.Style, 
pXML_GradientStyle_Enum ) )
+    if( !SvXMLUnitConverter::convertEnum( aOut, aGradient.GetGradientStyle(), 
pXML_GradientStyle_Enum ) )
         return;
 
     // Name
@@ -247,47 +259,57 @@ void XMLGradientStyleExport::exportXML(
     m_rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_STYLE, aStrValue );
 
     // Center x/y
-    if( aGradient.Style != awt::GradientStyle_LINEAR &&
-        aGradient.Style != awt::GradientStyle_AXIAL   )
+    if( aGradient.GetGradientStyle() != awt::GradientStyle_LINEAR &&
+        aGradient.GetGradientStyle() != awt::GradientStyle_AXIAL   )
     {
-        ::sax::Converter::convertPercent(aOut, aGradient.XOffset);
+        ::sax::Converter::convertPercent(aOut, aGradient.GetXOffset());
         aStrValue = aOut.makeStringAndClear();
         m_rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_CX, aStrValue );
-        ::sax::Converter::convertPercent(aOut, aGradient.YOffset);
+        ::sax::Converter::convertPercent(aOut, aGradient.GetYOffset());
         aStrValue = aOut.makeStringAndClear();
         m_rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_CY, aStrValue );
     }
 
+    // prep Start/EndColor, default black
+    basegfx::BColor aStartColor;
+    basegfx::BColor aEndColor;
+
+    if (!aGradient.GetColorStops().empty())
+    {
+        aStartColor = aGradient.GetColorStops().front().getStopColor();
+        aEndColor = aGradient.GetColorStops().back().getStopColor();
+    }
+
     // Color start
-    ::sax::Converter::convertColor(aOut, aGradient.StartColor);
+    ::sax::Converter::convertColor(aOut, Color(aStartColor));
     aStrValue = aOut.makeStringAndClear();
     m_rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_START_COLOR, aStrValue );
 
     // Color end
-    ::sax::Converter::convertColor(aOut, aGradient.EndColor);
+    ::sax::Converter::convertColor(aOut, Color(aEndColor));
     aStrValue = aOut.makeStringAndClear();
     m_rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_END_COLOR, aStrValue );
 
     // Intensity start
-    ::sax::Converter::convertPercent(aOut, aGradient.StartIntensity);
+    ::sax::Converter::convertPercent(aOut, aGradient.GetStartIntens());
     aStrValue = aOut.makeStringAndClear();
     m_rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_START_INTENSITY, aStrValue 
);
 
     // Intensity end
-    ::sax::Converter::convertPercent(aOut, aGradient.EndIntensity);
+    ::sax::Converter::convertPercent(aOut, aGradient.GetEndIntens());
     aStrValue = aOut.makeStringAndClear();
     m_rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_END_INTENSITY, aStrValue );
 
     // Angle
-    if( aGradient.Style != awt::GradientStyle_RADIAL )
+    if( aGradient.GetGradientStyle() != awt::GradientStyle_RADIAL )
     {
-        ::sax::Converter::convertAngle(aOut, aGradient.Angle, 
m_rExport.getSaneDefaultVersion());
+        ::sax::Converter::convertAngle(aOut, 
static_cast<sal_Int16>(aGradient.GetAngle()), 
m_rExport.getSaneDefaultVersion());
         aStrValue = aOut.makeStringAndClear();
         m_rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_GRADIENT_ANGLE, 
aStrValue );
     }
 
     // Border
-    ::sax::Converter::convertPercent( aOut, aGradient.Border );
+    ::sax::Converter::convertPercent( aOut, aGradient.GetBorder() );
     aStrValue = aOut.makeStringAndClear();
     m_rExport.AddAttribute( XML_NAMESPACE_DRAW, XML_BORDER, aStrValue );
 
@@ -299,15 +321,15 @@ void XMLGradientStyleExport::exportXML(
     // Do not export in standard ODF 1.3 or older.
     if ((m_rExport.getSaneDefaultVersion() & SvtSaveOptions::ODFSVER_EXTENDED) 
== 0)
         return;
-    sal_Int32 nCount = aGradient.ColorStops.getLength();
-    if (nCount == 0)
+
+    if (aGradient.GetColorStops().empty())
         return;
 
     double fPreviousOffset = 0.0;
-    for (auto& aCandidate : aGradient.ColorStops)
+    for (const auto& aCandidate : aGradient.GetColorStops())
     {
         // Attribute svg:offset. Make sure offsets are increasing.
-        double fOffset = std::clamp<double>(aCandidate.StopOffset, 0.0, 1.0);
+        double fOffset = std::clamp<double>(aCandidate.getStopOffset(), 0.0, 
1.0);
         if (fOffset < fPreviousOffset)
             fOffset = fPreviousOffset;
         m_rExport.AddAttribute(XML_NAMESPACE_SVG, XML_OFFSET, 
OUString::number(fOffset));
@@ -317,10 +339,10 @@ void XMLGradientStyleExport::exportXML(
         m_rExport.AddAttribute(XML_NAMESPACE_LO_EXT, XML_COLOR_TYPE, u"rgb");
 
         // Attribute loext:color-value, data type color, that is #rrggbb.
-        rendering::RGBColor aDecimalColor = aCandidate.StopColor;
-        ::Color aToolsColor(std::clamp<sal_uInt8>(std::round(aDecimalColor.Red 
* 255.0), 0, 255),
-                            
std::clamp<sal_uInt8>(std::round(aDecimalColor.Green * 255.0), 0, 255),
-                            
std::clamp<sal_uInt8>(std::round(aDecimalColor.Blue * 255.0), 0, 255));
+        const basegfx::BColor aDecimalColor(aCandidate.getStopColor());
+        ::Color 
aToolsColor(std::clamp<sal_uInt8>(std::round(aDecimalColor.getRed() * 255.0), 
0, 255),
+                            
std::clamp<sal_uInt8>(std::round(aDecimalColor.getGreen() * 255.0), 0, 255),
+                            
std::clamp<sal_uInt8>(std::round(aDecimalColor.getBlue() * 255.0), 0, 255));
         m_rExport.AddAttribute(XML_NAMESPACE_LO_EXT, XML_COLOR_VALUE,
                              rtl::OUStringChar('#') + 
aToolsColor.AsRGBHexString());
 

Reply via email to