[Libreoffice-commits] .: 3 commits - oox/inc oox/source sw/qa writerfilter/inc writerfilter/source

Lubos Lunak llunak at kemper.freedesktop.org
Tue May 22 08:27:58 PDT 2012


 oox/inc/oox/vml/vmlshapecontainer.hxx                 |    6 +--
 oox/source/shape/ShapeContextHandler.cxx              |    5 ---
 oox/source/vml/vmlshapecontainer.cxx                  |   11 ++++---
 sw/qa/extras/ooxmltok/data/n705956-2.docx             |binary
 sw/qa/extras/ooxmltok/ooxmltok.cxx                    |   28 ++++++++++++++++--
 writerfilter/inc/ooxml/OOXMLDocument.hxx              |    2 +
 writerfilter/source/ooxml/OOXMLDocumentImpl.cxx       |   10 ++++++
 writerfilter/source/ooxml/OOXMLDocumentImpl.hxx       |    3 +
 writerfilter/source/ooxml/OOXMLFastContextHandler.cxx |    2 +
 9 files changed, 52 insertions(+), 15 deletions(-)

New commits:
commit 04d600d4be7c50db4b3b505039eb8bc96856f593
Author: Luboš Luňák <l.lunak at suse.cz>
Date:   Tue May 22 17:21:13 2012 +0200

    rework getting shape for the .docx import filter
    
    This makes both sw/qa/extras/ooxmltok/data/n705956-{1|2}.docx testcases
    work at the same time. As far as I understand it, the .docx filter
    calls into oox and at the end if gets the shape, while the shape
    is removed from the ShapeContainer. In the case of recursion caused by
    <w:pict><v:shape><w:txbxContent><w:pict><v:shape>, clearing the whole
    list is wrong. Also, the OSL_ENSURE seems to suggest that there should
    not be more than one shape inserted by each read. So simply consider
    maShapes to be a stack when importing .docx .
    
    Change-Id: I7263aeaf74c8d31a05e64c56b880cbc6b00d7dd6

diff --git a/oox/inc/oox/vml/vmlshapecontainer.hxx b/oox/inc/oox/vml/vmlshapecontainer.hxx
index 2880625..9b11c6c 100644
--- a/oox/inc/oox/vml/vmlshapecontainer.hxx
+++ b/oox/inc/oox/vml/vmlshapecontainer.hxx
@@ -92,16 +92,14 @@ public:
     template< typename Functor >
     const ShapeBase*    findShape( const Functor& rFunctor ) const;
 
-    /** Returns the first shape in the collection (Word only). */
-    const ShapeBase*    getFirstShape() const;
+    /** Returns and removes the last shape in the collection (Word only). */
+    const ShapeBase*    takeLastShape();
 
     /** Creates and inserts all UNO shapes into the passed container. */
     void                convertAndInsert(
                             const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& rxShapes,
                             const ShapeParentAnchor* pParentAnchor = 0 ) const;
 
-    inline void                clearShapes( ) { maShapes.clear( ); }
-
 private:
     typedef RefVector< ShapeType >                  ShapeTypeVector;
     typedef RefVector< ShapeBase >                  ShapeVector;
