sw/qa/extras/rtfexport/data/tdf138210.rtf   |binary
 sw/qa/extras/rtfexport/rtfexport5.cxx       |    9 +++
 writerfilter/source/rtftok/rtfsdrimport.cxx |   74 +++++++++++++---------------
 3 files changed, 44 insertions(+), 39 deletions(-)

New commits:
commit 8c14adfa76956e76bac98330ce67f080c90af184
Author:     Mark Hung <mark...@gmail.com>
AuthorDate: Sat Nov 14 19:37:31 2020 +0800
Commit:     Mark Hung <mark...@gmail.com>
CommitDate: Sat Nov 21 02:32:49 2020 +0100

    tdf#138210 check if CustomShapeGeometry exist first.
    
    CustomShapeGeometry does not exist for a text frame. Getting
    the property throws an Exception and cause a general IO error.
    
    Change-Id: I0e31780292d45211bfd1250d0d359c72def50583
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/105834
    Tested-by: Jenkins
    Reviewed-by: Mark Hung <mark...@gmail.com>

diff --git a/sw/qa/extras/rtfexport/data/tdf138210.rtf 
b/sw/qa/extras/rtfexport/data/tdf138210.rtf
new file mode 100755
index 000000000000..d91a87d901e6
Binary files /dev/null and b/sw/qa/extras/rtfexport/data/tdf138210.rtf differ
diff --git a/sw/qa/extras/rtfexport/rtfexport5.cxx 
b/sw/qa/extras/rtfexport/rtfexport5.cxx
index 4bac42fecfb4..a48adfa653cd 100644
--- a/sw/qa/extras/rtfexport/rtfexport5.cxx
+++ b/sw/qa/extras/rtfexport/rtfexport5.cxx
@@ -25,6 +25,7 @@
 #include <com/sun/star/text/XPageCursor.hpp>
 #include <com/sun/star/text/XTextFieldsSupplier.hpp>
 #include <com/sun/star/text/XTextTablesSupplier.hpp>
+#include <com/sun/star/text/XTextFramesSupplier.hpp>
 #include <com/sun/star/text/XTextTable.hpp>
 #include <com/sun/star/text/XTextViewCursorSupplier.hpp>
 #include <com/sun/star/text/WritingMode2.hpp>
@@ -1251,6 +1252,14 @@ DECLARE_RTFEXPORT_TEST(testTdf129513, "tdf129513.rtf")
     CPPUNIT_ASSERT_EQUAL(OUString("In table"), xCell->getString());
 }
 
