[Libreoffice-commits] core.git: 2 commits - sc/source

Kohei Yoshida kohei.yoshida at collabora.com
Tue Aug 12 19:05:55 PDT 2014


 sc/source/filter/excel/xeescher.cxx |    5 ++
 sc/source/filter/excel/xestyle.cxx  |    5 +-
 sc/source/filter/inc/xeescher.hxx   |    2 +
 sc/source/filter/xcl97/xcl97rec.cxx |   70 +++++++++++++++++++++++++++++++-----
 4 files changed, 70 insertions(+), 12 deletions(-)

New commits:
commit 692878e3bb83c0fc104c5cca946c25ccf2d84ab2
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Tue Aug 12 21:24:17 2014 -0400

    bnc#822170: Let's not even try to export invalid chart objects.
    
    If we do, at best, Excel will complain about the document needing
    repair.  At worst Excel will skip some of the other valid drawing
    objects from being loaded.
    
    Change-Id: If3794d0ae9d8b44b124020bb12b5369dfebc95ae

diff --git a/sc/source/filter/excel/xeescher.cxx b/sc/source/filter/excel/xeescher.cxx
index 1223057..f3cd939 100644
--- a/sc/source/filter/excel/xeescher.cxx
+++ b/sc/source/filter/excel/xeescher.cxx
@@ -1190,6 +1190,11 @@ void XclExpChartObj::WriteShapeTransformation( sax_fastparser::FSHelperPtr pFS,
     pFS->endElementNS( XML_xdr, XML_xfrm );
 }
 
+const css::uno::Reference<css::chart::XChartDocument>& XclExpChartObj::GetChartDoc() const
+{
+    return mxChartDoc;
+}
+
 XclExpNote::XclExpNote( const XclExpRoot& rRoot, const ScAddress& rScPos,
         const ScPostIt* pScNote, const OUString& rAddText ) :
     XclExpRecord( EXC_ID_NOTE ),
diff --git a/sc/source/filter/inc/xeescher.hxx b/sc/source/filter/inc/xeescher.hxx
index 7171046..1703630 100644
--- a/sc/source/filter/inc/xeescher.hxx
+++ b/sc/source/filter/inc/xeescher.hxx
@@ -303,6 +303,8 @@ public:
     virtual void        WriteChartObj( sax_fastparser::FSHelperPtr pDrawing, XclExpXmlStream& rStrm );
     void WriteShapeTransformation( sax_fastparser::FSHelperPtr pFS, const XShapeRef& rXShape, bool bFlipH = false, bool bFlipV = false, sal_Int32 nRotation = 0 );
 
+    const css::uno::Reference<css::chart::XChartDocument>& GetChartDoc() const;
+
 private:
     typedef boost::shared_ptr< XclExpChart > XclExpChartRef;
     XclExpChartRef      mxChart;        /// The chart itself (BOF/EOF substream data).
diff --git a/sc/source/filter/xcl97/xcl97rec.cxx b/sc/source/filter/xcl97/xcl97rec.cxx
index e28bccf..ba20be7 100644
--- a/sc/source/filter/xcl97/xcl97rec.cxx
+++ b/sc/source/filter/xcl97/xcl97rec.cxx
@@ -71,6 +71,8 @@
 #include <com/sun/star/sheet/XCellAddressable.hpp>
 #include <com/sun/star/sheet/XCellRangeAddressable.hpp>
 #include <com/sun/star/embed/Aspects.hpp>
+#include <com/sun/star/chart2/XCoordinateSystemContainer.hpp>
+#include <com/sun/star/chart2/XChartTypeContainer.hpp>
 #include <oox/token/tokens.hxx>
 #include <oox/export/shapes.hxx>
 #include <oox/export/utils.hxx>
@@ -163,6 +165,8 @@ void XclExpObjList::Save( XclExpStream& rStrm )
         pSolverContainer->Save( rStrm );
 }
 
