drawingML export: gradient fill defined by imported theme

Plus avoid writing out empty <a:gradFill></a:gradFill>.

Change-Id: I50fa92b2cc30eedfe28a8c6af697d43d98a3aee8
This commit is contained in:
Zolnai Tamás
2014-02-20 11:48:35 +01:00
parent 1d512fb31c
commit 191f648ffd
4 changed files with 40 additions and 5 deletions

View File

@@ -853,7 +853,10 @@ Reference< XShape > Shape::createAndInsert(
PUT_PROP( aGradientStops, i, OUString::number( i ), aGradientStop );
++aIt;
}
putPropertyToGrabBag( "GradFillDefinition", Any( aGradientStops ) );
// If getFillProperties.moFillType is unused that means gradient is defined by a theme
// which is already saved into StyleFillRef property, so no need to save the explicit values too
if( getFillProperties().moFillType.has() )
putPropertyToGrabBag( "GradFillDefinition", Any( aGradientStops ) );
putPropertyToGrabBag( "OriginalGradFill", Any( aShapeProps[PROP_FillGradient] ) );
}
}

View File

@@ -339,15 +339,23 @@ void DrawingML::WriteGradientFill( Reference< XPropertySet > rXPropSet )
aGrabBag[i].Value >>= aOriginalGradient;
}
mpFS->startElementNS( XML_a, XML_gradFill, FSEND );
// check if an ooxml gradient had been imported and if the user has modified it
if( aGradientStops.hasElements() && EqualGradients( aOriginalGradient, aGradient ) )
if( EqualGradients( aOriginalGradient, aGradient ) )
{
WriteGrabBagGradientFill(aGradientStops, aGradient);
// If we have no gradient stops that means original gradient were defined by a theme.
if( aGradientStops.hasElements() )
{
mpFS->startElementNS( XML_a, XML_gradFill, FSEND );
WriteGrabBagGradientFill(aGradientStops, aGradient);
mpFS->endElementNS( XML_a, XML_gradFill );
}
}
else
{
mpFS->startElementNS( XML_a, XML_gradFill, FSEND );
WriteGradientFill(aGradient);
mpFS->endElementNS( XML_a, XML_gradFill );
mpFS->endElementNS( XML_a, XML_gradFill );
}
}
}

View File

@@ -3318,6 +3318,30 @@ DECLARE_OOXMLEXPORT_TEST(testDMLGroupShapeChildPosition, "dml-groupshape-childpo
CPPUNIT_ASSERT_EQUAL(sal_Int32(m_bExported ? -2119 : -2121), xChildGroup->getPosition().X);
CPPUNIT_ASSERT_EQUAL(sal_Int32(m_bExported ? 14028 : 14025), xChildGroup->getPosition().Y);
}
DECLARE_OOXMLEXPORT_TEST(testDMLGradientFillTheme, "dml-gradientfill-theme.docx")
{
// Problem was when a fill gradient was imported from a theme, (fillRef in ooxml)
// not just the theme was written out but the explicit values too
// Besides the duplication of values it causes problems with writing out
// <a:schemeClr val="phClr"> into document.xml, while phClr can be used just for theme definitions.
xmlDocPtr pXmlDoc = parseExport("word/document.xml");
if (!pXmlDoc)
return;
// check no explicit gradFill has been exported
assertXPath(pXmlDoc,
"/w:document/w:body/w:p[2]/w:r/mc:AlternateContent[1]/mc:Choice/w:drawing/wp:anchor/a:graphic/a:graphicData/wps:wsp/wps:spPr/a:gradFill",
0);
// check shape style has been exported
assertXPath(pXmlDoc,
"/w:document/w:body/w:p[2]/w:r/mc:AlternateContent/mc:Choice/w:drawing/wp:anchor/a:graphic/a:graphicData/wps:wsp/wps:style/a:fillRef",
"idx", "2");
assertXPath(pXmlDoc,
"/w:document/w:body/w:p[2]/w:r/mc:AlternateContent/mc:Choice/w:drawing/wp:anchor/a:graphic/a:graphicData/wps:wsp/wps:style/a:fillRef/a:schemeClr",
"val", "accent1");
}
#endif
CPPUNIT_PLUGIN_IMPLEMENT();