diff --git a/oox/source/shape/ShapeContextHandler.cxx b/oox/source/shape/ShapeContextHandler.cxx
index de27734..3234238 100644
--- a/oox/source/shape/ShapeContextHandler.cxx
+++ b/oox/source/shape/ShapeContextHandler.cxx
@@ -244,11 +244,8 @@ ShapeContextHandler::getShape() throw (uno::RuntimeException)
         if ( getContextHandler() == getDrawingShapeContext() )
         {
             mpDrawing->finalizeFragmentImport();
-            if( const ::oox::vml::ShapeBase* pShape = mpDrawing->getShapes().getFirstShape() )
-            {
+            if( const ::oox::vml::ShapeBase* pShape = mpDrawing->getShapes().takeLastShape() )
                 xResult = pShape->convertAndInsert( xShapes );
-                mpDrawing->getShapes( ).clearShapes( );
-            }
         }
         else if (mpShape.get() != NULL)
         {
diff --git a/oox/source/vml/vmlshapecontainer.cxx b/oox/source/vml/vmlshapecontainer.cxx
index 0309839..144aa78 100644
--- a/oox/source/vml/vmlshapecontainer.cxx
+++ b/oox/source/vml/vmlshapecontainer.cxx
@@ -118,11 +118,14 @@ const ShapeBase* ShapeContainer::getShapeById( const OUString& rShapeId, bool bD
    return 0;
 }
 
-const ShapeBase* ShapeContainer::getFirstShape() const
+const ShapeBase* ShapeContainer::takeLastShape()
 {
-    OSL_ENSURE( mrDrawing.getType() == VMLDRAWING_WORD, "ShapeContainer::getFirstShape - illegal call, Word filter only" );
-    OSL_ENSURE( maShapes.size() == 1, "ShapeContainer::getFirstShape - single shape expected" );
-    return maShapes.get( 0 ).get();
+    assert( mrDrawing.getType() == VMLDRAWING_WORD );
+    if( maShapes.empty())
+        return NULL;
+    const ShapeBase* ret = maShapes.back().get();
+    maShapes.pop_back();
+    return ret;
 }
 
 void ShapeContainer::convertAndInsert( const Reference< XShapes >& rxShapes, const ShapeParentAnchor* pParentAnchor ) const
commit db7e849d17e16a062942c08e28caba71c31e9d1c
Author: Luboš Luňák <l.lunak at suse.cz>
Date:   Tue May 22 17:00:02 2012 +0200

    better check for testcase failure
    
    Change-Id: Ie9a41292bd90919355991a187f17eb810dfc4dc1

diff --git a/sw/qa/extras/ooxmltok/ooxmltok.cxx b/sw/qa/extras/ooxmltok/ooxmltok.cxx
index c822bf4..b7ef2c6 100644
--- a/sw/qa/extras/ooxmltok/ooxmltok.cxx
+++ b/sw/qa/extras/ooxmltok/ooxmltok.cxx
@@ -255,6 +255,7 @@ xray graphic.Size
     uno::Reference<text::XTextDocument> textDocument(mxComponent, uno::UNO_QUERY);
     uno::Reference<drawing::XDrawPageSupplier> drawPageSupplier(textDocument, uno::UNO_QUERY);
     uno::Reference<drawing::XDrawPage> drawPage = drawPageSupplier->getDrawPage();
+    CPPUNIT_ASSERT_EQUAL( 1, drawPage->getCount());
     uno::Reference<drawing::XShape> image;
     drawPage->getByIndex(0) >>= image;
     uno::Reference<beans::XPropertySet> imageProperties(image, uno::UNO_QUERY);
commit 476316bfc9dd36c0613327c20822a193b5ca8d9b
Author: Luboš Luňák <l.lunak at suse.cz>
Date:   Tue May 22 16:57:07 2012 +0200

    do reuse shape context
    
    This is pretty much a revert of 60cb70b94537e9ff1155fb80255fc04ce41363b2.
    Turns out e.g. <v:shapetype> is not local only to its <w:pict>.
    Added a testcase.
    
    Change-Id: Ibbb9fe01bc2fc77dd67151bf4ca0905443eebf63

diff --git a/sw/qa/extras/ooxmltok/data/n705956-2.docx b/sw/qa/extras/ooxmltok/data/n705956-2.docx
new file mode 100644
index 0000000..1388185
Binary files /dev/null and b/sw/qa/extras/ooxmltok/data/n705956-2.docx differ
diff --git a/sw/qa/extras/ooxmltok/ooxmltok.cxx b/sw/qa/extras/ooxmltok/ooxmltok.cxx
index 2b639e0..c822bf4 100644
--- a/sw/qa/extras/ooxmltok/ooxmltok.cxx
+++ b/sw/qa/extras/ooxmltok/ooxmltok.cxx
@@ -56,7 +56,8 @@ public:
     void testN757890();
     void testFdo49940();
     void testN751077();
-    void testN705956();
+    void testN705956_1();
+    void testN705956_2();
 
     CPPUNIT_TEST_SUITE(Test);
 #if !defined(MACOSX) && !defined(WNT)
@@ -67,7 +68,8 @@ public:
     CPPUNIT_TEST(testN757890);
     CPPUNIT_TEST(testFdo49940);
     CPPUNIT_TEST(testN751077);
-    CPPUNIT_TEST(testN705956);
+    CPPUNIT_TEST(testN705956_1);
+    CPPUNIT_TEST(testN705956_2);
 #endif
     CPPUNIT_TEST_SUITE_END();
 
@@ -241,7 +243,7 @@ xray para.PageStyleName
     CPPUNIT_ASSERT_EQUAL( OUString( "First Page" ), value );
 }
 
