[Libreoffice-commits] core.git: sw/qa xmloff/source

Miklos Vajna vmiklos at collabora.co.uk
Tue Feb 25 03:12:05 PST 2014


 sw/qa/extras/odfexport/data/shape-relsize.odt |binary
 sw/qa/extras/odfexport/odfexport.cxx          |    8 ++++++++
 xmloff/source/draw/ximpshap.cxx               |   26 ++++++++++++++++++++++++++
 xmloff/source/draw/ximpshap.hxx               |    2 ++
 4 files changed, 36 insertions(+)

New commits:
commit 4da81e4a0bda96c3d25aa22341f94b58e584cefb
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Tue Feb 25 11:47:32 2014 +0100

    xmloff: import style:rel-width/height for drawinglayer shapes
    
    In case the underlying UNO object supports that, which is the case for
    Writer. Export was already working before.
    
    Change-Id: I4676c8349ebe1959da004d6e1a024a342da45049

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 0000000..05a3ffa
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 db75204..3d2450f 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<drawing::TextVerticalAdjust>(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<sal_Int16>(getShape(1), "RelativeWidth"));
+    CPPUNIT_ASSERT_EQUAL(sal_Int16(20), getProperty<sal_Int16>(getShape(1), "RelativeHeight"));
+}
+
 #endif
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/xmloff/source/draw/ximpshap.cxx b/xmloff/source/draw/ximpshap.cxx
index d9c95a0..8ba56a3 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<beans::XPropertySet> xPropertySet(xShape, uno::UNO_QUERY);
+            uno::Reference<beans::XPropertySetInfo> 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<uno::XInterface *>(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<sal_Int16>(nTmp);
+        }
+        else if (IsXMLToken(rLocalName, XML_REL_HEIGHT))
+        {
+            if (sax::Converter::convertPercent(nTmp, rValue))
+                mnRelHeight = static_cast<sal_Int16>(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 a4b8786..6ddb83b 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;
 


More information about the Libreoffice-commits mailing list