[Libreoffice-commits] .: 6 commits - oox/inc oox/source svtools/source sw/qa vcl/source writerfilter/source

Lubos Lunak llunak at kemper.freedesktop.org
Tue Jun 19 02:56:41 PDT 2012


 oox/inc/oox/vml/vmlshapecontainer.hxx             |   21 ++++++++++++++++++--
 oox/source/shape/ShapeContextHandler.cxx          |   13 +++++++++++-
 oox/source/vml/vmlshapecontainer.cxx              |   22 ++++++++++++++++-----
 svtools/source/graphic/grfmgr2.cxx                |    7 ++----
 sw/qa/extras/README                               |   23 ++++++++++++++++++++++
 sw/qa/extras/ooxmltok/ooxmltok.cxx                |   19 ++++++++++++++++--
 vcl/source/gdi/bitmap3.cxx                        |   22 ++++++++++-----------
 writerfilter/source/dmapper/DomainMapper_Impl.cxx |    4 +--
 8 files changed, 104 insertions(+), 27 deletions(-)

New commits:
commit dd4ce342c22290311c62f91981e0bb74984e52ea
Author: Luboš Luňák <l.lunak at suse.cz>
Date:   Fri Jun 15 21:26:15 2012 +0200

    no references to temporaries
    
    Change-Id: I6c7a7b88b64ec8c0eef8eac30ea3e6e40e271f76

