diff options
author | Jacobo Aragunde Pérez <jaragunde@igalia.com> | 2014-05-08 14:25:10 +0200 |
---|---|---|
committer | Jacobo Aragunde Pérez <jaragunde@igalia.com> | 2014-05-09 14:10:46 +0200 |
commit | 6566c218afec3cd8c4d36094777bc30b1970e9e4 (patch) | |
tree | 5982d9710abbe04199b34343e5afe1458c316678 | |
parent | 0df9ec782efeb24c02f7c5baef53bf2fa75a4bc5 (diff) |
ooxml: Preserve shape 3d effects: z, contour and extrusion
Shapes can contain 3D effects like in the following example:
<a:sp3d z="488950" extrusionH="63500" contourW="50800"/>
This patch preserves the a:sp3d tag and its attributes using the shape
grab bag and modifies an existing unit test to add this check.
Change-Id: Ice3cae39c71784be0f6c7f2700b07c21a5e1fb6e
-rw-r--r-- | include/oox/drawingml/scene3dcontext.hxx | 9 | ||||
-rw-r--r-- | include/oox/drawingml/shape3dproperties.hxx | 5 | ||||
-rw-r--r-- | oox/source/drawingml/scene3dcontext.cxx | 12 | ||||
-rw-r--r-- | oox/source/drawingml/shape.cxx | 4 | ||||
-rw-r--r-- | oox/source/drawingml/shape3dproperties.cxx | 26 | ||||
-rw-r--r-- | oox/source/drawingml/shapepropertiescontext.cxx | 3 | ||||
-rw-r--r-- | oox/source/export/drawingml.cxx | 30 | ||||
-rw-r--r-- | sw/qa/extras/ooxmlexport/data/shape-3d-effect-preservation.docx | bin | 17050 -> 18317 bytes | |||
-rw-r--r-- | sw/qa/extras/ooxmlexport/ooxmlsdrexport.cxx | 20 |
9 files changed, 103 insertions, 6 deletions
diff --git a/include/oox/drawingml/scene3dcontext.hxx b/include/oox/drawingml/scene3dcontext.hxx index 82af76eba44b..e4b7a62eef41 100644 --- a/include/oox/drawingml/scene3dcontext.hxx +++ b/include/oox/drawingml/scene3dcontext.hxx @@ -49,6 +49,15 @@ private: Shape3DProperties& mr3DProperties; }; +class Shape3DPropertiesContext : public ::oox::core::ContextHandler2 +{ +public: + Shape3DPropertiesContext( ::oox::core::ContextHandler2Helper& rParent, const ::oox::AttributeList& rAttribs, Shape3DProperties& r3DProperties ) throw(); + +private: + Shape3DProperties& mr3DProperties; +}; + } } #endif // INCLUDED_OOX_DRAWINGML_SCENE3DCONTEXT_HXX diff --git a/include/oox/drawingml/shape3dproperties.hxx b/include/oox/drawingml/shape3dproperties.hxx index 2577e3f9122d..a66d46cda14a 100644 --- a/include/oox/drawingml/shape3dproperties.hxx +++ b/include/oox/drawingml/shape3dproperties.hxx @@ -53,6 +53,10 @@ struct Shape3DProperties RotationProperties maCameraRotation; RotationProperties maLightRigRotation; + OptValue< sal_Int32 > mnExtrusionH; + OptValue< sal_Int32 > mnContourW; + OptValue< sal_Int32 > mnShapeZ; + /** Overwrites all members that are explicitly set in rSourceProps. */ void assignUsed( const Shape3DProperties& rSourceProps ); @@ -62,6 +66,7 @@ struct Shape3DProperties css::uno::Sequence< css::beans::PropertyValue > getCameraAttributes(); css::uno::Sequence< css::beans::PropertyValue > getLightRigAttributes(); + css::uno::Sequence< css::beans::PropertyValue > getShape3DAttributes(); }; diff --git a/oox/source/drawingml/scene3dcontext.cxx b/oox/source/drawingml/scene3dcontext.cxx index 7d95b7370503..bbae7abedd10 100644 --- a/oox/source/drawingml/scene3dcontext.cxx +++ b/oox/source/drawingml/scene3dcontext.cxx @@ -68,6 +68,18 @@ ContextHandlerRef Scene3DPropertiesContext::onCreateContext( sal_Int32 aElementT return 0; } +Shape3DPropertiesContext::Shape3DPropertiesContext( ContextHandler2Helper& rParent, const AttributeList& rAttribs, Shape3DProperties& r3DProperties ) throw() +: ContextHandler2( rParent ) +, mr3DProperties( r3DProperties ) +{ + if( rAttribs.hasAttribute( XML_extrusionH ) ) + mr3DProperties.mnExtrusionH = rAttribs.getInteger( XML_extrusionH, 0 ); + if( rAttribs.hasAttribute( XML_contourW ) ) + mr3DProperties.mnContourW = rAttribs.getInteger( XML_contourW, 0 ); + if( rAttribs.hasAttribute( XML_z ) ) + mr3DProperties.mnShapeZ = rAttribs.getInteger( XML_z, 0 ); +} + Scene3DRotationPropertiesContext::Scene3DRotationPropertiesContext( ContextHandler2Helper& rParent, RotationProperties& rRotationProperties ) throw() : ContextHandler2( rParent ) , mrRotationProperties( rRotationProperties ) diff --git a/oox/source/drawingml/shape.cxx b/oox/source/drawingml/shape.cxx index 564f51bbd3a0..da125cfa4ab9 100644 --- a/oox/source/drawingml/shape.cxx +++ b/oox/source/drawingml/shape.cxx @@ -940,11 +940,13 @@ Reference< XShape > Shape::createAndInsert( // add 3D effects if any Sequence< PropertyValue > aCamera3DEffects = get3DProperties().getCameraAttributes(); Sequence< PropertyValue > aLightRig3DEffects = get3DProperties().getLightRigAttributes(); + Sequence< PropertyValue > aShape3DEffects = get3DProperties().getShape3DAttributes(); if( aCamera3DEffects.getLength() > 0 || aLightRig3DEffects.getLength() > 0 ) { - Sequence< PropertyValue > a3DEffectsGrabBag( 2 ); + Sequence< PropertyValue > a3DEffectsGrabBag( 3 ); PUT_PROP( a3DEffectsGrabBag, 0, "Camera", Any( aCamera3DEffects ) ); PUT_PROP( a3DEffectsGrabBag, 1, "LightRig", Any( aLightRig3DEffects ) ); + PUT_PROP( a3DEffectsGrabBag, 2, "Shape3D", Any( aShape3DEffects ) ); putPropertyToGrabBag( "3DEffectProperties", Any( a3DEffectsGrabBag ) ); } } diff --git a/oox/source/drawingml/shape3dproperties.cxx b/oox/source/drawingml/shape3dproperties.cxx index 47346a963b1c..7da8a0b4d9f1 100644 --- a/oox/source/drawingml/shape3dproperties.cxx +++ b/oox/source/drawingml/shape3dproperties.cxx @@ -253,6 +253,32 @@ css::uno::Sequence< css::beans::PropertyValue > Shape3DProperties::getLightRigAt return aSeq; } +css::uno::Sequence< css::beans::PropertyValue > Shape3DProperties::getShape3DAttributes() +{ + css::uno::Sequence<css::beans::PropertyValue> aSeq(3); + sal_Int32 nSize = 0; + if( mnExtrusionH.has() ) + { + aSeq[nSize].Name = "extrusionH"; + aSeq[nSize].Value = css::uno::Any( mnExtrusionH.use() ); + nSize++; + } + if( mnContourW.has() ) + { + aSeq[nSize].Name = "contourW"; + aSeq[nSize].Value = css::uno::Any( mnContourW.use() ); + nSize++; + } + if( mnShapeZ.has() ) + { + aSeq[nSize].Name = "z"; + aSeq[nSize].Value = css::uno::Any( mnShapeZ.use() ); + nSize++; + } + aSeq.realloc( nSize ); + return aSeq; +} + } // namespace drawingml diff --git a/oox/source/drawingml/shapepropertiescontext.cxx b/oox/source/drawingml/shapepropertiescontext.cxx index 0823e67240c7..daf87312402c 100644 --- a/oox/source/drawingml/shapepropertiescontext.cxx +++ b/oox/source/drawingml/shapepropertiescontext.cxx @@ -99,8 +99,9 @@ ContextHandlerRef ShapePropertiesContext::onCreateContext( sal_Int32 aElementTok return new Scene3DPropertiesContext( *this, mrShape.get3DProperties() ); break; - // todo + // todo not supported by core, only for preservation via grab bags case A_TOKEN( sp3d ): // CT_Shape3D + return new Shape3DPropertiesContext( *this, rAttribs, mrShape.get3DProperties() ); break; } diff --git a/oox/source/export/drawingml.cxx b/oox/source/export/drawingml.cxx index abe338b70bf4..0b437db8acb9 100644 --- a/oox/source/export/drawingml.cxx +++ b/oox/source/export/drawingml.cxx @@ -2277,7 +2277,7 @@ void DrawingML::WriteShape3DEffects( Reference< XPropertySet > xPropSet ) return; // extract the relevant properties from the grab bag - Sequence< PropertyValue > aGrabBag, aEffectProps, aLightRigProps; + Sequence< PropertyValue > aGrabBag, aEffectProps, aLightRigProps, aShape3DProps; mAny >>= aGrabBag; for( sal_Int32 i=0; i < aGrabBag.getLength(); ++i ) if( aGrabBag[i].Name == "3DEffectProperties" ) @@ -2290,10 +2290,12 @@ void DrawingML::WriteShape3DEffects( Reference< XPropertySet > xPropSet ) a3DEffectProps[j].Value >>= aEffectProps; else if( a3DEffectProps[j].Name == "LightRig" ) a3DEffectProps[j].Value >>= aLightRigProps; + else if( a3DEffectProps[j].Name == "Shape3D" ) + a3DEffectProps[j].Value >>= aShape3DProps; } break; } - if( aEffectProps.getLength() == 0 && aLightRigProps.getLength() == 0 ) + if( aEffectProps.getLength() == 0 && aLightRigProps.getLength() == 0 && aShape3DProps.getLength() == 0 ) return; bool bCameraRotationPresent = false; @@ -2402,6 +2404,30 @@ void DrawingML::WriteShape3DEffects( Reference< XPropertySet > xPropSet ) mpFS->singleElementNS( XML_a, XML_lightRig, XML_rig, "threePt", XML_dir, "t", FSEND ); mpFS->endElementNS( XML_a, XML_scene3d ); + + if( aShape3DProps.getLength() == 0 ) + return; + + sax_fastparser::FastAttributeList *aShape3DAttrList = mpFS->createAttrList(); + for( sal_Int32 i=0; i < aShape3DProps.getLength(); ++i ) + { + if( aShape3DProps[i].Name == "extrusionH" || aShape3DProps[i].Name == "contourW" || aShape3DProps[i].Name == "z" ) + { + sal_Int32 nVal = 0, nToken = XML_none; + aShape3DProps[i].Value >>= nVal; + if( aShape3DProps[i].Name == "extrusionH" ) + nToken = XML_extrusionH; + else if( aShape3DProps[i].Name == "contourW" ) + nToken = XML_contourW; + else if( aShape3DProps[i].Name == "z" ) + nToken = XML_z; + aShape3DAttrList->add( nToken, OString::number( nVal ).getStr() ); + } + } + + sax_fastparser::XFastAttributeListRef xAttrList( aShape3DAttrList ); + mpFS->startElementNS( XML_a, XML_sp3d, xAttrList ); + mpFS->endElementNS( XML_a, XML_sp3d ); } } diff --git a/sw/qa/extras/ooxmlexport/data/shape-3d-effect-preservation.docx b/sw/qa/extras/ooxmlexport/data/shape-3d-effect-preservation.docx Binary files differindex ed414831e4c9..dd4a522aad12 100644 --- a/sw/qa/extras/ooxmlexport/data/shape-3d-effect-preservation.docx +++ b/sw/qa/extras/ooxmlexport/data/shape-3d-effect-preservation.docx diff --git a/sw/qa/extras/ooxmlexport/ooxmlsdrexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlsdrexport.cxx index 727aef9e9501..d7bcf07fa22b 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlsdrexport.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlsdrexport.cxx @@ -1151,7 +1151,7 @@ DECLARE_OOXMLEXPORT_TEST(testShape3DEffectPreservation, "shape-3d-effect-preserv if (!pXmlDoc) return; - // first shape + // first shape: extrusion and shift on z, rotated camera with zoom, rotated light rig 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:scene3d/a:camera", "prst", "perspectiveRelaxedModerately"); @@ -1184,7 +1184,14 @@ DECLARE_OOXMLEXPORT_TEST(testShape3DEffectPreservation, "shape-3d-effect-preserv "wp:anchor/a:graphic/a:graphicData/wps:wsp/wps:spPr/a:scene3d/a:lightRig/a:rot", "rev", "4800000"); - // second shape + 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:sp3d", + "extrusionH", "63500"); + 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:sp3d", + "z", "488950"); + + // second shape: extrusion with theme color, no camera or light rotation 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:scene3d/a:camera", "prst", "isometricLeftDown"); @@ -1200,6 +1207,15 @@ DECLARE_OOXMLEXPORT_TEST(testShape3DEffectPreservation, "shape-3d-effect-preserv 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:scene3d/a:lightRig/a:rot", 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:sp3d", + "extrusionH", "25400"); + + // third shape: colored countour and top and bottom bevel + 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"); } DECLARE_OOXMLEXPORT_TEST(fdo77719, "fdo77719.docx") |