-void Test::testN705956()
+void Test::testN705956_1()
 {
     load( "n705956-1.docx" );
 /*
@@ -263,6 +265,25 @@ xray graphic.Size
     CPPUNIT_ASSERT_EQUAL( static_cast<sal_Int32>(106), bitmap->getSize().Height );
 }
 
+void Test::testN705956_2()
+{
+    load( "n705956-2.docx" );
+/*
+<v:shapetype> must be global, reachable even from <v:shape> inside another <w:pict>
+image = ThisComponent.DrawPage.getByIndex(0)
+xray image.FillColor
+*/
+    uno::Reference<text::XTextDocument> textDocument(mxComponent, uno::UNO_QUERY);
+    uno::Reference<drawing::XDrawPageSupplier> drawPageSupplier(textDocument, uno::UNO_QUERY);
+    uno::Reference<drawing::XDrawPage> drawPage = drawPageSupplier->getDrawPage();
+    uno::Reference<drawing::XShape> image;
+    drawPage->getByIndex(0) >>= image;
+    uno::Reference<beans::XPropertySet> imageProperties(image, uno::UNO_QUERY);
+    sal_Int32 fillColor;
+    imageProperties->getPropertyValue( "FillColor" ) >>= fillColor;
+    CPPUNIT_ASSERT_EQUAL( 0xc0504d, fillColor );
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(Test);
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/writerfilter/inc/ooxml/OOXMLDocument.hxx b/writerfilter/inc/ooxml/OOXMLDocument.hxx
index 1e150b4..7ce8052 100644
--- a/writerfilter/inc/ooxml/OOXMLDocument.hxx
+++ b/writerfilter/inc/ooxml/OOXMLDocument.hxx
@@ -246,6 +246,8 @@ public:
     virtual void setXNoteType(const Id & nId) = 0;
     virtual const Id & getXNoteType() const = 0;
     virtual const ::rtl::OUString & getTarget() const = 0;
+    virtual uno::Reference<xml::sax::XFastShapeContextHandler> getShapeContext( ) = 0;
+    virtual void setShapeContext( uno::Reference<xml::sax::XFastShapeContextHandler> xContext ) = 0;
 };
 
 
diff --git a/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx b/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx
index 18357bc..acf84f9 100644
--- a/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx
+++ b/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx
@@ -401,6 +401,16 @@ uno::Reference<io::XInputStream> OOXMLDocumentImpl::getStorageStream()
     return mpStream->getStorageStream();
 }
 
+void OOXMLDocumentImpl::setShapeContext( uno::Reference<xml::sax::XFastShapeContextHandler> xContext )
+{
+    mxShapeContext = xContext;
+}
+
+uno::Reference<xml::sax::XFastShapeContextHandler> OOXMLDocumentImpl::getShapeContext( )
+{
+    return mxShapeContext;
+}
+
 OOXMLDocument *
 OOXMLDocumentFactory::createDocument
 (OOXMLStream::Pointer_t pStream)
diff --git a/writerfilter/source/ooxml/OOXMLDocumentImpl.hxx b/writerfilter/source/ooxml/OOXMLDocumentImpl.hxx
index d534b15..a20fbab 100644
--- a/writerfilter/source/ooxml/OOXMLDocumentImpl.hxx
+++ b/writerfilter/source/ooxml/OOXMLDocumentImpl.hxx
@@ -48,6 +48,7 @@ class OOXMLDocumentImpl : public OOXMLDocument
 
     uno::Reference<frame::XModel> mxModel;
     uno::Reference<drawing::XDrawPage> mxDrawPage;
+    uno::Reference<xml::sax::XFastShapeContextHandler> mxShapeContext;
 
     bool mbIsSubstream;
 
@@ -110,6 +111,8 @@ public:
     virtual void setXNoteType(const Id & rId);
     virtual const Id & getXNoteType() const;
     virtual const ::rtl::OUString & getTarget() const;
+    virtual uno::Reference<xml::sax::XFastShapeContextHandler> getShapeContext( );
+    virtual void setShapeContext( uno::Reference<xml::sax::XFastShapeContextHandler> xContext );
 };
 }}
 #endif // OOXML_DOCUMENT_IMPL_HXX
diff --git a/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx b/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx
index 4a4a076..0724c65 100644
--- a/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx
+++ b/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx
@@ -1918,6 +1918,7 @@ OOXMLFastContextHandlerShape::OOXMLFastContextHandlerShape
         uno::Reference<XMultiComponentFactory> rServiceManager
             (xContext->getServiceManager());
 
+        mrShapeContext.set( getDocument( )->getShapeContext( ) );
         if ( !mrShapeContext.is( ) )
         {
             // Define the shape context for the whole document
@@ -1928,6 +1929,7 @@ OOXMLFastContextHandlerShape::OOXMLFastContextHandlerShape
                    (RTL_CONSTASCII_USTRINGPARAM
                     ("com.sun.star.xml.sax.FastShapeContextHandler")), xContext),
                   uno::UNO_QUERY);
+            getDocument()->setShapeContext( mrShapeContext );
         }
 
         if (mrShapeContext.is())


More information about the Libreoffice-commits mailing list