+DECLARE_RTFEXPORT_TEST(testTdf138210, "tdf138210.rtf")
+{
+    uno::Reference<text::XTextFramesSupplier> xTextFramesSupplier(mxComponent, 
uno::UNO_QUERY);
+    uno::Reference<container::XIndexAccess> 
xIndexAccess(xTextFramesSupplier->getTextFrames(),
+                                                         uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount());
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/writerfilter/source/rtftok/rtfsdrimport.cxx 
b/writerfilter/source/rtftok/rtfsdrimport.cxx
index b98723e5aee3..01af8259ff91 100644
--- a/writerfilter/source/rtftok/rtfsdrimport.cxx
+++ b/writerfilter/source/rtftok/rtfsdrimport.cxx
@@ -918,46 +918,43 @@ void RTFSdrImport::resolve(RTFShape& rShape, bool bClose, 
ShapeOrPict const shap
     }
 
     // Creating CustomShapeGeometry property
-    std::vector<beans::PropertyValue> aGeometry;
-    if (aViewBox.X || aViewBox.Y || aViewBox.Width || aViewBox.Height)
+    if (bCustom && xPropertySet.is())
     {
-        aViewBox.Width -= aViewBox.X;
-        aViewBox.Height -= aViewBox.Y;
-        aPropertyValue.Name = "ViewBox";
-        aPropertyValue.Value <<= aViewBox;
-        aGeometry.push_back(aPropertyValue);
-    }
-    if (!aPath.empty())
-    {
-        aPropertyValue.Name = "Path";
-        aPropertyValue.Value <<= comphelper::containerToSequence(aPath);
-        aGeometry.push_back(aPropertyValue);
-    }
-    if (!aGeometry.empty() && xPropertySet.is() && !m_bTextFrame)
-        xPropertySet->setPropertyValue("CustomShapeGeometry",
-                                       
uno::Any(comphelper::containerToSequence(aGeometry)));
+        bool bChanged = false;
+        comphelper::SequenceAsHashMap aCustomShapeGeometry(
+            xPropertySet->getPropertyValue("CustomShapeGeometry"));
 
-    if (!aShapeText.isEmpty())
-    {
-        auto aGeomPropSeq = 
xPropertySet->getPropertyValue("CustomShapeGeometry")
-                                .get<uno::Sequence<beans::PropertyValue>>();
-        auto aGeomPropVec
-            = 
comphelper::sequenceToContainer<std::vector<beans::PropertyValue>>(aGeomPropSeq);
-        uno::Sequence<beans::PropertyValue> 
aPropertyValues(comphelper::InitPropertySequence({
-            { "TextPath", uno::makeAny(true) },
-        }));
-        auto it = std::find_if(
-            aGeomPropVec.begin(), aGeomPropVec.end(),
-            [](const beans::PropertyValue& rValue) { return rValue.Name == 
"TextPath"; });
-        if (it == aGeomPropVec.end())
-            aGeomPropVec.push_back(comphelper::makePropertyValue("TextPath", 
aPropertyValues));
-        else
-            it->Value <<= aPropertyValues;
+        if (aViewBox.X || aViewBox.Y || aViewBox.Width || aViewBox.Height)
+        {
+            aViewBox.Width -= aViewBox.X;
+            aViewBox.Height -= aViewBox.Y;
+            aCustomShapeGeometry["ViewBox"] <<= aViewBox;
+            bChanged = true;
+        }
+
+        if (!aPath.empty())
+        {
+            aCustomShapeGeometry["Path"] <<= 
comphelper::containerToSequence(aPath);
+            bChanged = true;
+        }
+
+        if (!aShapeText.isEmpty())
+        {
+            uno::Sequence<beans::PropertyValue> 
aSequence(comphelper::InitPropertySequence({
+                { "TextPath", uno::makeAny(true) },
+            }));
+            aCustomShapeGeometry["TextPath"] <<= aSequence;
+            xPropertySet->setPropertyValue("TextAutoGrowHeight", 
uno::makeAny(false));
+            xPropertySet->setPropertyValue("TextAutoGrowWidth", 
uno::makeAny(false));
+            bChanged = true;
+        }
 
-        xPropertySet->setPropertyValue("CustomShapeGeometry",
-                                       
uno::makeAny(comphelper::containerToSequence(aGeomPropVec)));
-        xPropertySet->setPropertyValue("TextAutoGrowHeight", 
uno::makeAny(false));
-        xPropertySet->setPropertyValue("TextAutoGrowWidth", 
uno::makeAny(false));
+        if (bChanged)
+        {
+            xPropertySet->setPropertyValue(
+                "CustomShapeGeometry",
+                
uno::makeAny(aCustomShapeGeometry.getAsConstPropertyValueList()));
+        }
     }
 
     if (!boost::logic::indeterminate(obRelFlipV) && xPropertySet.is())
@@ -1033,8 +1030,7 @@ void RTFSdrImport::resolve(RTFShape& rShape, bool bClose, 
ShapeOrPict const shap
 
         if (obFlipH == true || obFlipV == true)
         {
-            // Line shapes have no CustomShapeGeometry.
-            if (nType != ESCHER_ShpInst_Line)
+            if (bCustom)
             {
                 // This has to be set after position and size is set, 
otherwise flip will affect the position.
                 comphelper::SequenceAsHashMap aCustomShapeGeometry(
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to