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

Miklos Vajna vmiklos at suse.cz
Mon Jul 8 08:16:31 PDT 2013


 sw/qa/extras/rtfimport/data/groupshape.rtf     |   76 +++++++++++++++++++++++++
 sw/qa/extras/rtfimport/rtfimport.cxx           |   12 +++
 writerfilter/source/rtftok/rtfdocumentimpl.cxx |   20 +++++-
 writerfilter/source/rtftok/rtfdocumentimpl.hxx |    1 
 writerfilter/source/rtftok/rtfsdrimport.cxx    |   21 +++++-
 writerfilter/source/rtftok/rtfsdrimport.hxx    |    8 ++
 6 files changed, 131 insertions(+), 7 deletions(-)

New commits:
commit 2e11cb276e54c6fe4e903c7f44e36bc36798ba63
Author: Miklos Vajna <vmiklos at suse.cz>
Date:   Mon Jul 8 16:21:28 2013 +0200

    Related: fdo#66040 RTF import: by default, do create a group shape for \shpgrp
    
    The bugfix was just for the special case when we must create textframes
    due to the contained tables, this one add support for the default case
    when we want a real group shape.
    
    Change-Id: I74b77b233235959266a24660c970a79e41d8b272

diff --git a/sw/qa/extras/rtfimport/data/groupshape.rtf b/sw/qa/extras/rtfimport/data/groupshape.rtf
new file mode 100644
index 0000000..b237570
--- /dev/null
+++ b/sw/qa/extras/rtfimport/data/groupshape.rtf
@@ -0,0 +1,76 @@
+{\rtf1
+\paperw16840\paperh11907\margl567\margr567\margt567\margb567
+{\shpgrp
+{\*\shpinst\shpleft-201\shptop-585\shpright16112\shpbottom11321
+{\sp
+{\sn groupLeft}
+{\sv 288}
+}
+{\sp
+{\sn groupTop}
+{\sv -18}
+}
+{\sp
+{\sn groupRight}
+{\sv 16601}
+}
+{\sp
+{\sn groupBottom}
+{\sv 11888}
+}
+{\shp
+{\*\shpinst
+{\sp
+{\sn relLeft}
+{\sv 288}
+}
+{\sp
+{\sn relTop}
+{\sv -18}
+}
+{\sp
+{\sn relRight}
+{\sv 8225}
+}
+{\sp
+{\sn relBottom}
+{\sv 11888}
+}
+{\sp
+{\sn shapeType}
+{\sv 202}
+}
+{\shptxt foo
+}
+}
+}
+{\shp
+{\*\shpinst
+{\sp
+{\sn relLeft}
+{\sv 8664}
+}
+{\sp
+{\sn relTop}
+{\sv -18}
+}
+{\sp
+{\sn relRight}
+{\sv 16601}
+}
+{\sp
+{\sn relBottom}
+{\sv 11888}
+}
+{\sp
+{\sn shapeType}
+{\sv 202}
+}
+{\shptxt baz
+}
+}
+}
+}
+}
+\par
+}
diff --git a/sw/qa/extras/rtfimport/rtfimport.cxx b/sw/qa/extras/rtfimport/rtfimport.cxx
index b22e729..3aa8d19 100644
--- a/sw/qa/extras/rtfimport/rtfimport.cxx
+++ b/sw/qa/extras/rtfimport/rtfimport.cxx
@@ -151,6 +151,7 @@ public:
     void testN823675();
     void testFdo47802();
     void testFdo39001();
+    void testGroupshape();
 
     CPPUNIT_TEST_SUITE(Test);
 #if !defined(MACOSX) && !defined(WNT)
@@ -287,6 +288,7 @@ void Test::run()
         {"n823675.rtf", &Test::testN823675},
         {"fdo47802.rtf", &Test::testFdo47802},
         {"fdo39001.rtf", &Test::testFdo39001},
+        {"groupshape.rtf", &Test::testGroupshape},
     };
     header();
     for (unsigned int i = 0; i < SAL_N_ELEMENTS(aMethods); ++i)
@@ -1395,6 +1397,16 @@ void Test::testFdo39001()
     CPPUNIT_ASSERT_EQUAL(3, getPages());
 }
 
+void Test::testGroupshape()
+{
+    uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY);
+    uno::Reference<container::XIndexAccess> xDraws(xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY);
+    // There should be a single groupshape with 2 children.
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xDraws->getCount());
+    uno::Reference<drawing::XShapes> xGroupshape(xDraws->getByIndex(0), uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(2), xGroupshape->getCount());
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(Test);
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index 73d06c4..1cd2ad2 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -1682,7 +1682,18 @@ int RTFDocumentImpl::dispatchDestination(RTFKeyword nKeyword)
         case RTF_SHPGRP:
             {
                 RTFLookahead aLookahead(Strm(), m_pTokenizer->getGroupStart());
-                SAL_WARN_IF(!aLookahead.hasTable(), "writerfilter", "no table in groupshape, should create it!");
+                if (!aLookahead.hasTable())
+                {
+                    uno::Reference<drawing::XShapes> xGroupShape(m_xModelFactory->createInstance("com.sun.star.drawing.GroupShape"), uno::UNO_QUERY);
+                    uno::Reference<drawing::XDrawPageSupplier> xDrawSupplier(m_xDstDoc, uno::UNO_QUERY);
+                    if (xDrawSupplier.is())
+                    {
+                        uno::Reference<drawing::XShape> xShape(xGroupShape, uno::UNO_QUERY);
+                        xDrawSupplier->getDrawPage()->add(xShape);
+                    }
+                    m_pSdrImport->pushParent(xGroupShape);
+                    m_aStates.top().bCreatedShapeGroup = true;
+                }
                 m_aStates.top().nDestinationState = DESTINATION_SHAPEGROUP;
                 m_aStates.top().bInShapeGroup = true;
             }
@@ -4404,6 +4415,10 @@ int RTFDocumentImpl::popState()
         case DESTINATION_MEQARR:
             m_aMathBuffer.appendClosingTag(M_TOKEN(eqArr));
             break;
+        case DESTINATION_SHAPEGROUP:
+            if (aState.bCreatedShapeGroup)
+                m_pSdrImport->popParent();
+            break;
         default:
             break;
     }
@@ -4764,7 +4779,8 @@ RTFParserState::RTFParserState(RTFDocumentImpl *pDocumentImpl)
     bInListpicture(false),
     bInBackground(false),
     bHadShapeText(false),
-    bInShapeGroup(false)
+    bInShapeGroup(false),
+    bCreatedShapeGroup(false)
 {
 }
 
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.hxx b/writerfilter/source/rtftok/rtfdocumentimpl.hxx
index 5c39af1..6d05b90 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.hxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.hxx
@@ -263,6 +263,7 @@ namespace writerfilter {
 
                 bool bHadShapeText;
                 bool bInShapeGroup; ///< If we're inside a \shpgrp group.
+                bool bCreatedShapeGroup; ///< A GroupShape was created and pushed to the parent stack.
         };
 
         class RTFTokenizer;
diff --git a/writerfilter/source/rtftok/rtfsdrimport.cxx b/writerfilter/source/rtftok/rtfsdrimport.cxx
index e10457b..0494ac0 100644
--- a/writerfilter/source/rtftok/rtfsdrimport.cxx
+++ b/writerfilter/source/rtftok/rtfsdrimport.cxx
@@ -236,7 +236,8 @@ void RTFSdrImport::resolve(RTFShape& rShape, bool bClose)
                     break;
                 case ESCHER_ShpInst_Rectangle:
                 case ESCHER_ShpInst_TextBox:
-                    if (!bClose)
+                    // If we're inside a groupshape, can't use text frames.
+                    if (!bClose && m_aParents.size() == 1)
                     {
                         createShape("com.sun.star.text.TextFrame", xShape, xPropertySet);
                         bTextFrame = true;
commit 6d191c06c737e4c7f3e2c5f8b871d1037b4ce783
Author: Miklos Vajna <vmiklos at suse.cz>
Date:   Mon Jul 8 16:13:35 2013 +0200

    RTFSdrImport: support stacking of parents
    
    Change-Id: Ie8f039ce403832e54251a751609d91b8d608ed79

diff --git a/writerfilter/source/rtftok/rtfsdrimport.cxx b/writerfilter/source/rtftok/rtfsdrimport.cxx
index 0e07a45..e10457b 100644
--- a/writerfilter/source/rtftok/rtfsdrimport.cxx
+++ b/writerfilter/source/rtftok/rtfsdrimport.cxx
@@ -47,11 +47,13 @@ RTFSdrImport::RTFSdrImport(RTFDocumentImpl& rDocument,
 {
     uno::Reference<drawing::XDrawPageSupplier> xDrawings(xDstDoc, uno::UNO_QUERY);
     if (xDrawings.is())
-        m_xDrawPage.set(xDrawings->getDrawPage(), uno::UNO_QUERY);
+        m_aParents.push(xDrawings->getDrawPage());
 }
 
 RTFSdrImport::~RTFSdrImport()
 {
+    if (m_aParents.size())
+        m_aParents.pop();
 }
 
 void RTFSdrImport::createShape(OUString aStr, uno::Reference<drawing::XShape>& xShape, uno::Reference<beans::XPropertySet>& xPropertySet)
@@ -103,6 +105,16 @@ std::vector<beans::PropertyValue> RTFSdrImport::getTextFrameDefaults(bool bNew)
     return aRet;
 }
 
+void RTFSdrImport::pushParent(uno::Reference<drawing::XShapes> xParent)
+{
+    m_aParents.push(xParent);
+}
+
+void RTFSdrImport::popParent()
+{
+    m_aParents.pop();
+}
+
 void RTFSdrImport::resolveDhgt(uno::Reference<beans::XPropertySet> xPropertySet, sal_Int32 nZOrder)
 {
     writerfilter::dmapper::DomainMapper& rMapper = (writerfilter::dmapper::DomainMapper&)m_rImport.Mapper();
@@ -544,8 +556,8 @@ void RTFSdrImport::resolve(RTFShape& rShape, bool bClose)
         return;
     }
 
-    if (m_xDrawPage.is() && !bTextFrame)
-        m_xDrawPage->add(xShape);
+    if (m_aParents.size() && m_aParents.top().is() && !bTextFrame)
+        m_aParents.top()->add(xShape);
     if (bCustom && xShape.is())
     {
         uno::Reference<drawing::XEnhancedCustomShapeDefaulter> xDefaulter(xShape, uno::UNO_QUERY);
diff --git a/writerfilter/source/rtftok/rtfsdrimport.hxx b/writerfilter/source/rtftok/rtfsdrimport.hxx
index ab3c44c..bb09b00 100644
--- a/writerfilter/source/rtftok/rtfsdrimport.hxx
+++ b/writerfilter/source/rtftok/rtfsdrimport.hxx
@@ -10,6 +10,8 @@
 #ifndef _RTFSDRIMPORT_HXX_
 #define _RTFSDRIMPORT_HXX_
 
+#include <stack>
+
 #include <rtfdocumentimpl.hxx>
 
 namespace writerfilter {
@@ -32,12 +34,16 @@ namespace writerfilter {
                  * @param bNew if the frame is new-style or old-style.
                  */
                 std::vector<beans::PropertyValue> getTextFrameDefaults(bool bNew);
+                /// Push a new group shape to the parent stack.
+                void pushParent(uno::Reference<drawing::XShapes> xParent);
+                /// Pop the current group shape from the parent stack.
+                void popParent();
             private:
                 void createShape(OUString aService, uno::Reference<drawing::XShape>& xShape, uno::Reference<beans::XPropertySet>& xPropertySet);
                 void applyProperty(uno::Reference<drawing::XShape> xShape, OUString aKey, OUString aValue);
 
                 RTFDocumentImpl& m_rImport;
-                uno::Reference<drawing::XDrawPage> m_xDrawPage;
+                std::stack< uno::Reference<drawing::XShapes> > m_aParents;
                 uno::Reference<drawing::XShape> m_xShape;
         };
     } // namespace rtftok


More information about the Libreoffice-commits mailing list