diff options
author | Kurt Nordback <kurt.nordback@protonmail.com> | 2023-12-01 11:18:31 -0700 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2024-02-19 01:29:36 +0100 |
commit | 1cda27cf69054b006aa1b16cab8f56339274588b (patch) | |
tree | 7e517f2396e969ac4201ed52cf9846ef28a1ddd4 /oox | |
parent | bbc9ac1f08a5ee4b9f65eaf10110df328d95de95 (diff) |
tdf#50934: OfPie inport from OOXML, plus initial work for export
Change-Id: Ie17b583af28d274b3e7817c646dd4f5873e03fef
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/160733
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'oox')
-rw-r--r-- | oox/inc/drawingml/chart/typegroupcontext.hxx | 14 | ||||
-rw-r--r-- | oox/inc/drawingml/chart/typegroupconverter.hxx | 3 | ||||
-rw-r--r-- | oox/source/drawingml/chart/plotareacontext.cxx | 3 | ||||
-rw-r--r-- | oox/source/drawingml/chart/typegroupcontext.cxx | 30 | ||||
-rw-r--r-- | oox/source/drawingml/chart/typegroupconverter.cxx | 28 | ||||
-rw-r--r-- | oox/source/export/chartexport.cxx | 66 | ||||
-rw-r--r-- | oox/source/token/properties.txt | 1 |
7 files changed, 131 insertions, 14 deletions
diff --git a/oox/inc/drawingml/chart/typegroupcontext.hxx b/oox/inc/drawingml/chart/typegroupcontext.hxx index 5d5306d31fe0..d3af8436d7ac 100644 --- a/oox/inc/drawingml/chart/typegroupcontext.hxx +++ b/oox/inc/drawingml/chart/typegroupcontext.hxx @@ -92,7 +92,7 @@ public: }; -/** Handler for pie type group contexts (c:doughnutChart, c:ofPieChart, +/** Handler for pie type group contexts (c:doughnutChart, c:pie3DChart, c:pieChart elements). */ class PieTypeGroupContext final : public TypeGroupContextBase @@ -105,6 +105,18 @@ public: }; +/** Handler for of-pie type group contexts (c:ofPieChart elements). + */ +class OfPieTypeGroupContext final : public TypeGroupContextBase +{ +public: + explicit OfPieTypeGroupContext( ::oox::core::ContextHandler2Helper& rParent, TypeGroupModel& rModel ); + virtual ~OfPieTypeGroupContext() override; + + virtual ::oox::core::ContextHandlerRef onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) override; +}; + + /** Handler for radar type group context (c:radarChart element). */ class RadarTypeGroupContext final : public TypeGroupContextBase diff --git a/oox/inc/drawingml/chart/typegroupconverter.hxx b/oox/inc/drawingml/chart/typegroupconverter.hxx index 6b780dd0ae15..e017f81e19c7 100644 --- a/oox/inc/drawingml/chart/typegroupconverter.hxx +++ b/oox/inc/drawingml/chart/typegroupconverter.hxx @@ -21,6 +21,7 @@ #define INCLUDED_OOX_DRAWINGML_CHART_TYPEGROUPCONVERTER_HXX #include <drawingml/chart/converterbase.hxx> +#include <com/sun/star/chart2/PieChartSubType.hpp> namespace com::sun::star { namespace chart2 { class XChartType; } @@ -160,6 +161,8 @@ public: void convertPieRotation( PropertySet& rPropSet, sal_Int32 nOoxAngle ) const; /** Sets the passed OOXML pie explosion at the passed property set. */ void convertPieExplosion( PropertySet& rPropSet, sal_Int32 nOoxExplosion ) const; + /** Converts of-pie types */ + css::chart2::PieChartSubType convertOfPieType(sal_Int32 nOoxOfPieType ) const; private: /** Inserts the passed series into the chart type. Adds additional properties to the series. */ diff --git a/oox/source/drawingml/chart/plotareacontext.cxx b/oox/source/drawingml/chart/plotareacontext.cxx index 4afddee4700c..1004cdafb045 100644 --- a/oox/source/drawingml/chart/plotareacontext.cxx +++ b/oox/source/drawingml/chart/plotareacontext.cxx @@ -136,8 +136,9 @@ ContextHandlerRef PlotAreaContext::onCreateContext( sal_Int32 nElement, const At case C_TOKEN( lineChart ): case C_TOKEN( stockChart ): return new LineTypeGroupContext( *this, mrModel.maTypeGroups.create( nElement, bMSO2007Doc ) ); - case C_TOKEN( doughnutChart ): case C_TOKEN( ofPieChart ): + return new OfPieTypeGroupContext( *this, mrModel.maTypeGroups.create( nElement, bMSO2007Doc ) ); + case C_TOKEN( doughnutChart ): case C_TOKEN( pie3DChart ): case C_TOKEN( pieChart ): return new PieTypeGroupContext( *this, mrModel.maTypeGroups.create( nElement, bMSO2007Doc ) ); diff --git a/oox/source/drawingml/chart/typegroupcontext.cxx b/oox/source/drawingml/chart/typegroupcontext.cxx index 96c4d6fc2bfc..9604e58a2507 100644 --- a/oox/source/drawingml/chart/typegroupcontext.cxx +++ b/oox/source/drawingml/chart/typegroupcontext.cxx @@ -255,6 +255,36 @@ ContextHandlerRef PieTypeGroupContext::onCreateContext( sal_Int32 nElement, cons case C_TOKEN( holeSize ): mrModel.mnHoleSize = rAttribs.getInteger( XML_val, 10 ); return nullptr; + case C_TOKEN( ser ): + return new PieSeriesContext( *this, mrModel.maSeries.create(bMSO2007Doc) ); + case C_TOKEN( serLines ): + return new ShapePrWrapperContext( *this, mrModel.mxSerLines.create() ); + case C_TOKEN( varyColors ): + mrModel.mbVaryColors = rAttribs.getBool( XML_val, !bMSO2007Doc ); + return nullptr; + } + return nullptr; +} + +OfPieTypeGroupContext::OfPieTypeGroupContext( ContextHandler2Helper& rParent, TypeGroupModel& rModel ) : + TypeGroupContextBase( rParent, rModel ) +{ +} + +OfPieTypeGroupContext::~OfPieTypeGroupContext() +{ +} + +ContextHandlerRef OfPieTypeGroupContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) +{ + bool bMSO2007Doc = getFilter().isMSO2007Document(); + if( isRootElement() ) switch( nElement ) + { + case C_TOKEN( dLbls ): + return new DataLabelsContext( *this, mrModel.mxLabels.create(bMSO2007Doc) ); + case C_TOKEN( gapWidth ): + mrModel.mnGapWidth = rAttribs.getInteger( XML_val, 150 ); + return nullptr; case C_TOKEN( ofPieType ): mrModel.mnOfPieType = rAttribs.getToken( XML_val, XML_pie ); return nullptr; diff --git a/oox/source/drawingml/chart/typegroupconverter.cxx b/oox/source/drawingml/chart/typegroupconverter.cxx index 327a855f708f..9e8691be5919 100644 --- a/oox/source/drawingml/chart/typegroupconverter.cxx +++ b/oox/source/drawingml/chart/typegroupconverter.cxx @@ -26,6 +26,7 @@ #include <com/sun/star/chart2/PolarCoordinateSystem3d.hpp> #include <com/sun/star/chart2/CurveStyle.hpp> #include <com/sun/star/chart2/DataPointGeometry3D.hpp> +#include <com/sun/star/chart2/PieChartSubType.hpp> #include <com/sun/star/chart2/StackingDirection.hpp> #include <com/sun/star/chart2/Symbol.hpp> #include <com/sun/star/chart2/XChartTypeContainer.hpp> @@ -350,6 +351,13 @@ void TypeGroupConverter::convertFromModel( const Reference< XDiagram >& rxDiagra not support pie rotation. */ if( !is3dChart() && (maTypeInfo.meTypeId != TYPEID_OFPIE) ) convertPieRotation( aDiaProp, mrModel.mnFirstAngle ); + + if (maTypeInfo.meTypeId == TYPEID_OFPIE) { + aDiaProp.setProperty(PROP_SubPieType, + convertOfPieType(mrModel.mnOfPieType)); + } else { + aDiaProp.setProperty(PROP_SubPieType, PieChartSubType_NONE); + } } break; default:; @@ -575,6 +583,26 @@ void TypeGroupConverter::convertPieExplosion( PropertySet& rPropSet, sal_Int32 n } } +PieChartSubType TypeGroupConverter::convertOfPieType(sal_Int32 nOoxOfPieType ) const +{ + if( maTypeInfo.meTypeCategory == TYPECATEGORY_PIE ) { + switch (nOoxOfPieType) { + case XML_pie: + return PieChartSubType_PIE; + break; + case XML_bar: + return PieChartSubType_BAR; + break; + default: + OSL_FAIL( "TypeGroupConverter::convertOfPieType - unknown of-pie type" ); + return PieChartSubType_NONE; + } + } else { + return PieChartSubType_NONE; + } +} + + // private -------------------------------------------------------------------- void TypeGroupConverter::insertDataSeries( const Reference< XChartType >& rxChartType, const Reference< XDataSeries >& rxSeries, sal_Int32 nAxesSetIdx ) diff --git a/oox/source/export/chartexport.cxx b/oox/source/export/chartexport.cxx index e980a4f18f35..58114eb2820e 100644 --- a/oox/source/export/chartexport.cxx +++ b/oox/source/export/chartexport.cxx @@ -65,6 +65,7 @@ #include <com/sun/star/chart2/DataPointLabel.hpp> #include <com/sun/star/chart2/XDataPointCustomLabelField.hpp> #include <com/sun/star/chart2/DataPointCustomLabelFieldType.hpp> +#include <com/sun/star/chart2/PieChartSubType.hpp> #include <com/sun/star/chart2/Symbol.hpp> #include <com/sun/star/chart2/data/XDataSource.hpp> #include <com/sun/star/chart2/data/XDataProvider.hpp> @@ -1691,14 +1692,44 @@ void ChartExport::exportPlotArea(const Reference< css::chart::XChartDocument >& exportBubbleChart( xChartType ); break; } - case chart::TYPEID_OFPIE: - { - break; - } - case chart::TYPEID_DOUGHNUT: + case chart::TYPEID_DOUGHNUT: // doesn't currently happen + case chart::TYPEID_OFPIE: // doesn't currently happen case chart::TYPEID_PIE: { - exportPieChart( xChartType ); + sal_Int32 eCT = getChartType( ); + if(eCT == chart::TYPEID_DOUGHNUT) + { + exportDoughnutChart( xChartType ); + } + else + { + + PropertySet xChartTypeProp(rCT); + chart2::PieChartSubType subtype(chart2::PieChartSubType_NONE); + if (!xChartTypeProp.getProperty(subtype, PROP_SubPieType)) + { + subtype = chart2::PieChartSubType_NONE; + } + if (subtype != chart2::PieChartSubType_NONE) + { + const char* sSubType = "pie"; // default + switch (subtype) { + case chart2::PieChartSubType_PIE: + sSubType = "pie"; + break; + case chart2::PieChartSubType_BAR: + sSubType = "bar"; + break; + case chart2::PieChartSubType_NONE: + default: + assert(false); + } + + exportOfPieChart(xChartType, sSubType); + } else { + exportPieChart( xChartType ); + } + } break; } case chart::TYPEID_RADARLINE: @@ -2250,6 +2281,23 @@ void ChartExport::exportDoughnutChart( const Reference< chart2::XChartType >& xC pFS->endElement( FSNS( XML_c, XML_doughnutChart ) ); } +void ChartExport::exportOfPieChart( + const Reference< chart2::XChartType >& xChartType, + const char* sSubType ) +{ + FSHelperPtr pFS = GetFS(); + pFS->startElement(FSNS(XML_c, XML_ofPieChart)); + + pFS->singleElement(FSNS(XML_c, XML_ofPieType), XML_val, sSubType); + + exportVaryColors(xChartType); + + bool bPrimaryAxes = true; + exportAllSeries(xChartType, bPrimaryAxes); + + pFS->endElement( FSNS( XML_c, XML_ofPieChart ) ); +} + namespace { void writeDataLabelsRange(const FSHelperPtr& pFS, const XmlFilterBase* pFB, DataLabelsRange& rDLblsRange) @@ -2330,12 +2378,6 @@ void ChartExport::exportLineChart( const Reference< chart2::XChartType >& xChart void ChartExport::exportPieChart( const Reference< chart2::XChartType >& xChartType ) { - sal_Int32 eChartType = getChartType( ); - if(eChartType == chart::TYPEID_DOUGHNUT) - { - exportDoughnutChart( xChartType ); - return; - } FSHelperPtr pFS = GetFS(); sal_Int32 nTypeId = XML_pieChart; if( mbIs3DChart ) diff --git a/oox/source/token/properties.txt b/oox/source/token/properties.txt index a8764a432b5d..339e648b5f5b 100644 --- a/oox/source/token/properties.txt +++ b/oox/source/token/properties.txt @@ -535,6 +535,7 @@ StartWith StartingAngle State StringItemList +SubPieType SubViewSize Subtotals Suffix |