kbrown / rpms / libreoffice

Forked from rpms/libreoffice 2 years ago
Clone

Blame SOURCES/0098-bnc-822170-Let-s-not-even-try-to-export-invalid-char.patch

f085be
From f1d36a5eaaff6404fee0865947040e92026c7996 Mon Sep 17 00:00:00 2001
f085be
From: Kohei Yoshida <kohei.yoshida@collabora.com>
f085be
Date: Tue, 12 Aug 2014 21:24:17 -0400
f085be
Subject: [PATCH 098/137] bnc#822170: Let's not even try to export invalid
f085be
 chart objects.
f085be
f085be
If we do, at best, Excel will complain about the document needing
f085be
repair.  At worst Excel will skip some of the other valid drawing
f085be
objects from being loaded.
f085be
f085be
(cherry picked from commit 692878e3bb83c0fc104c5cca946c25ccf2d84ab2)
f085be
f085be
Conflicts:
f085be
	sc/source/filter/xcl97/xcl97rec.cxx
f085be
	sc/source/filter/excel/xeescher.cxx
f085be
f085be
Change-Id: If3794d0ae9d8b44b124020bb12b5369dfebc95ae
f085be
Reviewed-on: https://gerrit.libreoffice.org/10900
f085be
Reviewed-by: Eike Rathke <erack@redhat.com>
f085be
Tested-by: Eike Rathke <erack@redhat.com>
f085be
---
f085be
 sc/source/filter/excel/xeescher.cxx |  5 ++-
f085be
 sc/source/filter/inc/xeescher.hxx   |  2 ++
f085be
 sc/source/filter/xcl97/xcl97rec.cxx | 68 ++++++++++++++++++++++++++++++++-----
f085be
 3 files changed, 65 insertions(+), 10 deletions(-)
f085be
f085be
diff --git a/sc/source/filter/excel/xeescher.cxx b/sc/source/filter/excel/xeescher.cxx
f085be
index 241182c..bb3a2a5 100644
f085be
--- a/sc/source/filter/excel/xeescher.cxx
f085be
+++ b/sc/source/filter/excel/xeescher.cxx
f085be
@@ -1207,7 +1207,10 @@ void XclExpChartObj::WriteShapeTransformation( sax_fastparser::FSHelperPtr pFS,
f085be
     pFS->endElementNS( XML_xdr, XML_xfrm );
f085be
 }
f085be
 
f085be
-// ============================================================================
f085be
+const css::uno::Reference<css::chart::XChartDocument>& XclExpChartObj::GetChartDoc() const
f085be
+{
f085be
+    return mxChartDoc;
f085be
+}
f085be
 
f085be
 XclExpNote::XclExpNote( const XclExpRoot& rRoot, const ScAddress& rScPos,
f085be
         const ScPostIt* pScNote, const OUString& rAddText ) :
f085be
diff --git a/sc/source/filter/inc/xeescher.hxx b/sc/source/filter/inc/xeescher.hxx
f085be
index 4d7be77..cce4c66 100644
f085be
--- a/sc/source/filter/inc/xeescher.hxx
f085be
+++ b/sc/source/filter/inc/xeescher.hxx
f085be
@@ -324,6 +324,8 @@ public:
f085be
     virtual void        WriteChartObj( sax_fastparser::FSHelperPtr pDrawing, XclExpXmlStream& rStrm );
f085be
     void WriteShapeTransformation( sax_fastparser::FSHelperPtr pFS, const XShapeRef& rXShape, sal_Bool bFlipH = false, sal_Bool bFlipV = false, sal_Int32 nRotation = 0 );
f085be
 
f085be
+    const css::uno::Reference<css::chart::XChartDocument>& GetChartDoc() const;
f085be
+
f085be
 private:
f085be
     typedef boost::shared_ptr< XclExpChart > XclExpChartRef;
f085be
     XclExpChartRef      mxChart;        /// The chart itself (BOF/EOF substream data).
f085be
diff --git a/sc/source/filter/xcl97/xcl97rec.cxx b/sc/source/filter/xcl97/xcl97rec.cxx
f085be
index d61383a..24624cb 100644
f085be
--- a/sc/source/filter/xcl97/xcl97rec.cxx
f085be
+++ b/sc/source/filter/xcl97/xcl97rec.cxx
f085be
@@ -71,6 +71,8 @@
f085be
 #include <com/sun/star/sheet/XCellAddressable.hpp>
f085be
 #include <com/sun/star/sheet/XCellRangeAddressable.hpp>
f085be
 #include <com/sun/star/embed/Aspects.hpp>
f085be
+#include <com/sun/star/chart2/XCoordinateSystemContainer.hpp>
f085be
+#include <com/sun/star/chart2/XChartTypeContainer.hpp>
f085be
 #include <oox/token/tokens.hxx>
f085be
 #include <oox/export/shapes.hxx>
f085be
 #include <oox/export/utils.hxx>
f085be
@@ -162,6 +164,8 @@ void XclExpObjList::Save( XclExpStream& rStrm )
f085be
         pSolverContainer->Save( rStrm );