diff --git a/svtools/source/graphic/grfmgr2.cxx b/svtools/source/graphic/grfmgr2.cxx
index 1967e44..1a43fe8 100644
--- a/svtools/source/graphic/grfmgr2.cxx
+++ b/svtools/source/graphic/grfmgr2.cxx
@@ -387,7 +387,7 @@ sal_Bool GraphicManager::ImplCreateOutput( OutputDevice* pOut,
         BitmapEx        aOutBmpEx;
         Point           aOutPt;
         Size            aOutSz;
-        const Size&     rBmpSzPix = rBmpEx.GetSizePixel();
+        const Size      rBmpSzPix = rBmpEx.GetSizePixel();
         const long      nW = rBmpSzPix.Width();
         const long      nH = rBmpSzPix.Height();
         const long      nNewW = aUnrotatedSzPix.Width();
@@ -606,9 +606,8 @@ sal_Bool GraphicManager::ImplCreateOutput( OutputDevice* pOut,
         const double fScaleX = fOutWH / fGrfWH;
         const double fScaleY = 1.0;
 
-        const MapMode& rPrefMapMode( rMtf.GetPrefMapMode() );
-        const Size&    rSizePix( pOut->LogicToPixel( aNewSize,
-                                                     rPrefMapMode ) );
+        const MapMode rPrefMapMode( rMtf.GetPrefMapMode() );
+        const Size rSizePix( pOut->LogicToPixel( aNewSize, rPrefMapMode ) );
 
         // taking care of font width default if scaling metafile.
         // #117889# use existing metafile scan, to determine whether
commit 8bb5411cb5a848c5866385b4078ba83a3d646986
Author: Luboš Luňák <l.lunak at suse.cz>
Date:   Fri Jun 15 18:50:08 2012 +0200

    mark const data as const
    
    Change-Id: Icbd8a343b6cb1615b667451043c23b6f131a0f04

diff --git a/vcl/source/gdi/bitmap3.cxx b/vcl/source/gdi/bitmap3.cxx
index 42e7de3..4bef165 100644
--- a/vcl/source/gdi/bitmap3.cxx
+++ b/vcl/source/gdi/bitmap3.cxx
@@ -78,13 +78,13 @@
 // - Statics -
 // -----------
 
-sal_uLong nVCLRLut[ 6 ] = { 16, 17, 18, 19, 20, 21 };
-sal_uLong nVCLGLut[ 6 ] = { 0, 6, 12, 18, 24, 30 };
-sal_uLong nVCLBLut[ 6 ] = { 0, 36, 72, 108, 144, 180 };
+const extern sal_uLong nVCLRLut[ 6 ] = { 16, 17, 18, 19, 20, 21 };
+const extern sal_uLong nVCLGLut[ 6 ] = { 0, 6, 12, 18, 24, 30 };
+const extern sal_uLong nVCLBLut[ 6 ] = { 0, 36, 72, 108, 144, 180 };
 
 // ------------------------------------------------------------------------
 
-sal_uLong nVCLDitherLut[ 256 ] =
+const extern sal_uLong nVCLDitherLut[ 256 ] =
 {
        0, 49152, 12288, 61440,  3072, 52224, 15360, 64512,   768, 49920, 13056,
    62208,  3840, 52992, 16128, 65280, 32768, 16384, 45056, 28672, 35840, 19456,
@@ -114,7 +114,7 @@ sal_uLong nVCLDitherLut[ 256 ] =
 
 // ------------------------------------------------------------------------
 
-sal_uLong nVCLLut[ 256 ] =
+const extern sal_uLong nVCLLut[ 256 ] =
 {
          0,  1286,  2572,  3858,  5144,  6430,  7716,  9002,
      10288, 11574, 12860, 14146, 15432, 16718, 18004, 19290,
@@ -152,7 +152,7 @@ sal_uLong nVCLLut[ 256 ] =
 
 // ------------------------------------------------------------------------
 
-long FloydMap[256] =
+const long FloydMap[256] =
 {
     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1,
@@ -174,7 +174,7 @@ long FloydMap[256] =
 
 // ------------------------------------------------------------------------
 
-long FloydError1[61] =
+const long FloydError1[61] =
 {
     -7680, -7424, -7168, -6912, -6656, -6400, -6144,
     -5888, -5632, -5376, -5120, -4864, -4608, -4352,
@@ -188,7 +188,7 @@ long FloydError1[61] =
 
 // ------------------------------------------------------------------------
 
-long FloydError3[61] =
+const long FloydError3[61] =
 {
     -23040, -22272, -21504, -20736, -19968, -19200,
     -18432, -17664, -16896, -16128, -15360, -14592,
@@ -203,7 +203,7 @@ long FloydError3[61] =
 
 // ------------------------------------------------------------------------
 
-long FloydError5[61] =
+const long FloydError5[61] =
 {
     -38400, -37120, -35840, -34560, -33280, -32000,
     -30720, -29440, -28160, -26880, -25600, -24320,
@@ -219,7 +219,7 @@ long FloydError5[61] =
 
 // ------------------------------------------------------------------------
 
-long FloydError7[61] =
+const long FloydError7[61] =
 {
     -53760, -51968, -50176, -48384, -46592, -44800,
     -43008, -41216, -39424, -37632, -35840, -34048,
@@ -235,7 +235,7 @@ long FloydError7[61] =
 
 // ------------------------------------------------------------------------
 
-long FloydIndexMap[6] =
+const long FloydIndexMap[6] =
 {
     -30,  21, 72, 123, 174, 225
 };
commit 886e29cff76d0358889aa676dbe90765950c990e
Author: Luboš Luňák <l.lunak at suse.cz>
Date:   Wed Jun 13 18:04:51 2012 +0200

    rework handling the case of recursive ooxml shapes again
    
    Another attempt, whoever has written this apparently didn't consider
    the possibility of recursion at all, and this still feels a bit hackish.
    
    Writerfilter keeps just one oox::shape::ShapeContextHandler object during
    the entire time of parsing the document, because e.g. <v:shapetype> needs
    to be reachable even across VML block (see sw testcases for bnc#705956).
    This however presents a problem when VML contains <w:txbxContent> which
    contains another VML, as this code previously just took whatever has been
    read and returned it to writerfilter, and it broke with recursion.
    So now try to mark recursion entry and returns the right shape.
    
    Related to 36c12c246d886b2d96d7a2d4d0c250db9d925c74 and the previous
    commits it reverted.
    
    Change-Id: I949a6b52ec7540aa59b047c7b6e908b10fb3bdc1

diff --git a/oox/inc/oox/vml/vmlshapecontainer.hxx b/oox/inc/oox/vml/vmlshapecontainer.hxx
index 20671bb..f6be8e3 100644
--- a/oox/inc/oox/vml/vmlshapecontainer.hxx
+++ b/oox/inc/oox/vml/vmlshapecontainer.hxx
@@ -32,6 +32,7 @@
 #include <com/sun/star/awt/Rectangle.hpp>
 #include "oox/helper/refmap.hxx"
 #include "oox/helper/refvector.hxx"
+#include <stack>
 
 namespace com { namespace sun { namespace star {
     namespace drawing { class XShapes; }
@@ -92,16 +93,29 @@ public:
     template< typename Functor >
     const ShapeBase*    findShape( const Functor& rFunctor ) const;
 
-    /** Returns the first shape in the collection (Word only). */
-    const ShapeBase*    getFirstShape() const;
+    /**
+      (Word only) Returns the last shape in the collection, if it is after the last
+      mark from pushMark(), and removes it.
+    */
+    boost::shared_ptr< ShapeBase > takeLastShape();
+    /**
+      Adds a recursion mark to the stack. It is possible that a shape contains <w:txbxContent>
+      which contains another shape, and writerfilter needs to know which shape is from the inner
+      ooxml context and which from the outer ooxml context, while it is necessary to keep
+      at least shape types across such blocks. Therefore this function marks beginning
+      of each shape xml block, and takeLastShape() returns only shapes from this block.
+    */
+    void pushMark();
+    /**
+      Removes a recursion mark.
+    */
+    void popMark();
 
     /** 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;
@@ -113,6 +127,7 @@ private:
     ShapeVector         maShapes;           ///< All shape definitions.
     ShapeTypeMap        maTypesById;        ///< All shape templates mapped by identifier.
     ShapeMap            maShapesById;       ///< All shape definitions mapped by identifier.
+    std::stack< size_t > markStack;         ///< Recursion marks from pushMark()/popMark().
 };
 
 // ----------------------------------------------------------------------------
diff --git a/oox/source/shape/ShapeContextHandler.cxx b/oox/source/shape/ShapeContextHandler.cxx
index 04e2330..418ca7c 100644
--- a/oox/source/shape/ShapeContextHandler.cxx
+++ b/oox/source/shape/ShapeContextHandler.cxx
@@ -190,6 +190,11 @@ void SAL_CALL ShapeContextHandler::startFastElement
         createFastChildContext(Element, Attribs);
     }
 
+    // Entering VML block (startFastElement() is called for the outermost tag),
+    // handle possible recursion.
+    if ( getContextHandler() == getDrawingShapeContext() )
+        mpDrawing->getShapes().pushMark();
+
     uno::Reference<XFastContextHandler> xContextHandler(getContextHandler());
 
     if (xContextHandler.is())
@@ -201,6 +206,9 @@ void SAL_CALL ShapeContextHandler::startUnknownElement
  const uno::Reference< xml::sax::XFastAttributeList > & Attribs)
     throw (uno::RuntimeException, xml::sax::SAXException)
 {
+    if ( getContextHandler() == getDrawingShapeContext() )
+        mpDrawing->getShapes().pushMark();
+
     uno::Reference<XFastContextHandler> xContextHandler(getContextHandler());
 
     if (xContextHandler.is())
@@ -280,11 +288,11 @@ ShapeContextHandler::getShape() throw (uno::RuntimeException)
         if ( getContextHandler() == getDrawingShapeContext() )
         {
             mpDrawing->finalizeFragmentImport();
-            if( const ::oox::vml::ShapeBase* pShape = mpDrawing->getShapes().getFirstShape() )
-            {
+            if( boost::shared_ptr< vml::ShapeBase > pShape = mpDrawing->getShapes().takeLastShape() )
                 xResult = pShape->convertAndInsert( xShapes );
-                mpDrawing->getShapes( ).clearShapes( );
-            }
+            // Only now remove the recursion mark, because getShape() is called in writerfilter
+            // after endFastElement().
+            mpDrawing->getShapes().popMark();
         }
         else if (mxDiagramShapeContext.is())
         {
diff --git a/oox/source/vml/vmlshapecontainer.cxx b/oox/source/vml/vmlshapecontainer.cxx
index 0309839..c30994c 100644
--- a/oox/source/vml/vmlshapecontainer.cxx
+++ b/oox/source/vml/vmlshapecontainer.cxx
@@ -118,11 +118,26 @@ const ShapeBase* ShapeContainer::getShapeById( const OUString& rShapeId, bool bD
    return 0;
 }
 
-const ShapeBase* ShapeContainer::getFirstShape() const
+boost::shared_ptr< 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();
+    OSL_ENSURE( mrDrawing.getType() == VMLDRAWING_WORD, "ShapeContainer::takeLastShape - illegal call, Word filter only" );
+    assert( !markStack.empty());
+    if( markStack.top() >= maShapes.size())
+        return boost::shared_ptr< ShapeBase >();
+    boost::shared_ptr< ShapeBase > ret = maShapes.back();
+    maShapes.pop_back();
+    return ret;
+}
+
+void ShapeContainer::pushMark()
+{
+    markStack.push( maShapes.size());
+}
+
+void ShapeContainer::popMark()
+{
+    assert( !markStack.empty());
+    markStack.pop();
 }
 
 void ShapeContainer::convertAndInsert( const Reference< XShapes >& rxShapes, const ShapeParentAnchor* pParentAnchor ) const
commit 544ab2ed627e207adb54a0db9b31388e29d041a8
Author: Luboš Luňák <l.lunak at suse.cz>
Date:   Wed Jun 13 13:18:46 2012 +0200

    add finding out page width to a testcase
    
    Change-Id: I0de5e694adedf8812cc31036860991c853f38d93

diff --git a/sw/qa/extras/README b/sw/qa/extras/README
index ae174a5..57447fb 100644
--- a/sw/qa/extras/README
+++ b/sw/qa/extras/README
@@ -218,3 +218,26 @@ drawPage->getByIndex(0) >>= image;
 uno::Reference<beans::XPropertySet> imageProperties(image, uno::UNO_QUERY);
 uno::Reference<graphic::XGraphic> graphic;
 imageProperties->getPropertyValue( "Graphic" ) >>= graphic;
+
+
+=== Styles
+
+Styles provide information about many properties of (parts of) the document, for example
+page width:
+
+Basic:
+
+ThisComponent.StyleFamilies.PageStyles.Default.Width
+
+C++:
+
+uno::Reference<text::XTextDocument> textDocument(mxComponent, uno::UNO_QUERY);
+uno::Reference<style::XStyleFamiliesSupplier> styleFamiliesSupplier(mxComponent, uno::UNO_QUERY);
+uno::Reference<container::XNameAccess> styleFamilies = styleFamiliesSupplier->getStyleFamilies();
+uno::Reference<container::XNameAccess> pageStyles;
+styleFamilies->getByName("PageStyles") >>= pageStyles;
+uno::Reference<uno::XInterface> defaultStyle;
+pageStyles->getByName("Default") >>= defaultStyle;
+uno::Reference<beans::XPropertySet> styleProperties( defaultStyle, uno::UNO_QUERY );
+sal_Int32 width;
+styleProperties->getPropertyValue( "Width" ) >>= width;
diff --git a/sw/qa/extras/ooxmltok/ooxmltok.cxx b/sw/qa/extras/ooxmltok/ooxmltok.cxx
index 3afb8b7..2282b47 100644
--- a/sw/qa/extras/ooxmltok/ooxmltok.cxx
+++ b/sw/qa/extras/ooxmltok/ooxmltok.cxx
@@ -31,6 +31,7 @@
 #include <com/sun/star/beans/XPropertySet.hpp>
 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
 #include <com/sun/star/lang/XServiceInfo.hpp>
+#include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
 #include <com/sun/star/text/HoriOrientation.hpp>
 #include <com/sun/star/text/SetVariableType.hpp>
 #include <com/sun/star/text/TextContentAnchorType.hpp>
@@ -498,6 +499,12 @@ void Test::testSmartart()
 void Test::testN764745()
 {
     load( "n764745-alignment.docx" );
+/*
+shape = ThisComponent.DrawPage.getByIndex(0)
+xray shape.AnchorType
+xray shape.AnchorPosition.X
+xray ThisComponent.StyleFamilies.PageStyles.Default.Width
+*/
     uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY);
     uno::Reference<container::XIndexAccess> xDraws(xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY);
     uno::Reference<beans::XPropertySet> xPropertySet(xDraws->getByIndex(0), uno::UNO_QUERY);
@@ -508,8 +515,16 @@ void Test::testN764745()
     CPPUNIT_ASSERT_EQUAL(text::TextContentAnchorType_AS_CHARACTER, anchorType);
     awt::Point pos;
     xPropertySet->getPropertyValue("AnchorPosition") >>= pos;
-    // not sure how to find out the document width, but in my test the anchor x is >12000
-    CPPUNIT_ASSERT( pos.X > 10000 );
+    uno::Reference<style::XStyleFamiliesSupplier> styleFamiliesSupplier(mxComponent, uno::UNO_QUERY);
+    uno::Reference<container::XNameAccess> styleFamilies = styleFamiliesSupplier->getStyleFamilies();
+    uno::Reference<container::XNameAccess> pageStyles;
+    styleFamilies->getByName("PageStyles") >>= pageStyles;
+    uno::Reference<uno::XInterface> defaultStyle;
+    pageStyles->getByName("Default") >>= defaultStyle;
+    uno::Reference<beans::XPropertySet> styleProperties( defaultStyle, uno::UNO_QUERY );
+    sal_Int32 width;
+    styleProperties->getPropertyValue( "Width" ) >>= width;
+    CPPUNIT_ASSERT( pos.X > width / 2 );
 }
 
 void Test::testN766477()
commit 831c2d95289f41529ea1f85c90f8bb112e522d97
Author: Luboš Luňák <l.lunak at suse.cz>
Date:   Tue Jun 12 17:11:10 2012 +0200

    Revert "rework getting shape for the .docx import filter"
    
    Stupid containers with shared_ptr. Trying to remove the object
    from it gets it deleted because it's owned by the shared_ptr
    and there's no sensible way to wrestle it out of it. This will
    need to be redone somehow.
    
    This reverts commit 04d600d4be7c50db4b3b505039eb8bc96856f593.

diff --git a/oox/inc/oox/vml/vmlshapecontainer.hxx b/oox/inc/oox/vml/vmlshapecontainer.hxx
index 973890e..20671bb 100644
--- a/oox/inc/oox/vml/vmlshapecontainer.hxx
+++ b/oox/inc/oox/vml/vmlshapecontainer.hxx
@@ -92,14 +92,16 @@ public:
     template< typename Functor >
     const ShapeBase*    findShape( const Functor& rFunctor ) const;
 
-    /** Returns and removes the last shape in the collection (Word only). */
-    const ShapeBase*    takeLastShape();
+    /** Returns the first shape in the collection (Word only). */
+    const ShapeBase*    getFirstShape() const;
 
     /** 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 241ae86..04e2330 100644
--- a/oox/source/shape/ShapeContextHandler.cxx
+++ b/oox/source/shape/ShapeContextHandler.cxx
@@ -280,8 +280,11 @@ ShapeContextHandler::getShape() throw (uno::RuntimeException)
         if ( getContextHandler() == getDrawingShapeContext() )
         {
             mpDrawing->finalizeFragmentImport();
-            if( const ::oox::vml::ShapeBase* pShape = mpDrawing->getShapes().takeLastShape() )
+            if( const ::oox::vml::ShapeBase* pShape = mpDrawing->getShapes().getFirstShape() )
+            {
                 xResult = pShape->convertAndInsert( xShapes );
+                mpDrawing->getShapes( ).clearShapes( );
+            }
         }
         else if (mxDiagramShapeContext.is())
         {
diff --git a/oox/source/vml/vmlshapecontainer.cxx b/oox/source/vml/vmlshapecontainer.cxx
index 144aa78..0309839 100644
--- a/oox/source/vml/vmlshapecontainer.cxx
+++ b/oox/source/vml/vmlshapecontainer.cxx
@@ -118,14 +118,11 @@ const ShapeBase* ShapeContainer::getShapeById( const OUString& rShapeId, bool bD
    return 0;
 }
 
-const ShapeBase* ShapeContainer::takeLastShape()
+const ShapeBase* ShapeContainer::getFirstShape() const
 {
-    assert( mrDrawing.getType() == VMLDRAWING_WORD );
-    if( maShapes.empty())
-        return NULL;
-    const ShapeBase* ret = maShapes.back().get();
-    maShapes.pop_back();
-    return ret;
+    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();
 }
 
 void ShapeContainer::convertAndInsert( const Reference< XShapes >& rxShapes, const ShapeParentAnchor* pParentAnchor ) const
commit e28c8f3b75cb46906a8479cf9a52f272fdb17682
Author: Luboš Luňák <l.lunak at suse.cz>
Date:   Tue Jun 12 15:47:52 2012 +0200

    OSL_ENSURE -> SAL_WARN_IF
    
    Change-Id: Ib8e9976e618e676465f0baf1f38be7e3297ac853

diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index 1ca32f6..f8b9de9 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -381,8 +381,8 @@ void    DomainMapper_Impl::PopProperties(ContextType eId)
 PropertyMapPtr DomainMapper_Impl::GetTopContextOfType(ContextType eId)
 {
     PropertyMapPtr pRet;
-    OSL_ENSURE( !m_aPropertyStacks[eId].empty(),
-            "no context of this type available");
+    SAL_WARN_IF( m_aPropertyStacks[eId].empty(), "writerfilter",
+        "no context of type " << eId << " available");
     if(!m_aPropertyStacks[eId].empty())
         pRet = m_aPropertyStacks[eId].top();
     return pRet;


More information about the Libreoffice-commits mailing list