[Libreoffice-commits] core.git: oox/source

Miklos Vajna vmiklos at collabora.co.uk
Mon May 5 05:21:12 PDT 2014


 oox/source/shape/WpsContext.cxx |   31 ++++++++++++++++++-------------
 1 file changed, 18 insertions(+), 13 deletions(-)

New commits:
commit 315503314aaeed11d1e25d5a379d56fd3051dba0
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Mon May 5 14:11:45 2014 +0200

    oox: don't try to set Writer-specific properties on non-TextFrames...
    
    ... during DOCX import of shapes with text, so that we don't crash when
    the currently always active
    setServiceName("com.sun.star.text.TextFrame") call is not present.
    
    Change-Id: I5b005583ddcee81b9683e3b34e8f0a2e5faa4f95

diff --git a/oox/source/shape/WpsContext.cxx b/oox/source/shape/WpsContext.cxx
index 5723709..fa17304 100644
--- a/oox/source/shape/WpsContext.cxx
+++ b/oox/source/shape/WpsContext.cxx
@@ -73,20 +73,24 @@ oox::core::ContextHandlerRef WpsContext::onCreateContext(sal_Int32 nElementToken
                 }
             }
 
-            // Handle inset attributes for Writer textframes.
-            sal_Int32 aInsets[] = { XML_lIns, XML_tIns, XML_rIns, XML_bIns };
-            boost::optional<sal_Int32> oInsets[4];
-            for (size_t i = 0; i < SAL_N_ELEMENTS(aInsets); ++i)
+            uno::Reference<lang::XServiceInfo> xServiceInfo(mxShape, uno::UNO_QUERY);
+            uno::Reference<beans::XPropertySet> xPropertySet(mxShape, uno::UNO_QUERY);
+            if (xServiceInfo.is() && xServiceInfo->supportsService("com.sun.star.text.TextFrame"))
             {
-                OptValue<OUString> oValue = rAttribs.getString(aInsets[i]);
-                if (oValue.has())
-                    oInsets[i] = oox::drawingml::GetCoordinate(oValue.get());
+                // Handle inset attributes for Writer textframes.
+                sal_Int32 aInsets[] = { XML_lIns, XML_tIns, XML_rIns, XML_bIns };
+                boost::optional<sal_Int32> oInsets[4];
+                for (size_t i = 0; i < SAL_N_ELEMENTS(aInsets); ++i)
+                {
+                    OptValue<OUString> oValue = rAttribs.getString(aInsets[i]);
+                    if (oValue.has())
+                        oInsets[i] = oox::drawingml::GetCoordinate(oValue.get());
+                }
+                OUString aProps[] = { OUString("LeftBorderDistance"), OUString("TopBorderDistance"), OUString("RightBorderDistance"), OUString("BottomBorderDistance") };
+                for (size_t i = 0; i < SAL_N_ELEMENTS(aProps); ++i)
+                    if (oInsets[i])
+                        xPropertySet->setPropertyValue(aProps[i], uno::makeAny(*oInsets[i]));
             }
-            OUString aProps[] = { OUString("LeftBorderDistance"), OUString("TopBorderDistance"), OUString("RightBorderDistance"), OUString("BottomBorderDistance") };
-            uno::Reference<beans::XPropertySet> xPropertySet(mxShape, uno::UNO_QUERY);
-            for (size_t i = 0; i < SAL_N_ELEMENTS(aProps); ++i)
-                if (oInsets[i])
-                    xPropertySet->setPropertyValue(aProps[i], uno::makeAny(*oInsets[i]));
 
             // Handle text vertical adjustment inside a text frame
             if (rAttribs.hasAttribute(XML_anchor))
@@ -100,11 +104,12 @@ oox::core::ContextHandlerRef WpsContext::onCreateContext(sal_Int32 nElementToken
     case XML_noAutofit:
     case XML_spAutoFit:
     {
+        uno::Reference<lang::XServiceInfo> xServiceInfo(mxShape, uno::UNO_QUERY);
         // We can't use oox::drawingml::TextBodyPropertiesContext here, as this
         // is a child context of bodyPr, so the shape is already sent: we need
         // to alter the XShape directly.
         uno::Reference<beans::XPropertySet> xPropertySet(mxShape, uno::UNO_QUERY);
-        if (xPropertySet.is())
+        if (xPropertySet.is() && xServiceInfo->supportsService("com.sun.star.text.TextFrame"))
             xPropertySet->setPropertyValue("FrameIsAutomaticHeight", uno::makeAny(getBaseToken(nElementToken) == XML_spAutoFit));
     }
     break;


More information about the Libreoffice-commits mailing list