[Libreoffice-commits] core.git: 4 commits - sw/source

Jacobo Aragunde Pérez jaragunde at igalia.com
Fri Feb 28 04:23:38 PST 2014


 sw/source/filter/ww8/docxattributeoutput.cxx |  159 ++++++++++++++-------------
 sw/source/filter/ww8/docxattributeoutput.hxx |    1 
 sw/source/filter/ww8/docxexport.cxx          |    3 
 3 files changed, 87 insertions(+), 76 deletions(-)

New commits:
commit c5ecd9d2a79d4c2cd80fc7d037074806a021e579
Author: Jacobo Aragunde Pérez <jaragunde at igalia.com>
Date:   Fri Feb 28 10:51:48 2014 +0100

    Correct indentation
    
    Change-Id: I3ce85a17966c155c71cd3e3d1a142cc02ec34bd7

diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx
index ed87bf2..d7d9dea 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -3639,85 +3639,83 @@ void DocxAttributeOutput::WriteOLE( SwOLENode& rNode, const Size& rSize, const S
             break;
         }
 
-        // wrong indentation ahead
-
-        SwOLEObj& aObject = rNode.GetOLEObj();
-        uno::Reference < embed::XEmbeddedObject > xObj( aObject.GetOleRef() );
-        comphelper::EmbeddedObjectContainer* aContainer = aObject.GetObject().GetContainer();
-        OUString sObjectName = aContainer->GetEmbeddedObjectName( xObj );
-
-        // set some attributes according to the type of the embedded object
-        OUString sProgID, sMediaType, sRelationType;
-        for( sal_Int32 i=0; i < aObjectsInteropList.getLength(); ++i )
-            if ( aObjectsInteropList[i].Name == sObjectName )
-            {
-                aObjectsInteropList[i].Value >>= sProgID;
-                break;
-            }
-        if( sProgID.startsWith("Excel.Sheet") )
-        {
-            sMediaType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
-            sRelationType = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/package";
-        }
-        else if( sProgID.startsWith("PowerPoint.Show") )
-        {
-            sMediaType = "application/vnd.openxmlformats-officedocument.presentationml.presentation";
-            sRelationType = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/package";
-        }
-        else
+    SwOLEObj& aObject = rNode.GetOLEObj();
+    uno::Reference < embed::XEmbeddedObject > xObj( aObject.GetOleRef() );
+    comphelper::EmbeddedObjectContainer* aContainer = aObject.GetObject().GetContainer();
+    OUString sObjectName = aContainer->GetEmbeddedObjectName( xObj );
+
+    // set some attributes according to the type of the embedded object
+    OUString sProgID, sMediaType, sRelationType;
+    for( sal_Int32 i=0; i < aObjectsInteropList.getLength(); ++i )
+        if ( aObjectsInteropList[i].Name == sObjectName )
         {
-            sMediaType = "application/vnd.openxmlformats-officedocument.oleObject";
-            sRelationType = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/oleObject";
+            aObjectsInteropList[i].Value >>= sProgID;
+            break;
         }
+    if( sProgID.startsWith("Excel.Sheet") )
+    {
+        sMediaType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
+        sRelationType = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/package";
+    }
+    else if( sProgID.startsWith("PowerPoint.Show") )
+    {
+        sMediaType = "application/vnd.openxmlformats-officedocument.presentationml.presentation";
+        sRelationType = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/package";
+    }
+    else
+    {
+        sMediaType = "application/vnd.openxmlformats-officedocument.oleObject";
+        sRelationType = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/oleObject";
+    }
 
-        // write embedded file
-        OString sId = m_rExport.WriteOLEObject( aObject, sMediaType, sRelationType );
+    // write embedded file
+    OString sId = m_rExport.WriteOLEObject( aObject, sMediaType, sRelationType );
 
