[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-5.3' - include/oox oox/source sd/qa

Szymon Kłos szymon.klos at collabora.com
Tue Sep 26 09:38:28 UTC 2017


 include/oox/drawingml/fillproperties.hxx            |    2 -
 oox/source/drawingml/fillproperties.cxx             |   17 ++++++++++----
 oox/source/drawingml/fillpropertiesgroupcontext.cxx |    3 +-
 oox/source/drawingml/shape.cxx                      |    2 -
 oox/source/vml/vmlformatting.cxx                    |   23 ++++++++++++++------
 sd/qa/unit/data/pptx/tdf112088.pptx                 |binary
 sd/qa/unit/export-tests-ooxml2.cxx                  |   14 ++++++++++++
 7 files changed, 47 insertions(+), 14 deletions(-)

New commits:
commit a5853d13d3cab93e666301e90da786d55d02f1ee
Author: Szymon Kłos <szymon.klos at collabora.com>
Date:   Tue Sep 12 13:26:35 2017 +0200

    tdf#112088 gradient stop map -> multimap
    
    When two gradientstops were set to position 50%
    only one was stored and the exported file was
    detected as broken by MSO.
    
    Change-Id: I5fd1acde6051f734a5f3e4cff9bde01b675e1984
    Reviewed-on: https://gerrit.libreoffice.org/42210
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Szymon Kłos <szymon.klos at collabora.com>
    Reviewed-on: https://gerrit.libreoffice.org/42473
    Reviewed-by: Andras Timar <andras.timar at collabora.com>
    Tested-by: Andras Timar <andras.timar at collabora.com>

diff --git a/include/oox/drawingml/fillproperties.hxx b/include/oox/drawingml/fillproperties.hxx
index bed67d6fcc46..ef863c2a348e 100644
--- a/include/oox/drawingml/fillproperties.hxx
+++ b/include/oox/drawingml/fillproperties.hxx
@@ -48,7 +48,7 @@ class ShapePropertyMap;
 
 struct GradientFillProperties
 {
-    typedef ::std::map< double, Color > GradientStopMap;
+    typedef ::std::multimap< double, Color > GradientStopMap;
 
     GradientStopMap     maGradientStops;        /// Gradient stops (colors/transparence).
     OptValue< css::geometry::IntegerRectangle2D > moFillToRect;
diff --git a/oox/source/drawingml/fillproperties.cxx b/oox/source/drawingml/fillproperties.cxx
index ed01746b4c64..dc93623b9f6b 100644
--- a/oox/source/drawingml/fillproperties.cxx
+++ b/oox/source/drawingml/fillproperties.cxx
@@ -385,18 +385,20 @@ void FillProperties::pushToPropMap( ShapePropertyMap& rPropMap,
 
                         // Add a fake gradient stop at 0% and 100% if necessary, so that the gradient always starts
                         // at 0% and ends at 100%, to make following logic clearer (?).
-                        if( aGradientStops.find(0.0) == aGradientStops.end() )
+                        auto a0 = aGradientStops.find( 0.0 );
+                        if( a0 == aGradientStops.end() )
                         {
                             // temp variable required
                             Color aFirstColor(aGradientStops.begin()->second);
-                            aGradientStops[0.0] = aFirstColor;
+                            aGradientStops.emplace( 0.0, aFirstColor );
                         }
 
-                        if( aGradientStops.find(1.0) == aGradientStops.end() )
+                        auto a1 = aGradientStops.find( 1.0 );
+                        if( a1 == aGradientStops.end() )
                         {
                             // ditto
                             Color aLastColor(aGradientStops.rbegin()->second);
-                            aGradientStops[1.0] = aLastColor;
+                            aGradientStops.emplace( 1.0, aLastColor );
                         }
 
                         // Check if the gradient is symmetric, which we will emulate with an "axial" gradient.
@@ -427,7 +429,12 @@ void FillProperties::pushToPropMap( ShapePropertyMap& rPropMap,
                                 if( aItA->first != aItZ->first )
                                 {
                                     Color aMiddleColor = aItZ->second;
-                                    aGradientStops[0.5] = aMiddleColor;
+                                    auto a05 = aGradientStops.find( 0.5 );
+
+                                    if( a05 != aGradientStops.end() )
+                                        a05->second = aMiddleColor;
+                                    else
+                                        aGradientStops.emplace( 0.5, aMiddleColor );
                                 }
                                 // Drop the rest of the stops
                                 while( aGradientStops.rbegin()->first > 0.5 )
diff --git a/oox/source/drawingml/fillpropertiesgroupcontext.cxx b/oox/source/drawingml/fillpropertiesgroupcontext.cxx
index 22d68faabeb9..7214af4f7016 100644
--- a/oox/source/drawingml/fillpropertiesgroupcontext.cxx
+++ b/oox/source/drawingml/fillpropertiesgroupcontext.cxx
@@ -63,7 +63,8 @@ ContextHandlerRef GradientFillContext::onCreateContext(
             if( rAttribs.hasAttribute( XML_pos ) )
             {
                 double fPosition = getLimitedValue< double >( rAttribs.getDouble( XML_pos, 0.0 ) / 100000.0, 0.0, 1.0 );
-                return new ColorContext( *this, mrGradientProps.maGradientStops[ fPosition ] );
+                auto aElement = mrGradientProps.maGradientStops.emplace( fPosition, Color() );
+                return new ColorContext( *this, aElement->second );
             }
         break;
 
diff --git a/oox/source/drawingml/shape.cxx b/oox/source/drawingml/shape.cxx
index 2090057cb2b1..378aeb71171c 100644
--- a/oox/source/drawingml/shape.cxx
+++ b/oox/source/drawingml/shape.cxx
@@ -967,7 +967,7 @@ Reference< XShape > const & Shape::createAndInsert(
             if( aShapeProps.hasProperty( PROP_FillGradient ) )
             {
                 Sequence< PropertyValue > aGradientStops( aFillProperties.maGradientProps.maGradientStops.size() );
-                ::std::map< double, Color >::iterator aIt = aFillProperties.maGradientProps.maGradientStops.begin();
+                auto aIt = aFillProperties.maGradientProps.maGradientStops.begin();
                 for( size_t i = 0; i < aFillProperties.maGradientProps.maGradientStops.size(); ++i )
                 { // for each stop in the gradient definition:
 
diff --git a/oox/source/vml/vmlformatting.cxx b/oox/source/vml/vmlformatting.cxx
index d8183227d6e6..dc1edd877271 100644
--- a/oox/source/vml/vmlformatting.cxx
+++ b/oox/source/vml/vmlformatting.cxx
@@ -682,6 +682,15 @@ void FillModel::assignUsed( const FillModel& rSource )
     moRotate.assignIfUsed( rSource.moRotate );
 }
 
+void lcl_setGradientStop( std::multimap< double, Color >& rMap, const double fKey, const Color& rValue ) {
+    auto aElement = rMap.find( fKey );
+
+    if (aElement != rMap.end())
+        aElement->second = rValue;
+    else
+        rMap.emplace( fKey, rValue );
+}
+
 void FillModel::pushToPropMap( ShapePropertyMap& rPropMap, const GraphicHelper& rGraphicHelper ) const
 {
     /*  Convert VML fill formatting to DrawingML fill formatting and let the
@@ -723,8 +732,10 @@ void FillModel::pushToPropMap( ShapePropertyMap& rPropMap, const GraphicHelper&
                         // simulate axial gradient by 3-step DrawingML gradient
                         const Color& rOuterColor = bOuterToInner ? aColor1 : aColor2;
                         const Color& rInnerColor = bOuterToInner ? aColor2 : aColor1;
-                        aFillProps.maGradientProps.maGradientStops[ 0.0 ] = aFillProps.maGradientProps.maGradientStops[ 1.0 ] = rOuterColor;
-                        aFillProps.maGradientProps.maGradientStops[ 0.5 ] = rInnerColor;
+
+                        lcl_setGradientStop( aFillProps.maGradientProps.maGradientStops, 0.0, rOuterColor);
+                        lcl_setGradientStop( aFillProps.maGradientProps.maGradientStops, 1.0, rOuterColor);
+                        lcl_setGradientStop( aFillProps.maGradientProps.maGradientStops, 0.5, rInnerColor );
                     }
                     else    // focus of -100%, 0%, and 100% is linear gradient
                     {
@@ -736,8 +747,8 @@ void FillModel::pushToPropMap( ShapePropertyMap& rPropMap, const GraphicHelper&
                         if( fFocus < -0.5 || fFocus > 0.5 )
                             (nVmlAngle += 180) %= 360;
                         // set the start and stop colors
-                        aFillProps.maGradientProps.maGradientStops[ 0.0 ] = aColor1;
-                        aFillProps.maGradientProps.maGradientStops[ 1.0 ] = aColor2;
+                        lcl_setGradientStop( aFillProps.maGradientProps.maGradientStops, 0.0, aColor1 );
+                        lcl_setGradientStop( aFillProps.maGradientProps.maGradientStops, 1.0, aColor2 );
                     }
 
                     // VML counts counterclockwise from bottom, DrawingML clockwise from left
@@ -762,8 +773,8 @@ void FillModel::pushToPropMap( ShapePropertyMap& rPropMap, const GraphicHelper&
 
                     // set the start and stop colors (focus of 0% means outer-to-inner)
                     bool bOuterToInner = (-0.5 <= fFocus) && (fFocus <= 0.5);
-                    aFillProps.maGradientProps.maGradientStops[ 0.0 ] = bOuterToInner ? aColor2 : aColor1;
-                    aFillProps.maGradientProps.maGradientStops[ 1.0 ] = bOuterToInner ? aColor1 : aColor2;
+                    lcl_setGradientStop( aFillProps.maGradientProps.maGradientStops, 0.0, bOuterToInner ? aColor2 : aColor1 );
+                    lcl_setGradientStop( aFillProps.maGradientProps.maGradientStops, 1.0, bOuterToInner ? aColor1 : aColor2 );
                 }
             }
             break;
diff --git a/sd/qa/unit/data/pptx/tdf112088.pptx b/sd/qa/unit/data/pptx/tdf112088.pptx
new file mode 100755
index 000000000000..5ad58192e5bb
Binary files /dev/null and b/sd/qa/unit/data/pptx/tdf112088.pptx differ
diff --git a/sd/qa/unit/export-tests-ooxml2.cxx b/sd/qa/unit/export-tests-ooxml2.cxx
index 13accd5e5c13..eee4dadbbeb5 100644
--- a/sd/qa/unit/export-tests-ooxml2.cxx
+++ b/sd/qa/unit/export-tests-ooxml2.cxx
@@ -109,6 +109,7 @@ public:
     void testTdf112280();
     void testTdf112552();
     void testTdf112557();
+    void testTdf112088();
 
     CPPUNIT_TEST_SUITE(SdOOXMLExportTest2);
 
@@ -141,6 +142,7 @@ public:
     CPPUNIT_TEST(testTdf112280);
     CPPUNIT_TEST(testTdf112552);
     CPPUNIT_TEST(testTdf112557);
+    CPPUNIT_TEST(testTdf112088);
 
     CPPUNIT_TEST_SUITE_END();
 
@@ -886,6 +888,18 @@ void SdOOXMLExportTest2::testTdf112557()
     xDocShRef->DoClose();
 }
 
+void SdOOXMLExportTest2::testTdf112088()
+{
+    ::sd::DrawDocShellRef xDocShRef = loadURL(m_directories.getURLFromSrc("sd/qa/unit/data/pptx/tdf112088.pptx"), PPTX);
+    utl::TempFile tempFile;
+    xDocShRef = saveAndReload(xDocShRef.get(), PPTX, &tempFile);
+    xDocShRef->DoClose();
+
+    // check gradient stops
+    xmlDocPtr pXmlDocContent = parseExport(tempFile, "ppt/slides/slide1.xml");
+    assertXPathChildren(pXmlDocContent, "/p:sld/p:cSld/p:spTree/p:sp[3]/p:spPr/a:gradFill/a:gsLst", 2);
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(SdOOXMLExportTest2);
 
 CPPUNIT_PLUGIN_IMPLEMENT();


More information about the Libreoffice-commits mailing list