diff options
author | Katarina Machalkova <kmachalkova@suse.cz> | 2010-10-21 17:41:56 +0200 |
---|---|---|
committer | Katarina Machalkova <kmachalkova@suse.cz> | 2010-10-27 14:03:48 +0200 |
commit | b9d1610aa212c4283a8af73c6050a0e60993c484 (patch) | |
tree | 9ff488a245ed4083dbf811c683b5c1258c937388 | |
parent | 61623da8d9a0eb756b0a39707b8b27c8566b33fa (diff) |
Merged xlsx-shared-oox-chart-export-part1.diff from ooo-build
-rw-r--r-- | sc/source/filter/excel/xeescher.cxx | 124 | ||||
-rw-r--r-- | sc/source/filter/inc/xcl97rec.hxx | 2 | ||||
-rw-r--r-- | sc/source/filter/inc/xeescher.hxx | 8 | ||||
-rw-r--r-- | sc/source/filter/xcl97/xcl97rec.cxx | 17 |
4 files changed, 143 insertions, 8 deletions
diff --git a/sc/source/filter/excel/xeescher.cxx b/sc/source/filter/excel/xeescher.cxx index 59f989d22ed7..440d9a5df984 100644 --- a/sc/source/filter/excel/xeescher.cxx +++ b/sc/source/filter/excel/xeescher.cxx @@ -42,6 +42,10 @@ #include <com/sun/star/form/binding/XListEntrySink.hpp> #include <com/sun/star/form/binding/XListEntrySource.hpp> #include <com/sun/star/script/ScriptEventDescriptor.hpp> +#include <com/sun/star/chart2/XChartDocument.hpp> +#include <com/sun/star/awt/Point.hpp> +#include <com/sun/star/awt/Size.hpp> +#include <com/sun/star/container/XNamed.hpp> #include <set> #include <rtl/ustrbuf.h> @@ -83,6 +87,8 @@ #include <oox/core/tokens.hxx> #include <oox/export/drawingml.hxx> +#include <oox/export/chartexport.hxx> +#include <oox/export/utils.hxx> using ::rtl::OString; using ::rtl::OUString; @@ -104,7 +110,10 @@ using ::com::sun::star::form::binding::XListEntrySource; using ::com::sun::star::script::ScriptEventDescriptor; using ::com::sun::star::table::CellAddress; using ::com::sun::star::table::CellRangeAddress; +using ::com::sun::star::chart2::XChartDocument; +using ::com::sun::star::container::XNamed; using ::oox::drawingml::DrawingML; +using ::oox::drawingml::ChartExport; #define HMM2XL(x) ((x)/26.5)+0.5 @@ -1046,7 +1055,7 @@ void XclExpTbxControlObj::WriteSbs( XclExpStream& rStrm ) XclExpChartObj::XclExpChartObj( XclExpObjectManager& rObjMgr, Reference< XShape > xShape, const Rectangle* pChildAnchor ) : XclObj( rObjMgr, EXC_OBJTYPE_CHART ), - XclExpRoot( rObjMgr.GetRoot() ) + XclExpRoot( rObjMgr.GetRoot() ), mxShape( xShape ) { // create the MSODRAWING record contents for the chart object mrEscherEx.OpenContainer( ESCHER_SpContainer ); @@ -1080,6 +1089,7 @@ XclExpChartObj::XclExpChartObj( XclExpObjectManager& rObjMgr, Reference< XShape ScfPropertySet aShapeProp( xShape ); Reference< XModel > xModel; aShapeProp.GetProperty( xModel, CREATE_OUSTRING( "Model" ) ); + mxChartDoc.set( xModel,UNO_QUERY ); ::com::sun::star::awt::Rectangle aBoundRect; aShapeProp.GetProperty( aBoundRect, CREATE_OUSTRING( "BoundRect" ) ); Rectangle aChartRect( Point( aBoundRect.X, aBoundRect.Y ), Size( aBoundRect.Width, aBoundRect.Height ) ); @@ -1098,6 +1108,118 @@ void XclExpChartObj::Save( XclExpStream& rStrm ) mxChart->Save( rStrm ); } +void XclExpChartObj::SaveXml( XclExpXmlStream& rStrm ) +{ + OSL_TRACE("XclExpChartObj::SaveXml -- Entry point to export chart"); + sax_fastparser::FSHelperPtr pDrawing = rStrm.GetCurrentStream(); + + // FIXME: two cell? it seems the two cell anchor is incorrect. + pDrawing->startElement( FSNS( XML_xdr, XML_twoCellAnchor ), // OOXTODO: oneCellAnchor, absoluteAnchor + XML_editAs, "oneCell", + FSEND ); + Reference< XPropertySet > xPropSet( mxShape, UNO_QUERY ); + if (xPropSet.is()) + { + XclObjAny::WriteFromTo( rStrm, mxShape, GetTab() ); + Reference< XModel > xModel( mxChartDoc, UNO_QUERY ); + ChartExport aChartExport( XML_xdr, pDrawing, xModel, &rStrm, DrawingML::DOCUMENT_XLSX ); + static sal_Int32 nChartCount = 0; + nChartCount++; + aChartExport.WriteChartObj( mxShape, nChartCount ); + // TODO: get the correcto chart number + //WriteChartObj( pDrawing, rStrm ); + } + + pDrawing->singleElement( FSNS( XML_xdr, XML_clientData), + // OOXTODO: XML_fLocksWithSheet + // OOXTODO: XML_fPrintsWithSheet + FSEND ); + pDrawing->endElement( FSNS( XML_xdr, XML_twoCellAnchor ) ); +} + +void XclExpChartObj::WriteChartObj( sax_fastparser::FSHelperPtr pDrawing, XclExpXmlStream& rStrm ) +{ + pDrawing->startElement( FSNS( XML_xdr, XML_graphicFrame ), FSEND ); + + pDrawing->startElement( FSNS( XML_xdr, XML_nvGraphicFramePr ), FSEND ); + + // TODO: get the correct chart name chart id + OUString sName = CREATE_OUSTRING("Object 1"); + Reference< XNamed > xNamed( mxShape, UNO_QUERY ); + if (xNamed.is()) + { + sName = xNamed->getName(); + } + sal_Int32 nID = rStrm.GetUniqueId(); + + pDrawing->singleElement( FSNS( XML_xdr, XML_cNvPr ), + XML_id, I32S( nID ), + XML_name, USS( sName ), + FSEND ); + + pDrawing->singleElement( FSNS( XML_xdr, XML_cNvGraphicFramePr ), + FSEND ); + + pDrawing->endElement( FSNS( XML_xdr, XML_nvGraphicFramePr ) ); + + // visual chart properties + //pDrawing->startElement( FSNS( XML_xdr, XML_xfrm ), FSEND ); + WriteShapeTransformation( pDrawing, mxShape ); + //pDrawing->endElement( FSNS( XML_xdr, XML_xfrm ) ); + + // writer chart object + pDrawing->startElement( FSNS( XML_a, XML_graphic ), FSEND ); + pDrawing->startElement( FSNS( XML_a, XML_graphicData ), + XML_uri, "http://schemas.openxmlformats.org/drawingml/2006/chart", + FSEND ); + OUString sId; + // TODO: + static sal_Int32 nChartCount = 0; + nChartCount++; + sax_fastparser::FSHelperPtr pChart = rStrm.CreateOutputStream( + XclXmlUtils::GetStreamName( "xl/", "charts/chart", nChartCount ), + XclXmlUtils::GetStreamName( "../", "charts/chart", nChartCount ), + rStrm.GetCurrentStream()->getOutputStream(), + "application/vnd.openxmlformats-officedocument.drawingml.chart+xml", + "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart", + &sId ); + + pDrawing->singleElement( FSNS( XML_c, XML_chart ), + FSNS( XML_xmlns, XML_c ), "http://schemas.openxmlformats.org/drawingml/2006/chart", + FSNS( XML_xmlns, XML_r ), "http://schemas.openxmlformats.org/officeDocument/2006/relationships", + FSNS( XML_r, XML_id ), XclXmlUtils::ToOString( sId ).getStr(), + FSEND ); + + rStrm.PushStream( pChart ); + Reference< XModel > xModel( mxChartDoc, UNO_QUERY ); + ChartExport aChartExport( XML_xdr, pChart, xModel, &rStrm, DrawingML::DOCUMENT_XLSX ); + aChartExport.ExportContent(); + + rStrm.PopStream(); + + pDrawing->endElement( FSNS( XML_a, XML_graphicData ) ); + pDrawing->endElement( FSNS( XML_a, XML_graphic ) ); + pDrawing->endElement( FSNS( XML_xdr, XML_graphicFrame ) ); + +} + +void XclExpChartObj::WriteShapeTransformation( sax_fastparser::FSHelperPtr pFS, const XShapeRef& rXShape, sal_Bool bFlipH, sal_Bool bFlipV, sal_Int32 nRotation ) +{ + ::com::sun::star::awt::Point aPos = rXShape->getPosition(); + ::com::sun::star::awt::Size aSize = rXShape->getSize(); + + pFS->startElementNS( XML_xdr, XML_xfrm, + XML_flipH, bFlipH ? "1" : NULL, + XML_flipV, bFlipV ? "1" : NULL, + XML_rot, nRotation ? I32S( nRotation ) : NULL, + FSEND ); + + pFS->singleElementNS( XML_a, XML_off, XML_x, IS( MM100toEMU( aPos.X ) ), XML_y, IS( MM100toEMU( aPos.Y ) ), FSEND ); + pFS->singleElementNS( XML_a, XML_ext, XML_cx, IS( MM100toEMU( aSize.Width ) ), XML_cy, IS( MM100toEMU( aSize.Height ) ), FSEND ); + + pFS->endElementNS( XML_xdr, XML_xfrm ); +} + // ============================================================================ XclExpNote::XclExpNote( const XclExpRoot& rRoot, const ScAddress& rScPos, diff --git a/sc/source/filter/inc/xcl97rec.hxx b/sc/source/filter/inc/xcl97rec.hxx index 2ec132d13bba..4ee1099961c2 100644 --- a/sc/source/filter/inc/xcl97rec.hxx +++ b/sc/source/filter/inc/xcl97rec.hxx @@ -254,6 +254,8 @@ public: virtual void Save( XclExpStream& rStrm ); virtual void SaveXml( XclExpXmlStream& rStrm ); + static void WriteFromTo( XclExpXmlStream& rStrm, const XclObjAny& rObj ); + static void WriteFromTo( XclExpXmlStream& rStrm, const com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& rShape, SCTAB nTab ); private: com::sun::star::uno::Reference< com::sun::star::drawing::XShape > diff --git a/sc/source/filter/inc/xeescher.hxx b/sc/source/filter/inc/xeescher.hxx index c2affff628a3..cc626926549c 100644 --- a/sc/source/filter/inc/xeescher.hxx +++ b/sc/source/filter/inc/xeescher.hxx @@ -32,6 +32,7 @@ #include <filter/msfilter/escherex.hxx> #include "xcl97rec.hxx" #include "xlescher.hxx" +#include <com/sun/star/chart/XChartDocument.hpp> #include "svx/sdtaitm.hxx" @@ -313,6 +314,8 @@ class XclExpChart; class XclExpChartObj : public XclObj, protected XclExpRoot { public: + typedef ::com::sun::star::uno::Reference< ::com::sun::star::chart::XChartDocument > XChartDocRef; + typedef ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > XShapeRef; explicit XclExpChartObj( XclExpObjectManager& rObjMgr, ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > xShape, @@ -321,10 +324,15 @@ public: /** Writes the OBJ record and the entire chart substream. */ virtual void Save( XclExpStream& rStrm ); + virtual void SaveXml( XclExpXmlStream& rStrm ); + virtual void WriteChartObj( sax_fastparser::FSHelperPtr pDrawing, XclExpXmlStream& rStrm ); + void WriteShapeTransformation( sax_fastparser::FSHelperPtr pFS, const XShapeRef& rXShape, sal_Bool bFlipH = false, sal_Bool bFlipV = false, sal_Int32 nRotation = 0 ); private: typedef ScfRef< XclExpChart > XclExpChartRef; XclExpChartRef mxChart; /// The chart itself (BOF/EOF substream data). + XShapeRef mxShape; + XChartDocRef mxChartDoc; }; // ============================================================================ diff --git a/sc/source/filter/xcl97/xcl97rec.cxx b/sc/source/filter/xcl97/xcl97rec.cxx index fe6bf5cf6bf3..e369d8948be7 100644 --- a/sc/source/filter/xcl97/xcl97rec.cxx +++ b/sc/source/filter/xcl97/xcl97rec.cxx @@ -933,19 +933,17 @@ ExcBof8_Base::ExcBof8_Base() nFileHistory = 0x00000000; nLowestBiffVer = 0x00000006; // Biff8 } - -static void -WriteFromTo( XclExpXmlStream& rStrm, const XclObjAny& rObj ) +void XclObjAny::WriteFromTo( XclExpXmlStream& rStrm, const Reference< XShape >& rShape, SCTAB nTab ) { sax_fastparser::FSHelperPtr pDrawing = rStrm.GetCurrentStream(); - awt::Point aTopLeft = rObj.GetShape()->getPosition(); - awt::Size aSize = rObj.GetShape()->getSize(); + awt::Point aTopLeft = rShape->getPosition(); + awt::Size aSize = rShape->getSize(); Rectangle aLocation( aTopLeft.X, aTopLeft.Y, aTopLeft.X + aSize.Width, aTopLeft.Y + aSize.Height ); - ScRange aRange = rStrm.GetRoot().GetDoc().GetRange( rObj.GetTab(), aLocation ); + ScRange aRange = rStrm.GetRoot().GetDoc().GetRange( nTab, aLocation ); Rectangle aRangeRect = rStrm.GetRoot().GetDoc().GetMMRect( aRange.aStart.Col(), aRange.aStart.Row(), aRange.aEnd.Col()-1, aRange.aEnd.Row()-1, - rObj.GetTab() ); + nTab ); pDrawing->startElement( FSNS( XML_xdr, XML_from ), @@ -969,6 +967,11 @@ WriteFromTo( XclExpXmlStream& rStrm, const XclObjAny& rObj ) pDrawing->endElement( FSNS( XML_xdr, XML_to ) ); } +void XclObjAny::WriteFromTo( XclExpXmlStream& rStrm, const XclObjAny& rObj ) +{ + WriteFromTo( rStrm, rObj.GetShape(), rObj.GetTab() ); +} + static void WritePicPr( sax_fastparser::FSHelperPtr pDrawing, sal_Int32 nId, Reference< XPropertySet > xPropSet ) { |