diff options
author | Szymon Kłos <szymon.klos@collabora.com> | 2017-09-12 13:26:35 +0200 |
---|---|---|
committer | Andras Timar <andras.timar@collabora.com> | 2017-09-26 11:38:08 +0200 |
commit | a5853d13d3cab93e666301e90da786d55d02f1ee (patch) | |
tree | 3376828def1b66b8ebb07b91f78bb8c958c3cd5f /oox | |
parent | 3a2da5ebadd45511b5505fb72d9ca2d4254304cc (diff) |
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@libreoffice.org>
Reviewed-by: Szymon Kłos <szymon.klos@collabora.com>
Reviewed-on: https://gerrit.libreoffice.org/42473
Reviewed-by: Andras Timar <andras.timar@collabora.com>
Tested-by: Andras Timar <andras.timar@collabora.com>
Diffstat (limited to 'oox')
-rw-r--r-- | oox/source/drawingml/fillproperties.cxx | 17 | ||||
-rw-r--r-- | oox/source/drawingml/fillpropertiesgroupcontext.cxx | 3 | ||||
-rw-r--r-- | oox/source/drawingml/shape.cxx | 2 | ||||
-rw-r--r-- | oox/source/vml/vmlformatting.cxx | 23 |
4 files changed, 32 insertions, 13 deletions
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; |