f085be
 }
f085be
 
f085be
+namespace {
f085be
+
f085be
 static bool IsVmlObject( const XclObj *rObj )
f085be
 {
f085be
     switch( rObj->GetObjType() )
f085be
@@ -186,11 +190,61 @@ static sal_Int32 GetVmlObjectCount( XclExpObjList& rList )
f085be
     return nNumVml;
f085be
 }
f085be
 
f085be
+bool IsValidObject( const XclObj& rObj )
f085be
+{
f085be
+    if (rObj.GetObjType() == EXC_OBJTYPE_CHART)
f085be
+    {
f085be
+        // Chart object.  Make sure it's a valid chart object.  We skip
f085be
+        // invalid chart objects from exporting to prevent Excel from
f085be
+        // complaining on load.
f085be
+
f085be
+        const XclExpChartObj& rChartObj = static_cast<const XclExpChartObj&>(rObj);
f085be
+        uno::Reference<chart2::XChartDocument> xChartDoc(rChartObj.GetChartDoc(), uno::UNO_QUERY);
f085be
+        if (!xChartDoc.is())
f085be
+            return false;
f085be
+
f085be
+        uno::Reference<chart2::XDiagram> xDiagram = xChartDoc->getFirstDiagram();
f085be
+        if (!xDiagram.is())
f085be
+            return false;
f085be
+
f085be
+        uno::Reference<chart2::XCoordinateSystemContainer> xCooSysContainer(xDiagram, uno::UNO_QUERY);
f085be
+        if (!xCooSysContainer.is())
f085be
+            return false;
f085be
+
f085be
+        uno::Sequence<uno::Reference<chart2::XCoordinateSystem> > xCooSysSeq = xCooSysContainer->getCoordinateSystems();
f085be
+        if (!xCooSysSeq.getLength())
f085be
+            return false;
f085be
+
f085be
+        for (sal_Int32 nCooSys = 0; nCooSys < xCooSysSeq.getLength(); ++nCooSys)
f085be
+        {
f085be
+            Reference<chart2::XChartTypeContainer> xChartTypeCont(xCooSysSeq[nCooSys], uno::UNO_QUERY);
f085be
+            if (!xChartTypeCont.is())
f085be
+                return false;
f085be
+
f085be
+            uno::Sequence<uno::Reference<chart2::XChartType> > xChartTypeSeq = xChartTypeCont->getChartTypes();
f085be
+            if (!xChartTypeSeq.getLength())
f085be
+                // No chart type.  Not good.
f085be
+                return false;
f085be
+        }
f085be
+    }
f085be
+
f085be
+    return true;
f085be
+}
f085be
 
f085be
 static void SaveDrawingMLObjects( XclExpObjList& rList, XclExpXmlStream& rStrm, sal_Int32& nDrawingMLCount )
f085be
 {
f085be
-    sal_Int32 nVmlObjects = GetVmlObjectCount( rList );
f085be
-    if( (rList.size() - nVmlObjects) == 0 )
f085be
+    std::vector<XclObj*> aList;
f085be
+    aList.reserve(rList.size());
f085be
+    std::vector<XclObj*>::iterator it = rList.begin(), itEnd = rList.end();
f085be
+    for (; it != itEnd; ++it)
f085be
+    {
f085be
+        if (IsVmlObject(*it) || !IsValidObject(**it))
f085be
+            continue;
f085be
+
f085be
+        aList.push_back(*it);
f085be
+    }
f085be
+
f085be
+    if (aList.empty())
f085be
         return;
f085be
 
f085be
     sal_Int32 nDrawing = ++nDrawingMLCount;
f085be
@@ -214,13 +268,8 @@ static void SaveDrawingMLObjects( XclExpObjList& rList, XclExpXmlStream& rStrm,
f085be
             FSNS( XML_xmlns, XML_r ),   "http://schemas.openxmlformats.org/officeDocument/2006/relationships",
f085be
             FSEND );
f085be
 
f085be
-    std::vector<XclObj*>::iterator pIter;
f085be
-    for ( pIter = rList.begin(); pIter != rList.end(); ++pIter )
f085be
-    {
f085be
-        if( IsVmlObject( *pIter ) )
f085be
-            continue;
f085be
-        (*pIter)->SaveXml( rStrm );
f085be
-    }
f085be
+    for (it = aList.begin(), itEnd = aList.end(); it != itEnd; ++it)
f085be
+        (*it)->SaveXml(rStrm);
f085be
 
f085be
     pDrawing->endElement( FSNS( XML_xdr, XML_wsDr ) );
f085be
 
f085be
@@ -267,6 +316,7 @@ static void SaveVmlObjects( XclExpObjList& rList, XclExpXmlStream& rStrm, sal_In
f085be
     rStrm.PopStream();
f085be
 }
f085be
 
f085be
+}
f085be
 
f085be
 void XclExpObjList::SaveXml( XclExpXmlStream& rStrm )
f085be
 {
f085be
-- 
f085be
1.9.3
f085be