diff options
author | Jacobo Aragunde Pérez <jaragunde@igalia.com> | 2014-05-16 09:56:58 +0200 |
---|---|---|
committer | Jacobo Aragunde Pérez <jaragunde@igalia.com> | 2014-05-16 14:11:22 +0200 |
commit | be415a0f9a65d44d1042b313141f49c617bedd93 (patch) | |
tree | b1aa4442f415ffb70d9f419d0c5f69a2d177237f /oox | |
parent | a5835285068c1b03171b7953c2fea185111f4da2 (diff) |
ooxml: Preserve shape effects when there's more than one
Transformed the preservation process of shape effects to be able to
store more than one effect. For that we:
* Created the Effect struct and added a vector member to the
EffectProperties struct.
* Changed the shadow effect to use the new Effect struct,
EffectShadowProperties struct is preserved because the direction
field still has some use but we should remove it.
* Changed the structure of the grab bag to store more than one effect.
* Modified an existing unit test to check shapes with several effects.
Change-Id: I0dd908fa1d9578827c02ef6272fc9e2b914391be
Diffstat (limited to 'oox')
-rw-r--r-- | oox/source/drawingml/effectproperties.cxx | 71 | ||||
-rw-r--r-- | oox/source/drawingml/effectpropertiescontext.cxx | 77 | ||||
-rw-r--r-- | oox/source/drawingml/shape.cxx | 53 | ||||
-rw-r--r-- | oox/source/export/drawingml.cxx | 102 |
4 files changed, 160 insertions, 143 deletions
diff --git a/oox/source/drawingml/effectproperties.cxx b/oox/source/drawingml/effectproperties.cxx index be3b3d00cd18..be4af0c252d2 100644 --- a/oox/source/drawingml/effectproperties.cxx +++ b/oox/source/drawingml/effectproperties.cxx @@ -30,54 +30,57 @@ void EffectShadowProperties::assignUsed(const EffectShadowProperties& rSourcePro void EffectProperties::assignUsed( const EffectProperties& rSourceProps ) { maShadow.assignUsed(rSourceProps.maShadow); - msUnsupportedEffectName.assignIfUsed( rSourceProps.msUnsupportedEffectName ); - maUnsupportedEffectAttribs = rSourceProps.maUnsupportedEffectAttribs; + if( rSourceProps.maEffects.size() > 0 ) + maEffects = rSourceProps.maEffects; } void EffectProperties::pushToPropMap( PropertyMap& rPropMap, const GraphicHelper& rGraphicHelper ) const { - if (maShadow.moShadowDist.has()) - { - // Negative X or Y dist indicates left or up, respectively - double nAngle = (maShadow.moShadowDir.get(0) / PER_DEGREE) * F_PI180; - sal_Int32 nDist = convertEmuToHmm(maShadow.moShadowDist.get(0)); - sal_Int32 nXDist = cos(nAngle) * nDist; - sal_Int32 nYDist = sin(nAngle) * nDist; - - rPropMap.setProperty( PROP_Shadow, true ); - rPropMap.setProperty( PROP_ShadowXDistance, nXDist); - rPropMap.setProperty( PROP_ShadowYDistance, nYDist); - rPropMap.setProperty( PROP_ShadowColor, maShadow.moShadowColor.getColor(rGraphicHelper, -1 ) ); - rPropMap.setProperty( PROP_ShadowTransparence, maShadow.moShadowColor.getTransparency()); - } -} - -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); + for( std::vector< Effect* >::const_iterator it = maEffects.begin(); it != maEffects.end(); ++it ) + if( (*it)->msName == "outerShdw" ) + { + sal_Int32 nAttrDir = 0, nAttrDist = 0; + std::map< OUString, css::uno::Any >::iterator attribIt = (*it)->maAttribs.find( "dir" ); + if( attribIt != (*it)->maAttribs.end() ) + attribIt->second >>= nAttrDir; + + attribIt = (*it)->maAttribs.find( "dist" ); + if( attribIt != (*it)->maAttribs.end() ) + attribIt->second >>= nAttrDist; + + // Negative X or Y dist indicates left or up, respectively + double nAngle = ( nAttrDir / PER_DEGREE ) * F_PI180; + sal_Int32 nDist = convertEmuToHmm( nAttrDist ); + sal_Int32 nXDist = cos(nAngle) * nDist; + sal_Int32 nYDist = sin(nAngle) * nDist; + + rPropMap.setProperty( PROP_Shadow, true ); + rPropMap.setProperty( PROP_ShadowXDistance, nXDist); + rPropMap.setProperty( PROP_ShadowYDistance, nYDist); + rPropMap.setProperty( PROP_ShadowColor, (*it)->moColor.getColor(rGraphicHelper, -1 ) ); + rPropMap.setProperty( PROP_ShadowTransparence, (*it)->moColor.getTransparency()); + } } -css::beans::PropertyValue EffectProperties::getUnsupportedEffect() +css::beans::PropertyValue Effect::getEffect() { css::beans::PropertyValue pRet; - if(!msUnsupportedEffectName.has()) + if( msName.isEmpty() ) 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; + css::uno::Sequence< css::beans::PropertyValue > aSeq( maAttribs.size() ); + sal_uInt32 i = 0; + for( std::map< OUString, css::uno::Any >::iterator it = maAttribs.begin(); it != maAttribs.end(); ++it ) + { + aSeq[i].Name = it->first; + aSeq[i].Value = it->second; + i++; + } - pRet.Name = msUnsupportedEffectName.use(); + pRet.Name = msName; pRet.Value = css::uno::Any( aSeq ); - msUnsupportedEffectName.reset(); - maUnsupportedEffectAttribs.clear(); - return pRet; } diff --git a/oox/source/drawingml/effectpropertiescontext.cxx b/oox/source/drawingml/effectpropertiescontext.cxx index 2493ec94c3de..fa515d1ca568 100644 --- a/oox/source/drawingml/effectpropertiescontext.cxx +++ b/oox/source/drawingml/effectpropertiescontext.cxx @@ -33,80 +33,66 @@ EffectPropertiesContext::~EffectPropertiesContext() { } -void EffectPropertiesContext::saveUnsupportedAttribs( const AttributeList& rAttribs ) +void EffectPropertiesContext::saveUnsupportedAttribs( Effect& rEffect, const AttributeList& rAttribs ) { if( rAttribs.hasAttribute( XML_algn ) ) - mrEffectProperties.appendUnsupportedEffectAttrib( "algn", - makeAny( rAttribs.getString( XML_algn, "" ) ) ); + rEffect.maAttribs["algn"] = makeAny( rAttribs.getString( XML_algn, "" ) ); if( rAttribs.hasAttribute( XML_blurRad ) ) - mrEffectProperties.appendUnsupportedEffectAttrib( "blurRad", - makeAny( rAttribs.getInteger( XML_blurRad, 0 ) ) ); + rEffect.maAttribs["blurRad"] = makeAny( rAttribs.getInteger( XML_blurRad, 0 ) ); if( rAttribs.hasAttribute( XML_dir ) ) - mrEffectProperties.appendUnsupportedEffectAttrib( "dir", - makeAny( rAttribs.getInteger( XML_dir, 0 ) ) ); + rEffect.maAttribs["dir"] = makeAny( rAttribs.getInteger( XML_dir, 0 ) ); if( rAttribs.hasAttribute( XML_dist ) ) - mrEffectProperties.appendUnsupportedEffectAttrib( "dist", - makeAny( rAttribs.getInteger( XML_dist, 0 ) ) ); + rEffect.maAttribs["dist"] = makeAny( rAttribs.getInteger( XML_dist, 0 ) ); if( rAttribs.hasAttribute( XML_kx ) ) - mrEffectProperties.appendUnsupportedEffectAttrib( "kx", - makeAny( rAttribs.getInteger( XML_kx, 0 ) ) ); + rEffect.maAttribs["kx"] = makeAny( rAttribs.getInteger( XML_kx, 0 ) ); if( rAttribs.hasAttribute( XML_ky ) ) - mrEffectProperties.appendUnsupportedEffectAttrib( "ky", - makeAny( rAttribs.getInteger( XML_ky, 0 ) ) ); + rEffect.maAttribs["ky"] = makeAny( rAttribs.getInteger( XML_ky, 0 ) ); if( rAttribs.hasAttribute( XML_rotWithShape ) ) - mrEffectProperties.appendUnsupportedEffectAttrib( "rotWithShape", - makeAny( rAttribs.getInteger( XML_rotWithShape, 0 ) ) ); + rEffect.maAttribs["rotWithShape"] = makeAny( rAttribs.getInteger( XML_rotWithShape, 0 ) ); if( rAttribs.hasAttribute( XML_sx ) ) - mrEffectProperties.appendUnsupportedEffectAttrib( "sx", - makeAny( rAttribs.getInteger( XML_sx, 0 ) ) ); + rEffect.maAttribs["sx"] = makeAny( rAttribs.getInteger( XML_sx, 0 ) ); if( rAttribs.hasAttribute( XML_sy ) ) - mrEffectProperties.appendUnsupportedEffectAttrib( "sy", - makeAny( rAttribs.getInteger( XML_sy, 0 ) ) ); + rEffect.maAttribs["sy"] = makeAny( rAttribs.getInteger( XML_sy, 0 ) ); if( rAttribs.hasAttribute( XML_rad ) ) - mrEffectProperties.appendUnsupportedEffectAttrib( "rad", - makeAny( rAttribs.getInteger( XML_rad, 0 ) ) ); + rEffect.maAttribs["rad"] = makeAny( rAttribs.getInteger( XML_rad, 0 ) ); if( rAttribs.hasAttribute( XML_endA ) ) - mrEffectProperties.appendUnsupportedEffectAttrib( "endA", - makeAny( rAttribs.getInteger( XML_endA, 0 ) ) ); + rEffect.maAttribs["endA"] = makeAny( rAttribs.getInteger( XML_endA, 0 ) ); if( rAttribs.hasAttribute( XML_endPos ) ) - mrEffectProperties.appendUnsupportedEffectAttrib( "endPos", - makeAny( rAttribs.getInteger( XML_endPos, 0 ) ) ); + rEffect.maAttribs["endPos"] = makeAny( rAttribs.getInteger( XML_endPos, 0 ) ); if( rAttribs.hasAttribute( XML_fadeDir ) ) - mrEffectProperties.appendUnsupportedEffectAttrib( "fadeDir", - makeAny( rAttribs.getInteger( XML_fadeDir, 0 ) ) ); + rEffect.maAttribs["fadeDir"] = makeAny( rAttribs.getInteger( XML_fadeDir, 0 ) ); if( rAttribs.hasAttribute( XML_stA ) ) - mrEffectProperties.appendUnsupportedEffectAttrib( "stA", - makeAny( rAttribs.getInteger( XML_stA, 0 ) ) ); + rEffect.maAttribs["stA"] = makeAny( rAttribs.getInteger( XML_stA, 0 ) ); if( rAttribs.hasAttribute( XML_stPos ) ) - mrEffectProperties.appendUnsupportedEffectAttrib( "stPos", - makeAny( rAttribs.getInteger( XML_stPos, 0 ) ) ); + rEffect.maAttribs["stPos"] = makeAny( rAttribs.getInteger( XML_stPos, 0 ) ); if( rAttribs.hasAttribute( XML_grow ) ) - mrEffectProperties.appendUnsupportedEffectAttrib( "grow", - makeAny( rAttribs.getInteger( XML_grow, 0 ) ) ); + rEffect.maAttribs["grow"] = makeAny( rAttribs.getInteger( XML_grow, 0 ) ); } ContextHandlerRef EffectPropertiesContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) { + sal_Int32 nPos = mrEffectProperties.maEffects.size(); + mrEffectProperties.maEffects.push_back( new Effect() ); switch( nElement ) { case A_TOKEN( outerShdw ): { - mrEffectProperties.msUnsupportedEffectName = "outerShdw"; - saveUnsupportedAttribs( rAttribs ); + mrEffectProperties.maEffects[nPos]->msName = "outerShdw"; + saveUnsupportedAttribs( *mrEffectProperties.maEffects[nPos], rAttribs ); mrEffectProperties.maShadow.moShadowDist = rAttribs.getInteger( XML_dist, 0 ); mrEffectProperties.maShadow.moShadowDir = rAttribs.getInteger( XML_dir, 0 ); - return new ColorContext( *this, mrEffectProperties.maShadow.moShadowColor ); + return new ColorContext( *this, mrEffectProperties.maEffects[nPos]->moColor ); } break; case A_TOKEN( innerShdw ): { - mrEffectProperties.msUnsupportedEffectName = "innerShdw"; - saveUnsupportedAttribs( rAttribs ); + mrEffectProperties.maEffects[nPos]->msName = "innerShdw"; + saveUnsupportedAttribs( *mrEffectProperties.maEffects[nPos], rAttribs ); mrEffectProperties.maShadow.moShadowDist = rAttribs.getInteger( XML_dist, 0 ); mrEffectProperties.maShadow.moShadowDir = rAttribs.getInteger( XML_dir, 0 ); - return new ColorContext( *this, mrEffectProperties.maShadow.moShadowColor ); + return new ColorContext( *this, mrEffectProperties.maEffects[nPos]->moColor ); } break; case A_TOKEN( glow ): @@ -115,19 +101,20 @@ ContextHandlerRef EffectPropertiesContext::onCreateContext( sal_Int32 nElement, case A_TOKEN( blur ): { if( nElement == A_TOKEN( glow ) ) - mrEffectProperties.msUnsupportedEffectName = "glow"; + mrEffectProperties.maEffects[nPos]->msName = "glow"; else if( nElement == A_TOKEN( softEdge ) ) - mrEffectProperties.msUnsupportedEffectName = "softEdge"; + mrEffectProperties.maEffects[nPos]->msName = "softEdge"; else if( nElement == A_TOKEN( reflection ) ) - mrEffectProperties.msUnsupportedEffectName = "reflection"; + mrEffectProperties.maEffects[nPos]->msName = "reflection"; else if( nElement == A_TOKEN( blur ) ) - mrEffectProperties.msUnsupportedEffectName = "blur"; - saveUnsupportedAttribs( rAttribs ); - return new ColorContext( *this, mrEffectProperties.maShadow.moShadowColor ); + mrEffectProperties.maEffects[nPos]->msName = "blur"; + saveUnsupportedAttribs( *mrEffectProperties.maEffects[nPos], rAttribs ); + return new ColorContext( *this, mrEffectProperties.maEffects[nPos]->moColor ); } break; } + mrEffectProperties.maEffects.pop_back(); return 0; } diff --git a/oox/source/drawingml/shape.cxx b/oox/source/drawingml/shape.cxx index bce735782f9c..b319c3800449 100644 --- a/oox/source/drawingml/shape.cxx +++ b/oox/source/drawingml/shape.cxx @@ -911,30 +911,41 @@ Reference< XShape > Shape::createAndInsert( } // store unsupported effect attributes in the grab bag - PropertyValue aEffect = aEffectProperties.getUnsupportedEffect(); - if( aEffect.Name != "" ) + if( aEffectProperties.maEffects.size() > 0 ) { - 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 + Sequence< PropertyValue > aEffects( aEffectProperties.maEffects.size() ); + sal_uInt32 i = 0; + for( std::vector< Effect* >::iterator it = aEffectProperties.maEffects.begin(); + it != aEffectProperties.maEffects.end(); ++it ) { - // scheme color with name and transformations - PUT_PROP( aEffectsGrabBag, 1, "ShadowColorSchemeClr", sColorScheme ); - PUT_PROP( aEffectsGrabBag, 2, "ShadowColorTransformations", - aEffectProperties.maShadow.moShadowColor.getTransformations() ); - } + PropertyValue aEffect = (*it)->getEffect(); + if( !aEffect.Name.isEmpty() ) + { + Sequence< PropertyValue > aEffectsGrabBag( 3 ); + PUT_PROP( aEffectsGrabBag, 0, "Attribs", aEffect.Value ); - putPropertyToGrabBag( "EffectProperties", Any( aEffectsGrabBag ) ); + Color& aColor( (*it)->moColor ); + OUString sColorScheme = aColor.getSchemeName(); + if( sColorScheme.isEmpty() ) + { + // RGB color and transparency value + PUT_PROP( aEffectsGrabBag, 1, "RgbClr", + aColor.getColor( rGraphicHelper, nFillPhClr ) ); + PUT_PROP( aEffectsGrabBag, 2, "RgbClrTransparency", + aColor.getTransparency() ); + } + else + { + // scheme color with name and transformations + PUT_PROP( aEffectsGrabBag, 1, "SchemeClr", sColorScheme ); + PUT_PROP( aEffectsGrabBag, 2, "SchemeClrTransformations", + aColor.getTransformations() ); + } + PUT_PROP( aEffects, i, aEffect.Name, aEffectsGrabBag ); + ++i; + } + } + putPropertyToGrabBag( "EffectProperties", Any( aEffects ) ); } // add 3D effects if any diff --git a/oox/source/export/drawingml.cxx b/oox/source/export/drawingml.cxx index 1d663e48ce0b..037466ad9eaf 100644 --- a/oox/source/export/drawingml.cxx +++ b/oox/source/export/drawingml.cxx @@ -2076,57 +2076,45 @@ void DrawingML::WriteShapeStyle( Reference< XPropertySet > xPropSet ) mpFS->singleElementNS( XML_a, XML_fontRef, XML_idx, "minor", FSEND ); } -void DrawingML::WriteShapeEffects( Reference< XPropertySet > rXPropSet ) +void DrawingML::WriteShapeEffect( const OUString& sName, const Sequence< PropertyValue >& aEffectProps ) { - if( !GetProperty( rXPropSet, "InteropGrabBag" ) ) + if( aEffectProps.getLength() == 0 ) return; - Sequence< PropertyValue > aGrabBag, aEffectProps; - mAny >>= aGrabBag; - for( sal_Int32 i=0; i < aGrabBag.getLength(); ++i ) + // assign the proper tag and enable bContainsColor if necessary + sal_Int32 nEffectToken = 0; + bool bContainsColor = false; + if( sName == "outerShdw" ) { - if( aGrabBag[i].Name == "EffectProperties" ) - aGrabBag[i].Value >>= aEffectProps; + nEffectToken = FSNS( XML_a, XML_outerShdw ); + bContainsColor = true; } - if( aEffectProps.getLength() == 0 ) - return; + else if( sName == "innerShdw" ) + { + nEffectToken = FSNS( XML_a, XML_innerShdw ); + bContainsColor = true; + } + else if( sName == "glow" ) + { + nEffectToken = FSNS( XML_a, XML_glow ); + bContainsColor = true; + } + else if( sName == "softEdge" ) + nEffectToken = FSNS( XML_a, XML_softEdge ); + else if( sName == "reflection" ) + nEffectToken = FSNS( XML_a, XML_reflection ); + else if( sName == "blur" ) + nEffectToken = FSNS( XML_a, XML_blur ); OUString sSchemeClr; - bool bContainsColor = false; sal_uInt32 nRgbClr = 0; - sal_Int32 nEffectToken = 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" || aEffectProps[i].Name == "innerShdw" - || aEffectProps[i].Name == "glow" || aEffectProps[i].Name == "softEdge" - || aEffectProps[i].Name == "reflection" || aEffectProps[i].Name == "blur" ) + if( aEffectProps[i].Name == "Attribs" ) { - // assign the proper tag and enable bContainsColor if necessary - if( aEffectProps[i].Name == "outerShdw" ) - { - nEffectToken = FSNS( XML_a, XML_outerShdw ); - bContainsColor = true; - } - else if( aEffectProps[i].Name == "innerShdw" ) - { - nEffectToken = FSNS( XML_a, XML_innerShdw ); - bContainsColor = true; - } - else if( aEffectProps[i].Name == "glow" ) - { - nEffectToken = FSNS( XML_a, XML_glow ); - bContainsColor = true; - } - else if( aEffectProps[i].Name == "softEdge" ) - nEffectToken = FSNS( XML_a, XML_softEdge ); - else if( aEffectProps[i].Name == "reflection" ) - nEffectToken = FSNS( XML_a, XML_reflection ); - else if( aEffectProps[i].Name == "blur" ) - nEffectToken = FSNS( XML_a, XML_blur ); - // read tag attributes uno::Sequence< beans::PropertyValue > aOuterShdwProps; aEffectProps[i].Value >>= aOuterShdwProps; @@ -2230,22 +2218,22 @@ void DrawingML::WriteShapeEffects( Reference< XPropertySet > rXPropSet ) } } } - else if(aEffectProps[i].Name == "ShadowRgbClr") + else if(aEffectProps[i].Name == "RgbClr") { aEffectProps[i].Value >>= nRgbClr; } - else if(aEffectProps[i].Name == "ShadowRgbClrTransparency") + else if(aEffectProps[i].Name == "RgbClrTransparency") { 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") + else if(aEffectProps[i].Name == "SchemeClr") { aEffectProps[i].Value >>= sSchemeClr; } - else if(aEffectProps[i].Name == "ShadowColorTransformations") + else if(aEffectProps[i].Name == "SchemeClrTransformations") { aEffectProps[i].Value >>= aTransformations; } @@ -2253,7 +2241,6 @@ void DrawingML::WriteShapeEffects( Reference< XPropertySet > rXPropSet ) if( nEffectToken > 0 ) { - mpFS->startElementNS(XML_a, XML_effectLst, FSEND); sax_fastparser::XFastAttributeListRef xAttrList( aOuterShdwAttrList ); mpFS->startElement( nEffectToken, xAttrList ); @@ -2266,10 +2253,39 @@ void DrawingML::WriteShapeEffects( Reference< XPropertySet > rXPropSet ) } mpFS->endElement( nEffectToken ); - mpFS->endElementNS(XML_a, XML_effectLst); } } +void DrawingML::WriteShapeEffects( Reference< XPropertySet > rXPropSet ) +{ + if( !GetProperty( rXPropSet, "InteropGrabBag" ) ) + return; + + Sequence< PropertyValue > aGrabBag, aEffects; + mAny >>= aGrabBag; + for( sal_Int32 i=0; i < aGrabBag.getLength(); ++i ) + { + if( aGrabBag[i].Name == "EffectProperties" ) + { + aGrabBag[i].Value >>= aEffects; + break; + } + } + if( aEffects.getLength() == 0 ) + return; + + mpFS->startElementNS(XML_a, XML_effectLst, FSEND); + + for( sal_Int32 i=0; i < aEffects.getLength(); ++i ) + { + Sequence< PropertyValue > aEffectProps; + aEffects[i].Value >>= aEffectProps; + WriteShapeEffect( aEffects[i].Name, aEffectProps ); + } + + mpFS->endElementNS(XML_a, XML_effectLst); +} + void DrawingML::WriteShape3DEffects( Reference< XPropertySet > xPropSet ) { // check existence of the grab bag |