Blame SOURCES/0018-Resolves-fdo-52226-swap-in-graphics-on-.docx-and-.rt.patch

f085be
From 5b11f8b75b1ee6da439c3cd7892990b601e03d83 Mon Sep 17 00:00:00 2001
f085be
From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= <caolanm@redhat.com>
f085be
Date: Mon, 14 Jul 2014 11:36:32 +0100
f085be
Subject: [PATCH 018/137] Resolves: fdo#52226 swap in graphics on .docx and
f085be
 .rtf export
f085be
f085be
(cherry picked from commit 9dd5caac62083f7162d83319284df68ee83e3777)
f085be
f085be
Conflicts:
f085be
	sw/source/filter/ww8/docxattributeoutput.cxx
f085be
	sw/source/filter/ww8/rtfattributeoutput.cxx
f085be
	sw/source/filter/ww8/wrtww8gr.cxx
f085be
f085be
Change-Id: Ie818b382c0b17760c720ff2f2c73a3697989f97e
f085be
Reviewed-on: https://gerrit.libreoffice.org/10296
f085be
Reviewed-by: David Tardon <dtardon@redhat.com>
f085be
Tested-by: David Tardon <dtardon@redhat.com>
f085be
---
f085be
 sw/source/filter/ww8/docxattributeoutput.cxx | 18 +++++++++++++++++-
f085be
 sw/source/filter/ww8/rtfattributeoutput.cxx  | 28 +++++++++++++++++++---------
f085be
 sw/source/filter/ww8/wrtww8gr.cxx            |  2 +-
f085be
 3 files changed, 37 insertions(+), 11 deletions(-)
