summaryrefslogtreecommitdiff
path: root/oox
diff options
context:
space:
mode:
authorJacobo Aragunde Pérez <jaragunde@igalia.com>2014-01-14 18:43:06 +0100
committerJacobo Aragunde Pérez <jaragunde@igalia.com>2014-01-18 14:51:42 +0100
commit15e01d90b92a84cba538940614ea30df401a9976 (patch)
tree978b6d6802af74a558d17264596d54cc78e46a01 /oox
parent2e34ceeb92b6d61a2bd7a1ac1e2828fbf7c9f176 (diff)
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: <wps:style> ... <a:fillRef idx="1"> <a:schemeClr val="accent1"/> </a:fillRef> ... </wps:style> 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 <a:fillRef> tag is opened. The ShapeStyleRef object contains the idx value and a Color object which will contain the inner tag <a:schemeClr>. 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 <a:schemeClr> is opened. Later, Shape::createAndInsert is called by the ShapeContextHandler to create the actual XShape, this happens when the tag <wps:wsp> 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 <wps:style> 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
Diffstat (limited to 'oox')
-rw-r--r--oox/source/drawingml/colorchoicecontext.cxx5
-rw-r--r--oox/source/drawingml/shape.cxx33
-rw-r--r--oox/source/export/drawingml.cxx46
-rw-r--r--oox/source/export/shapes.cxx4
4 files changed, 88 insertions, 0 deletions
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<rtl::OUString> 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 <a:lnRef>
+ mpFS->singleElementNS( XML_a, XML_lnRef, XML_idx, I32S( 0 ), FSEND );
+
+ // write <a:fillRef>
+ 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 <a:fillRef>
+ mpFS->singleElementNS( XML_a, XML_fillRef, XML_idx, I32S( 0 ), FSEND );
+
+ // write mock <a:effectRef>
+ mpFS->singleElementNS( XML_a, XML_effectRef, XML_idx, I32S( 0 ), FSEND );
+ // write mock <a:fontRef>
+ 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 );