From b399c1a38cf7217bf530af3a78e8472d97890ac8 Mon Sep 17 00:00:00 2001 From: Cédric Bosdonnat Date: Mon, 29 Apr 2013 15:41:37 +0200 Subject: n#592908: docx import, fixed handling of w10:wrap commit f837c4288cdae4921b3fb6747ba2e2cd5ce2dcd2 moved the handling of w10:wrap tag in oox, but thus no wrapping was imported any more. The fix consists in letting the w10:wrap element be handled by writerfilter's dmapper if the shape has already been retrieved from oox (which is the case for textboxes). In other cases, make sure that we don't set the Surround property once again in writerfilter as that would override what has been done in oox. (cherry picked from commit 51d5e90b7c09cb980bc72a2c6b1a65303ef15ea2) Conflicts: oox/inc/oox/vml/vmlshape.hxx sw/qa/extras/ooxmlimport/ooxmlimport.cxx Change-Id: I8ab158641afcf6b9945c52238e7f5adb9e8b3adf --- include/oox/vml/vmlshape.hxx | 2 ++ oox/source/token/properties.txt | 1 + oox/source/vml/vmlshape.cxx | 20 +++++++++++++++++ oox/source/vml/vmlshapecontext.cxx | 2 ++ sw/qa/extras/ooxmlimport/data/n592908-frame.docx | Bin 0 -> 13589 bytes sw/qa/extras/ooxmlimport/data/n592908-picture.docx | Bin 0 -> 62593 bytes sw/qa/extras/ooxmlimport/ooxmlimport.cxx | 24 +++++++++++++++++++++ writerfilter/source/dmapper/OLEHandler.cxx | 12 +---------- .../source/ooxml/OOXMLFastContextHandler.cxx | 8 +++---- .../source/ooxml/OOXMLFastContextHandler.hxx | 2 ++ 10 files changed, 56 insertions(+), 15 deletions(-) create mode 100644 sw/qa/extras/ooxmlimport/data/n592908-frame.docx create mode 100644 sw/qa/extras/ooxmlimport/data/n592908-picture.docx diff --git a/include/oox/vml/vmlshape.hxx b/include/oox/vml/vmlshape.hxx index 7b6a4a9376c7..e16fe90635c8 100644 --- a/include/oox/vml/vmlshape.hxx +++ b/include/oox/vml/vmlshape.hxx @@ -93,6 +93,8 @@ struct OOX_DLLPUBLIC ShapeTypeModel OptValue< OUString > moGraphicTitle; ///< Title of the graphic. OptValue< OUString > moWrapAnchorX; ///< The base object from which our horizontal positioning should be calculated. OptValue< OUString > moWrapAnchorY; ///< The base object from which our vertical positioning should be calculated. + OptValue< ::rtl::OUString > moWrapType; ///< How to wrap the text around the object + OptValue< ::rtl::OUString > moWrapSide; ///< On which side to wrap the text around the object explicit ShapeTypeModel(); diff --git a/oox/source/token/properties.txt b/oox/source/token/properties.txt index 243058010841..fb3e5a5e4529 100644 --- a/oox/source/token/properties.txt +++ b/oox/source/token/properties.txt @@ -465,6 +465,7 @@ StringItemList Subtotals SubViewSize Suffix +Surround SwapXAndYAxis Symbol SymbolColor diff --git a/oox/source/vml/vmlshape.cxx b/oox/source/vml/vmlshape.cxx index 3239151aa0f0..0af325d52233 100644 --- a/oox/source/vml/vmlshape.cxx +++ b/oox/source/vml/vmlshape.cxx @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -405,6 +406,24 @@ SimpleShape::SimpleShape( Drawing& rDrawing, const OUString& rService ) : { } +void lcl_setSurround(PropertySet& rPropSet, const ShapeTypeModel& rTypeModel) +{ + sal_Int32 nSurround = com::sun::star::text::WrapTextMode_THROUGHT; + if ( rTypeModel.moWrapType.get() == "square" || rTypeModel.moWrapType .get()== "tight" || + rTypeModel.moWrapType.get() == "through" ) + { + nSurround = com::sun::star::text::WrapTextMode_PARALLEL; + if ( rTypeModel.moWrapSide.get() == "left" ) + nSurround = com::sun::star::text::WrapTextMode_LEFT; + else if ( rTypeModel.moWrapSide.get() == "right" ) + nSurround = com::sun::star::text::WrapTextMode_RIGHT; + } + else if ( rTypeModel.moWrapType.get() == "topAndBottom" ) + nSurround = com::sun::star::text::WrapTextMode_NONE; + + rPropSet.setProperty(PROP_Surround, nSurround); +} + void lcl_SetAnchorType(PropertySet& rPropSet, const ShapeTypeModel& rTypeModel) { if ( rTypeModel.maPositionHorizontal == "center" ) @@ -449,6 +468,7 @@ void lcl_SetAnchorType(PropertySet& rPropSet, const ShapeTypeModel& rTypeModel) { rPropSet.setProperty(PROP_AnchorType, text::TextContentAnchorType_AS_CHARACTER); } + lcl_setSurround( rPropSet, rTypeModel ); } Reference< XShape > SimpleShape::implConvertAndInsert( const Reference< XShapes >& rxShapes, const awt::Rectangle& rShapeRect ) const diff --git a/oox/source/vml/vmlshapecontext.cxx b/oox/source/vml/vmlshapecontext.cxx index c5edd00e65ac..e0f8cfb659a7 100644 --- a/oox/source/vml/vmlshapecontext.cxx +++ b/oox/source/vml/vmlshapecontext.cxx @@ -360,6 +360,8 @@ ContextHandlerRef ShapeTypeContext::onCreateContext( sal_Int32 nElement, const A case NMSP_vmlWord | XML_wrap: mrTypeModel.moWrapAnchorX = rAttribs.getString(XML_anchorx); mrTypeModel.moWrapAnchorY = rAttribs.getString(XML_anchory); + mrTypeModel.moWrapType = rAttribs.getString(XML_type); + mrTypeModel.moWrapSide = rAttribs.getString(XML_side); break; case VML_TOKEN( shadow ): { diff --git a/sw/qa/extras/ooxmlimport/data/n592908-frame.docx b/sw/qa/extras/ooxmlimport/data/n592908-frame.docx new file mode 100644 index 000000000000..ff59cacbad79 Binary files /dev/null and b/sw/qa/extras/ooxmlimport/data/n592908-frame.docx differ diff --git a/sw/qa/extras/ooxmlimport/data/n592908-picture.docx b/sw/qa/extras/ooxmlimport/data/n592908-picture.docx new file mode 100644 index 000000000000..2766d3691cdd Binary files /dev/null and b/sw/qa/extras/ooxmlimport/data/n592908-picture.docx differ diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx index 25e44951faf3..423900f70d33 100644 --- a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx +++ b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx @@ -107,6 +107,8 @@ public: void testTableWidth(); void testConditionalstylesTbllook(); void testFdo63685(); + void testN592908_Frame(); + void testN592908_Picture(); CPPUNIT_TEST_SUITE(Test); #if !defined(MACOSX) && !defined(WNT) @@ -184,6 +186,8 @@ void Test::run() {"table_width.docx", &Test::testTableWidth}, {"conditionalstyles-tbllook.docx", &Test::testConditionalstylesTbllook}, {"fdo63685.docx", &Test::testFdo63685}, + {"n592908-frame.docx", &Test::testN592908_Frame}, + {"n592908-picture.docx", &Test::testN592908_Picture}, }; header(); for (unsigned int i = 0; i < SAL_N_ELEMENTS(aMethods); ++i) @@ -1315,6 +1319,26 @@ void Test::testFdo63685() CPPUNIT_ASSERT_EQUAL(sal_Int32(318), getProperty(xDraws->getByIndex(0), "TopMargin")); } +void Test::testN592908_Frame() +{ + uno::Reference xDrawPageSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference xDraws(xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY); + uno::Reference xPropertySet(xDraws->getByIndex(0), uno::UNO_QUERY); + text::WrapTextMode eValue; + xPropertySet->getPropertyValue("Surround") >>= eValue; + CPPUNIT_ASSERT_EQUAL(eValue, text::WrapTextMode_PARALLEL); +} + +void Test::testN592908_Picture() +{ + uno::Reference xDrawPageSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference xDraws(xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY); + uno::Reference xPropertySet(xDraws->getByIndex(0), uno::UNO_QUERY); + text::WrapTextMode eValue; + xPropertySet->getPropertyValue("Surround") >>= eValue; + CPPUNIT_ASSERT_EQUAL(eValue, text::WrapTextMode_PARALLEL); +} + CPPUNIT_TEST_SUITE_REGISTRATION(Test); CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/writerfilter/source/dmapper/OLEHandler.cxx b/writerfilter/source/dmapper/OLEHandler.cxx index ae4490f30cc3..e2a333535ecb 100644 --- a/writerfilter/source/dmapper/OLEHandler.cxx +++ b/writerfilter/source/dmapper/OLEHandler.cxx @@ -113,17 +113,7 @@ void OLEHandler::lcl_attribute(Id rName, Value & rVal) { SAL_WARN("writerfilter", "Exception in OLE Handler: " << e.Message); } - - try - { - xShapeProps->setPropertyValue( - rNameSupplier.GetName( PROP_SURROUND ), - uno::makeAny( m_nWrapMode ) ); - } - catch( const uno::Exception& e ) - { - SAL_WARN("writerfilter", "Exception while setting wrap mode: " << e.Message); - } + // No need to set the wrapping here as it's either set in oox or will be set later } } break; diff --git a/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx b/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx index 8c02cca4bcbc..f4a7924432ea 100644 --- a/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx +++ b/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx @@ -2283,11 +2283,14 @@ OOXMLFastContextHandlerWrapper::lcl_createFastChildContext bool bInNamespaces = mMyNamespaces.find(nNameSpace) != mMyNamespaces.end(); bool bInTokens = mMyTokens.find( Element ) != mMyTokens.end( ); + OOXMLFastContextHandlerShape* pShapeCtx = (OOXMLFastContextHandlerShape*)mpParent; + // We have methods to _add_ individual tokens or whole namespaces to be // processed by writerfilter (instead of oox), but we have no method to // filter out a single token. Just hardwire the wrap token here till we // need a more generic solution. - if ( bInNamespaces && Element != static_cast(NS_vml_wordprocessingDrawing | OOXML_wrap) ) + bool bIsWrap = Element == static_cast(NS_vml_wordprocessingDrawing | OOXML_wrap); + if ( bInNamespaces && ((pShapeCtx->isShapeSent() && bIsWrap) || !bIsWrap) ) xResult.set(OOXMLFactory::getInstance()->createFastChildContextFromStart(this, Element)); else if (mxContext.is()) { @@ -2302,10 +2305,7 @@ OOXMLFastContextHandlerWrapper::lcl_createFastChildContext xResult.set(this); if ( bInTokens ) - { - OOXMLFastContextHandlerShape* pShapeCtx = (OOXMLFastContextHandlerShape*)mpParent; pShapeCtx->sendShape( Element ); - } return xResult; } diff --git a/writerfilter/source/ooxml/OOXMLFastContextHandler.hxx b/writerfilter/source/ooxml/OOXMLFastContextHandler.hxx index b47f611046a8..b1941b65c179 100644 --- a/writerfilter/source/ooxml/OOXMLFastContextHandler.hxx +++ b/writerfilter/source/ooxml/OOXMLFastContextHandler.hxx @@ -531,6 +531,7 @@ public: virtual ResourceEnum_t getResource() const { return SHAPE; } void sendShape( Token_t Element ); + bool isShapeSent( ) { return m_bShapeSent; } protected: typedef uno::Reference ShapeContextRef; @@ -633,6 +634,7 @@ private: set mMyNamespaces; set mMyTokens; OOXMLPropertySet::Pointer_t mpPropertySet; + bool mbShapeSent; OOXMLFastContextHandler * getFastContextHandler() const; }; -- cgit