Blame SOURCES/0019-Related-fdo-52226-ensure-graphics-are-swapped-in-on-.patch

f085be
From b0282d868b418b4ecdb19cbb633c9399ac84161b 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 12:13:21 +0100
f085be
Subject: [PATCH 019/137] Related: fdo#52226 ensure graphics are swapped in on
f085be
 DrawingML::WriteImage
f085be
f085be
I imagine it would be best that the Graphics were delivered pre-swapped in by
f085be
higher levels in case there are second level caches or more complex caching
f085be
systemed wrapped around it, so warn about it in debug mode but give it a
f085be
last-ditch shot anyway. i.e. while the .docx problem should be fixed there
f085be
is a report of a very similar .xlsx problem
f085be
f085be
Change-Id: Ie40ee10fe5cba8ff9c321f47b83e33ee2c1425fd
f085be
(cherry picked from commit 6e580f3f53ae2de086a08c8ba1958b67874eb9c5)
f085be
Reviewed-on: https://gerrit.libreoffice.org/10300
f085be
Reviewed-by: David Tardon <dtardon@redhat.com>
f085be
Tested-by: David Tardon <dtardon@redhat.com>
f085be
---
f085be
 oox/source/export/drawingml.cxx | 34 ++++++++++++++++++++++++++--------
f085be
 vcl/source/gdi/cvtgrf.cxx       |  2 ++
f085be
 2 files changed, 28 insertions(+), 8 deletions(-)
f085be
f085be
diff --git a/oox/source/export/drawingml.cxx b/oox/source/export/drawingml.cxx
f085be
index dd6605b..847d21c 100644
f085be
--- a/oox/source/export/drawingml.cxx
f085be
+++ b/oox/source/export/drawingml.cxx
f085be
@@ -495,14 +495,32 @@ OUString DrawingML::WriteImage( const Graphic& rGraphic )
f085be
             break;
f085be
         default: {
f085be
             GraphicType aType = rGraphic.GetType();
f085be
-            if ( aType == GRAPHIC_BITMAP ) {
f085be
-                GraphicConverter::Export( aStream, rGraphic, CVT_PNG );
f085be
-                sMediaType = "image/png";
f085be
-                pExtension = ".png";
f085be
-            } else if ( aType == GRAPHIC_GDIMETAFILE ) {
f085be
-                GraphicConverter::Export( aStream, rGraphic, CVT_EMF );
f085be
-                sMediaType = "image/x-emf";
f085be
-                pExtension = ".emf";
f085be
+            if ( aType == GRAPHIC_BITMAP || aType == GRAPHIC_GDIMETAFILE) {
f085be
+                bool bSwapped = rGraphic.IsSwapOut();
f085be
+
f085be
+                //Warn rather than just happily swap in because of the comments
f085be
+                //in the sw export filters about needing to go through the
f085be
+                //hairy SwGrfNode::SwapIn which we would subvert by swapping in
f085be
+                //without it knowing about it, so while those ones are fixed we
f085be
+                //probably have to assume that we should ideally be presented
f085be
+                //here with already swapped in graphics.
f085be
+                SAL_WARN_IF(bSwapped, "oox", "attempted to output swapped out graphic");
f085be
+
f085be
+                if (bSwapped)
f085be
+                    const_cast<Graphic&>(rGraphic).SwapIn();
f085be
+
f085be
+                if ( aType == GRAPHIC_BITMAP ) {
f085be
+                    GraphicConverter::Export( aStream, rGraphic, CVT_PNG );
f085be
+                    sMediaType = "image/png";
f085be
+                    pExtension = ".png";
f085be
+                } else {
f085be
+                    GraphicConverter::Export( aStream, rGraphic, CVT_EMF );
f085be
+                    sMediaType = "image/x-emf";
f085be
+                    pExtension = ".emf";
f085be
+                }
f085be
+
f085be
+                if (bSwapped)
f085be
+                    const_cast<Graphic&>(rGraphic).SwapOut();
f085be
             } else {
f085be
                 OSL_TRACE( "unhandled graphic type" );
f085be
                 break;
f085be
diff --git a/vcl/source/gdi/cvtgrf.cxx b/vcl/source/gdi/cvtgrf.cxx
f085be
index 02ca288..d395670 100644
f085be
--- a/vcl/source/gdi/cvtgrf.cxx
f085be
+++ b/vcl/source/gdi/cvtgrf.cxx
f085be
@@ -57,6 +57,8 @@ sal_uLong GraphicConverter::Import( SvStream& rIStm, Graphic& rGraphic, sal_uLon
f085be
 
f085be
 sal_uLong GraphicConverter::Export( SvStream& rOStm, const Graphic& rGraphic, sal_uLong nFormat )
f085be
 {
f085be
+    SAL_WARN_IF(rGraphic.IsSwapOut(), "vcl.filter", "exporting a swapped out graphic!");
f085be
+
f085be
     GraphicConverter*   pCvt = ImplGetSVData()->maGDIData.mpGrfConverter;
f085be
     sal_uLong               nRet = ERRCODE_IO_GENERAL;
f085be
 
f085be
-- 
f085be
1.9.3
f085be