f085be
f085be
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx
f085be
index 2056863..22612f5 100644
f085be
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
f085be
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
f085be
@@ -2757,13 +2757,29 @@ void DocxAttributeOutput::FlyFrameGraphic( const SwGrfNode* pGrfNode, const Size
f085be
         // inline, we also have to write the image itself
f085be
         const Graphic* pGraphic = 0;
f085be
         if (pGrfNode)
f085be
-            pGraphic = &const_cast< Graphic& >( pGrfNode->GetGrf() );
f085be
+            pGraphic = &pGrfNode->GetGrf();
f085be
         else
f085be
             pGraphic = pOLENode->GetGraphic();
f085be
 
f085be
         m_rDrawingML.SetFS( m_pSerializer ); // to be sure that we write to the right stream
f085be
+
f085be
+        bool bSwapped = pGraphic->IsSwapOut();
f085be
+        if (bSwapped)
f085be
+        {
f085be
+            if (pGrfNode)
f085be
+            {
f085be
+                // always swapin via the Node
f085be
+                const_cast<SwGrfNode*>(pGrfNode)->SwapIn();
f085be
+            }
f085be
+            else
f085be
+                const_cast<Graphic*>(pGraphic)->SwapIn();
f085be
+        }
f085be
+
f085be
         OUString aImageId = m_rDrawingML.WriteImage( *pGraphic );
f085be
 
f085be
+        if (bSwapped)
f085be
+            const_cast<Graphic*>(pGraphic)->SwapOut();
f085be
+
f085be
         aRelId = OUStringToOString( aImageId, RTL_TEXTENCODING_UTF8 );
f085be
 
f085be
         nImageType = XML_embed;
f085be
diff --git a/sw/source/filter/ww8/rtfattributeoutput.cxx b/sw/source/filter/ww8/rtfattributeoutput.cxx
f085be
index f73ab4d..9b3887f 100644
f085be
--- a/sw/source/filter/ww8/rtfattributeoutput.cxx
f085be
+++ b/sw/source/filter/ww8/rtfattributeoutput.cxx
f085be
@@ -3610,17 +3610,24 @@ void RtfAttributeOutput::FlyFrameGraphic( const SwFlyFrmFmt* pFlyFrmFmt, const S
f085be
     const sal_uInt8* pGraphicAry = 0;
f085be
     sal_uInt32 nSize = 0;
f085be
 
f085be
-    Graphic aGraphic(pGrfNode->GetGrf());
f085be
+    const Graphic& rGraphic(pGrfNode->GetGrf());
f085be
 
f085be
     // If there is no graphic there is not much point in parsing it
f085be
-    if(aGraphic.GetType()==GRAPHIC_NONE)
f085be
+    if (rGraphic.GetType()==GRAPHIC_NONE)
f085be
         return;
f085be
 
f085be
+    bool bSwapped = rGraphic.IsSwapOut();
f085be
+    if (bSwapped)
f085be
+    {
f085be
+        // always swapin via the Node
f085be
+        const_cast<SwGrfNode*>(pGrfNode)->SwapIn();
f085be
+    }
f085be
+
f085be
     GfxLink aGraphicLink;
f085be
     const sal_Char* pBLIPType = 0;
f085be
-    if (aGraphic.IsLink())
f085be
+    if (rGraphic.IsLink())
f085be
     {
f085be
-        aGraphicLink = aGraphic.GetLink();
f085be
+        aGraphicLink = rGraphic.GetLink();
f085be
         nSize = aGraphicLink.GetDataSize();
f085be
         pGraphicAry = aGraphicLink.GetData();
f085be
         switch (aGraphicLink.GetType())
f085be
@@ -3640,10 +3647,10 @@ void RtfAttributeOutput::FlyFrameGraphic( const SwFlyFrmFmt* pFlyFrmFmt, const S
f085be
         }
f085be
     }
f085be
 
f085be
-    GraphicType eGraphicType = aGraphic.GetType();
f085be
+    GraphicType eGraphicType = rGraphic.GetType();
f085be
     if (!pGraphicAry)
f085be
     {
f085be
-        if (ERRCODE_NONE == GraphicConverter::Export(aStream, aGraphic,
f085be
+        if (ERRCODE_NONE == GraphicConverter::Export(aStream, rGraphic,
f085be
                     (eGraphicType == GRAPHIC_BITMAP) ? CVT_PNG : CVT_WMF))
f085be
         {
f085be
             pBLIPType = (eGraphicType == GRAPHIC_BITMAP) ?
f085be
@@ -3654,7 +3661,7 @@ void RtfAttributeOutput::FlyFrameGraphic( const SwFlyFrmFmt* pFlyFrmFmt, const S
f085be
         }
f085be
     }
f085be
 
f085be
-    Size aMapped(eGraphicType == GRAPHIC_BITMAP ? aGraphic.GetSizePixel() : aGraphic.GetPrefSize());
f085be
+    Size aMapped(eGraphicType == GRAPHIC_BITMAP ? rGraphic.GetSizePixel() : rGraphic.GetPrefSize());
f085be
 
f085be
     const SwCropGrf &rCr = (const SwCropGrf &)pGrfNode->GetAttr(RES_GRFATR_CROPGRF);
f085be
 
f085be
@@ -3683,7 +3690,7 @@ void RtfAttributeOutput::FlyFrameGraphic( const SwFlyFrmFmt* pFlyFrmFmt, const S
f085be
     else
f085be
     {
f085be
         aStream.Seek(0);
f085be
-        GraphicConverter::Export(aStream, aGraphic, CVT_WMF);
f085be
+        GraphicConverter::Export(aStream, rGraphic, CVT_WMF);
f085be
         pBLIPType = OOO_STRING_SVTOOLS_RTF_WMETAFILE;
f085be
         aStream.Seek(STREAM_SEEK_TO_END);
f085be
         nSize = aStream.Tell();
f085be
@@ -3697,7 +3704,7 @@ void RtfAttributeOutput::FlyFrameGraphic( const SwFlyFrmFmt* pFlyFrmFmt, const S
f085be
         m_rExport.Strm() << "}" "{" OOO_STRING_SVTOOLS_RTF_NONSHPPICT;
f085be
 
f085be
         aStream.Seek(0);
f085be
-        GraphicConverter::Export(aStream, aGraphic, CVT_WMF);
f085be
+        GraphicConverter::Export(aStream, rGraphic, CVT_WMF);
f085be
         pBLIPType = OOO_STRING_SVTOOLS_RTF_WMETAFILE;
f085be
         aStream.Seek(STREAM_SEEK_TO_END);
f085be
         nSize = aStream.Tell();
f085be
@@ -3708,6 +3715,9 @@ void RtfAttributeOutput::FlyFrameGraphic( const SwFlyFrmFmt* pFlyFrmFmt, const S
f085be
         m_rExport.Strm() << '}';
f085be
     }
f085be
 
f085be
+    if (bSwapped)
f085be
+        const_cast<Graphic&>(rGraphic).SwapOut();
f085be
+
f085be
     m_rExport.Strm() << SAL_NEWLINE_STRING;
f085be
 }
f085be
 
f085be
diff --git a/sw/source/filter/ww8/wrtww8gr.cxx b/sw/source/filter/ww8/wrtww8gr.cxx
f085be
index 61a8c17..5075a89 100644
f085be
--- a/sw/source/filter/ww8/wrtww8gr.cxx
f085be
+++ b/sw/source/filter/ww8/wrtww8gr.cxx
f085be
@@ -724,7 +724,7 @@ void SwWW8WrGrf::WriteGrfFromGrfNode(SvStream& rStrm, const SwGrfNode &rGrfNd,
f085be
         {
f085be
             Graphic& rGrf = const_cast<Graphic&>(rGrfNd.GetGrf());
f085be
             bool bSwapped = rGrf.IsSwapOut() ? true : false;
f085be
-            // immer ueber den Node einswappen!
f085be
+            // always swapin via the Node
f085be
             const_cast<SwGrfNode&>(rGrfNd).SwapIn();
f085be
 
f085be
             GDIMetaFile aMeta;
f085be
-- 
f085be
1.9.3
f085be