From 15e01d90b92a84cba538940614ea30df401a9976 Mon Sep 17 00:00:00 2001 From: Jacobo Aragunde PĂ©rez Date: Tue, 14 Jan 2014 18:43:06 +0100 Subject: ooxml: Preserve shape style attribute fillRef Shape style attributes contain the default format for the shape in case that no direct format is specified for it. This is an example of the attribute we want to preserve with this patch: ... ... The relevant values in these tags are stored at the maShapeStyleRefs member in the Shape object. The storage happens at ShapeStyleContext::onCreateContext which is run when the tag is opened. The ShapeStyleRef object contains the idx value and a Color object which will contain the inner tag . The Color object has been modified to store the string value of schemeClr. The storage happens at ColorValueContext::onStartElement which is run when the tag is opened. Later, Shape::createAndInsert is called by the ShapeContextHandler to create the actual XShape, this happens when the tag is closed. createAndInsert puts idx and schemeClr values into the InteropGrabBag property of the XShape with the name StyleFillRef. On export time, when the shape data is written at ShapeExport::WriteCustomShape, we added a call to DrawingML::WriteShapeStyle. This method will check the existence of the InteropGrabBag property in the shape, read the StyleFillRef prop inside it and output the proper XML to the style definition. DrawingML::WriteShapeStyle also writes some mock tags into the because we found that they are compulsory. We will replace them with the proper data in further patches. The method putPropertyToGrabBag was added to the Shape object for convenience. The data files for some /sd/qa/ unit tests were updated to reflect the new property StyleFillRef inside the InteropGrabBag. Change-Id: I5ffa5242852461a1a709a8f169d40f0d7a2c9aa3 --- oox/source/drawingml/colorchoicecontext.cxx | 5 ++++ oox/source/drawingml/shape.cxx | 33 +++++++++++++++++++++ oox/source/export/drawingml.cxx | 46 +++++++++++++++++++++++++++++ oox/source/export/shapes.cxx | 4 +++ 4 files changed, 88 insertions(+) (limited to 'oox') diff --git a/oox/source/drawingml/colorchoicecontext.cxx b/oox/source/drawingml/colorchoicecontext.cxx index 951033d8bb47..076b245034e0 100644 --- a/oox/source/drawingml/colorchoicecontext.cxx +++ b/oox/source/drawingml/colorchoicecontext.cxx @@ -69,7 +69,12 @@ void ColorValueContext::onStartElement( const AttributeList& rAttribs ) break; case A_TOKEN( schemeClr ): + { mrColor.setSchemeClr( rAttribs.getToken( XML_val, XML_TOKEN_INVALID ) ); + oox::OptValue sSchemeName = rAttribs.getString( XML_val ); + if( sSchemeName.has() ) + mrColor.setSchemeName( sSchemeName.use() ); + } break; case A_TOKEN( prstClr ): diff --git a/oox/source/drawingml/shape.cxx b/oox/source/drawingml/shape.cxx index c368363fc9ce..09d74bf2ded1 100644 --- a/oox/source/drawingml/shape.cxx +++ b/oox/source/drawingml/shape.cxx @@ -564,6 +564,21 @@ Reference< XShape > Shape::createAndInsert( if( const FillProperties* pFillProps = pTheme->getFillStyle( pFillRef->mnThemedIdx ) ) aFillProperties.assignUsed( *pFillProps ); nFillPhClr = pFillRef->maPhClr.getColor( rGraphicHelper ); + + OUString sColorScheme = pFillRef->maPhClr.getSchemeName(); + if( !sColorScheme.isEmpty() ) + { + Sequence< PropertyValue > aProperties(2); + aProperties[0].Name = "SchemeClr"; + aProperties[0].Value = Any( sColorScheme ); + aProperties[1].Name = "Idx"; + aProperties[1].Value = Any( pFillRef->mnThemedIdx ); + + PropertyValue pStyleFillRef; + pStyleFillRef.Name = "StyleFillRef"; + pStyleFillRef.Value = Any( aProperties ); + putPropertyToGrabBag( pStyleFillRef ); + } } if( const ShapeStyleRef* pEffectRef = getShapeStyleRef( XML_effectRef ) ) { @@ -1037,6 +1052,24 @@ void Shape::finalizeXShape( XmlFilterBase& rFilter, const Reference< XShapes >& } } +void Shape::putPropertyToGrabBag( const PropertyValue& pProperty ) +{ + Reference< XPropertySet > xSet( mxShape, UNO_QUERY ); + Reference< XPropertySetInfo > xSetInfo( xSet->getPropertySetInfo() ); + const OUString& aGrabBagPropName = OUString( UNO_NAME_MISC_OBJ_INTEROPGRABBAG ); + if( mxShape.is() && xSet.is() && xSetInfo.is() && xSetInfo->hasPropertyByName( aGrabBagPropName ) ) + { + Sequence< PropertyValue > aGrabBag; + xSet->getPropertyValue( aGrabBagPropName ) >>= aGrabBag; + + sal_Int32 length = aGrabBag.getLength(); + aGrabBag.realloc( length + 1 ); + aGrabBag[length] = pProperty; + + xSet->setPropertyValue( aGrabBagPropName, Any( aGrabBag ) ); + } +} + // ============================================================================ } } diff --git a/oox/source/export/drawingml.cxx b/oox/source/export/drawingml.cxx index b533d747371b..e98a3260837a 100644 --- a/oox/source/export/drawingml.cxx +++ b/oox/source/export/drawingml.cxx @@ -1620,6 +1620,52 @@ void DrawingML::WriteFill( Reference< XPropertySet > xPropSet ) return; } +void DrawingML::WriteShapeStyle( Reference< XPropertySet > xPropSet ) +{ + // check existence of the grab bag + if ( !GetProperty( xPropSet, "InteropGrabBag" ) ) + return; + + // extract the relevant properties from the grab bag + Sequence< PropertyValue > aGrabBag; + Sequence< PropertyValue > aFillRefProperties; + mAny >>= aGrabBag; + for( sal_Int32 i=0; i < aGrabBag.getLength(); ++i) + if( aGrabBag[i].Name == "StyleFillRef" ) + { + aGrabBag[i].Value >>= aFillRefProperties; + break; + } + + // write mock + mpFS->singleElementNS( XML_a, XML_lnRef, XML_idx, I32S( 0 ), FSEND ); + + // write + if( aFillRefProperties.getLength() > 0 ) + { + OUString sSchemeClr; + sal_uInt32 nIdx; + for( sal_Int32 i=0; i < aFillRefProperties.getLength(); ++i) + if( aFillRefProperties[i].Name == "SchemeClr" ) + aFillRefProperties[i].Value >>= sSchemeClr; + else if( aFillRefProperties[i].Name == "Idx" ) + aFillRefProperties[i].Value >>= nIdx; + mpFS->startElementNS( XML_a, XML_fillRef, XML_idx, I32S( nIdx ), FSEND ); + mpFS->singleElementNS( XML_a, XML_schemeClr, XML_val, + OUStringToOString( sSchemeClr, RTL_TEXTENCODING_ASCII_US ).getStr(), + FSEND ); + mpFS->endElementNS( XML_a, XML_fillRef ); + } + else + // write mock + mpFS->singleElementNS( XML_a, XML_fillRef, XML_idx, I32S( 0 ), FSEND ); + + // write mock + mpFS->singleElementNS( XML_a, XML_effectRef, XML_idx, I32S( 0 ), FSEND ); + // write mock + mpFS->singleElementNS( XML_a, XML_fontRef, XML_idx, "minor", FSEND ); +} + } } diff --git a/oox/source/export/shapes.cxx b/oox/source/export/shapes.cxx index 76dd7431ced0..cdbe0d68f468 100644 --- a/oox/source/export/shapes.cxx +++ b/oox/source/export/shapes.cxx @@ -369,6 +369,10 @@ ShapeExport& ShapeExport::WriteCustomShape( Reference< XShape > xShape ) pFS->endElementNS( mnXmlNamespace, XML_spPr ); + pFS->startElementNS( mnXmlNamespace, XML_style, FSEND ); + WriteShapeStyle( rXPropSet ); + pFS->endElementNS( mnXmlNamespace, XML_style ); + // write text WriteTextBox( xShape, mnXmlNamespace ); -- cgit