diff --git a/sw/qa/extras/odfexport/data/shape-relsize.odt b/sw/qa/extras/odfexport/data/shape-relsize.odt new file mode 100755 index 000000000000..05a3ffa591ff Binary files /dev/null and b/sw/qa/extras/odfexport/data/shape-relsize.odt differ diff --git a/sw/qa/extras/odfexport/odfexport.cxx b/sw/qa/extras/odfexport/odfexport.cxx index db752040e4a9..3d2450f4cb92 100644 --- a/sw/qa/extras/odfexport/odfexport.cxx +++ b/sw/qa/extras/odfexport/odfexport.cxx @@ -350,6 +350,14 @@ DECLARE_ODFEXPORT_TEST(testTextFrameVertAdjust, "textframe-vertadjust.odt") xFrame.set(getTextFrameByName("Rectangle 3"), uno::UNO_QUERY); CPPUNIT_ASSERT_EQUAL(drawing::TextVerticalAdjust_BOTTOM, getProperty(xFrame, "TextVerticalAdjust")); } + +DECLARE_ODFEXPORT_TEST(testShapeRelsize, "shape-relsize.odt") +{ + // These were all 0, as style:rel-width/height was ignored on import for shapes. + CPPUNIT_ASSERT_EQUAL(sal_Int16(40), getProperty(getShape(1), "RelativeWidth")); + CPPUNIT_ASSERT_EQUAL(sal_Int16(20), getProperty(getShape(1), "RelativeHeight")); +} + #endif CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/xmloff/source/draw/ximpshap.cxx b/xmloff/source/draw/ximpshap.cxx index d9c95a03b671..8ba56a37d23b 100644 --- a/xmloff/source/draw/ximpshap.cxx +++ b/xmloff/source/draw/ximpshap.cxx @@ -151,6 +151,8 @@ SdXMLShapeContext::SdXMLShapeContext( , mbIsUserTransformed(sal_False) , mnZOrder(-1) , maSize(1, 1) + , mnRelWidth(0) + , mnRelHeight(0) , maPosition(0, 0) , maUsedTransformation() , mbVisible(true) @@ -454,6 +456,16 @@ void SdXMLShapeContext::AddShape(uno::Reference< drawing::XShape >& xShape) xImp->shapeWithZIndexAdded( xShape, mnZOrder ); } + if (mnRelWidth || mnRelHeight) + { + uno::Reference xPropertySet(xShape, uno::UNO_QUERY); + uno::Reference xPropertySetInfo = xPropertySet->getPropertySetInfo(); + if (mnRelWidth && xPropertySetInfo->hasPropertyByName("RelativeWidth")) + xPropertySet->setPropertyValue("RelativeWidth", uno::makeAny(mnRelWidth)); + if (mnRelHeight && xPropertySetInfo->hasPropertyByName("RelativeHeight")) + xPropertySet->setPropertyValue("RelativeHeight", uno::makeAny(mnRelHeight)); + } + if( !maShapeId.isEmpty() ) { uno::Reference< uno::XInterface > xRef( static_cast(xShape.get()) ); @@ -888,6 +900,20 @@ void SdXMLShapeContext::processAttribute( sal_uInt16 nPrefix, const OUString& rL maShapeDescription = rValue; } } + else if (nPrefix == XML_NAMESPACE_STYLE) + { + sal_Int32 nTmp; + if (IsXMLToken(rLocalName, XML_REL_WIDTH)) + { + if (sax::Converter::convertPercent(nTmp, rValue)) + mnRelWidth = static_cast(nTmp); + } + else if (IsXMLToken(rLocalName, XML_REL_HEIGHT)) + { + if (sax::Converter::convertPercent(nTmp, rValue)) + mnRelHeight = static_cast(nTmp); + } + } else if( (XML_NAMESPACE_NONE == nPrefix) || (XML_NAMESPACE_XML == nPrefix) ) { if( IsXMLToken( rLocalName, XML_ID ) ) diff --git a/xmloff/source/draw/ximpshap.hxx b/xmloff/source/draw/ximpshap.hxx index a4b8786840b8..6ddb83b12b79 100644 --- a/xmloff/source/draw/ximpshap.hxx +++ b/xmloff/source/draw/ximpshap.hxx @@ -73,6 +73,8 @@ protected: SdXMLImExTransform2D mnTransform; com::sun::star::awt::Size maSize; + sal_Int16 mnRelWidth; + sal_Int16 mnRelHeight; com::sun::star::awt::Point maPosition; basegfx::B2DHomMatrix maUsedTransformation;