Kaydet (Commit) 71b4af85 authored tarafından Jacobo Aragunde Pérez's avatar Jacobo Aragunde Pérez

ooxml: Preserve outer shadow effect on shapes.

The goal is preserving the shadow effect with all its attributes using
the shape grab bag. This is the relevant piece of XML in the document:

    <a:effectLst>
      <a:outerShdw blurRad="50800" dist="38100"
      dir="2700000" algn="tl" rotWithShape="0">
        <a:schemeClr val="accent1">
          <a:alpha val="40000" />
        </a:schemeClr>
      </a:outerShdw>
    </a:effectLst>

In first place, we added members to the structure EffectProperties to
store the effect name and attributes. Later, when we create the shape,
we add them to the shape grab bag together with the shadow color (if
it is a theme color we store its name and transformations like in
other cases). Finally, we read back all these data from the shape grab
bag and write them back to the document.

I added a unit test for this shape property.

Change-Id: Idda2d5e2970cb8563e2ed13a84b2fa2d4b99aa70
üst 5d2826da
...@@ -34,6 +34,10 @@ struct OOX_DLLPUBLIC EffectProperties ...@@ -34,6 +34,10 @@ struct OOX_DLLPUBLIC EffectProperties
{ {
EffectShadowProperties maShadow; EffectShadowProperties maShadow;
/** Store unsupported effect type name and its attributes */
OptValue< OUString > msUnsupportedEffectName;
std::vector< css::beans::PropertyValue > maUnsupportedEffectAttribs;
/** Overwrites all members that are explicitly set in rSourceProps. */ /** Overwrites all members that are explicitly set in rSourceProps. */
void assignUsed( const EffectProperties& rSourceProps ); void assignUsed( const EffectProperties& rSourceProps );
...@@ -41,6 +45,9 @@ struct OOX_DLLPUBLIC EffectProperties ...@@ -41,6 +45,9 @@ struct OOX_DLLPUBLIC EffectProperties
void pushToPropMap( void pushToPropMap(
PropertyMap& rPropMap, PropertyMap& rPropMap,
const GraphicHelper& rGraphicHelper ) const; const GraphicHelper& rGraphicHelper ) const;
void appendUnsupportedEffectAttrib( const OUString& aKey, const css::uno::Any& aValue );
css::beans::PropertyValue getUnsupportedEffect();
}; };
......
...@@ -173,6 +173,7 @@ public: ...@@ -173,6 +173,7 @@ public:
void WritePolyPolygon( const PolyPolygon& rPolyPolygon ); void WritePolyPolygon( const PolyPolygon& rPolyPolygon );
void WriteFill( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xPropSet ); void WriteFill( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xPropSet );
void WriteShapeStyle( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > rXPropSet ); void WriteShapeStyle( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > rXPropSet );
void WriteShapeEffects( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > rXPropSet );
static void ResetCounters(); static void ResetCounters();
......
...@@ -30,6 +30,8 @@ void EffectShadowProperties::assignUsed(const EffectShadowProperties& rSourcePro ...@@ -30,6 +30,8 @@ void EffectShadowProperties::assignUsed(const EffectShadowProperties& rSourcePro
void EffectProperties::assignUsed( const EffectProperties& rSourceProps ) void EffectProperties::assignUsed( const EffectProperties& rSourceProps )
{ {
maShadow.assignUsed(rSourceProps.maShadow); maShadow.assignUsed(rSourceProps.maShadow);
msUnsupportedEffectName.assignIfUsed( rSourceProps.msUnsupportedEffectName );
maUnsupportedEffectAttribs = rSourceProps.maUnsupportedEffectAttribs;
} }
void EffectProperties::pushToPropMap( PropertyMap& rPropMap, void EffectProperties::pushToPropMap( PropertyMap& rPropMap,
...@@ -51,6 +53,34 @@ void EffectProperties::pushToPropMap( PropertyMap& rPropMap, ...@@ -51,6 +53,34 @@ void EffectProperties::pushToPropMap( PropertyMap& rPropMap,
} }
} }
void EffectProperties::appendUnsupportedEffectAttrib( const OUString& aKey, const css::uno::Any& aValue )
{
css::beans::PropertyValue aProperty;
aProperty.Name = aKey;
aProperty.Value = aValue;
maUnsupportedEffectAttribs.push_back(aProperty);
}
css::beans::PropertyValue EffectProperties::getUnsupportedEffect()
{
css::beans::PropertyValue pRet;
if(!msUnsupportedEffectName.has())
return pRet;
css::uno::Sequence<css::beans::PropertyValue> aSeq(maUnsupportedEffectAttribs.size());
css::beans::PropertyValue* pSeq = aSeq.getArray();
for (std::vector<css::beans::PropertyValue>::iterator i = maUnsupportedEffectAttribs.begin(); i != maUnsupportedEffectAttribs.end(); ++i)
*pSeq++ = *i;
pRet.Name = msUnsupportedEffectName.use();
pRet.Value = css::uno::Any( aSeq );
msUnsupportedEffectName.reset();
maUnsupportedEffectAttribs.clear();
return pRet;
}
} // namespace drawingml } // namespace drawingml
......
...@@ -39,6 +39,35 @@ ContextHandlerRef EffectPropertiesContext::onCreateContext( sal_Int32 nElement, ...@@ -39,6 +39,35 @@ ContextHandlerRef EffectPropertiesContext::onCreateContext( sal_Int32 nElement,
{ {
case A_TOKEN( outerShdw ): case A_TOKEN( outerShdw ):
{ {
mrEffectProperties.msUnsupportedEffectName = "outerShdw";
if( rAttribs.hasAttribute( XML_algn ) )
mrEffectProperties.appendUnsupportedEffectAttrib( "algn",
makeAny( rAttribs.getString( XML_algn, "" ) ) );
if( rAttribs.hasAttribute( XML_blurRad ) )
mrEffectProperties.appendUnsupportedEffectAttrib( "blurRad",
makeAny( rAttribs.getInteger( XML_blurRad, 0 ) ) );
if( rAttribs.hasAttribute( XML_dir ) )
mrEffectProperties.appendUnsupportedEffectAttrib( "dir",
makeAny( rAttribs.getInteger( XML_dir, 0 ) ) );
if( rAttribs.hasAttribute( XML_dist ) )
mrEffectProperties.appendUnsupportedEffectAttrib( "dist",
makeAny( rAttribs.getInteger( XML_dist, 0 ) ) );
if( rAttribs.hasAttribute( XML_kx ) )
mrEffectProperties.appendUnsupportedEffectAttrib( "kx",
makeAny( rAttribs.getInteger( XML_kx, 0 ) ) );
if( rAttribs.hasAttribute( XML_ky ) )
mrEffectProperties.appendUnsupportedEffectAttrib( "ky",
makeAny( rAttribs.getInteger( XML_ky, 0 ) ) );
if( rAttribs.hasAttribute( XML_rotWithShape ) )
mrEffectProperties.appendUnsupportedEffectAttrib( "rotWithShape",
makeAny( rAttribs.getInteger( XML_rotWithShape, 0 ) ) );
if( rAttribs.hasAttribute( XML_sx ) )
mrEffectProperties.appendUnsupportedEffectAttrib( "sx",
makeAny( rAttribs.getInteger( XML_sx, 0 ) ) );
if( rAttribs.hasAttribute( XML_sy ) )
mrEffectProperties.appendUnsupportedEffectAttrib( "sy",
makeAny( rAttribs.getInteger( XML_sy, 0 ) ) );
mrEffectProperties.maShadow.moShadowDist = rAttribs.getInteger( XML_dist, 0 ); mrEffectProperties.maShadow.moShadowDist = rAttribs.getInteger( XML_dist, 0 );
mrEffectProperties.maShadow.moShadowDir = rAttribs.getInteger( XML_dir, 0 ); mrEffectProperties.maShadow.moShadowDir = rAttribs.getInteger( XML_dir, 0 );
return new ColorContext( *this, mrEffectProperties.maShadow.moShadowColor ); return new ColorContext( *this, mrEffectProperties.maShadow.moShadowColor );
......
...@@ -893,6 +893,33 @@ Reference< XShape > Shape::createAndInsert( ...@@ -893,6 +893,33 @@ Reference< XShape > Shape::createAndInsert(
putPropertyToGrabBag( "GradFillDefinition", Any( aGradientStops ) ); putPropertyToGrabBag( "GradFillDefinition", Any( aGradientStops ) );
putPropertyToGrabBag( "OriginalGradFill", aShapeProps.getProperty(PROP_FillGradient) ); putPropertyToGrabBag( "OriginalGradFill", aShapeProps.getProperty(PROP_FillGradient) );
} }
// store unsupported effect attributes in the grab bag
PropertyValue aEffect = aEffectProperties.getUnsupportedEffect();
if( aEffect.Name != "" )
{
Sequence< PropertyValue > aEffectsGrabBag( 3 );
PUT_PROP( aEffectsGrabBag, 0, aEffect.Name, aEffect.Value );
OUString sColorScheme = aEffectProperties.maShadow.moShadowColor.getSchemeName();
if( sColorScheme.isEmpty() )
{
// RGB color and transparency value
PUT_PROP( aEffectsGrabBag, 1, "ShadowRgbClr",
aEffectProperties.maShadow.moShadowColor.getColor( rGraphicHelper, nFillPhClr ) );
PUT_PROP( aEffectsGrabBag, 2, "ShadowRgbClrTransparency",
aEffectProperties.maShadow.moShadowColor.getTransparency() );
}
else
{
// scheme color with name and transformations
PUT_PROP( aEffectsGrabBag, 1, "ShadowColorSchemeClr", sColorScheme );
PUT_PROP( aEffectsGrabBag, 2, "ShadowColorTransformations",
aEffectProperties.maShadow.moShadowColor.getTransformations() );
}
putPropertyToGrabBag( "EffectProperties", Any( aEffectsGrabBag ) );
}
} }
// These can have a custom geometry, so position should be set here, // These can have a custom geometry, so position should be set here,
......
...@@ -2076,6 +2076,124 @@ void DrawingML::WriteShapeStyle( Reference< XPropertySet > xPropSet ) ...@@ -2076,6 +2076,124 @@ void DrawingML::WriteShapeStyle( Reference< XPropertySet > xPropSet )
mpFS->singleElementNS( XML_a, XML_fontRef, XML_idx, "minor", FSEND ); mpFS->singleElementNS( XML_a, XML_fontRef, XML_idx, "minor", FSEND );
} }
void DrawingML::WriteShapeEffects( Reference< XPropertySet > rXPropSet )
{
if( !GetProperty( rXPropSet, "InteropGrabBag" ) )
return;
Sequence< PropertyValue > aGrabBag, aEffectProps;
mAny >>= aGrabBag;
for( sal_Int32 i=0; i < aGrabBag.getLength(); ++i )
{
if( aGrabBag[i].Name == "EffectProperties" )
aGrabBag[i].Value >>= aEffectProps;
}
if( aEffectProps.getLength() == 0 )
return;
OUString sSchemeClr;
sal_uInt32 nRgbClr = 0;
sal_Int32 nAlpha = MAX_PERCENT;
Sequence< PropertyValue > aTransformations;
sax_fastparser::FastAttributeList *aOuterShdwAttrList = mpFS->createAttrList();
for( sal_Int32 i=0; i < aEffectProps.getLength(); ++i )
{
if(aEffectProps[i].Name == "outerShdw")
{
uno::Sequence< beans::PropertyValue > aOuterShdwProps;
aEffectProps[0].Value >>= aOuterShdwProps;
for( sal_Int32 j=0; j < aOuterShdwProps.getLength(); ++j )
{
if( aOuterShdwProps[j].Name == "algn" )
{
OUString sVal;
aOuterShdwProps[j].Value >>= sVal;
aOuterShdwAttrList->add( XML_algn, OUStringToOString( sVal, RTL_TEXTENCODING_UTF8 ).getStr() );
}
else if( aOuterShdwProps[j].Name == "blurRad" )
{
sal_Int32 nVal = 0;
aOuterShdwProps[j].Value >>= nVal;
aOuterShdwAttrList->add( XML_blurRad, OString::number( nVal ).getStr() );
}
else if( aOuterShdwProps[j].Name == "dir" )
{
sal_Int32 nVal = 0;
aOuterShdwProps[j].Value >>= nVal;
aOuterShdwAttrList->add( XML_dir, OString::number( nVal ).getStr() );
}
else if( aOuterShdwProps[j].Name == "dist" )
{
sal_Int32 nVal = 0;
aOuterShdwProps[j].Value >>= nVal;
aOuterShdwAttrList->add( XML_dist, OString::number( nVal ).getStr() );
}
else if( aOuterShdwProps[j].Name == "kx" )
{
sal_Int32 nVal = 0;
aOuterShdwProps[j].Value >>= nVal;
aOuterShdwAttrList->add( XML_kx, OString::number( nVal ).getStr() );
}
else if( aOuterShdwProps[j].Name == "ky" )
{
sal_Int32 nVal = 0;
aOuterShdwProps[j].Value >>= nVal;
aOuterShdwAttrList->add( XML_ky, OString::number( nVal ).getStr() );
}
else if( aOuterShdwProps[j].Name == "rotWithShape" )
{
sal_Int32 nVal = 0;
aOuterShdwProps[j].Value >>= nVal;
aOuterShdwAttrList->add( XML_rotWithShape, OString::number( nVal ).getStr() );
}
else if( aOuterShdwProps[j].Name == "sx" )
{
sal_Int32 nVal = 0;
aOuterShdwProps[j].Value >>= nVal;
aOuterShdwAttrList->add( XML_sx, OString::number( nVal ).getStr() );
}
else if( aOuterShdwProps[j].Name == "sy" )
{
sal_Int32 nVal = 0;
aOuterShdwProps[j].Value >>= nVal;
aOuterShdwAttrList->add( XML_sy, OString::number( nVal ).getStr() );
}
}
}
else if(aEffectProps[i].Name == "ShadowRgbClr")
{
aEffectProps[i].Value >>= nRgbClr;
}
else if(aEffectProps[i].Name == "ShadowRgbClrTransparency")
{
sal_Int32 nTransparency;
aEffectProps[i].Value >>= nTransparency;
// Calculate alpha value (see oox/source/drawingml/color.cxx : getTransparency())
nAlpha = MAX_PERCENT - ( PER_PERCENT * nTransparency );
}
else if(aEffectProps[i].Name == "ShadowColorSchemeClr")
{
aEffectProps[i].Value >>= sSchemeClr;
}
else if(aEffectProps[i].Name == "ShadowColorTransformations")
{
aEffectProps[i].Value >>= aTransformations;
}
}
mpFS->startElementNS(XML_a, XML_effectLst, FSEND);
sax_fastparser::XFastAttributeListRef xAttrList( aOuterShdwAttrList );
mpFS->startElementNS( XML_a, XML_outerShdw, xAttrList );
if( sSchemeClr.isEmpty() )
WriteColor( nRgbClr, nAlpha );
else
WriteColor( sSchemeClr, aTransformations );
mpFS->endElementNS( XML_a, XML_outerShdw );
mpFS->endElementNS(XML_a, XML_effectLst);
}
} }
} }
......
...@@ -373,6 +373,7 @@ ShapeExport& ShapeExport::WriteCustomShape( Reference< XShape > xShape ) ...@@ -373,6 +373,7 @@ ShapeExport& ShapeExport::WriteCustomShape( Reference< XShape > xShape )
{ {
WriteFill( rXPropSet ); WriteFill( rXPropSet );
WriteOutline( rXPropSet ); WriteOutline( rXPropSet );
WriteShapeEffects( rXPropSet );
} }
pFS->endElementNS( mnXmlNamespace, XML_spPr ); pFS->endElementNS( mnXmlNamespace, XML_spPr );
......
...@@ -1029,6 +1029,65 @@ DECLARE_OOXMLEXPORT_TEST(testFdo76979, "fdo76979.docx") ...@@ -1029,6 +1029,65 @@ DECLARE_OOXMLEXPORT_TEST(testFdo76979, "fdo76979.docx")
assertXPath(pXmlDoc, "//wps:spPr/a:solidFill/a:srgbClr", "val", "FFFFFF"); assertXPath(pXmlDoc, "//wps:spPr/a:solidFill/a:srgbClr", "val", "FFFFFF");
} }
DECLARE_OOXMLEXPORT_TEST(testShapeEffectPreservation, "shape-effect-preservation.docx")
{
xmlDocPtr pXmlDoc = parseExport("word/document.xml");
if (!pXmlDoc)
return;
// first shape with outer shadow, rgb color
assertXPath(pXmlDoc, "/w:document/w:body/w:p[1]/w:r/mc:AlternateContent/mc:Choice/w:drawing/"
"wp:anchor/a:graphic/a:graphicData/wps:wsp/wps:spPr/a:effectLst/a:outerShdw",
"algn", "tl");
assertXPath(pXmlDoc, "/w:document/w:body/w:p[1]/w:r/mc:AlternateContent/mc:Choice/w:drawing/"
"wp:anchor/a:graphic/a:graphicData/wps:wsp/wps:spPr/a:effectLst/a:outerShdw",
"blurRad", "50800");
assertXPath(pXmlDoc, "/w:document/w:body/w:p[1]/w:r/mc:AlternateContent/mc:Choice/w:drawing/"
"wp:anchor/a:graphic/a:graphicData/wps:wsp/wps:spPr/a:effectLst/a:outerShdw",
"dir", "2700000");
assertXPath(pXmlDoc, "/w:document/w:body/w:p[1]/w:r/mc:AlternateContent/mc:Choice/w:drawing/"
"wp:anchor/a:graphic/a:graphicData/wps:wsp/wps:spPr/a:effectLst/a:outerShdw",
"dist", "38100");
assertXPath(pXmlDoc, "/w:document/w:body/w:p[1]/w:r/mc:AlternateContent/mc:Choice/w:drawing/"
"wp:anchor/a:graphic/a:graphicData/wps:wsp/wps:spPr/a:effectLst/a:outerShdw",
"rotWithShape", "0");
assertXPath(pXmlDoc, "/w:document/w:body/w:p[1]/w:r/mc:AlternateContent/mc:Choice/w:drawing/"
"wp:anchor/a:graphic/a:graphicData/wps:wsp/wps:spPr/a:effectLst/a:outerShdw/a:srgbClr",
"val", "000000");
assertXPath(pXmlDoc, "/w:document/w:body/w:p[1]/w:r/mc:AlternateContent/mc:Choice/w:drawing/"
"wp:anchor/a:graphic/a:graphicData/wps:wsp/wps:spPr/a:effectLst/a:outerShdw/a:srgbClr/a:alpha",
"val", "40000");
// second shape with outer shadow, scheme color
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:spPr/a:effectLst/a:outerShdw",
"algn", "tl");
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:spPr/a:effectLst/a:outerShdw",
"blurRad", "114300");
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:spPr/a:effectLst/a:outerShdw",
"dir", "2700000");
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:spPr/a:effectLst/a:outerShdw",
"dist", "203200");
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:spPr/a:effectLst/a:outerShdw",
"rotWithShape", "0");
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:spPr/a:effectLst/a:outerShdw/a:schemeClr",
"val", "accent1");
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:spPr/a:effectLst/a:outerShdw/a:schemeClr/a:lumMod",
"val", "40000");
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:spPr/a:effectLst/a:outerShdw/a:schemeClr/a:lumOff",
"val", "60000");
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:spPr/a:effectLst/a:outerShdw/a:schemeClr/a:alpha",
"val", "40000");
}
#endif #endif
CPPUNIT_PLUGIN_IMPLEMENT(); CPPUNIT_PLUGIN_IMPLEMENT();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment