summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacobo Aragunde Pérez <jaragunde@igalia.com>2014-05-09 12:01:46 +0200
committerJacobo Aragunde Pérez <jaragunde@igalia.com>2014-05-09 14:11:38 +0200
commitf6422b3dfcb00e451ef103127aace1856dc752a9 (patch)
tree135bd8dd5be8354897e125b73ba4f626d3794504
parent6566c218afec3cd8c4d36094777bc30b1970e9e4 (diff)
ooxml: Preserve shape 3d effects: top and bottom bevel
Shapes 3D effects can specify top and bottom bevels like in the following example: <a:sp3d z="488950" extrusionH="63500" contourW="50800"> <a:bevelT w="139700" h="88900" prst="cross"/> <a:bevelB h="88900" prst="relaxedInset"/> </a:sp3d> This patch preserves the a:bevel* tags and their attributes using the shape grab bag and modifies an existing unit test to add this check. Change-Id: I4762111e4d2f75ba2fd3721a126aa324a28a853c
-rw-r--r--include/oox/drawingml/scene3dcontext.hxx2
-rw-r--r--include/oox/drawingml/shape3dproperties.hxx12
-rw-r--r--oox/source/drawingml/scene3dcontext.cxx26
-rw-r--r--oox/source/drawingml/shape3dproperties.cxx61
-rw-r--r--oox/source/export/drawingml.cxx52
-rw-r--r--sw/qa/extras/ooxmlexport/ooxmlsdrexport.cxx15
6 files changed, 167 insertions, 1 deletions
diff --git a/include/oox/drawingml/scene3dcontext.hxx b/include/oox/drawingml/scene3dcontext.hxx
index e4b7a62eef41..d016445528b6 100644
--- a/include/oox/drawingml/scene3dcontext.hxx
+++ b/include/oox/drawingml/scene3dcontext.hxx
@@ -54,6 +54,8 @@ class Shape3DPropertiesContext : public ::oox::core::ContextHandler2
public:
Shape3DPropertiesContext( ::oox::core::ContextHandler2Helper& rParent, const ::oox::AttributeList& rAttribs, Shape3DProperties& r3DProperties ) throw();
+ ::oox::core::ContextHandlerRef onCreateContext( ::sal_Int32 Element, const ::oox::AttributeList& rAttribs ) SAL_OVERRIDE;
+
private:
Shape3DProperties& mr3DProperties;
};
diff --git a/include/oox/drawingml/shape3dproperties.hxx b/include/oox/drawingml/shape3dproperties.hxx
index a66d46cda14a..32e0f27ae56b 100644
--- a/include/oox/drawingml/shape3dproperties.hxx
+++ b/include/oox/drawingml/shape3dproperties.hxx
@@ -43,6 +43,13 @@ struct RotationProperties
OptValue< sal_Int32 > mnRevolution;
};
+struct BevelProperties
+{
+ OptValue< sal_Int32 > mnPreset;
+ OptValue< sal_Int32 > mnWidth;
+ OptValue< sal_Int32 > mnHeight;
+};
+
struct Shape3DProperties
{
OptValue< sal_Int32 > mnPreset;
@@ -57,16 +64,21 @@ struct Shape3DProperties
OptValue< sal_Int32 > mnContourW;
OptValue< sal_Int32 > mnShapeZ;
+ OptValue< BevelProperties > maTopBevelProperties;
+ OptValue< BevelProperties > maBottomBevelProperties;
+
/** Overwrites all members that are explicitly set in rSourceProps. */
void assignUsed( const Shape3DProperties& rSourceProps );
OUString getCameraPrstName( sal_Int32 nElement );
OUString getLightRigName( sal_Int32 nElement );
OUString getLightRigDirName( sal_Int32 nElement );
+ OUString getBevelPresetTypeString( sal_Int32 nType );
css::uno::Sequence< css::beans::PropertyValue > getCameraAttributes();
css::uno::Sequence< css::beans::PropertyValue > getLightRigAttributes();
css::uno::Sequence< css::beans::PropertyValue > getShape3DAttributes();
+ css::uno::Sequence< css::beans::PropertyValue > getBevelAttributes( BevelProperties rProps );
};
diff --git a/oox/source/drawingml/scene3dcontext.cxx b/oox/source/drawingml/scene3dcontext.cxx
index bbae7abedd10..124a74183f48 100644
--- a/oox/source/drawingml/scene3dcontext.cxx
+++ b/oox/source/drawingml/scene3dcontext.cxx
@@ -80,6 +80,32 @@ Shape3DPropertiesContext::Shape3DPropertiesContext( ContextHandler2Helper& rPare
mr3DProperties.mnShapeZ = rAttribs.getInteger( XML_z, 0 );
}
+ContextHandlerRef Shape3DPropertiesContext::onCreateContext( sal_Int32 aElementToken, const AttributeList& rAttribs )
+{
+ switch( aElementToken )
+ {
+ case A_TOKEN( bevelT ):
+ case A_TOKEN( bevelB ):
+ {
+ BevelProperties aProps;
+ if( rAttribs.hasAttribute( XML_w ) )
+ aProps.mnWidth = rAttribs.getInteger( XML_w, 0 );
+ if( rAttribs.hasAttribute( XML_h ) )
+ aProps.mnHeight = rAttribs.getInteger( XML_h, 0 );
+ if( rAttribs.hasAttribute( XML_prst ) )
+ aProps.mnPreset = rAttribs.getToken( XML_prst, XML_none );
+
+ if( aElementToken == A_TOKEN( bevelT ) )
+ mr3DProperties.maTopBevelProperties.set( aProps );
+ else
+ mr3DProperties.maBottomBevelProperties.set( aProps );
+
+ break;
+ }
+ }
+ return 0;
+}
+
Scene3DRotationPropertiesContext::Scene3DRotationPropertiesContext( ContextHandler2Helper& rParent, RotationProperties& rRotationProperties ) throw()
: ContextHandler2( rParent )
, mrRotationProperties( rRotationProperties )
diff --git a/oox/source/drawingml/shape3dproperties.cxx b/oox/source/drawingml/shape3dproperties.cxx
index 7da8a0b4d9f1..28d907922b31 100644
--- a/oox/source/drawingml/shape3dproperties.cxx
+++ b/oox/source/drawingml/shape3dproperties.cxx
@@ -171,6 +171,27 @@ OUString Shape3DProperties::getLightRigDirName( sal_Int32 nElement )
return OUString();
}
+OUString Shape3DProperties::getBevelPresetTypeString( sal_Int32 nType )
+{
+ switch (nType)
+ {
+ case XML_relaxedInset: return OUString("relaxedInset");
+ case XML_circle: return OUString("circle");
+ case XML_slope: return OUString("slope");
+ case XML_cross: return OUString("cross");
+ case XML_angle: return OUString("angle");
+ case XML_softRound: return OUString("softRound");
+ case XML_convex: return OUString("convex");
+ case XML_coolSlant: return OUString("coolSlant");
+ case XML_divot: return OUString("divot");
+ case XML_riblet: return OUString("riblet");
+ case XML_hardEdge: return OUString("hardEdge");
+ case XML_artDeco: return OUString("artDeco");
+ }
+ SAL_WARN( "oox.drawingml", "Shape3DProperties::getBevelPresetTypeString - unexpected token" );
+ return OUString();
+}
+
css::uno::Sequence< css::beans::PropertyValue > Shape3DProperties::getCameraAttributes()
{
css::uno::Sequence<css::beans::PropertyValue> aSeq(6);
@@ -253,10 +274,36 @@ css::uno::Sequence< css::beans::PropertyValue > Shape3DProperties::getLightRigAt
return aSeq;
}
-css::uno::Sequence< css::beans::PropertyValue > Shape3DProperties::getShape3DAttributes()
+css::uno::Sequence< css::beans::PropertyValue > Shape3DProperties::getBevelAttributes( BevelProperties rProps )
{
css::uno::Sequence<css::beans::PropertyValue> aSeq(3);
sal_Int32 nSize = 0;
+ if( rProps.mnPreset.has() )
+ {
+ aSeq[nSize].Name = "prst";
+ aSeq[nSize].Value = css::uno::Any( getBevelPresetTypeString( rProps.mnPreset.use() ) );
+ nSize++;
+ }
+ if( rProps.mnWidth.has() )
+ {
+ aSeq[nSize].Name = "w";
+ aSeq[nSize].Value = css::uno::Any( rProps.mnWidth.use() );
+ nSize++;
+ }
+ if( rProps.mnHeight.has() )
+ {
+ aSeq[nSize].Name = "h";
+ aSeq[nSize].Value = css::uno::Any( rProps.mnHeight.use() );
+ nSize++;
+ }
+ aSeq.realloc( nSize );
+ return aSeq;
+}
+
+css::uno::Sequence< css::beans::PropertyValue > Shape3DProperties::getShape3DAttributes()
+{
+ css::uno::Sequence<css::beans::PropertyValue> aSeq(5);
+ sal_Int32 nSize = 0;
if( mnExtrusionH.has() )
{
aSeq[nSize].Name = "extrusionH";
@@ -275,6 +322,18 @@ css::uno::Sequence< css::beans::PropertyValue > Shape3DProperties::getShape3DAtt
aSeq[nSize].Value = css::uno::Any( mnShapeZ.use() );
nSize++;
}
+ if( maTopBevelProperties.has() )
+ {
+ aSeq[nSize].Name = "bevelT";
+ aSeq[nSize].Value = css::uno::Any( getBevelAttributes( maTopBevelProperties.use() ) );
+ nSize++;
+ }
+ if( maBottomBevelProperties.has() )
+ {
+ aSeq[nSize].Name = "bevelB";
+ aSeq[nSize].Value = css::uno::Any( getBevelAttributes( maBottomBevelProperties.use() ) );
+ nSize++;
+ }
aSeq.realloc( nSize );
return aSeq;
}
diff --git a/oox/source/export/drawingml.cxx b/oox/source/export/drawingml.cxx
index 0b437db8acb9..90000a1b78ea 100644
--- a/oox/source/export/drawingml.cxx
+++ b/oox/source/export/drawingml.cxx
@@ -2408,6 +2408,9 @@ void DrawingML::WriteShape3DEffects( Reference< XPropertySet > xPropSet )
if( aShape3DProps.getLength() == 0 )
return;
+ bool bBevelTPresent = false, bBevelBPresent = false;
+ sax_fastparser::FastAttributeList *aBevelTAttrList = mpFS->createAttrList();
+ sax_fastparser::FastAttributeList *aBevelBAttrList = mpFS->createAttrList();
sax_fastparser::FastAttributeList *aShape3DAttrList = mpFS->createAttrList();
for( sal_Int32 i=0; i < aShape3DProps.getLength(); ++i )
{
@@ -2423,10 +2426,59 @@ void DrawingML::WriteShape3DEffects( Reference< XPropertySet > xPropSet )
nToken = XML_z;
aShape3DAttrList->add( nToken, OString::number( nVal ).getStr() );
}
+ if( aShape3DProps[i].Name == "bevelT" || aShape3DProps[i].Name == "bevelB" )
+ {
+ Sequence< PropertyValue > aBevelProps;
+ aShape3DProps[i].Value >>= aBevelProps;
+ if ( aBevelProps.getLength() == 0 )
+ continue;
+
+ sax_fastparser::FastAttributeList *aBevelAttrList = NULL;
+ if( aShape3DProps[i].Name == "bevelT" )
+ {
+ bBevelTPresent = true;
+ aBevelAttrList = aBevelTAttrList;
+ }
+ else
+ {
+ bBevelBPresent = true;
+ aBevelAttrList = aBevelBAttrList;
+ }
+ for( sal_Int32 j=0; j < aBevelProps.getLength(); ++j )
+ {
+ if( aBevelProps[j].Name == "w" || aBevelProps[j].Name == "h" )
+ {
+ sal_Int32 nVal = 0, nToken = XML_none;
+ aBevelProps[j].Value >>= nVal;
+ if( aBevelProps[j].Name == "w" )
+ nToken = XML_w;
+ else if( aBevelProps[j].Name == "h" )
+ nToken = XML_h;
+ aBevelAttrList->add( nToken, OString::number( nVal ).getStr() );
+ }
+ else if( aBevelProps[j].Name == "prst" )
+ {
+ OUString sVal;
+ aBevelProps[j].Value >>= sVal;
+ aBevelAttrList->add( XML_prst, OUStringToOString( sVal, RTL_TEXTENCODING_UTF8 ).getStr() );
+ }
+ }
+
+ }
}
sax_fastparser::XFastAttributeListRef xAttrList( aShape3DAttrList );
mpFS->startElementNS( XML_a, XML_sp3d, xAttrList );
+ if( bBevelTPresent )
+ {
+ sax_fastparser::XFastAttributeListRef xBevelAttrList( aBevelTAttrList );
+ mpFS->singleElementNS( XML_a, XML_bevelT, xBevelAttrList );
+ }
+ if( bBevelBPresent )
+ {
+ sax_fastparser::XFastAttributeListRef xBevelAttrList( aBevelBAttrList );
+ mpFS->singleElementNS( XML_a, XML_bevelB, xBevelAttrList );
+ }
mpFS->endElementNS( XML_a, XML_sp3d );
}
diff --git a/sw/qa/extras/ooxmlexport/ooxmlsdrexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlsdrexport.cxx
index d7bcf07fa22b..1bee43eaabf9 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlsdrexport.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlsdrexport.cxx
@@ -1216,6 +1216,21 @@ DECLARE_OOXMLEXPORT_TEST(testShape3DEffectPreservation, "shape-3d-effect-preserv
assertXPath(pXmlDoc, "/w:document/w:body/w:p[3]/w:r/mc:AlternateContent/mc:Choice/w:drawing/"
"wp:anchor/a:graphic/a:graphicData/wps:wsp/wps:spPr/a:sp3d",
"contourW", "50800");
+ assertXPath(pXmlDoc, "/w:document/w:body/w:p[3]/w:r/mc:AlternateContent/mc:Choice/w:drawing/"
+ "wp:anchor/a:graphic/a:graphicData/wps:wsp/wps:spPr/a:sp3d/a:bevelT",
+ "w", "139700");
+ assertXPath(pXmlDoc, "/w:document/w:body/w:p[3]/w:r/mc:AlternateContent/mc:Choice/w:drawing/"
+ "wp:anchor/a:graphic/a:graphicData/wps:wsp/wps:spPr/a:sp3d/a:bevelT",
+ "h", "88900");
+ assertXPath(pXmlDoc, "/w:document/w:body/w:p[3]/w:r/mc:AlternateContent/mc:Choice/w:drawing/"
+ "wp:anchor/a:graphic/a:graphicData/wps:wsp/wps:spPr/a:sp3d/a:bevelT",
+ "prst", "cross");
+ assertXPath(pXmlDoc, "/w:document/w:body/w:p[3]/w:r/mc:AlternateContent/mc:Choice/w:drawing/"
+ "wp:anchor/a:graphic/a:graphicData/wps:wsp/wps:spPr/a:sp3d/a:bevelB",
+ "h", "88900");
+ assertXPath(pXmlDoc, "/w:document/w:body/w:p[3]/w:r/mc:AlternateContent/mc:Choice/w:drawing/"
+ "wp:anchor/a:graphic/a:graphicData/wps:wsp/wps:spPr/a:sp3d/a:bevelB",
+ "prst", "relaxedInset");
}
DECLARE_OOXMLEXPORT_TEST(fdo77719, "fdo77719.docx")