-        if( sId.isEmpty() )
-        {
-            // the embedded file could not be saved
-            // fallback: save as an image
-            FlyFrameGraphic( 0, rSize, rFlyFrmFmt, &rNode );
-            return;
-        }
+    if( sId.isEmpty() )
+    {
+        // the embedded file could not be saved
+        // fallback: save as an image
+        FlyFrameGraphic( 0, rSize, rFlyFrmFmt, &rNode );
+        return;
+    }
+
+    // write preview image
+    const Graphic* pGraphic = rNode.GetGraphic();
+    OUString sImageId = m_rDrawingML.WriteImage( *pGraphic );
+
+    m_pSerializer->startElementNS( XML_w, XML_object, FSEND );
+
+    OStringBuffer sShapeStyle, sShapeId;
+    sShapeStyle.append( "width:" ).append( double( rSize.Width() ) / 20 )
+                        .append( "pt;height:" ).append( double( rSize.Height() ) / 20 )
+                        .append( "pt" ); //from VMLExport::AddRectangleDimensions(), it does: value/20
+    sShapeId.append( "ole_" ).append( sId );
+
+    // shape definition
+    m_pSerializer->startElementNS( XML_v, XML_shape,
+                                   XML_id, sShapeId.getStr(),
+                                   XML_style, sShapeStyle.getStr(),
+                                   FSNS( XML_o, XML_ole ), "", //compulsory, even if it's empty
+                                   FSEND );
+
+    // shape filled with the preview image
+    m_pSerializer->singleElementNS( XML_v, XML_imagedata,
+                                    FSNS( XML_r, XML_id ), OUStringToOString( sImageId, RTL_TEXTENCODING_UTF8 ).getStr(),
+                                    FSEND );
+
+    m_pSerializer->endElementNS( XML_v, XML_shape );
+
+    // OLE object definition
+    m_pSerializer->singleElementNS( XML_o, XML_OLEObject,
+                                    XML_Type, "Embed",
+                                    XML_ProgID, OUStringToOString( sProgID, RTL_TEXTENCODING_UTF8 ).getStr(),
+                                    XML_ShapeID, sShapeId.getStr(),
+                                    XML_DrawAspect, "Content",
+                                    XML_ObjectID, "_" + OString::number( rand() ),
+                                    FSNS( XML_r, XML_id ), sId.getStr(),
+                                    FSEND );
 
