Blob Blame History Raw
From 5b11f8b75b1ee6da439c3cd7892990b601e03d83 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= <caolanm@redhat.com>
Date: Mon, 14 Jul 2014 11:36:32 +0100
Subject: [PATCH 018/137] Resolves: fdo#52226 swap in graphics on .docx and
 .rtf export

(cherry picked from commit 9dd5caac62083f7162d83319284df68ee83e3777)

Conflicts:
	sw/source/filter/ww8/docxattributeoutput.cxx
	sw/source/filter/ww8/rtfattributeoutput.cxx
	sw/source/filter/ww8/wrtww8gr.cxx

Change-Id: Ie818b382c0b17760c720ff2f2c73a3697989f97e
Reviewed-on: https://gerrit.libreoffice.org/10296
Reviewed-by: David Tardon <dtardon@redhat.com>
Tested-by: David Tardon <dtardon@redhat.com>
---
 sw/source/filter/ww8/docxattributeoutput.cxx | 18 +++++++++++++++++-
 sw/source/filter/ww8/rtfattributeoutput.cxx  | 28 +++++++++++++++++++---------
 sw/source/filter/ww8/wrtww8gr.cxx            |  2 +-
 3 files changed, 37 insertions(+), 11 deletions(-)

diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx
index 2056863..22612f5 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -2757,13 +2757,29 @@ void DocxAttributeOutput::FlyFrameGraphic( const SwGrfNode* pGrfNode, const Size
         // inline, we also have to write the image itself
         const Graphic* pGraphic = 0;
         if (pGrfNode)
-            pGraphic = &const_cast< Graphic& >( pGrfNode->GetGrf() );
+            pGraphic = &pGrfNode->GetGrf();
         else
             pGraphic = pOLENode->GetGraphic();
 
         m_rDrawingML.SetFS( m_pSerializer ); // to be sure that we write to the right stream
+
+        bool bSwapped = pGraphic->IsSwapOut();
+        if (bSwapped)
+        {
+            if (pGrfNode)
+            {
+                // always swapin via the Node
+                const_cast<SwGrfNode*>(pGrfNode)->SwapIn();
+            }
+            else
+                const_cast<Graphic*>(pGraphic)->SwapIn();
+        }
+
         OUString aImageId = m_rDrawingML.WriteImage( *pGraphic );
 
+        if (bSwapped)
+            const_cast<Graphic*>(pGraphic)->SwapOut();
+
         aRelId = OUStringToOString( aImageId, RTL_TEXTENCODING_UTF8 );
 
         nImageType = XML_embed;
diff --git a/sw/source/filter/ww8/rtfattributeoutput.cxx b/sw/source/filter/ww8/rtfattributeoutput.cxx
index f73ab4d..9b3887f 100644
--- a/sw/source/filter/ww8/rtfattributeoutput.cxx
+++ b/sw/source/filter/ww8/rtfattributeoutput.cxx
@@ -3610,17 +3610,24 @@ void RtfAttributeOutput::FlyFrameGraphic( const SwFlyFrmFmt* pFlyFrmFmt, const S
     const sal_uInt8* pGraphicAry = 0;
     sal_uInt32 nSize = 0;
 
-    Graphic aGraphic(pGrfNode->GetGrf());
+    const Graphic& rGraphic(pGrfNode->GetGrf());
 
     // If there is no graphic there is not much point in parsing it
-    if(aGraphic.GetType()==GRAPHIC_NONE)
+    if (rGraphic.GetType()==GRAPHIC_NONE)
         return;
 
+    bool bSwapped = rGraphic.IsSwapOut();
+    if (bSwapped)
+    {
+        // always swapin via the Node
+        const_cast<SwGrfNode*>(pGrfNode)->SwapIn();
+    }
+
     GfxLink aGraphicLink;
     const sal_Char* pBLIPType = 0;
-    if (aGraphic.IsLink())
+    if (rGraphic.IsLink())
     {
-        aGraphicLink = aGraphic.GetLink();
+        aGraphicLink = rGraphic.GetLink();
         nSize = aGraphicLink.GetDataSize();
         pGraphicAry = aGraphicLink.GetData();
         switch (aGraphicLink.GetType())
@@ -3640,10 +3647,10 @@ void RtfAttributeOutput::FlyFrameGraphic( const SwFlyFrmFmt* pFlyFrmFmt, const S
         }
     }
 
-    GraphicType eGraphicType = aGraphic.GetType();
+    GraphicType eGraphicType = rGraphic.GetType();
     if (!pGraphicAry)
     {
-        if (ERRCODE_NONE == GraphicConverter::Export(aStream, aGraphic,
+        if (ERRCODE_NONE == GraphicConverter::Export(aStream, rGraphic,
                     (eGraphicType == GRAPHIC_BITMAP) ? CVT_PNG : CVT_WMF))
         {
             pBLIPType = (eGraphicType == GRAPHIC_BITMAP) ?
@@ -3654,7 +3661,7 @@ void RtfAttributeOutput::FlyFrameGraphic( const SwFlyFrmFmt* pFlyFrmFmt, const S
         }
     }
 
-    Size aMapped(eGraphicType == GRAPHIC_BITMAP ? aGraphic.GetSizePixel() : aGraphic.GetPrefSize());
+    Size aMapped(eGraphicType == GRAPHIC_BITMAP ? rGraphic.GetSizePixel() : rGraphic.GetPrefSize());
 
     const SwCropGrf &rCr = (const SwCropGrf &)pGrfNode->GetAttr(RES_GRFATR_CROPGRF);
 
@@ -3683,7 +3690,7 @@ void RtfAttributeOutput::FlyFrameGraphic( const SwFlyFrmFmt* pFlyFrmFmt, const S
     else
     {
         aStream.Seek(0);
-        GraphicConverter::Export(aStream, aGraphic, CVT_WMF);
+        GraphicConverter::Export(aStream, rGraphic, CVT_WMF);
         pBLIPType = OOO_STRING_SVTOOLS_RTF_WMETAFILE;
         aStream.Seek(STREAM_SEEK_TO_END);
         nSize = aStream.Tell();
@@ -3697,7 +3704,7 @@ void RtfAttributeOutput::FlyFrameGraphic( const SwFlyFrmFmt* pFlyFrmFmt, const S
         m_rExport.Strm() << "}" "{" OOO_STRING_SVTOOLS_RTF_NONSHPPICT;
 
         aStream.Seek(0);
-        GraphicConverter::Export(aStream, aGraphic, CVT_WMF);
+        GraphicConverter::Export(aStream, rGraphic, CVT_WMF);
         pBLIPType = OOO_STRING_SVTOOLS_RTF_WMETAFILE;
         aStream.Seek(STREAM_SEEK_TO_END);
         nSize = aStream.Tell();
@@ -3708,6 +3715,9 @@ void RtfAttributeOutput::FlyFrameGraphic( const SwFlyFrmFmt* pFlyFrmFmt, const S
         m_rExport.Strm() << '}';
     }
 
+    if (bSwapped)
+        const_cast<Graphic&>(rGraphic).SwapOut();
+
     m_rExport.Strm() << SAL_NEWLINE_STRING;
 }
 
diff --git a/sw/source/filter/ww8/wrtww8gr.cxx b/sw/source/filter/ww8/wrtww8gr.cxx
index 61a8c17..5075a89 100644
--- a/sw/source/filter/ww8/wrtww8gr.cxx
+++ b/sw/source/filter/ww8/wrtww8gr.cxx
@@ -724,7 +724,7 @@ void SwWW8WrGrf::WriteGrfFromGrfNode(SvStream& rStrm, const SwGrfNode &rGrfNd,
         {
             Graphic& rGrf = const_cast<Graphic&>(rGrfNd.GetGrf());
             bool bSwapped = rGrf.IsSwapOut() ? true : false;
-            // immer ueber den Node einswappen!
+            // always swapin via the Node
             const_cast<SwGrfNode&>(rGrfNd).SwapIn();
 
             GDIMetaFile aMeta;
-- 
1.9.3