summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSzymon Kłos <szymon.klos@collabora.com>2017-09-12 13:26:35 +0200
committerSzymon Kłos <szymon.klos@collabora.com>2017-09-18 15:42:12 +0200
commit89879b0051529cb8d16da6c8b4b1203679f8f734 (patch)
tree46fa6ec9fe412a94813bc07d6344c15bd5135db2
parent0f3b52bc2c289dd5684b6661bf335e9aa92d48db (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>
-rw-r--r--oox/inc/drawingml/fillproperties.hxx2
-rw-r--r--oox/source/drawingml/fillproperties.cxx17
-rw-r--r--oox/source/drawingml/misccontexts.cxx3
-rw-r--r--oox/source/drawingml/shape.cxx2
-rw-r--r--oox/source/vml/vmlformatting.cxx23
-rwxr-xr-xsd/qa/unit/data/pptx/tdf112088.pptxbin0 -> 30317 bytes
-rw-r--r--sd/qa/unit/export-tests-ooxml2.cxx14
7 files changed, 47 insertions, 14 deletions
diff --git a/oox/inc/drawingml/fillproperties.hxx b/oox/inc/drawingml/fillproperties.hxx
index 15b503161440..affd8e1602eb 100644
--- a/oox/inc/drawingml/fillproperties.hxx
+++ b/oox/inc/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 925db22fb5f9..d18f6249b0fc 100644
--- a/oox/source/drawingml/fillproperties.cxx
+++ b/oox/source/drawingml/fillproperties.cxx
@@ -379,18 +379,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.
@@ -421,7 +423,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/misccontexts.cxx b/oox/source/drawingml/misccontexts.cxx
index 499d5137b8b2..6e0d7651bcc5 100644
--- a/oox/source/drawingml/misccontexts.cxx
+++ b/oox/source/drawingml/misccontexts.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 e75f6e8ca3d1..ddf829bcea5a 100644
--- a/oox/source/drawingml/shape.cxx
+++ b/oox/source/drawingml/shape.cxx
@@ -999,7 +999,7 @@ Reference< XShape > const & Shape::createAndInsert(
if( aShapeProps.hasProperty( PROP_FillGradient ) )
{
std::vector<beans::PropertyValue> aGradientStops;
- ::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 86443dd5c298..e87bdab45f29 100644
--- a/oox/source/vml/vmlformatting.cxx
+++ b/oox/source/vml/vmlformatting.cxx
@@ -708,6 +708,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
@@ -749,8 +758,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
{
@@ -762,8 +773,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
@@ -788,8 +799,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
--- /dev/null
+++ b/sd/qa/unit/data/pptx/tdf112088.pptx
Binary files differ
diff --git a/sd/qa/unit/export-tests-ooxml2.cxx b/sd/qa/unit/export-tests-ooxml2.cxx
index 999d0744b562..820f02723c52 100644
--- a/sd/qa/unit/export-tests-ooxml2.cxx
+++ b/sd/qa/unit/export-tests-ooxml2.cxx
@@ -106,6 +106,7 @@ public:
void testRotateFlip();
void testTdf106867();
void testTdf112280();
+ void testTdf112088();
CPPUNIT_TEST_SUITE(SdOOXMLExportTest2);
@@ -139,6 +140,7 @@ public:
CPPUNIT_TEST(testRotateFlip);
CPPUNIT_TEST(testTdf106867);
CPPUNIT_TEST(testTdf112280);
+ CPPUNIT_TEST(testTdf112088);
CPPUNIT_TEST_SUITE_END();
@@ -1039,6 +1041,18 @@ void SdOOXMLExportTest2::testTdf112280()
"by", "21600000");
}
+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();