-        // write preview image
-        const Graphic* pGraphic = rNode.GetGraphic();
-        OUString sImageId = m_rDrawingML.WriteImage( *pGraphic );
-
-        m_pSerializer->startElementNS( XML_w, XML_object, FSEND );
-
-        OStringBuffer sShapeStyle, sShapeId;
-        sShapeStyle.append( "width:" ).append( double( rSize.Width() ) / 20 )
-                            .append( "pt;height:" ).append( double( rSize.Height() ) / 20 )
-                            .append( "pt" ); //from VMLExport::AddRectangleDimensions(), it does: value/20
-        sShapeId.append( "ole_" ).append( sId );
-
-        // shape definition
-        m_pSerializer->startElementNS( XML_v, XML_shape,
-                                       XML_id, sShapeId.getStr(),
-                                       XML_style, sShapeStyle.getStr(),
-                                       FSNS( XML_o, XML_ole ), "", //compulsory, even if it's empty
-                                       FSEND );
-
-        // shape filled with the preview image
-        m_pSerializer->singleElementNS( XML_v, XML_imagedata,
-                                        FSNS( XML_r, XML_id ), OUStringToOString( sImageId, RTL_TEXTENCODING_UTF8 ).getStr(),
-                                        FSEND );
-
-        m_pSerializer->endElementNS( XML_v, XML_shape );
-
-        // OLE object definition
-        m_pSerializer->singleElementNS( XML_o, XML_OLEObject,
-                                        XML_Type, "Embed",
-                                        XML_ProgID, OUStringToOString( sProgID, RTL_TEXTENCODING_UTF8 ).getStr(),
-                                        XML_ShapeID, sShapeId.getStr(),
-                                        XML_DrawAspect, "Content",
-                                        XML_ObjectID, "_" + OString::number( rand() ),
-                                        FSNS( XML_r, XML_id ), sId.getStr(),
-                                        FSEND );
-
-        m_pSerializer->endElementNS( XML_w, XML_object );
+    m_pSerializer->endElementNS( XML_w, XML_object );
 }
 
 /*
commit 21d356f691a7c1859f85a19c79060a3d31cffc21
Author: Jacobo Aragunde Pérez <jaragunde at igalia.com>
Date:   Fri Feb 28 10:44:53 2014 +0100

    sw: export OLE objects outside run properties
    
    Until now the export of OLE objects was being done adding them to the
    m_postponedOLE member and reading that member when the run properties
    are closed, but it can happen that we receive an OLE object while not
    in the middle of the row properties.
    
    We have extracted the code that actually does the export to a
    separate method and call it if m_postponedOLE is not available.
    
    Some lines are incorrectly indented to make the purpose of this patch
    more evident, and will be corrected in the next patch.
    
    Change-Id: I3e0d785c99c659ec35d0c02dfc52367dcb6880b7

diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx
index f50c592..ed87bf2 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -3596,8 +3596,10 @@ void DocxAttributeOutput::WritePostponedFormControl(const SdrObject* pObject)
 bool DocxAttributeOutput::PostponeOLE( const SdrObject*, SwOLENode& rNode, const Size& rSize, const SwFlyFrmFmt* pFlyFrmFmt )
 {
     if( m_postponedOLE == NULL )
-        return false;
-    m_postponedOLE->push_back( PostponedOLE( &rNode, rSize, pFlyFrmFmt ) );
+        //cannot be postponed, try to write now
+        WriteOLE( rNode, rSize, pFlyFrmFmt );
+    else
+        m_postponedOLE->push_back( PostponedOLE( &rNode, rSize, pFlyFrmFmt ) );
     return true;
 }
 
@@ -3611,6 +3613,20 @@ void DocxAttributeOutput::WritePostponedOLE()
 
     SAL_INFO( "sw.ww8", OSL_THIS_FUNC );
 
+    for( std::list< PostponedOLE >::iterator it = m_postponedOLE->begin();
+         it != m_postponedOLE->end();
+         ++it )
+    {
+        WriteOLE( *it->object, it->size, it->frame );
+    }
+
+    // clear list of postponed objects
+    delete m_postponedOLE;
+    m_postponedOLE = NULL;
+}
+
+void DocxAttributeOutput::WriteOLE( SwOLENode& rNode, const Size& rSize, const SwFlyFrmFmt* rFlyFrmFmt )
+{
     // get interoperability information about embedded objects
     uno::Reference< beans::XPropertySet > xPropSet( m_rExport.pDoc->GetDocShell()->GetBaseModel(), uno::UNO_QUERY_THROW );
     OUString pName = UNO_NAME_MISC_OBJ_INTEROPGRABBAG;
@@ -3623,11 +3639,9 @@ void DocxAttributeOutput::WritePostponedOLE()
             break;
         }
 
-    for( std::list< PostponedOLE >::iterator it = m_postponedOLE->begin();
-         it != m_postponedOLE->end();
-         ++it )
-    {
-        SwOLEObj& aObject = it->object->GetOLEObj();
+        // wrong indentation ahead
+
+        SwOLEObj& aObject = rNode.GetOLEObj();
         uno::Reference < embed::XEmbeddedObject > xObj( aObject.GetOleRef() );
         comphelper::EmbeddedObjectContainer* aContainer = aObject.GetObject().GetContainer();
         OUString sObjectName = aContainer->GetEmbeddedObjectName( xObj );
@@ -3663,19 +3677,19 @@ void DocxAttributeOutput::WritePostponedOLE()
         {
             // the embedded file could not be saved
             // fallback: save as an image
-            FlyFrameGraphic( 0, it->size, it->frame, it->object );
-            continue;
+            FlyFrameGraphic( 0, rSize, rFlyFrmFmt, &rNode );
+            return;
         }
 
         // write preview image
-        const Graphic* pGraphic = const_cast< SwOLENode* >( it->object )->GetGraphic();
+        const Graphic* pGraphic = rNode.GetGraphic();
         OUString sImageId = m_rDrawingML.WriteImage( *pGraphic );
 
         m_pSerializer->startElementNS( XML_w, XML_object, FSEND );
 
         OStringBuffer sShapeStyle, sShapeId;
-        sShapeStyle.append( "width:" ).append( double( it->size.Width() ) / 20 )
-                            .append( "pt;height:" ).append( double( it->size.Height() ) / 20 )
+        sShapeStyle.append( "width:" ).append( double( rSize.Width() ) / 20 )
+                            .append( "pt;height:" ).append( double( rSize.Height() ) / 20 )
                             .append( "pt" ); //from VMLExport::AddRectangleDimensions(), it does: value/20
         sShapeId.append( "ole_" ).append( sId );
 
@@ -3704,11 +3718,6 @@ void DocxAttributeOutput::WritePostponedOLE()
                                         FSEND );
 
         m_pSerializer->endElementNS( XML_w, XML_object );
-    }
-
-    // clear list of postponed objects
-    delete m_postponedOLE;
-    m_postponedOLE = NULL;
 }
 
 /*
diff --git a/sw/source/filter/ww8/docxattributeoutput.hxx b/sw/source/filter/ww8/docxattributeoutput.hxx
index 77bf6af..b765315 100644
--- a/sw/source/filter/ww8/docxattributeoutput.hxx
+++ b/sw/source/filter/ww8/docxattributeoutput.hxx
@@ -394,6 +394,7 @@ private:
     bool WriteOLEChart( const SdrObject* pSdrObj, const Size& rSize );
     bool WriteOLEMath( const SdrObject* pSdrObj, const SwOLENode& rNode, const Size& rSize );
     bool PostponeOLE( const SdrObject* pSdrObj, SwOLENode& rNode, const Size& rSize, const SwFlyFrmFmt* pFlyFrmFmt );
+    void WriteOLE( SwOLENode& rNode, const Size& rSize, const SwFlyFrmFmt* rFlyFrmFmt );
 
     /// checks whether the current component is a diagram
     bool IsDiagram (const SdrObject* sdrObject);
commit 94b46d202c71d35741ad32ed520a191114a0d250
Author: Jacobo Aragunde Pérez <jaragunde at igalia.com>
Date:   Fri Feb 28 10:38:48 2014 +0100

    Correct wrong variable name.
    
    Change-Id: Ic76e328e7600aab54dfb8318e1d9667fa6d309a5

diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx
index c4700b4..f50c592 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -3595,7 +3595,7 @@ void DocxAttributeOutput::WritePostponedFormControl(const SdrObject* pObject)
 
 bool DocxAttributeOutput::PostponeOLE( const SdrObject*, SwOLENode& rNode, const Size& rSize, const SwFlyFrmFmt* pFlyFrmFmt )
 {
-    if( m_postponedVMLDrawing == NULL )
+    if( m_postponedOLE == NULL )
         return false;
     m_postponedOLE->push_back( PostponedOLE( &rNode, rSize, pFlyFrmFmt ) );
     return true;
commit de90456c71aa121cb0a6d0f7b316b3da0e6088fc
Author: Jacobo Aragunde Pérez <jaragunde at igalia.com>
Date:   Fri Feb 28 10:30:48 2014 +0100

    sw: prevent crash
    
    In case some error happens when exporting OLE to docx.
    
    Change-Id: I5673f13e2fb4bc7887f1fc54771532c049129047

diff --git a/sw/source/filter/ww8/docxexport.cxx b/sw/source/filter/ww8/docxexport.cxx
index d768906..669b3c1 100644
--- a/sw/source/filter/ww8/docxexport.cxx
+++ b/sw/source/filter/ww8/docxexport.cxx
@@ -382,6 +382,9 @@ OString DocxExport::WriteOLEObject( SwOLEObj& rObject, OUString sMediaType, OUSt
 // function copied from embeddedobj/source/msole/oleembed.cxx
 bool DocxExport::lcl_CopyStream( uno::Reference<io::XInputStream> xIn, uno::Reference<io::XOutputStream> xOut )
 {
+    if( !xIn.is() || !xOut.is() )
+        return false;
+
     const sal_Int32 nChunkSize = 4096;
     uno::Sequence< sal_Int8 > aData(nChunkSize);
     sal_Int32 nTotalRead = 0;


More information about the Libreoffice-commits mailing list