+namespace {
+
 static bool IsVmlObject( const XclObj *rObj )
 {
     switch( rObj->GetObjType() )
@@ -186,10 +190,61 @@ static sal_Int32 GetVmlObjectCount( XclExpObjList& rList )
     return nNumVml;
 }
 
+bool IsValidObject( const XclObj& rObj )
+{
+    if (rObj.GetObjType() == EXC_OBJTYPE_CHART)
+    {
+        // Chart object.  Make sure it's a valid chart object.  We skip
+        // invalid chart objects from exporting to prevent Excel from
+        // complaining on load.
+
+        const XclExpChartObj& rChartObj = static_cast<const XclExpChartObj&>(rObj);
+        uno::Reference<chart2::XChartDocument> xChartDoc(rChartObj.GetChartDoc(), uno::UNO_QUERY);
+        if (!xChartDoc.is())
+            return false;
+
+        uno::Reference<chart2::XDiagram> xDiagram = xChartDoc->getFirstDiagram();
+        if (!xDiagram.is())
+            return false;
+
+        uno::Reference<chart2::XCoordinateSystemContainer> xCooSysContainer(xDiagram, uno::UNO_QUERY);
+        if (!xCooSysContainer.is())
+            return false;
+
+        uno::Sequence<uno::Reference<chart2::XCoordinateSystem> > xCooSysSeq = xCooSysContainer->getCoordinateSystems();
+        if (!xCooSysSeq.getLength())
+            return false;
+
+        for (sal_Int32 nCooSys = 0; nCooSys < xCooSysSeq.getLength(); ++nCooSys)
+        {
+            Reference<chart2::XChartTypeContainer> xChartTypeCont(xCooSysSeq[nCooSys], uno::UNO_QUERY);
+            if (!xChartTypeCont.is())
+                return false;
+
+            uno::Sequence<uno::Reference<chart2::XChartType> > xChartTypeSeq = xChartTypeCont->getChartTypes();
+            if (!xChartTypeSeq.getLength())
+                // No chart type.  Not good.
+                return false;
+        }
+    }
+
+    return true;
+}
+
 static void SaveDrawingMLObjects( XclExpObjList& rList, XclExpXmlStream& rStrm, sal_Int32& nDrawingMLCount )
 {
-    sal_Int32 nVmlObjects = GetVmlObjectCount( rList );
-    if( (rList.size() - nVmlObjects) == 0 )
+    std::vector<XclObj*> aList;
+    aList.reserve(rList.size());
+    std::vector<XclObj*>::iterator it = rList.begin(), itEnd = rList.end();
+    for (; it != itEnd; ++it)
+    {
+        if (IsVmlObject(*it) || !IsValidObject(**it))
+            continue;
+
+        aList.push_back(*it);
+    }
+
+    if (aList.empty())
         return;
 
     sal_Int32 nDrawing = ++nDrawingMLCount;
@@ -213,13 +268,8 @@ static void SaveDrawingMLObjects( XclExpObjList& rList, XclExpXmlStream& rStrm,
             FSNS( XML_xmlns, XML_r ),   "http://schemas.openxmlformats.org/officeDocument/2006/relationships",
             FSEND );
 
-    std::vector<XclObj*>::iterator pIter;
-    for ( pIter = rList.begin(); pIter != rList.end(); ++pIter )
-    {
-        if( IsVmlObject( *pIter ) )
-            continue;
-        (*pIter)->SaveXml( rStrm );
-    }
+    for (it = aList.begin(), itEnd = aList.end(); it != itEnd; ++it)
+        (*it)->SaveXml(rStrm);
 
     pDrawing->endElement( FSNS( XML_xdr, XML_wsDr ) );
 
@@ -266,6 +316,8 @@ static void SaveVmlObjects( XclExpObjList& rList, XclExpXmlStream& rStrm, sal_In
     rStrm.PopStream();
 }
 
+}
+
 void XclExpObjList::SaveXml( XclExpXmlStream& rStrm )
 {
     if( pSolverContainer )
commit 1e68aabdeaacd8d4cac94d46925a55e2a93880d7
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Tue Aug 12 17:10:40 2014 -0400

    Don't export builtinId of 54 or above.
    
    Change-Id: I5ab651e0c92ab032d892080f979aa4f53295a8b6

diff --git a/sc/source/filter/excel/xestyle.cxx b/sc/source/filter/excel/xestyle.cxx
index f4c7640..7d21206 100644
--- a/sc/source/filter/excel/xestyle.cxx
+++ b/sc/source/filter/excel/xestyle.cxx
@@ -2213,9 +2213,8 @@ void XclExpStyle::SaveXml( XclExpXmlStream& rStrm )
     rStrm.GetCurrentStream()->singleElement( XML_cellStyle,
             XML_name,           sName.getStr(),
             XML_xfId,           OString::number( nXFId ).getStr(),
-/* mso-excel 2007 complains when it finds builtinId >= 55, it is not
- * bothered by multiple 54 values. */
-#define CELL_STYLE_MAX_BUILTIN_ID 55
+// builtinId of 54 or above is invalid according to OpenXML SDK validator.
+#define CELL_STYLE_MAX_BUILTIN_ID 54
                                              XML_builtinId, OString::number( std::min( static_cast<sal_Int32>( CELL_STYLE_MAX_BUILTIN_ID - 1 ), static_cast <sal_Int32>( mnStyleId ) ) ).getStr(),
             // OOXTODO: XML_iLevel,
             // OOXTODO: XML_hidden,


More information about the Libreoffice-commits mailing list