diff options
Diffstat (limited to '')
27 files changed, 7956 insertions, 0 deletions
diff --git a/oox/source/drawingml/chart/axiscontext.cxx b/oox/source/drawingml/chart/axiscontext.cxx new file mode 100644 index 000000000..b90857785 --- /dev/null +++ b/oox/source/drawingml/chart/axiscontext.cxx @@ -0,0 +1,298 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <drawingml/chart/axiscontext.hxx> + +#include <drawingml/shapepropertiescontext.hxx> +#include <drawingml/textbodycontext.hxx> +#include <drawingml/chart/axismodel.hxx> +#include <drawingml/chart/titlecontext.hxx> +#include <oox/core/xmlfilterbase.hxx> +#include <oox/helper/attributelist.hxx> +#include <oox/token/namespaces.hxx> +#include <oox/token/tokens.hxx> + +namespace oox::drawingml::chart { + +using ::oox::core::ContextHandlerRef; +using ::oox::core::ContextHandler2Helper; + +AxisDispUnitsContext::AxisDispUnitsContext( ContextHandler2Helper& rParent, AxisDispUnitsModel& rModel ) : + ContextBase< AxisDispUnitsModel >( rParent, rModel ) +{ +} + +AxisDispUnitsContext::~AxisDispUnitsContext() +{ +} + +ContextHandlerRef AxisDispUnitsContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) +{ + switch( getCurrentElement() ) + { + case C_TOKEN( dispUnits ): + switch( nElement ) + { + case C_TOKEN( builtInUnit ): + mrModel.mnBuiltInUnit = rAttribs.getString( XML_val, "thousands" ); + return nullptr; + case C_TOKEN( custUnit ): + mrModel.mfCustomUnit = rAttribs.getDouble( XML_val, 0.0 ); + return nullptr; + case C_TOKEN( dispUnitsLbl ): + return this; + } + break; + + case C_TOKEN( dispUnitsLbl ): + switch( nElement ) + { + case C_TOKEN( layout ): + return new LayoutContext( *this, mrModel.mxLayout.create() ); + case C_TOKEN( spPr ): + return new ShapePropertiesContext( *this, mrModel.mxShapeProp.create() ); + case C_TOKEN( tx ): + return new TextContext( *this, mrModel.mxText.create() ); + case C_TOKEN( txPr ): + return new TextBodyContext( *this, mrModel.mxTextProp.create() ); + } + break; + } + return nullptr; +} + +AxisContextBase::AxisContextBase( ContextHandler2Helper& rParent, AxisModel& rModel ) : + ContextBase< AxisModel >( rParent, rModel ) +{ +} + +AxisContextBase::~AxisContextBase() +{ +} + +ContextHandlerRef AxisContextBase::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) +{ + bool bMSO2007Doc = getFilter().isMSO2007Document(); + switch( getCurrentElement() ) + { + case C_TOKEN( catAx ): + case C_TOKEN( dateAx ): + case C_TOKEN( serAx ): + case C_TOKEN( valAx ): + switch( nElement ) + { + case C_TOKEN( axId ): + mrModel.mnAxisId = rAttribs.getInteger( XML_val, -1 ); + return nullptr; + case C_TOKEN( crossAx ): + mrModel.mnCrossAxisId = rAttribs.getInteger( XML_val, -1 ); + return nullptr; + case C_TOKEN( crosses ): + mrModel.mnCrossMode = rAttribs.getToken( XML_val, XML_autoZero ); + return nullptr; + case C_TOKEN( crossesAt ): + mrModel.mofCrossesAt = rAttribs.getDouble( XML_val, 0.0 ); + return nullptr; + case C_TOKEN( delete ): + mrModel.mbDeleted = rAttribs.getBool( XML_val, !bMSO2007Doc ); + return nullptr; + case C_TOKEN( majorGridlines ): + return new ShapePrWrapperContext( *this, mrModel.mxMajorGridLines.create() ); + case C_TOKEN( majorTickMark ): + mrModel.mnMajorTickMark = rAttribs.getToken( XML_val, bMSO2007Doc ? XML_out : XML_cross ); + return nullptr; + case C_TOKEN(axPos): + mrModel.mnAxisPos = rAttribs.getToken( XML_val, XML_TOKEN_INVALID ); + return nullptr; + case C_TOKEN( minorGridlines ): + return new ShapePrWrapperContext( *this, mrModel.mxMinorGridLines.create() ); + case C_TOKEN( minorTickMark ): + mrModel.mnMinorTickMark = rAttribs.getToken( XML_val, bMSO2007Doc ? XML_none : XML_cross ); + return nullptr; + case C_TOKEN( numFmt ): + mrModel.maNumberFormat.setAttributes( rAttribs ); + return nullptr; + case C_TOKEN( scaling ): + return this; + case C_TOKEN( spPr ): + return new ShapePropertiesContext( *this, mrModel.mxShapeProp.create() ); + case C_TOKEN( tickLblPos ): + mrModel.mnTickLabelPos = rAttribs.getToken( XML_val, XML_nextTo ); + return nullptr; + case C_TOKEN( title ): + { + bool bVerticalDefault = mrModel.mnAxisPos == XML_l || mrModel.mnAxisPos == XML_r; + sal_Int32 nDefaultRotation = bVerticalDefault ? -5400000 : 0; + return new TitleContext( *this, mrModel.mxTitle.create(nDefaultRotation) ); + } + case C_TOKEN( txPr ): + return new TextBodyContext( *this, mrModel.mxTextProp.create() ); + } + break; + + case C_TOKEN( scaling ): + switch( nElement ) + { + case C_TOKEN( logBase ): + mrModel.mofLogBase = rAttribs.getDouble( XML_val, 0.0 ); + return nullptr; + case C_TOKEN( max ): + mrModel.mofMax = rAttribs.getDouble( XML_val, 0.0 ); + return nullptr; + case C_TOKEN( min ): + mrModel.mofMin = rAttribs.getDouble( XML_val, 0.0 ); + return nullptr; + case C_TOKEN( orientation ): + mrModel.mnOrientation = rAttribs.getToken( XML_val, XML_minMax ); + return nullptr; + } + break; + } + return nullptr; +} + +CatAxisContext::CatAxisContext( ContextHandler2Helper& rParent, AxisModel& rModel ) : + AxisContextBase( rParent, rModel ) +{ +} + +CatAxisContext::~CatAxisContext() +{ +} + +ContextHandlerRef CatAxisContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) +{ + bool bMSO2007Doc = getFilter().isMSO2007Document(); + if( isRootElement() ) switch( nElement ) + { + case C_TOKEN( auto ): + mrModel.mbAuto = rAttribs.getBool( XML_val, !bMSO2007Doc ); + return nullptr; + case C_TOKEN( lblAlgn ): + mrModel.mnLabelAlign = rAttribs.getToken( XML_val, XML_ctr ); + return nullptr; + case C_TOKEN( lblOffset ): + mrModel.mnLabelOffset = rAttribs.getInteger( XML_val, 100 ); + return nullptr; + case C_TOKEN( noMultiLvlLbl ): + mrModel.mbNoMultiLevel = rAttribs.getBool( XML_val, !bMSO2007Doc ); + return nullptr; + case C_TOKEN( tickLblSkip ): + mrModel.mnTickLabelSkip = rAttribs.getInteger( XML_val, 0 ); + return nullptr; + case C_TOKEN( tickMarkSkip ): + mrModel.mnTickMarkSkip = rAttribs.getInteger( XML_val, 0 ); + return nullptr; + } + return AxisContextBase::onCreateContext( nElement, rAttribs ); +} + +DateAxisContext::DateAxisContext( ContextHandler2Helper& rParent, AxisModel& rModel ) : + AxisContextBase( rParent, rModel ) +{ +} + +DateAxisContext::~DateAxisContext() +{ +} + +ContextHandlerRef DateAxisContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) +{ + bool bMSO2007Doc = getFilter().isMSO2007Document(); + if( isRootElement() ) switch( nElement ) + { + case C_TOKEN( auto ): + mrModel.mbAuto = rAttribs.getBool( XML_val, !bMSO2007Doc ); + return nullptr; + case C_TOKEN( baseTimeUnit ): + mrModel.monBaseTimeUnit = rAttribs.getToken( XML_val, XML_days ); + return nullptr; + case C_TOKEN( lblOffset ): + mrModel.mnLabelOffset = rAttribs.getInteger( XML_val, 100 ); + return nullptr; + case C_TOKEN( majorTimeUnit ): + mrModel.mnMajorTimeUnit = rAttribs.getToken( XML_val, XML_days ); + return nullptr; + case C_TOKEN( majorUnit ): + mrModel.mofMajorUnit = rAttribs.getDouble( XML_val, 0.0 ); + return nullptr; + case C_TOKEN( minorTimeUnit ): + mrModel.mnMinorTimeUnit = rAttribs.getToken( XML_val, XML_days ); + return nullptr; + case C_TOKEN( minorUnit ): + mrModel.mofMinorUnit = rAttribs.getDouble( XML_val, 0.0 ); + return nullptr; + } + return AxisContextBase::onCreateContext( nElement, rAttribs ); +} + +SerAxisContext::SerAxisContext( ContextHandler2Helper& rParent, AxisModel& rModel ) : + AxisContextBase( rParent, rModel ) +{ +} + +SerAxisContext::~SerAxisContext() +{ +} + +ContextHandlerRef SerAxisContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) +{ + if( isRootElement() ) switch( nElement ) + { + case C_TOKEN( tickLblSkip ): + mrModel.mnTickLabelSkip = rAttribs.getInteger( XML_val, 0 ); + return nullptr; + case C_TOKEN( tickMarkSkip ): + mrModel.mnTickMarkSkip = rAttribs.getInteger( XML_val, 0 ); + return nullptr; + } + return AxisContextBase::onCreateContext( nElement, rAttribs ); +} + +ValAxisContext::ValAxisContext( ContextHandler2Helper& rParent, AxisModel& rModel ) : + AxisContextBase( rParent, rModel ) +{ +} + +ValAxisContext::~ValAxisContext() +{ +} + +ContextHandlerRef ValAxisContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) +{ + if( isRootElement() ) switch( nElement ) + { + case C_TOKEN( crossBetween ): + mrModel.mnCrossBetween = rAttribs.getToken( XML_val, -1 ); + return nullptr; + case C_TOKEN( dispUnits ): + return new AxisDispUnitsContext( *this, mrModel.mxDispUnits.create() ); + case C_TOKEN( majorUnit ): + mrModel.mofMajorUnit = rAttribs.getDouble( XML_val, 0.0 ); + return nullptr; + case C_TOKEN( minorUnit ): + mrModel.mofMinorUnit = rAttribs.getDouble( XML_val, 0.0 ); + return nullptr; + } + return AxisContextBase::onCreateContext( nElement, rAttribs ); +} + +} // namespace oox::drawingml::chart + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/oox/source/drawingml/chart/axisconverter.cxx b/oox/source/drawingml/chart/axisconverter.cxx new file mode 100644 index 000000000..8599c68e6 --- /dev/null +++ b/oox/source/drawingml/chart/axisconverter.cxx @@ -0,0 +1,418 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <drawingml/chart/axisconverter.hxx> +#include <ooxresid.hxx> +#include <strings.hrc> + +#include <com/sun/star/chart/ChartAxisArrangeOrderType.hpp> +#include <com/sun/star/chart/ChartAxisLabelPosition.hpp> +#include <com/sun/star/chart/ChartAxisMarkPosition.hpp> +#include <com/sun/star/chart/ChartAxisPosition.hpp> +#include <com/sun/star/chart/TimeInterval.hpp> +#include <com/sun/star/chart/TimeUnit.hpp> +#include <com/sun/star/chart2/AxisType.hpp> +#include <com/sun/star/chart2/TickmarkStyle.hpp> +#include <com/sun/star/chart2/LinearScaling.hpp> +#include <com/sun/star/chart2/LogarithmicScaling.hpp> +#include <com/sun/star/chart2/XAxis.hpp> +#include <com/sun/star/chart2/XCoordinateSystem.hpp> +#include <com/sun/star/chart2/XTitled.hpp> +#include <drawingml/chart/axismodel.hxx> +#include <drawingml/chart/titleconverter.hxx> +#include <drawingml/chart/typegroupconverter.hxx> +#include <drawingml/lineproperties.hxx> +#include <oox/token/namespaces.hxx> +#include <oox/token/properties.hxx> +#include <oox/token/tokens.hxx> +#include <comphelper/processfactory.hxx> +#include <osl/diagnose.h> + +namespace oox::drawingml::chart { + +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::chart2; +using namespace ::com::sun::star::uno; + +namespace { + +void lclSetValueOrClearAny( Any& orAny, const OptValue< double >& rofValue ) +{ + if( rofValue.has() ) orAny <<= rofValue.get(); else orAny.clear(); +} + +bool lclIsLogarithmicScale( const AxisModel& rAxisModel ) +{ + return rAxisModel.mofLogBase.has() && (2.0 <= rAxisModel.mofLogBase.get()) && (rAxisModel.mofLogBase.get() <= 1000.0); +} + +sal_Int32 lclGetApiTimeUnit( sal_Int32 nTimeUnit ) +{ + using namespace ::com::sun::star::chart; + switch( nTimeUnit ) + { + case XML_days: return TimeUnit::DAY; + case XML_months: return TimeUnit::MONTH; + case XML_years: return TimeUnit::YEAR; + default: OSL_ENSURE( false, "lclGetApiTimeUnit - unexpected time unit" ); + } + return TimeUnit::DAY; +} + +void lclConvertTimeInterval( Any& orInterval, const OptValue< double >& rofUnit, sal_Int32 nTimeUnit ) +{ + if( rofUnit.has() && (1.0 <= rofUnit.get()) && (rofUnit.get() <= SAL_MAX_INT32) ) + orInterval <<= css::chart::TimeInterval( static_cast< sal_Int32 >( rofUnit.get() ), lclGetApiTimeUnit( nTimeUnit ) ); + else + orInterval.clear(); +} + +css::chart::ChartAxisLabelPosition lclGetLabelPosition( sal_Int32 nToken ) +{ + using namespace ::com::sun::star::chart; + switch( nToken ) + { + case XML_high: return ChartAxisLabelPosition_OUTSIDE_END; + case XML_low: return ChartAxisLabelPosition_OUTSIDE_START; + case XML_nextTo: return ChartAxisLabelPosition_NEAR_AXIS; + } + return ChartAxisLabelPosition_NEAR_AXIS; +} + +sal_Int32 lclGetTickMark( sal_Int32 nToken ) +{ + using namespace ::com::sun::star::chart2::TickmarkStyle; + switch( nToken ) + { + case XML_in: return INNER; + case XML_out: return OUTER; + case XML_cross: return INNER | OUTER; + } + return css::chart2::TickmarkStyle::NONE; +} + +/** + * The groups is of percent type only when all of its members are of percent + * type. + */ +bool isPercent( const RefVector<TypeGroupConverter>& rTypeGroups ) +{ + if (rTypeGroups.empty()) + return false; + + for (auto const& typeGroup : rTypeGroups) + { + TypeGroupConverter& rConv = *typeGroup; + if (!rConv.isPercent()) + return false; + } + + return true; +} + +} // namespace + +AxisConverter::AxisConverter( const ConverterRoot& rParent, AxisModel& rModel ) : + ConverterBase< AxisModel >( rParent, rModel ) +{ +} + +AxisConverter::~AxisConverter() +{ +} + +void AxisConverter::convertFromModel( + const Reference< XCoordinateSystem >& rxCoordSystem, + RefVector<TypeGroupConverter>& rTypeGroups, const AxisModel* pCrossingAxis, sal_Int32 nAxesSetIdx, sal_Int32 nAxisIdx ) +{ + if (rTypeGroups.empty()) + return; + + Reference< XAxis > xAxis; + try + { + namespace cssc = ::com::sun::star::chart; + namespace cssc2 = ::com::sun::star::chart2; + + const TypeGroupInfo& rTypeInfo = rTypeGroups.front()->getTypeInfo(); + ObjectFormatter& rFormatter = getFormatter(); + + // create the axis object (always) + xAxis.set( createInstance( "com.sun.star.chart2.Axis" ), UNO_QUERY_THROW ); + PropertySet aAxisProp( xAxis ); + // #i58688# axis enabled + aAxisProp.setProperty( PROP_Show, !mrModel.mbDeleted ); + + // axis line, tick, and gridline properties --------------------------- + + // show axis labels + aAxisProp.setProperty( PROP_DisplayLabels, mrModel.mnTickLabelPos != XML_none ); + aAxisProp.setProperty( PROP_LabelPosition, lclGetLabelPosition( mrModel.mnTickLabelPos ) ); + // no X axis line in radar charts + if( (nAxisIdx == API_X_AXIS) && (rTypeInfo.meTypeCategory == TYPECATEGORY_RADAR) ) + mrModel.mxShapeProp.getOrCreate().getLineProperties().maLineFill.moFillType = XML_noFill; + // axis line and tick label formatting + rFormatter.convertFormatting( aAxisProp, mrModel.mxShapeProp, mrModel.mxTextProp, OBJECTTYPE_AXIS ); + // tick label rotation + ObjectFormatter::convertTextRotation( aAxisProp, mrModel.mxTextProp, true ); + + // tick mark style + aAxisProp.setProperty( PROP_MajorTickmarks, lclGetTickMark( mrModel.mnMajorTickMark ) ); + aAxisProp.setProperty( PROP_MinorTickmarks, lclGetTickMark( mrModel.mnMinorTickMark ) ); + aAxisProp.setProperty( PROP_MarkPosition, cssc::ChartAxisMarkPosition_AT_AXIS ); + + // main grid + PropertySet aGridProp( xAxis->getGridProperties() ); + aGridProp.setProperty( PROP_Show, mrModel.mxMajorGridLines.is() ); + if( mrModel.mxMajorGridLines.is() ) + rFormatter.convertFrameFormatting( aGridProp, mrModel.mxMajorGridLines, OBJECTTYPE_MAJORGRIDLINE ); + + // sub grid + Sequence< Reference< XPropertySet > > aSubGridPropSeq = xAxis->getSubGridProperties(); + if( aSubGridPropSeq.hasElements() ) + { + PropertySet aSubGridProp( aSubGridPropSeq[ 0 ] ); + aSubGridProp.setProperty( PROP_Show, mrModel.mxMinorGridLines.is() ); + if( mrModel.mxMinorGridLines.is() ) + rFormatter.convertFrameFormatting( aSubGridProp, mrModel.mxMinorGridLines, OBJECTTYPE_MINORGRIDLINE ); + } + + // axis type and X axis categories ------------------------------------ + + ScaleData aScaleData = xAxis->getScaleData(); + // set axis type + switch( nAxisIdx ) + { + case API_X_AXIS: + if( rTypeInfo.mbCategoryAxis ) + { + OSL_ENSURE( (mrModel.mnTypeId == C_TOKEN( catAx )) || (mrModel.mnTypeId == C_TOKEN( dateAx )), + "AxisConverter::convertFromModel - unexpected axis model type (must: c:catAx or c:dateAx)" ); + bool bDateAxis = mrModel.mnTypeId == C_TOKEN( dateAx ); + // tdf#132076: set axis type to date, if it is a date axis! + aScaleData.AxisType = bDateAxis ? cssc2::AxisType::DATE : cssc2::AxisType::CATEGORY; + aScaleData.AutoDateAxis = mrModel.mbAuto; + /* TODO: create main category axis labels once, while InternalDataProvider + can not handle different category names on the primary and secondary category axis. */ + if( nAxesSetIdx == 0 ) + aScaleData.Categories = rTypeGroups.front()->createCategorySequence(); + /* set default ShiftedCategoryPosition values for some charttype, + because the XML can contain wrong CrossBetween value, if came from MSO */ + if( rTypeGroups.front()->is3dChart() && (rTypeInfo.meTypeId == TYPEID_BAR || rTypeInfo.meTypeId == TYPEID_HORBAR || rTypeInfo.meTypeId == TYPEID_STOCK) ) + aScaleData.ShiftedCategoryPosition = true; + else if( rTypeInfo.meTypeId == TYPEID_RADARLINE || rTypeInfo.meTypeId == TYPEID_RADARAREA ) + aScaleData.ShiftedCategoryPosition = false; + else if( pCrossingAxis->mnCrossBetween != -1 ) /*because of backwards compatibility*/ + aScaleData.ShiftedCategoryPosition = pCrossingAxis->mnCrossBetween == XML_between; + else if( rTypeInfo.meTypeCategory == TYPECATEGORY_BAR || rTypeInfo.meTypeId == TYPEID_LINE || rTypeInfo.meTypeId == TYPEID_STOCK ) + aScaleData.ShiftedCategoryPosition = true; + } + else + { + OSL_ENSURE( mrModel.mnTypeId == C_TOKEN( valAx ), "AxisConverter::convertFromModel - unexpected axis model type (must: c:valAx)" ); + aScaleData.AxisType = cssc2::AxisType::REALNUMBER; + } + break; + case API_Y_AXIS: + OSL_ENSURE( mrModel.mnTypeId == C_TOKEN( valAx ), "AxisConverter::convertFromModel - unexpected axis model type (must: c:valAx)" ); + aScaleData.AxisType = isPercent(rTypeGroups) ? cssc2::AxisType::PERCENT : cssc2::AxisType::REALNUMBER; + break; + case API_Z_AXIS: + OSL_ENSURE( mrModel.mnTypeId == C_TOKEN( serAx ), "AxisConverter::convertFromModel - unexpected axis model type (must: c:serAx)" ); + OSL_ENSURE( rTypeGroups.front()->isDeep3dChart(), "AxisConverter::convertFromModel - series axis not supported by this chart type" ); + aScaleData.AxisType = cssc2::AxisType::SERIES; + break; + } + + // axis scaling and increment ----------------------------------------- + + switch( aScaleData.AxisType ) + { + case cssc2::AxisType::CATEGORY: + case cssc2::AxisType::SERIES: + case cssc2::AxisType::DATE: + { + /* Determine date axis type from XML type identifier, and not + via aScaleData.AxisType, as this value sticks to CATEGORY + for automatic category/date axes). */ + if( mrModel.mnTypeId == C_TOKEN( dateAx ) ) + { + // scaling algorithm + aScaleData.Scaling = LinearScaling::create( comphelper::getProcessComponentContext() ); + // min/max + lclSetValueOrClearAny( aScaleData.Minimum, mrModel.mofMin ); + lclSetValueOrClearAny( aScaleData.Maximum, mrModel.mofMax ); + // major/minor increment + lclConvertTimeInterval( aScaleData.TimeIncrement.MajorTimeInterval, mrModel.mofMajorUnit, mrModel.mnMajorTimeUnit ); + lclConvertTimeInterval( aScaleData.TimeIncrement.MinorTimeInterval, mrModel.mofMinorUnit, mrModel.mnMinorTimeUnit ); + // base time unit + if( mrModel.monBaseTimeUnit.has() ) + aScaleData.TimeIncrement.TimeResolution <<= lclGetApiTimeUnit( mrModel.monBaseTimeUnit.get() ); + else + aScaleData.TimeIncrement.TimeResolution.clear(); + } + else + { + // do not overlap text unless all labels are visible + aAxisProp.setProperty( PROP_TextOverlap, mrModel.mnTickLabelSkip == 1 ); + // do not break text into several lines unless the rotation is 0 degree + aAxisProp.setProperty( PROP_TextBreak, ObjectFormatter::getTextRotation( mrModel.mxTextProp ) ); + // do not stagger labels in two lines + aAxisProp.setProperty( PROP_ArrangeOrder, cssc::ChartAxisArrangeOrderType_SIDE_BY_SIDE ); + //! TODO #i58731# show n-th category + } + } + break; + case cssc2::AxisType::REALNUMBER: + case cssc2::AxisType::PERCENT: + { + // scaling algorithm + const bool bLogScale = lclIsLogarithmicScale( mrModel ); + if( bLogScale ) + aScaleData.Scaling = LogarithmicScaling::create( comphelper::getProcessComponentContext() ); + else + aScaleData.Scaling = LinearScaling::create( comphelper::getProcessComponentContext() ); + // min/max + lclSetValueOrClearAny( aScaleData.Minimum, mrModel.mofMin ); + lclSetValueOrClearAny( aScaleData.Maximum, mrModel.mofMax ); + // major increment + IncrementData& rIncrementData = aScaleData.IncrementData; + if( mrModel.mofMajorUnit.has() && aScaleData.Scaling.is() ) + rIncrementData.Distance <<= aScaleData.Scaling->doScaling( mrModel.mofMajorUnit.get() ); + else + lclSetValueOrClearAny( rIncrementData.Distance, mrModel.mofMajorUnit ); + // minor increment + Sequence< SubIncrement >& rSubIncrementSeq = rIncrementData.SubIncrements; + rSubIncrementSeq.realloc( 1 ); + Any& rIntervalCount = rSubIncrementSeq[ 0 ].IntervalCount; + rIntervalCount.clear(); + if( bLogScale ) + { + if( mrModel.mofMinorUnit.has() ) + rIntervalCount <<= sal_Int32( 9 ); + } + else if( mrModel.mofMajorUnit.has() && mrModel.mofMinorUnit.has() && (0.0 < mrModel.mofMinorUnit.get()) && (mrModel.mofMinorUnit.get() <= mrModel.mofMajorUnit.get()) ) + { + double fCount = mrModel.mofMajorUnit.get() / mrModel.mofMinorUnit.get() + 0.5; + if( (1.0 <= fCount) && (fCount < 1001.0) ) + rIntervalCount <<= static_cast< sal_Int32 >( fCount ); + } + else if( !mrModel.mofMinorUnit.has() ) + { + // tdf#114168 If minor unit is not set then set interval to 5, as MS Excel do. + rIntervalCount <<= static_cast< sal_Int32 >( 5 ); + } + } + break; + default: + OSL_FAIL( "AxisConverter::convertFromModel - unknown axis type" ); + } + + /* Do not set a value to the Origin member anymore (already done via + new axis properties 'CrossoverPosition' and 'CrossoverValue'). */ + aScaleData.Origin.clear(); + + // axis orientation --------------------------------------------------- + + // #i85167# pie/donut charts need opposite direction at Y axis + // #i87747# radar charts need opposite direction at X axis + bool bMirrorDirection = + ((nAxisIdx == API_Y_AXIS) && (rTypeInfo.meTypeCategory == TYPECATEGORY_PIE)) || + ((nAxisIdx == API_X_AXIS) && (rTypeInfo.meTypeCategory == TYPECATEGORY_RADAR)); + bool bReverse = (mrModel.mnOrientation == XML_maxMin) != bMirrorDirection; + aScaleData.Orientation = bReverse ? cssc2::AxisOrientation_REVERSE : cssc2::AxisOrientation_MATHEMATICAL; + + // write back scaling data + xAxis->setScaleData( aScaleData ); + + // number format ------------------------------------------------------ + if( !mrModel.mbDeleted && aScaleData.AxisType != cssc2::AxisType::SERIES ) + { + getFormatter().convertNumberFormat(aAxisProp, mrModel.maNumberFormat, true); + } + + // position of crossing axis ------------------------------------------ + + bool bManualCrossing = mrModel.mofCrossesAt.has(); + cssc::ChartAxisPosition eAxisPos = cssc::ChartAxisPosition_VALUE; + if( !bManualCrossing ) switch( mrModel.mnCrossMode ) + { + case XML_min: eAxisPos = cssc::ChartAxisPosition_START; break; + case XML_max: eAxisPos = cssc::ChartAxisPosition_END; break; + case XML_autoZero: eAxisPos = cssc::ChartAxisPosition_ZERO; break; + } + if( !mrModel.mbAuto ) + aAxisProp.setProperty( PROP_CrossoverPosition, eAxisPos ); + + // calculate automatic origin depending on scaling mode of crossing axis + bool bCrossingLogScale = pCrossingAxis && lclIsLogarithmicScale( *pCrossingAxis ); + double fCrossingPos = bManualCrossing ? mrModel.mofCrossesAt.get() : (bCrossingLogScale ? 1.0 : 0.0); + aAxisProp.setProperty( PROP_CrossoverValue, fCrossingPos ); + + // axis title --------------------------------------------------------- + + // in radar charts, title objects may exist, but are not shown + if( mrModel.mxTitle.is() && (rTypeGroups.front()->getTypeInfo().meTypeCategory != TYPECATEGORY_RADAR) ) + { + Reference< XTitled > xTitled( xAxis, UNO_QUERY_THROW ); + TitleConverter aTitleConv( *this, *mrModel.mxTitle ); + aTitleConv.convertFromModel( xTitled, OoxResId(STR_DIAGRAM_AXISTITLE), OBJECTTYPE_AXISTITLE, nAxesSetIdx, nAxisIdx ); + } + + // axis data unit label ----------------------------------------------- + AxisDispUnitsConverter axisDispUnitsConverter (*this, mrModel.mxDispUnits.getOrCreate()); + axisDispUnitsConverter.convertFromModel(xAxis); + } + catch( Exception& ) + { + } + + if( xAxis.is() && rxCoordSystem.is() ) try + { + // insert axis into coordinate system + rxCoordSystem->setAxisByDimension( nAxisIdx, xAxis, nAxesSetIdx ); + } + catch( Exception& ) + { + OSL_FAIL( "AxisConverter::convertFromModel - cannot insert axis into coordinate system" ); + } +} + +AxisDispUnitsConverter::AxisDispUnitsConverter( const ConverterRoot& rParent, AxisDispUnitsModel& rModel ) : + ConverterBase< AxisDispUnitsModel >( rParent, rModel ) +{ +} + +AxisDispUnitsConverter::~AxisDispUnitsConverter() +{ +} + +void AxisDispUnitsConverter::convertFromModel( const Reference< XAxis >& rxAxis ) +{ + PropertySet aPropSet( rxAxis ); + if (!mrModel.mnBuiltInUnit.isEmpty() ) + { + aPropSet.setProperty(PROP_DisplayUnits, true); + aPropSet.setProperty( PROP_BuiltInUnit, mrModel.mnBuiltInUnit ); + } +} + +} // namespace oox::drawingml::chart + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/oox/source/drawingml/chart/axismodel.cxx b/oox/source/drawingml/chart/axismodel.cxx new file mode 100644 index 000000000..d84c707eb --- /dev/null +++ b/oox/source/drawingml/chart/axismodel.cxx @@ -0,0 +1,63 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <drawingml/chart/axismodel.hxx> +#include <oox/token/tokens.hxx> + +namespace oox::drawingml::chart { + +AxisDispUnitsModel::AxisDispUnitsModel() : + mfCustomUnit( 0.0 ) +{ +} + +AxisDispUnitsModel::~AxisDispUnitsModel() +{ +} + +AxisModel::AxisModel( sal_Int32 nTypeId, bool bMSO2007Doc ) : + mnAxisId( -1 ), + mnAxisPos( XML_TOKEN_INVALID ), + mnCrossAxisId( -1 ), + mnCrossBetween( -1 ), + mnCrossMode( XML_autoZero ), + mnLabelAlign( XML_ctr ), + mnLabelOffset( 100 ), + mnMajorTickMark( bMSO2007Doc ? XML_out : XML_cross ), + mnMajorTimeUnit( XML_days ), + mnMinorTickMark( bMSO2007Doc ? XML_none : XML_cross ), + mnMinorTimeUnit( XML_days ), + mnOrientation( XML_minMax ), + mnTickLabelPos( XML_nextTo ), + mnTickLabelSkip( 0 ), + mnTickMarkSkip( 0 ), + mnTypeId( nTypeId ), + mbAuto( false ), + mbDeleted( !bMSO2007Doc ), + mbNoMultiLevel( false ) +{ +} + +AxisModel::~AxisModel() +{ +} + +} // namespace oox::drawingml::chart + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/oox/source/drawingml/chart/chartcontextbase.cxx b/oox/source/drawingml/chart/chartcontextbase.cxx new file mode 100644 index 000000000..5423c52b3 --- /dev/null +++ b/oox/source/drawingml/chart/chartcontextbase.cxx @@ -0,0 +1,107 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <drawingml/chart/chartcontextbase.hxx> + +#include <oox/drawingml/chart/modelbase.hxx> +#include <oox/helper/attributelist.hxx> +#include <oox/token/namespaces.hxx> +#include <oox/token/tokens.hxx> +#include <drawingml/shapepropertiescontext.hxx> + +namespace oox::drawingml::chart { + +using ::oox::core::ContextHandler2Helper; +using ::oox::core::ContextHandlerRef; + +ShapePrWrapperContext::ShapePrWrapperContext( ContextHandler2Helper& rParent, Shape& rModel ) : + ContextBase< Shape >( rParent, rModel ) +{ +} + +ShapePrWrapperContext::~ShapePrWrapperContext() +{ +} + +ContextHandlerRef ShapePrWrapperContext::onCreateContext( sal_Int32 nElement, const AttributeList& ) +{ + return (isRootElement() && (nElement == C_TOKEN( spPr ))) ? new ShapePropertiesContext( *this, mrModel ) : nullptr; +} + +LayoutContext::LayoutContext( ContextHandler2Helper& rParent, LayoutModel& rModel ) : + ContextBase< LayoutModel >( rParent, rModel ) +{ +} + +LayoutContext::~LayoutContext() +{ +} + +ContextHandlerRef LayoutContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) +{ + switch( getCurrentElement() ) + { + case C_TOKEN( layout ): + switch( nElement ) + { + case C_TOKEN( manualLayout ): + mrModel.mbAutoLayout = false; + return this; + } + break; + + case C_TOKEN( manualLayout ): + switch( nElement ) + { + case C_TOKEN( x ): + mrModel.mfX = rAttribs.getDouble( XML_val, 0.0 ); + return nullptr; + case C_TOKEN( y ): + mrModel.mfY = rAttribs.getDouble( XML_val, 0.0 ); + return nullptr; + case C_TOKEN( w ): + mrModel.mfW = rAttribs.getDouble( XML_val, 0.0 ); + return nullptr; + case C_TOKEN( h ): + mrModel.mfH = rAttribs.getDouble( XML_val, 0.0 ); + return nullptr; + case C_TOKEN( xMode ): + mrModel.mnXMode = rAttribs.getToken( XML_val, XML_factor ); + return nullptr; + case C_TOKEN( yMode ): + mrModel.mnYMode = rAttribs.getToken( XML_val, XML_factor ); + return nullptr; + case C_TOKEN( wMode ): + mrModel.mnWMode = rAttribs.getToken( XML_val, XML_factor ); + return nullptr; + case C_TOKEN( hMode ): + mrModel.mnHMode = rAttribs.getToken( XML_val, XML_factor ); + return nullptr; + case C_TOKEN( layoutTarget ): + mrModel.mnTarget = rAttribs.getToken( XML_val, XML_outer ); + return nullptr; + } + break; + } + return nullptr; +} + +} // namespace oox::drawingml::chart + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/oox/source/drawingml/chart/chartconverter.cxx b/oox/source/drawingml/chart/chartconverter.cxx new file mode 100644 index 000000000..e75b1c09c --- /dev/null +++ b/oox/source/drawingml/chart/chartconverter.cxx @@ -0,0 +1,157 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <oox/drawingml/chart/chartconverter.hxx> + +#include <com/sun/star/chart2/XChartDocument.hpp> +#include <com/sun/star/chart2/data/XDataReceiver.hpp> +#include <com/sun/star/util/XNumberFormatsSupplier.hpp> +#include <drawingml/chart/chartspaceconverter.hxx> +#include <drawingml/chart/chartspacemodel.hxx> +#include <oox/helper/containerhelper.hxx> +#include <oox/core/xmlfilterbase.hxx> +#include <osl/diagnose.h> + +using ::oox::drawingml::chart::DataSequenceModel; +using ::com::sun::star::uno::Any; +namespace oox::drawingml::chart { + +using namespace ::com::sun::star; +using namespace ::com::sun::star::chart2; +using namespace ::com::sun::star::chart2::data; +using namespace ::com::sun::star::drawing; +using namespace ::com::sun::star::uno; + +using ::oox::core::XmlFilterBase; + +static const sal_Unicode API_TOKEN_ARRAY_OPEN = '{'; +static const sal_Unicode API_TOKEN_ARRAY_CLOSE = '}'; +static const sal_Unicode API_TOKEN_ARRAY_COLSEP = ';'; + +// Code similar to oox/source/xls/formulabase.cxx +static OUString lclGenerateApiString( const OUString& rString ) +{ + OUString aRetString = rString; + sal_Int32 nQuotePos = aRetString.getLength(); + while( (nQuotePos = aRetString.lastIndexOf( '"', nQuotePos )) >= 0 ) + aRetString = aRetString.replaceAt( nQuotePos, 1, "\"\"" ); + return "\"" + aRetString + "\""; +} + +static OUString lclGenerateApiArray(const std::vector<Any>& rRow, sal_Int32 nStart, sal_Int32 nCount) +{ + OSL_ENSURE( !rRow.empty(), "ChartConverter::lclGenerateApiArray - missing matrix values" ); + OUStringBuffer aBuffer; + aBuffer.append( API_TOKEN_ARRAY_OPEN ); + for (auto aBeg = rRow.begin() + nStart, aIt = aBeg, aEnd = aBeg + nCount; aIt != aEnd; ++aIt) + { + double fValue = 0.0; + OUString aString; + if( aIt != aBeg ) + aBuffer.append( API_TOKEN_ARRAY_COLSEP ); + if( *aIt >>= fValue ) + aBuffer.append( fValue ); + else if( *aIt >>= aString ) + aBuffer.append( lclGenerateApiString( aString ) ); + else + aBuffer.append( "\"\"" ); + } + aBuffer.append( API_TOKEN_ARRAY_CLOSE ); + return aBuffer.makeStringAndClear(); +} + +ChartConverter::ChartConverter() +{ +} + +ChartConverter::~ChartConverter() +{ +} + +void ChartConverter::convertFromModel( XmlFilterBase& rFilter, + ChartSpaceModel& rChartModel, const Reference< XChartDocument >& rxChartDoc, + const Reference< XShapes >& rxExternalPage, const awt::Point& rChartPos, const awt::Size& rChartSize ) +{ + OSL_ENSURE( rxChartDoc.is(), "ChartConverter::convertFromModel - missing chart document" ); + if( rxChartDoc.is() ) + { + Reference< data::XDataReceiver > xDataReceiver( rxChartDoc, uno::UNO_QUERY_THROW ); + Reference< util::XNumberFormatsSupplier > xNumberFormatsSupplier( rFilter.getModel(), uno::UNO_QUERY ); + if (xNumberFormatsSupplier.is()) + xDataReceiver->attachNumberFormatsSupplier( xNumberFormatsSupplier ); + + ConverterRoot aConvBase( rFilter, *this, rChartModel, rxChartDoc, rChartSize ); + ChartSpaceConverter aSpaceConv( aConvBase, rChartModel ); + aSpaceConv.convertFromModel( rxExternalPage, rChartPos ); + } +} + +void ChartConverter::createDataProvider( const Reference< XChartDocument >& rxChartDoc ) +{ + try + { + if( !rxChartDoc->hasInternalDataProvider() ) + rxChartDoc->createInternalDataProvider( false ); + } + catch( Exception& ) + { + } +} + +Reference< XDataSequence > ChartConverter::createDataSequence( + const Reference< XDataProvider >& rxDataProvider, const DataSequenceModel& rDataSeq, + const OUString& rRole ) +{ + Reference< XDataSequence > xDataSeq; + if( rxDataProvider.is() ) + { + OUString aRangeRep; + if( !rDataSeq.maData.empty() || (rRole == "values-y" && rDataSeq.mnPointCount > 0) ) try + { + // create a single-row array from constant source data + // (multiple levels in the case of complex categories) + std::vector<Any> aRow(rDataSeq.mnLevelCount * rDataSeq.mnPointCount); + for (auto const& elem : rDataSeq.maData) + aRow.at(elem.first) = elem.second; + + for (sal_Int32 i = rDataSeq.mnLevelCount-1; i >= 0; i--) + { + aRangeRep = lclGenerateApiArray( aRow, i * rDataSeq.mnPointCount, rDataSeq.mnPointCount); + + if (!aRangeRep.isEmpty()) + { + // create or add a new level to the data sequence + xDataSeq = rxDataProvider->createDataSequenceByValueArray(rRole, aRangeRep); + if (i == 0) + return xDataSeq; + } + } + } + catch( Exception& ) + { + OSL_FAIL( "ChartConverter::createDataSequence - cannot create data sequence" ); + } + } + + return nullptr; +} + +} // namespace oox::drawingml::chart + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/oox/source/drawingml/chart/chartdrawingfragment.cxx b/oox/source/drawingml/chart/chartdrawingfragment.cxx new file mode 100644 index 000000000..85eeb2986 --- /dev/null +++ b/oox/source/drawingml/chart/chartdrawingfragment.cxx @@ -0,0 +1,233 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <drawingml/chart/chartdrawingfragment.hxx> + +#include <osl/diagnose.h> + +#include <basegfx/matrix/b2dhommatrix.hxx> +#include <com/sun/star/awt/Rectangle.hpp> +#include <oox/core/xmlfilterbase.hxx> +#include <oox/drawingml/connectorshapecontext.hxx> +#include <oox/drawingml/graphicshapecontext.hxx> +#include <oox/drawingml/shapecontext.hxx> +#include <oox/drawingml/shapegroupcontext.hxx> +#include <oox/helper/attributelist.hxx> +#include <oox/token/namespaces.hxx> +#include <oox/token/tokens.hxx> + +namespace oox::drawingml::chart { + +using namespace ::com::sun::star; +using namespace ::com::sun::star::drawing; +using namespace ::com::sun::star::uno; +using namespace ::oox::core; + +ShapeAnchor::ShapeAnchor( bool bRelSize ) : + mbRelSize( bRelSize ) +{ +} + +void ShapeAnchor::importExt( const AttributeList& rAttribs ) +{ + OSL_ENSURE( !mbRelSize, "ShapeAnchor::importExt - unexpected 'cdr:ext' element" ); + maSize.Width = rAttribs.getHyper( XML_cx, 0 ); + maSize.Height = rAttribs.getHyper( XML_cy, 0 ); +} + +void ShapeAnchor::setPos( sal_Int32 nElement, sal_Int32 nParentContext, const OUString& rValue ) +{ + AnchorPosModel* pAnchorPos = nullptr; + switch( nParentContext ) + { + case CDR_TOKEN( from ): + pAnchorPos = &maFrom; + break; + case CDR_TOKEN( to ): + OSL_ENSURE( mbRelSize, "ShapeAnchor::setPos - unexpected 'cdr:to' element" ); + pAnchorPos = &maTo; + break; + default: + OSL_FAIL( "ShapeAnchor::setPos - unexpected parent element" ); + } + if( pAnchorPos ) switch( nElement ) + { + case CDR_TOKEN( x ): pAnchorPos->mfX = rValue.toDouble(); break; + case CDR_TOKEN( y ): pAnchorPos->mfY = rValue.toDouble(); break; + default: OSL_FAIL( "ShapeAnchor::setPos - unexpected element" ); + } +} + +EmuRectangle ShapeAnchor::calcAnchorRectEmu( const EmuRectangle& rChartRect ) const +{ + EmuRectangle aAnchorRect( -1, -1, -1, -1 ); + + OSL_ENSURE( maFrom.isValid(), "ShapeAnchor::calcAnchorRectEmu - invalid from position" ); + OSL_ENSURE( mbRelSize ? maTo.isValid() : maSize.isValid(), "ShapeAnchor::calcAnchorRectEmu - invalid to/size" ); + if( maFrom.isValid() && (mbRelSize ? maTo.isValid() : maSize.isValid()) ) + { + // calculate shape position + aAnchorRect.X = static_cast< sal_Int64 >( maFrom.mfX * rChartRect.Width + 0.5 ); + aAnchorRect.Y = static_cast< sal_Int64 >( maFrom.mfY * rChartRect.Height + 0.5 ); + + // calculate shape size + if( mbRelSize ) + { + aAnchorRect.Width = static_cast< sal_Int64 >( maTo.mfX * rChartRect.Width + 0.5 ) - aAnchorRect.X; + if( aAnchorRect.Width < 0 ) + { + aAnchorRect.X += aAnchorRect.Width; + aAnchorRect.Width *= -1; + } + aAnchorRect.Height = static_cast< sal_Int64 >( maTo.mfY * rChartRect.Height + 0.5 ) - aAnchorRect.Y; + if( aAnchorRect.Height < 0 ) + { + aAnchorRect.Y += aAnchorRect.Height; + aAnchorRect.Height *= -1; + } + } + else + { + aAnchorRect.setSize( maSize ); + } + } + + return aAnchorRect; +} + +ChartDrawingFragment::ChartDrawingFragment( XmlFilterBase& rFilter, + const OUString& rFragmentPath, const Reference< XShapes >& rxDrawPage, + const awt::Size& rChartSize, const awt::Point& rShapesOffset, bool bOleSupport ) : + FragmentHandler2( rFilter, rFragmentPath ), + mxDrawPage( rxDrawPage ), + mbOleSupport( bOleSupport ) +{ + maChartRectEmu.X = convertHmmToEmu( rShapesOffset.X ); + maChartRectEmu.Y = convertHmmToEmu( rShapesOffset.Y ); + maChartRectEmu.Width = convertHmmToEmu( rChartSize.Width ); + maChartRectEmu.Height = convertHmmToEmu( rChartSize.Height ); +} + +ChartDrawingFragment::~ChartDrawingFragment() +{ +} + +ContextHandlerRef ChartDrawingFragment::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) +{ + switch( getCurrentElement() ) + { + case XML_ROOT_CONTEXT: + if( nElement == C_TOKEN( userShapes ) ) return this; + break; + + case C_TOKEN( userShapes ): + switch( nElement ) + { + case CDR_TOKEN( absSizeAnchor ): + mxAnchor = std::make_shared<ShapeAnchor>( false ); + return this; + case CDR_TOKEN( relSizeAnchor ): + mxAnchor = std::make_shared<ShapeAnchor>( true ); + return this; + } + break; + + case CDR_TOKEN( absSizeAnchor ): + case CDR_TOKEN( relSizeAnchor ): + switch( nElement ) + { + case CDR_TOKEN( sp ): + mxShape = std::make_shared<Shape>( "com.sun.star.drawing.CustomShape" ); + return new ShapeContext( *this, ShapePtr(), mxShape ); + case CDR_TOKEN( cxnSp ): + mxShape = std::make_shared<Shape>( "com.sun.star.drawing.ConnectorShape" ); + return new ConnectorShapeContext( *this, ShapePtr(), mxShape ); + case CDR_TOKEN( pic ): + mxShape = std::make_shared<Shape>( "com.sun.star.drawing.GraphicObjectShape" ); + return new GraphicShapeContext( *this, ShapePtr(), mxShape ); + case CDR_TOKEN( graphicFrame ): + if( !mbOleSupport ) + return nullptr; + mxShape = std::make_shared<Shape>( "com.sun.star.drawing.GraphicObjectShape" ); + return new GraphicalObjectFrameContext( *this, ShapePtr(), mxShape, true ); + case CDR_TOKEN( grpSp ): + mxShape = std::make_shared<Shape>( "com.sun.star.drawing.GroupShape" ); + return new ShapeGroupContext( *this, ShapePtr(), mxShape ); + + case CDR_TOKEN( from ): + case CDR_TOKEN( to ): + return this; + + case CDR_TOKEN( ext ): + if( mxAnchor ) mxAnchor->importExt( rAttribs ); + return nullptr; + } + break; + + case CDR_TOKEN( from ): + case CDR_TOKEN( to ): + switch( nElement ) + { + case CDR_TOKEN( x ): + case CDR_TOKEN( y ): + return this; // collect value in onEndElement() + } + break; + } + return nullptr; +} + +void ChartDrawingFragment::onCharacters( const OUString& rChars ) +{ + if( isCurrentElement( CDR_TOKEN( x ), CDR_TOKEN( y ) ) && mxAnchor ) + mxAnchor->setPos( getCurrentElement(), getParentElement(), rChars ); +} + +void ChartDrawingFragment::onEndElement() +{ + if( !isCurrentElement( CDR_TOKEN( absSizeAnchor ), CDR_TOKEN( relSizeAnchor ) ) ) + return; + + if( mxDrawPage.is() && mxShape && mxAnchor ) + { + EmuRectangle aShapeRectEmu = mxAnchor->calcAnchorRectEmu( maChartRectEmu ); + if( (aShapeRectEmu.X >= 0) && (aShapeRectEmu.Y >= 0) && (aShapeRectEmu.Width >= 0) && (aShapeRectEmu.Height >= 0) ) + { + // TODO: DrawingML implementation expects 32-bit coordinates for EMU rectangles (change that to EmuRectangle) + awt::Rectangle aShapeRectEmu32( + getLimitedValue< sal_Int32, sal_Int64 >( aShapeRectEmu.X, 0, SAL_MAX_INT32 ), + getLimitedValue< sal_Int32, sal_Int64 >( aShapeRectEmu.Y, 0, SAL_MAX_INT32 ), + getLimitedValue< sal_Int32, sal_Int64 >( aShapeRectEmu.Width, 0, SAL_MAX_INT32 ), + getLimitedValue< sal_Int32, sal_Int64 >( aShapeRectEmu.Height, 0, SAL_MAX_INT32 ) ); + + // Set the position and size before calling addShape(). + mxShape->setPosition(awt::Point(aShapeRectEmu32.X, aShapeRectEmu32.Y)); + mxShape->setSize(awt::Size(aShapeRectEmu32.Width, aShapeRectEmu32.Height)); + + basegfx::B2DHomMatrix aMatrix; + mxShape->addShape( getFilter(), getFilter().getCurrentTheme(), mxDrawPage, aMatrix, mxShape->getFillProperties() ); + } + } + mxShape.reset(); + mxAnchor.reset(); +} + +} // namespace oox::drawingml::chart + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/oox/source/drawingml/chart/chartspaceconverter.cxx b/oox/source/drawingml/chart/chartspaceconverter.cxx new file mode 100644 index 000000000..342b6190a --- /dev/null +++ b/oox/source/drawingml/chart/chartspaceconverter.cxx @@ -0,0 +1,295 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <drawingml/chart/chartspaceconverter.hxx> + +#include <com/sun/star/chart/MissingValueTreatment.hpp> +#include <com/sun/star/chart/XChartDocument.hpp> +#include <com/sun/star/chart2/XChartDocument.hpp> +#include <com/sun/star/chart2/XChartType.hpp> +#include <com/sun/star/chart2/XChartTypeContainer.hpp> +#include <com/sun/star/chart2/XCoordinateSystemContainer.hpp> +#include <com/sun/star/chart2/XDataSeriesContainer.hpp> +#include <com/sun/star/chart2/XTitled.hpp> +#include <com/sun/star/drawing/XDrawPageSupplier.hpp> +#include <oox/core/xmlfilterbase.hxx> +#include <oox/drawingml/chart/chartconverter.hxx> +#include <oox/token/properties.hxx> +#include <oox/token/tokens.hxx> +#include <drawingml/chart/chartdrawingfragment.hxx> +#include <drawingml/chart/chartspacemodel.hxx> +#include <drawingml/chart/plotareaconverter.hxx> +#include <drawingml/chart/titleconverter.hxx> +#include <ooxresid.hxx> +#include <strings.hrc> + +using namespace ::com::sun::star; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::Exception; +using ::com::sun::star::uno::UNO_QUERY; +using ::com::sun::star::uno::UNO_QUERY_THROW; +using ::com::sun::star::uno::makeAny; +using ::com::sun::star::drawing::XDrawPageSupplier; +using ::com::sun::star::drawing::XShapes; +using ::com::sun::star::chart2::XDiagram; +using ::com::sun::star::chart2::XTitled; + +namespace oox::drawingml::chart { + +using namespace ::com::sun::star::awt; +using namespace ::com::sun::star::chart2; +using namespace ::com::sun::star::chart2::data; +using namespace ::com::sun::star::drawing; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::util; + +ChartSpaceConverter::ChartSpaceConverter( const ConverterRoot& rParent, ChartSpaceModel& rModel ) : + ConverterBase< ChartSpaceModel >( rParent, rModel ) +{ +} + +ChartSpaceConverter::~ChartSpaceConverter() +{ +} + +// Formulas with no numeric values and strings are zeroes in OOXML line charts also in the mode DispBlanksAs=gap, +// unlike in OpenDocument LEAVE_GAP mode. As a workaround, we will use the OpenDocument mode USE_ZERO, if the OOXML +// line chart has got formulas with no numeric values and strings, but it doesn't have empty cells, showing the +// same chart as in MSO. (Empty cells need gaps, so in that case, we cannot use this workaround). +static bool lcl_useWorkaroundForNoGapInOOXML( Reference< chart2::XChartDocument > const & xChartDoc) +{ + Reference <chart2::XDiagram > xDiagram = xChartDoc->getFirstDiagram(); + if ( !xDiagram.is() ) + return false; + + Reference< chart2::XCoordinateSystemContainer > xCooSysContainer( xDiagram, UNO_QUERY_THROW ); + + Sequence< Reference< chart2::XCoordinateSystem > > xCooSysSequence( xCooSysContainer->getCoordinateSystems()); + if ( !xCooSysSequence.hasElements() ) + return false; + + Reference< chart2::XChartTypeContainer > xChartTypeContainer( xCooSysSequence[0], UNO_QUERY_THROW ); + + Sequence< Reference< chart2::XChartType > > xChartTypeSequence( xChartTypeContainer->getChartTypes() ); + if ( !xChartTypeSequence.hasElements() ) + return false; + + const Reference<chart2::XChartType>& xCT = xChartTypeSequence[0]; + + if ( xCT->getChartType() != "com.sun.star.chart2.LineChartType" ) + return false; + + Reference<chart2::XDataSeriesContainer> xDSCont(xCT, uno::UNO_QUERY); + + if (!xDSCont.is()) + return false; + + const Sequence<uno::Reference<chart2::XDataSeries> > aDataSeriesSeq = xDSCont->getDataSeries(); + + bool bHasNoGapBlankValue = false; + bool bHasEmptyCell = false; + + for (const auto& rDataSeries : aDataSeriesSeq) + { + uno::Reference<chart2::data::XDataSource> xDSrc(rDataSeries, uno::UNO_QUERY); + if (!xDSrc.is()) + return false; + + const uno::Sequence<Reference<chart2::data::XLabeledDataSequence> > aDataSeqs = xDSrc->getDataSequences(); + for (const auto& rDataSeq : aDataSeqs) + { + Reference<chart2::data::XDataSequence> xValues = rDataSeq->getValues(); + if(!xValues.is()) + return false; + Reference<beans::XPropertySet> xPropSet(xValues, uno::UNO_QUERY); + if (!xPropSet.is()) + continue; + + OUString aRoleName; + xPropSet->getPropertyValue("Role") >>= aRoleName; + if (aRoleName == "values-y") + { + const uno::Sequence<uno::Any> aData = xValues->getData(); + for (const auto& rVal : aData) + { + double fVal; + OUString sStr; + if (rVal >>= fVal) + continue; + else if (rVal >>= sStr) + bHasNoGapBlankValue = true; + else + bHasEmptyCell = true; + } + } + } + } + + return bHasNoGapBlankValue && !bHasEmptyCell; +} + +void ChartSpaceConverter::convertFromModel( const Reference< XShapes >& rxExternalPage, const awt::Point& rChartPos ) +{ + /* create data provider (virtual function in the ChartConverter class, + derived converters may create an external data provider) */ + getChartConverter().createDataProvider( getChartDocument() ); + + // formatting of the chart background. The default fill style varies with applications. + PropertySet aBackPropSet( getChartDocument()->getPageBackground() ); + getFormatter().convertFrameFormatting( aBackPropSet, mrModel.mxShapeProp, OBJECTTYPE_CHARTSPACE ); + + bool bMSO2007Doc = getFilter().isMSO2007Document(); + // convert plot area (container of all chart type groups) + PlotAreaConverter aPlotAreaConv( *this, mrModel.mxPlotArea.getOrCreate() ); + aPlotAreaConv.convertFromModel( mrModel.mxView3D.getOrCreate(bMSO2007Doc) ); + + // plot area converter has created the diagram object + Reference< XDiagram > xDiagram = getChartDocument()->getFirstDiagram(); + + // convert wall and floor formatting in 3D charts + if( xDiagram.is() && aPlotAreaConv.isWall3dChart() ) + { + WallFloorConverter aFloorConv( *this, mrModel.mxFloor.getOrCreate() ); + aFloorConv.convertFromModel( xDiagram, OBJECTTYPE_FLOOR ); + + WallFloorConverter aWallConv( *this, mrModel.mxBackWall.getOrCreate() ); + aWallConv.convertFromModel( xDiagram, OBJECTTYPE_WALL ); + } + + // chart title + /* tdf#119138 autoTitleDeleted might be omitted by generators other than Excel + while providing custom title. mbAutoTitleDel is set only based on the attribute value + and the default also varies on whether MSO 2007 or newer is the generator, see tdf#78080 */ + if( !mrModel.mbAutoTitleDel || mrModel.mxTitle.is() ) try + { + /* If the title model is missing, but the chart shows exactly one + series, the series title is shown as chart title. */ + OUString aAutoTitle = aPlotAreaConv.getAutomaticTitle(); + if( mrModel.mxTitle.is() || !aAutoTitle.isEmpty() ) + { + if( aAutoTitle.isEmpty() ) + aAutoTitle = OoxResId(STR_DIAGRAM_TITLE); + Reference< XTitled > xTitled( getChartDocument(), UNO_QUERY_THROW ); + TitleConverter aTitleConv( *this, mrModel.mxTitle.getOrCreate() ); + aTitleConv.convertFromModel( xTitled, aAutoTitle, OBJECTTYPE_CHARTTITLE ); + } + } + catch( Exception& ) + { + } + + // legend + if( xDiagram.is() && mrModel.mxLegend.is() ) + { + LegendConverter aLegendConv( *this, *mrModel.mxLegend ); + aLegendConv.convertFromModel( xDiagram ); + } + + // treatment of missing values + if( xDiagram.is() ) + { + using namespace ::com::sun::star::chart::MissingValueTreatment; + sal_Int32 nMissingValues = LEAVE_GAP; + switch( mrModel.mnDispBlanksAs ) + { + case XML_gap: nMissingValues = LEAVE_GAP; break; + case XML_zero: nMissingValues = USE_ZERO; break; + case XML_span: nMissingValues = CONTINUE; break; + } + + // use a workaround, if it's possible for the difference of OOXML and OpenDocument + if ( nMissingValues == LEAVE_GAP && lcl_useWorkaroundForNoGapInOOXML(getChartDocument()) ) + nMissingValues = USE_ZERO; + + PropertySet aDiaProp( xDiagram ); + aDiaProp.setProperty( PROP_MissingValueTreatment, nMissingValues ); + } + + /* Following all conversions needing the old Chart1 API that involves full + initialization of the chart view. */ + namespace cssc = ::com::sun::star::chart; + Reference< cssc::XChartDocument > xChart1Doc( getChartDocument(), UNO_QUERY ); + if( xChart1Doc.is() ) + { + /* Set the IncludeHiddenCells property via the old API as only this + ensures that the data provider and all created sequences get this + flag correctly. */ + PropertySet aDiaProp( xChart1Doc->getDiagram() ); + aDiaProp.setProperty( PROP_IncludeHiddenCells, !mrModel.mbPlotVisOnly ); + + // plot area position and size + aPlotAreaConv.convertPositionFromModel(); + + // positions of main title and all axis titles + convertTitlePositions(); + } + + // embedded drawing shapes + if( !mrModel.maDrawingPath.isEmpty() ) try + { + /* Get the internal draw page of the chart document, if no external + drawing page has been passed. */ + Reference< XShapes > xShapes; + awt::Point aShapesOffset( 0, 0 ); + if( rxExternalPage.is() ) + { + xShapes = rxExternalPage; + // offset for embedded shapes to move them inside the chart area + aShapesOffset = rChartPos; + } + else + { + Reference< XDrawPageSupplier > xDrawPageSupp( getChartDocument(), UNO_QUERY_THROW ); + xShapes.set( xDrawPageSupp->getDrawPage(), UNO_QUERY_THROW ); + } + + /* If an external drawing page is passed, all embedded shapes will be + inserted there (used e.g. with 'chart sheets' in spreadsheet + documents). In this case, all types of shapes including OLE objects + are supported. If the shapes are inserted into the internal chart + drawing page instead, it is not possible to embed OLE objects. */ + bool bOleSupport = rxExternalPage.is(); + + // now, xShapes is not null anymore + getFilter().importFragment( new ChartDrawingFragment( + getFilter(), mrModel.maDrawingPath, xShapes, getChartSize(), aShapesOffset, bOleSupport ) ); + } + catch( Exception& ) + { + } + + // pivot chart + if ( mrModel.mbPivotChart ) + { + PropertySet aProps( getChartDocument() ); + aProps.setProperty( PROP_DisableDataTableDialog , true ); + aProps.setProperty( PROP_DisableComplexChartTypes , true ); + } + + if(!mrModel.maSheetPath.isEmpty() ) + { + Reference< css::chart::XChartDocument > xChartDoc( getChartDocument(), UNO_QUERY ); + PropertySet aProps( xChartDoc->getDiagram() ); + aProps.setProperty( PROP_ExternalData , uno::makeAny(mrModel.maSheetPath) ); + } +} + +} // namespace oox::drawingml::chart + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/oox/source/drawingml/chart/chartspacefragment.cxx b/oox/source/drawingml/chart/chartspacefragment.cxx new file mode 100644 index 000000000..aa045d4a5 --- /dev/null +++ b/oox/source/drawingml/chart/chartspacefragment.cxx @@ -0,0 +1,124 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <drawingml/chart/chartspacefragment.hxx> + +#include <drawingml/shapepropertiescontext.hxx> +#include <drawingml/textbodycontext.hxx> +#include <drawingml/chart/chartspacemodel.hxx> +#include <drawingml/chart/plotareacontext.hxx> +#include <drawingml/chart/titlecontext.hxx> +#include <oox/core/xmlfilterbase.hxx> +#include <oox/helper/attributelist.hxx> +#include <oox/token/namespaces.hxx> + +namespace oox::drawingml::chart { + +using namespace ::oox::core; + +ChartSpaceFragment::ChartSpaceFragment( XmlFilterBase& rFilter, const OUString& rFragmentPath, ChartSpaceModel& rModel ) : + FragmentBase< ChartSpaceModel >( rFilter, rFragmentPath, rModel ) +{ +} + +ChartSpaceFragment::~ChartSpaceFragment() +{ +} + +ContextHandlerRef ChartSpaceFragment::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) +{ + bool bMSO2007Document = getFilter().isMSO2007Document(); + switch( getCurrentElement() ) + { + case XML_ROOT_CONTEXT: + switch( nElement ) + { + case C_TOKEN( chartSpace ): + return this; + } + break; + + case C_TOKEN( chartSpace ): + switch( nElement ) + { + case C_TOKEN( chart ): + return this; + case C_TOKEN( spPr ): + return new ShapePropertiesContext( *this, mrModel.mxShapeProp.create() ); + case C_TOKEN( style ): + mrModel.mnStyle = rAttribs.getInteger( XML_val, 2 ); + return nullptr; + case C_TOKEN( txPr ): + return new TextBodyContext( *this, mrModel.mxTextProp.create() ); + case C_TOKEN( userShapes ): + mrModel.maDrawingPath = getFragmentPathFromRelId( rAttribs.getString( R_TOKEN( id ), OUString() ) ); + return nullptr; + case C_TOKEN( pivotSource ): + mrModel.mbPivotChart = true; + return nullptr; + case C_TOKEN (externalData): + mrModel.maSheetPath = getFragmentPathFromRelId(rAttribs.getString(R_TOKEN(id),OUString())); + return nullptr; + } + break; + + case C_TOKEN( chart ): + switch( nElement ) + { + case C_TOKEN( autoTitleDeleted ): + { + + mrModel.mbAutoTitleDel = rAttribs.getBool( XML_val, !bMSO2007Document ); + return nullptr; + } + case C_TOKEN( backWall ): + return new WallFloorContext( *this, mrModel.mxBackWall.create() ); + case C_TOKEN( dispBlanksAs ): + { + // default value is XML_gap for MSO 2007 and XML_zero in OOXML + mrModel.mnDispBlanksAs = rAttribs.getToken( XML_val, bMSO2007Document ? XML_gap : XML_zero ); + return nullptr; + } + case C_TOKEN( floor ): + return new WallFloorContext( *this, mrModel.mxFloor.create() ); + case C_TOKEN( legend ): + return new LegendContext( *this, mrModel.mxLegend.create() ); + case C_TOKEN( plotArea ): + return new PlotAreaContext( *this, mrModel.mxPlotArea.create() ); + case C_TOKEN( plotVisOnly ): + mrModel.mbPlotVisOnly = rAttribs.getBool( XML_val, !bMSO2007Document ); + return nullptr; + case C_TOKEN( showDLblsOverMax ): + mrModel.mbShowLabelsOverMax = rAttribs.getBool( XML_val, !bMSO2007Document ); + return nullptr; + case C_TOKEN( sideWall ): + return new WallFloorContext( *this, mrModel.mxSideWall.create() ); + case C_TOKEN( title ): + return new TitleContext( *this, mrModel.mxTitle.create() ); + case C_TOKEN( view3D ): + return new View3DContext( *this, mrModel.mxView3D.create(bMSO2007Document) ); + } + break; + } + return nullptr; +} + +} // namespace oox::drawingml::chart + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/oox/source/drawingml/chart/chartspacemodel.cxx b/oox/source/drawingml/chart/chartspacemodel.cxx new file mode 100644 index 000000000..3aa7366ff --- /dev/null +++ b/oox/source/drawingml/chart/chartspacemodel.cxx @@ -0,0 +1,41 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <drawingml/chart/chartspacemodel.hxx> +#include <oox/token/tokens.hxx> + +namespace oox::drawingml::chart { + +ChartSpaceModel::ChartSpaceModel(bool bMSO2007Doc) : + mnDispBlanksAs( bMSO2007Doc ? XML_gap : XML_zero ), // difference between OOXML spec and MSO 2007 + mnStyle( 2 ), + mbAutoTitleDel( !bMSO2007Doc ), // difference between OOXML spec and MSO 2007 + mbPlotVisOnly( !bMSO2007Doc ), + mbShowLabelsOverMax( !bMSO2007Doc ), + mbPivotChart( false ) +{ +} + +ChartSpaceModel::~ChartSpaceModel() +{ +} + +} // namespace oox::drawingml::chart + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/oox/source/drawingml/chart/converterbase.cxx b/oox/source/drawingml/chart/converterbase.cxx new file mode 100644 index 000000000..d8f7b5649 --- /dev/null +++ b/oox/source/drawingml/chart/converterbase.cxx @@ -0,0 +1,439 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <drawingml/chart/converterbase.hxx> + +#include <com/sun/star/chart/XAxisXSupplier.hpp> +#include <com/sun/star/chart/XAxisYSupplier.hpp> +#include <com/sun/star/chart/XAxisZSupplier.hpp> +#include <com/sun/star/chart/XChartDocument.hpp> +#include <com/sun/star/chart/XSecondAxisTitleSupplier.hpp> +#include <com/sun/star/chart2/XChartDocument.hpp> +#include <com/sun/star/chart2/RelativePosition.hpp> +#include <com/sun/star/chart2/RelativeSize.hpp> +#include <com/sun/star/chart2/XTitle.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <osl/diagnose.h> +#include <basegfx/numeric/ftools.hxx> +#include <oox/core/xmlfilterbase.hxx> +#include <oox/token/properties.hxx> +#include <oox/token/tokens.hxx> + + +namespace oox::drawingml::chart { + +namespace cssc = ::com::sun::star::chart; + +using namespace ::com::sun::star; +using namespace ::com::sun::star::chart2; +using namespace ::com::sun::star::drawing; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::uno; + +using ::oox::core::XmlFilterBase; + +namespace { + +struct TitleKey : public ::std::pair< ObjectType, ::std::pair< sal_Int32, sal_Int32 > > +{ + explicit TitleKey( ObjectType eObjType, sal_Int32 nMainIdx = -1, sal_Int32 nSubIdx = -1 ) + { first = eObjType; second.first = nMainIdx; second.second = nSubIdx; } +}; + +/** A helper structure to store all data related to title objects. Needed for + the conversion of manual title positions that needs the old Chart1 API. + */ +struct TitleLayoutInfo +{ + typedef Reference< XShape > (*GetShapeFunc)( const Reference< cssc::XChartDocument >& ); + + Reference< XTitle > mxTitle; /// The API title object. + ModelRef< LayoutModel > mxLayout; /// The layout model, if existing. + GetShapeFunc mpGetShape; /// Helper function to receive the title shape. + + explicit TitleLayoutInfo() : mpGetShape( nullptr ) {} + + void convertTitlePos( + ConverterRoot const & rRoot, + const Reference< cssc::XChartDocument >& rxChart1Doc ); +}; + +void TitleLayoutInfo::convertTitlePos( ConverterRoot const & rRoot, const Reference< cssc::XChartDocument >& rxChart1Doc ) +{ + if( !(mxTitle.is() && mpGetShape) ) + return; + + try + { + // try to get the title shape + Reference< XShape > xTitleShape = mpGetShape( rxChart1Doc ); + // get title rotation angle, needed for correction of position of top-left edge + double fAngle = 0.0; + PropertySet aTitleProp( mxTitle ); + aTitleProp.getProperty( fAngle, PROP_TextRotation ); + // convert the position + LayoutModel& rLayout = mxLayout.getOrCreate(); + LayoutConverter aLayoutConv( rRoot, rLayout ); + aLayoutConv.convertFromModel( xTitleShape, fAngle ); + } + catch( Exception& ) + { + } +} + +/* The following local functions implement getting the XShape interface of all + supported title objects (chart and axes). This needs some effort due to the + design of the old Chart1 API used to access these objects. */ + +/** A code fragment that returns a shape object from the passed shape supplier + using the specified interface function. Checks a boolean property first. */ +#define OOX_FRAGMENT_GETTITLESHAPE( shape_supplier, supplier_func, property_name ) \ + PropertySet aPropSet( shape_supplier ); \ + if( shape_supplier.is() && aPropSet.getBoolProperty( PROP_##property_name ) ) \ + return shape_supplier->supplier_func(); \ + return Reference< XShape >(); \ + +/** Implements a function returning the drawing shape of an axis title, if + existing, using the specified API interface and its function. */ +#define OOX_DEFINEFUNC_GETAXISTITLESHAPE( func_name, interface_type, supplier_func, property_name ) \ +Reference< XShape > func_name( const Reference< cssc::XChartDocument >& rxChart1Doc ) \ +{ \ + Reference< cssc::interface_type > xAxisSupp( rxChart1Doc->getDiagram(), UNO_QUERY ); \ + OOX_FRAGMENT_GETTITLESHAPE( xAxisSupp, supplier_func, property_name ) \ +} + +/** Returns the drawing shape of the main title, if existing. */ +Reference< XShape > lclGetMainTitleShape( const Reference< cssc::XChartDocument >& rxChart1Doc ) +{ + OOX_FRAGMENT_GETTITLESHAPE( rxChart1Doc, getTitle, HasMainTitle ) +} + +OOX_DEFINEFUNC_GETAXISTITLESHAPE( lclGetXAxisTitleShape, XAxisXSupplier, getXAxisTitle, HasXAxisTitle ) +OOX_DEFINEFUNC_GETAXISTITLESHAPE( lclGetYAxisTitleShape, XAxisYSupplier, getYAxisTitle, HasYAxisTitle ) +OOX_DEFINEFUNC_GETAXISTITLESHAPE( lclGetZAxisTitleShape, XAxisZSupplier, getZAxisTitle, HasZAxisTitle ) +OOX_DEFINEFUNC_GETAXISTITLESHAPE( lclGetSecXAxisTitleShape, XSecondAxisTitleSupplier, getSecondXAxisTitle, HasSecondaryXAxisTitle ) +OOX_DEFINEFUNC_GETAXISTITLESHAPE( lclGetSecYAxisTitleShape, XSecondAxisTitleSupplier, getSecondYAxisTitle, HasSecondaryYAxisTitle ) + +#undef OOX_DEFINEFUNC_GETAXISTITLESHAPE +#undef OOX_IMPLEMENT_GETTITLESHAPE + +} // namespace + +struct ConverterData +{ + ObjectFormatter maFormatter; + std::map< TitleKey, TitleLayoutInfo > + maTitles; + XmlFilterBase& mrFilter; + ChartConverter& mrConverter; + Reference< XChartDocument > mxDoc; + awt::Size maSize; + + explicit ConverterData( + XmlFilterBase& rFilter, + ChartConverter& rChartConverter, + const ChartSpaceModel& rChartModel, + const Reference< XChartDocument >& rxChartDoc, + const awt::Size& rChartSize ); + ~ConverterData(); +}; + +ConverterData::ConverterData( + XmlFilterBase& rFilter, + ChartConverter& rChartConverter, + const ChartSpaceModel& rChartModel, + const Reference< XChartDocument >& rxChartDoc, + const awt::Size& rChartSize ) : + maFormatter( rFilter, rxChartDoc, rChartModel ), + mrFilter( rFilter ), + mrConverter( rChartConverter ), + mxDoc( rxChartDoc ), + maSize( rChartSize ) +{ + OSL_ENSURE( mxDoc.is(), "ConverterData::ConverterData - missing chart document" ); + // lock the model to suppress internal updates during conversion + try + { + mxDoc->lockControllers(); + } + catch( Exception& ) + { + } + + // prepare conversion of title positions + maTitles[ TitleKey( OBJECTTYPE_CHARTTITLE ) ].mpGetShape = lclGetMainTitleShape; + maTitles[ TitleKey( OBJECTTYPE_AXISTITLE, API_PRIM_AXESSET, API_X_AXIS ) ].mpGetShape = lclGetXAxisTitleShape; + maTitles[ TitleKey( OBJECTTYPE_AXISTITLE, API_PRIM_AXESSET, API_Y_AXIS ) ].mpGetShape = lclGetYAxisTitleShape; + maTitles[ TitleKey( OBJECTTYPE_AXISTITLE, API_PRIM_AXESSET, API_Z_AXIS ) ].mpGetShape = lclGetZAxisTitleShape; + maTitles[ TitleKey( OBJECTTYPE_AXISTITLE, API_SECN_AXESSET, API_X_AXIS ) ].mpGetShape = lclGetSecXAxisTitleShape; + maTitles[ TitleKey( OBJECTTYPE_AXISTITLE, API_SECN_AXESSET, API_Y_AXIS ) ].mpGetShape = lclGetSecYAxisTitleShape; +} + +ConverterData::~ConverterData() +{ + // unlock the model + try + { + mxDoc->unlockControllers(); + } + catch( Exception& ) + { + } +} + +ConverterRoot::ConverterRoot( + XmlFilterBase& rFilter, + ChartConverter& rChartConverter, + const ChartSpaceModel& rChartModel, + const Reference< XChartDocument >& rxChartDoc, + const awt::Size& rChartSize ) : + mxData( std::make_shared<ConverterData>( rFilter, rChartConverter, rChartModel, rxChartDoc, rChartSize ) ) +{ +} + +ConverterRoot::~ConverterRoot() +{ +} + +Reference< XInterface > ConverterRoot::createInstance( const OUString& rServiceName ) const +{ + Reference< XInterface > xInt; + try + { + Reference<XMultiServiceFactory> xMSF(getComponentContext()->getServiceManager(), uno::UNO_QUERY_THROW); + + xInt = xMSF->createInstance( rServiceName ); + } + catch( Exception& ) + { + } + OSL_ENSURE( xInt.is(), "ConverterRoot::createInstance - cannot create instance" ); + return xInt; +} + +Reference< XComponentContext > const & ConverterRoot::getComponentContext() const +{ + return mxData->mrFilter.getComponentContext(); +} + +XmlFilterBase& ConverterRoot::getFilter() const +{ + return mxData->mrFilter; +} + +ChartConverter& ConverterRoot::getChartConverter() const +{ + return mxData->mrConverter; +} + +Reference< XChartDocument > const & ConverterRoot::getChartDocument() const +{ + return mxData->mxDoc; +} + +const awt::Size& ConverterRoot::getChartSize() const +{ + return mxData->maSize; +} + +ObjectFormatter& ConverterRoot::getFormatter() const +{ + return mxData->maFormatter; +} + +void ConverterRoot::registerTitleLayout( const Reference< XTitle >& rxTitle, + const ModelRef< LayoutModel >& rxLayout, ObjectType eObjType, sal_Int32 nMainIdx, sal_Int32 nSubIdx ) +{ + OSL_ENSURE( rxTitle.is(), "ConverterRoot::registerTitleLayout - missing title object" ); + TitleLayoutInfo& rTitleInfo = mxData->maTitles[ TitleKey( eObjType, nMainIdx, nSubIdx ) ]; + OSL_ENSURE( rTitleInfo.mpGetShape, "ConverterRoot::registerTitleLayout - invalid title key" ); + rTitleInfo.mxTitle = rxTitle; + rTitleInfo.mxLayout = rxLayout; +} + +void ConverterRoot::convertTitlePositions() +{ + try + { + Reference< cssc::XChartDocument > xChart1Doc( mxData->mxDoc, UNO_QUERY_THROW ); + for (auto & title : mxData->maTitles) + title.second.convertTitlePos( *this, xChart1Doc ); + } + catch( Exception& ) + { + } +} + +namespace { + +/** Returns a position value in the chart area in 1/100 mm. */ +sal_Int32 lclCalcPosition( sal_Int32 nChartSize, double fPos, sal_Int32 nPosMode ) +{ + switch( nPosMode ) + { + case XML_edge: // absolute start position as factor of chart size + return getLimitedValue< sal_Int32, double >( nChartSize * fPos + 0.5, 0, nChartSize ); + case XML_factor: // position relative to object default position + OSL_FAIL( "lclCalcPosition - relative positioning not supported" ); + return -1; + }; + + OSL_FAIL( "lclCalcPosition - unknown positioning mode" ); + return -1; +} + +/** Returns a size value in the chart area in 1/100 mm. */ +sal_Int32 lclCalcSize( sal_Int32 nPos, sal_Int32 nChartSize, double fSize, sal_Int32 nSizeMode ) +{ + sal_Int32 nValue = getLimitedValue< sal_Int32, double >( nChartSize * fSize + 0.5, 0, nChartSize ); + switch( nSizeMode ) + { + case XML_factor: // passed value is width/height + return nValue; + case XML_edge: // passed value is right/bottom position + return nValue - nPos + 1; + }; + + OSL_FAIL( "lclCalcSize - unknown size mode" ); + return -1; +} + +/** Returns a relative size value in the chart area. */ +double lclCalcRelSize( double fPos, double fSize, sal_Int32 nSizeMode ) +{ + switch( nSizeMode ) + { + case XML_factor: // passed value is width/height + break; + case XML_edge: // passed value is right/bottom position + fSize -= fPos; + break; + default: + OSL_ENSURE( false, "lclCalcRelSize - unknown size mode" ); + fSize = 0.0; + }; + return getLimitedValue< double, double >( fSize, 0.0, 1.0 - fPos ); +} + +} // namespace + +LayoutConverter::LayoutConverter( const ConverterRoot& rParent, LayoutModel& rModel ) : + ConverterBase< LayoutModel >( rParent, rModel ) +{ +} + +LayoutConverter::~LayoutConverter() +{ +} + +bool LayoutConverter::calcAbsRectangle( awt::Rectangle& orRect ) const +{ + if( !mrModel.mbAutoLayout ) + { + awt::Size aChartSize = getChartSize(); + if( aChartSize.Width <= 0 || aChartSize.Height <= 0 ) + { + aChartSize = getDefaultPageSize(); + } + orRect.X = lclCalcPosition( aChartSize.Width, mrModel.mfX, mrModel.mnXMode ); + orRect.Y = lclCalcPosition( aChartSize.Height, mrModel.mfY, mrModel.mnYMode ); + if( (orRect.X >= 0) && (orRect.Y >= 0) ) + { + orRect.Width = lclCalcSize( orRect.X, aChartSize.Width, mrModel.mfW, mrModel.mnWMode ); + orRect.Height = lclCalcSize( orRect.Y, aChartSize.Height, mrModel.mfH, mrModel.mnHMode ); + return (orRect.Width > 0) && (orRect.Height > 0); + } + } + return false; +} + +bool LayoutConverter::convertFromModel( PropertySet& rPropSet ) +{ + if( !mrModel.mbAutoLayout && + (mrModel.mnXMode == XML_edge) && (mrModel.mfX >= 0.0) && + (mrModel.mnYMode == XML_edge) && (mrModel.mfY >= 0.0) ) + { + RelativePosition aPos( + getLimitedValue< double, double >( mrModel.mfX, 0.0, 1.0 ), + getLimitedValue< double, double >( mrModel.mfY, 0.0, 1.0 ), + Alignment_TOP_LEFT ); + rPropSet.setProperty( PROP_RelativePosition, aPos ); + + RelativeSize aSize( + lclCalcRelSize( aPos.Primary, mrModel.mfW, mrModel.mnWMode ), + lclCalcRelSize( aPos.Secondary, mrModel.mfH, mrModel.mnHMode ) ); + if( (aSize.Primary > 0.0) && (aSize.Secondary > 0.0) ) + { + rPropSet.setProperty( PROP_RelativeSize, aSize ); + return true; + } + } + return false; +} + +void LayoutConverter::convertFromModel( const Reference< XShape >& rxShape, double fRotationAngle ) +{ + if( mrModel.mbAutoLayout ) + return; + + awt::Size aChartSize = getChartSize(); + if( aChartSize.Width <= 0 || aChartSize.Height <= 0 ) + { + aChartSize = getDefaultPageSize(); + } + awt::Point aShapePos( + lclCalcPosition( aChartSize.Width, mrModel.mfX, mrModel.mnXMode ), + lclCalcPosition( aChartSize.Height, mrModel.mfY, mrModel.mnYMode ) ); + if( !((aShapePos.X >= 0) && (aShapePos.Y >= 0)) ) + return; + + bool bPropSet = false; + // the call to XShape.getSize() may recalc the chart view + awt::Size aShapeSize = rxShape->getSize(); + // rotated shapes need special handling... + if( aShapeSize.Height > 0 || aShapeSize.Width > 0 ) + { + double fSin = fabs(sin(basegfx::deg2rad(fRotationAngle))); + // add part of height to X direction, if title is rotated down + if( fRotationAngle > 180.0 ) + aShapePos.X += static_cast<sal_Int32>(fSin * aShapeSize.Height + 0.5); + // add part of width to Y direction, if title is rotated up + else if( fRotationAngle > 0.0 ) + aShapePos.Y += static_cast<sal_Int32>(fSin * aShapeSize.Width + 0.5); + } + else if( fRotationAngle == 90.0 || fRotationAngle == 270.0 ) + { + PropertySet aShapeProp( rxShape ); + RelativePosition aPos( + getLimitedValue< double, double >(mrModel.mfX, 0.0, 1.0), + getLimitedValue< double, double >(mrModel.mfY, 0.0, 1.0), + fRotationAngle == 90.0 ? Alignment_TOP_RIGHT : Alignment_BOTTOM_LEFT ); + // set the resulting position at the shape + if( aShapeProp.setProperty(PROP_RelativePosition, aPos) ) + bPropSet = true; + } + // set the resulting position at the shape + if( !bPropSet ) + rxShape->setPosition( aShapePos ); +} + +} // namespace oox + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/oox/source/drawingml/chart/datasourcecontext.cxx b/oox/source/drawingml/chart/datasourcecontext.cxx new file mode 100644 index 000000000..16cd509e4 --- /dev/null +++ b/oox/source/drawingml/chart/datasourcecontext.cxx @@ -0,0 +1,306 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <drawingml/chart/datasourcecontext.hxx> + +#include <oox/drawingml/chart/datasourcemodel.hxx> + +#include <oox/core/xmlfilterbase.hxx> +#include <oox/helper/attributelist.hxx> +#include <oox/token/namespaces.hxx> +#include <oox/token/tokens.hxx> +#include <svl/zforlist.hxx> +#include <osl/diagnose.h> + +namespace oox::drawingml::chart { + +using ::oox::core::ContextHandler2Helper; +using ::oox::core::ContextHandlerRef; + +using namespace ::com::sun::star; + +DoubleSequenceContext::DoubleSequenceContext( ContextHandler2Helper& rParent, DataSequenceModel& rModel ) : + DataSequenceContextBase( rParent, rModel ), + mnPtIndex( -1 ) +{ +} + +DoubleSequenceContext::~DoubleSequenceContext() +{ +} + +ContextHandlerRef DoubleSequenceContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) +{ + switch( getCurrentElement() ) + { + case C_TOKEN( numRef ): + switch( nElement ) + { + case C_TOKEN( f ): + case C_TOKEN( numCache ): + return this; + } + break; + + case C_TOKEN( numCache ): + case C_TOKEN( numLit ): + switch( nElement ) + { + case C_TOKEN( formatCode ): + return this; + case C_TOKEN( ptCount ): + mrModel.mnPointCount = rAttribs.getInteger( XML_val, -1 ); + return nullptr; + case C_TOKEN( pt ): + mnPtIndex = rAttribs.getInteger( XML_idx, -1 ); + return this; + } + break; + + case C_TOKEN( pt ): + switch( nElement ) + { + case C_TOKEN( v ): + return this; + } + break; + } + return nullptr; +} + +void DoubleSequenceContext::onCharacters( const OUString& rChars ) +{ + switch( getCurrentElement() ) + { + case C_TOKEN( f ): + mrModel.maFormula = rChars; + break; + case C_TOKEN( formatCode ): + mrModel.maFormatCode = rChars; + break; + case C_TOKEN( v ): + if( mnPtIndex >= 0 ) + { + /* Import categories as String even though it could + * be values. + * n#810508: xVal needs to be imported as double + * TODO: NumberFormat conversion, remove the check then. + */ + if( isParentElement( C_TOKEN( cat ), 4 ) ) + { + // workaround for bug n#889755 + SvNumberFormatter* pNumFrmt = getNumberFormatter(); + if( pNumFrmt ) + { + sal_uInt32 nKey = pNumFrmt->GetEntryKey( mrModel.maFormatCode ); + bool bNoKey = ( nKey == NUMBERFORMAT_ENTRY_NOT_FOUND ); + if( bNoKey ) + { + OUString aFormatCode = mrModel.maFormatCode; + sal_Int32 nCheckPos = 0; + SvNumFormatType nType; + pNumFrmt->PutEntry( aFormatCode, nCheckPos, nType, nKey ); + bNoKey = (nCheckPos != 0); + } + if( bNoKey ) + { + mrModel.maData[ mnPtIndex ] <<= rChars; + } + else + { + double fValue = rChars.toDouble(); + ::Color* pColor = nullptr; + OUString aFormattedValue; + // tdf#91250: use UNLIMITED_PRECISION in case of GENERAL Number Format of category axis labels + if( pNumFrmt->GetStandardPrec() != SvNumberFormatter::UNLIMITED_PRECISION ) + pNumFrmt->ChangeStandardPrec(SvNumberFormatter::UNLIMITED_PRECISION); + pNumFrmt->GetOutputString( fValue, nKey, aFormattedValue, &pColor ); + mrModel.maData[ mnPtIndex ] <<= aFormattedValue; + } + } + else + { + mrModel.maData[ mnPtIndex ] <<= rChars; + } + } + else + { + mrModel.maData[ mnPtIndex ] <<= rChars.toDouble(); + } + } + break; + } +} + + +SvNumberFormatter* DoubleSequenceContext::getNumberFormatter() +{ + if( mpNumberFormatter == nullptr ) + { + uno::Reference<uno::XComponentContext> rContext = + getFilter().getComponentContext(); + mpNumberFormatter.reset( + new SvNumberFormatter(rContext, LANGUAGE_DONTKNOW) ); + } + return mpNumberFormatter.get(); +} + + +StringSequenceContext::StringSequenceContext( ContextHandler2Helper& rParent, DataSequenceModel& rModel ) + : DataSequenceContextBase( rParent, rModel ) + , mnPtIndex(-1) +{ +} + +StringSequenceContext::~StringSequenceContext() +{ +} + +ContextHandlerRef StringSequenceContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) +{ + switch( getCurrentElement() ) + { + case C_TOKEN( multiLvlStrRef ): + switch( nElement ) + { + case C_TOKEN( f ): + case C_TOKEN( multiLvlStrCache ): + return this; + } + break; + + case C_TOKEN( strRef ): + switch( nElement ) + { + case C_TOKEN( f ): + case C_TOKEN( strCache ): + return this; + } + break; + + case C_TOKEN( strCache ): + case C_TOKEN( strLit ): + switch( nElement ) + { + case C_TOKEN( ptCount ): + mrModel.mnPointCount = rAttribs.getInteger( XML_val, -1 ); + return nullptr; + case C_TOKEN( pt ): + mnPtIndex = rAttribs.getInteger( XML_idx, -1 ); + return this; + } + break; + + case C_TOKEN( multiLvlStrCache ): + switch (nElement) + { + case C_TOKEN( ptCount ): + mrModel.mnPointCount = rAttribs.getInteger(XML_val, -1); + mrModel.mnLevelCount--; // normalize level count + return nullptr; + case C_TOKEN( lvl ): + mrModel.mnLevelCount++; + return this; + } + break; + + case C_TOKEN( lvl ): + switch (nElement) + { + case C_TOKEN(pt): + mnPtIndex = rAttribs.getInteger(XML_idx, -1); + return this; + } + break; + + case C_TOKEN( pt ): + switch( nElement ) + { + case C_TOKEN( v ): + return this; + } + break; + } + return nullptr; +} + +void StringSequenceContext::onCharacters( const OUString& rChars ) +{ + switch( getCurrentElement() ) + { + case C_TOKEN( f ): + mrModel.maFormula = rChars; + break; + case C_TOKEN( v ): + if( mnPtIndex >= 0 ) + mrModel.maData[ (mrModel.mnLevelCount-1) * mrModel.mnPointCount + mnPtIndex ] <<= rChars; + break; + } +} + +DataSourceContext::DataSourceContext( ContextHandler2Helper& rParent, DataSourceModel& rModel ) : + ContextBase< DataSourceModel >( rParent, rModel ) +{ +} + +DataSourceContext::~DataSourceContext() +{ +} + +ContextHandlerRef DataSourceContext::onCreateContext( sal_Int32 nElement, const AttributeList& ) +{ + switch( getCurrentElement() ) + { + case C_TOKEN( cat ): + case C_TOKEN( xVal ): + switch( nElement ) + { + case C_TOKEN( multiLvlStrRef ): + case C_TOKEN( strLit ): + case C_TOKEN( strRef ): + OSL_ENSURE( !mrModel.mxDataSeq, "DataSourceContext::onCreateContext - multiple data sequences" ); + return new StringSequenceContext( *this, mrModel.mxDataSeq.create() ); + + case C_TOKEN( numLit ): + case C_TOKEN( numRef ): + OSL_ENSURE( !mrModel.mxDataSeq, "DataSourceContext::onCreateContext - multiple data sequences" ); + return new DoubleSequenceContext( *this, mrModel.mxDataSeq.create() ); + } + break; + + case C_TOKEN( plus ): + case C_TOKEN( minus ): + case C_TOKEN( val ): + case C_TOKEN( yVal ): + case C_TOKEN( bubbleSize ): + switch( nElement ) + { + case C_TOKEN( numLit ): + case C_TOKEN( numRef ): + OSL_ENSURE( !mrModel.mxDataSeq, "DataSourceContext::onCreateContext - multiple data sequences" ); + return new DoubleSequenceContext( *this, mrModel.mxDataSeq.create() ); + } + break; + } + return nullptr; +} + +} // namespace oox::drawingml::chart + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/oox/source/drawingml/chart/datasourceconverter.cxx b/oox/source/drawingml/chart/datasourceconverter.cxx new file mode 100644 index 000000000..723994265 --- /dev/null +++ b/oox/source/drawingml/chart/datasourceconverter.cxx @@ -0,0 +1,102 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <drawingml/chart/datasourceconverter.hxx> + +#include <com/sun/star/chart2/XChartDocument.hpp> +#include <oox/drawingml/chart/chartconverter.hxx> +#include <oox/drawingml/chart/datasourcemodel.hxx> +#include <oox/token/properties.hxx> + +namespace oox::drawingml::chart { + +using namespace ::com::sun::star::chart2::data; +using namespace ::com::sun::star::uno; + +DataSequenceConverter::DataSequenceConverter( const ConverterRoot& rParent, DataSequenceModel& rModel ) : + ConverterBase< DataSequenceModel >( rParent, rModel ) +{ +} + +DataSequenceConverter::~DataSequenceConverter() +{ +} + +Reference< XDataSequence > DataSequenceConverter::createDataSequence( const OUString& rRole ) +{ + // create data sequence from data source model (virtual call at chart converter) + Reference< XDataSequence > xDataSeq; + // the internal data table does not support complex labels + // this is only supported in Calc!!! + // merge the labels into a single one + if(rRole == "label") + { + mrModel.mnPointCount = std::min<sal_Int32>(mrModel.mnPointCount, 1); + OUStringBuffer aTitle; + bool bFirst = true; + for (auto const& elem : mrModel.maData) + { + Any aAny = elem.second; + if(aAny.has<OUString>()) + { + if(!bFirst) + aTitle.append(" "); + + aTitle.append(aAny.get<OUString>()); + bFirst = false; + } + } + + if(!bFirst) + { + mrModel.maData.clear(); + mrModel.maData.insert(std::make_pair<sal_Int32, Any>(0, Any(aTitle.makeStringAndClear()))); + } + } + xDataSeq = getChartConverter().createDataSequence(getChartDocument()->getDataProvider(), mrModel, rRole); + + // set sequence role + PropertySet aSeqProp( xDataSeq ); + aSeqProp.setProperty( PROP_Role, rRole ); + return xDataSeq; +} + +DataSourceConverter::DataSourceConverter( const ConverterRoot& rParent, DataSourceModel& rModel ) : + ConverterBase< DataSourceModel >( rParent, rModel ) +{ +} + +DataSourceConverter::~DataSourceConverter() +{ +} + +Reference< XDataSequence > DataSourceConverter::createDataSequence( const OUString& rRole ) +{ + Reference< XDataSequence > xDataSeq; + if( mrModel.mxDataSeq.is() ) + { + DataSequenceConverter aDataSeqConv( *this, *mrModel.mxDataSeq ); + xDataSeq = aDataSeqConv.createDataSequence( rRole ); + } + return xDataSeq; +} + +} // namespace oox::drawingml::chart + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/oox/source/drawingml/chart/datasourcemodel.cxx b/oox/source/drawingml/chart/datasourcemodel.cxx new file mode 100644 index 000000000..e83b6b355 --- /dev/null +++ b/oox/source/drawingml/chart/datasourcemodel.cxx @@ -0,0 +1,44 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <oox/drawingml/chart/datasourcemodel.hxx> + +namespace oox::drawingml::chart { + +DataSequenceModel::DataSequenceModel() : + mnPointCount( -1 ), + mnLevelCount( 1 ) +{ +} + +DataSequenceModel::~DataSequenceModel() +{ +} + +DataSourceModel::DataSourceModel() +{ +} + +DataSourceModel::~DataSourceModel() +{ +} + +} // namespace oox::drawingml::chart + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/oox/source/drawingml/chart/modelbase.cxx b/oox/source/drawingml/chart/modelbase.cxx new file mode 100644 index 000000000..feb5b9aed --- /dev/null +++ b/oox/source/drawingml/chart/modelbase.cxx @@ -0,0 +1,58 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <oox/drawingml/chart/modelbase.hxx> + +#include <oox/helper/attributelist.hxx> +#include <oox/token/tokens.hxx> + +namespace oox::drawingml::chart { + +NumberFormat::NumberFormat() : + mbSourceLinked( true ) +{ +} + +void NumberFormat::setAttributes( const AttributeList& rAttribs ) +{ + mbSourceLinked = rAttribs.getBool( XML_sourceLinked, true); + maFormatCode = rAttribs.getString( XML_formatCode, OUString() ); +} + +LayoutModel::LayoutModel() : + mfX( 0.0 ), + mfY( 0.0 ), + mfW( 0.0 ), + mfH( 0.0 ), + mnXMode( XML_factor ), + mnYMode( XML_factor ), + mnWMode( XML_factor ), + mnHMode( XML_factor ), + mnTarget( XML_outer ), + mbAutoLayout( true ) +{ +} + +LayoutModel::~LayoutModel() +{ +} + +} // namespace oox::drawingml::chart + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/oox/source/drawingml/chart/objectformatter.cxx b/oox/source/drawingml/chart/objectformatter.cxx new file mode 100644 index 000000000..60cac2395 --- /dev/null +++ b/oox/source/drawingml/chart/objectformatter.cxx @@ -0,0 +1,1160 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <drawingml/chart/objectformatter.hxx> + +#include <com/sun/star/chart2/XChartDocument.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/util/XNumberFormatsSupplier.hpp> +#include <com/sun/star/util/XNumberFormatTypes.hpp> +#include <osl/thread.h> +#include <osl/diagnose.h> +#include <rtl/strbuf.hxx> +#include <oox/core/xmlfilterbase.hxx> +#include <drawingml/fillproperties.hxx> +#include <drawingml/lineproperties.hxx> +#include <oox/drawingml/shapepropertymap.hxx> +#include <drawingml/textbody.hxx> +#include <drawingml/textparagraph.hxx> +#include <oox/drawingml/theme.hxx> +#include <drawingml/chart/chartspacemodel.hxx> +#include <oox/helper/modelobjecthelper.hxx> +#include <oox/helper/graphichelper.hxx> +#include <oox/token/properties.hxx> +#include <oox/token/tokens.hxx> + +namespace oox::drawingml::chart { + +using namespace ::com::sun::star::chart2; +using namespace ::com::sun::star::graphic; +using namespace ::com::sun::star::lang; +using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::util; + +using ::oox::core::XmlFilterBase; + +namespace { + +struct AutoFormatPatternEntry +{ + sal_Int32 mnColorToken; /// Theme color token. + sal_Int32 mnModToken; /// Color modification token. + sal_Int32 mnModValue; /// Color modification value. +}; + +#define AUTOFORMAT_PATTERN_COLOR( color_token ) \ + { color_token, XML_TOKEN_INVALID, 0 } + +#define AUTOFORMAT_PATTERN_COLORMOD( color_token, mod_token, mod_value ) \ + { color_token, mod_token, mod_value } + +#define AUTOFORMAT_PATTERN_END() \ + AUTOFORMAT_PATTERN_COLOR( XML_TOKEN_INVALID ) + +static const AutoFormatPatternEntry spAutoFormatPattern1[] = +{ + AUTOFORMAT_PATTERN_COLORMOD( XML_dk1, XML_tint, 88500 ), + AUTOFORMAT_PATTERN_COLORMOD( XML_dk1, XML_tint, 55000 ), + AUTOFORMAT_PATTERN_COLORMOD( XML_dk1, XML_tint, 78000 ), + AUTOFORMAT_PATTERN_COLORMOD( XML_dk1, XML_tint, 92500 ), + AUTOFORMAT_PATTERN_COLORMOD( XML_dk1, XML_tint, 70000 ), + AUTOFORMAT_PATTERN_COLORMOD( XML_dk1, XML_tint, 30000 ), + AUTOFORMAT_PATTERN_END() +}; + +static const AutoFormatPatternEntry spAutoFormatPattern2[] = +{ + AUTOFORMAT_PATTERN_COLOR( XML_accent1 ), + AUTOFORMAT_PATTERN_COLOR( XML_accent2 ), + AUTOFORMAT_PATTERN_COLOR( XML_accent3 ), + AUTOFORMAT_PATTERN_COLOR( XML_accent4 ), + AUTOFORMAT_PATTERN_COLOR( XML_accent5 ), + AUTOFORMAT_PATTERN_COLOR( XML_accent6 ), + AUTOFORMAT_PATTERN_END() +}; + +static const AutoFormatPatternEntry spAutoFormatPattern3[] = +{ + AUTOFORMAT_PATTERN_COLORMOD( XML_accent1, XML_shade, 50000 ), + AUTOFORMAT_PATTERN_COLORMOD( XML_accent2, XML_shade, 50000 ), + AUTOFORMAT_PATTERN_COLORMOD( XML_accent3, XML_shade, 50000 ), + AUTOFORMAT_PATTERN_COLORMOD( XML_accent4, XML_shade, 50000 ), + AUTOFORMAT_PATTERN_COLORMOD( XML_accent5, XML_shade, 50000 ), + AUTOFORMAT_PATTERN_COLORMOD( XML_accent6, XML_shade, 50000 ), + AUTOFORMAT_PATTERN_END() +}; + +static const AutoFormatPatternEntry spAutoFormatPattern4[] = +{ + AUTOFORMAT_PATTERN_COLORMOD( XML_dk1, XML_tint, 5000 ), + AUTOFORMAT_PATTERN_COLORMOD( XML_dk1, XML_tint, 55000 ), + AUTOFORMAT_PATTERN_COLORMOD( XML_dk1, XML_tint, 78000 ), + AUTOFORMAT_PATTERN_COLORMOD( XML_dk1, XML_tint, 15000 ), + AUTOFORMAT_PATTERN_COLORMOD( XML_dk1, XML_tint, 70000 ), + AUTOFORMAT_PATTERN_COLORMOD( XML_dk1, XML_tint, 30000 ), + AUTOFORMAT_PATTERN_END() +}; + +#undef AUTOFORMAT_PATTERN_COLOR +#undef AUTOFORMAT_PATTERN_COLORMOD +#undef AUTOFORMAT_PATTERN_END + +struct AutoFormatEntry +{ + sal_Int32 mnFirstStyleIdx; /// First chart style index. + sal_Int32 mnLastStyleIdx; /// Last chart style index. + sal_Int32 mnThemedIdx; /// Themed style index. + sal_Int32 mnColorToken; /// Theme color token. + sal_Int32 mnModToken; /// Color modification token. + sal_Int32 mnModValue; /// Color modification value. + sal_Int32 mnRelLineWidth; /// Relative line width (percent). + const AutoFormatPatternEntry* mpPattern;/// Color cycling pattern for data series. + bool mbFadedColor; /// True = Faded color for data series. +}; + +#define AUTOFORMAT_COLOR( first, last, themed_style, color_token ) \ + { first, last, themed_style, color_token, XML_TOKEN_INVALID, 0, 100, nullptr, false } + +#define AUTOFORMAT_COLORMOD( first, last, themed_style, color_token, mod_token, mod_value ) \ + { first, last, themed_style, color_token, mod_token, mod_value, 100, nullptr, false } + +#define AUTOFORMAT_ACCENTSMOD( first, themed_style, mod_token, mod_value ) \ + AUTOFORMAT_COLORMOD( first, first, themed_style, XML_accent1, mod_token, mod_value ), \ + AUTOFORMAT_COLORMOD( first + 1, first + 1, themed_style, XML_accent2, mod_token, mod_value ), \ + AUTOFORMAT_COLORMOD( first + 2, first + 2, themed_style, XML_accent3, mod_token, mod_value ), \ + AUTOFORMAT_COLORMOD( first + 3, first + 3, themed_style, XML_accent4, mod_token, mod_value ), \ + AUTOFORMAT_COLORMOD( first + 4, first + 4, themed_style, XML_accent5, mod_token, mod_value ), \ + AUTOFORMAT_COLORMOD( first + 5, first + 5, themed_style, XML_accent6, mod_token, mod_value ) + +#define AUTOFORMAT_PATTERN( first, last, themed_style, line_width, pattern ) \ + { first, last, themed_style, XML_TOKEN_INVALID, XML_TOKEN_INVALID, 0, line_width, pattern, false } + +#define AUTOFORMAT_FADED( first, last, themed_style, color_token, line_width ) \ + { first, last, themed_style, color_token, XML_TOKEN_INVALID, 0, line_width, nullptr, true } + +#define AUTOFORMAT_FADEDACCENTS( first, themed_style, line_width ) \ + AUTOFORMAT_FADED( first, first, themed_style, XML_accent1, line_width ), \ + AUTOFORMAT_FADED( first + 1, first + 1, themed_style, XML_accent2, line_width ), \ + AUTOFORMAT_FADED( first + 2, first + 2, themed_style, XML_accent3, line_width ), \ + AUTOFORMAT_FADED( first + 3, first + 3, themed_style, XML_accent4, line_width ), \ + AUTOFORMAT_FADED( first + 4, first + 4, themed_style, XML_accent5, line_width ), \ + AUTOFORMAT_FADED( first + 5, first + 5, themed_style, XML_accent6, line_width ) + +#define AUTOFORMAT_INVISIBLE( first, last ) \ + AUTOFORMAT_COLOR( first, last, -1, XML_TOKEN_INVALID ) + +#define AUTOFORMAT_END() \ + AUTOFORMAT_INVISIBLE( -1, -1 ) + +static const AutoFormatEntry spNoFormats[] = +{ + AUTOFORMAT_INVISIBLE( 1, 48 ), + AUTOFORMAT_END() +}; + +static const AutoFormatEntry spChartSpaceFill[] = +{ + AUTOFORMAT_COLOR( 1, 32, THEMED_STYLE_SUBTLE, XML_bg1 ), + AUTOFORMAT_COLOR( 33, 40, THEMED_STYLE_SUBTLE, XML_lt1 ), + AUTOFORMAT_COLOR( 41, 48, THEMED_STYLE_SUBTLE, XML_dk1 ), + AUTOFORMAT_END() +}; + +static const AutoFormatEntry spDataTableLines[] = +{ + AUTOFORMAT_COLORMOD( 1, 32, THEMED_STYLE_SUBTLE, XML_tx1, XML_tint, 75000 ), + AUTOFORMAT_COLORMOD( 33, 40, THEMED_STYLE_SUBTLE, XML_dk1, XML_tint, 75000 ), + // 41...48: no line, same as Chart2 + AUTOFORMAT_END() +}; + +static const AutoFormatEntry spPlotArea2dFills[] = +{ + AUTOFORMAT_COLOR( 1, 32, THEMED_STYLE_SUBTLE, XML_bg1 ), + AUTOFORMAT_COLORMOD( 33, 34, THEMED_STYLE_SUBTLE, XML_dk1, XML_tint, 20000 ), + AUTOFORMAT_ACCENTSMOD( 35, THEMED_STYLE_SUBTLE, XML_tint, 20000 ), // tint not documented!? + AUTOFORMAT_COLORMOD( 41, 48, THEMED_STYLE_SUBTLE, XML_dk1, XML_tint, 95000 ), + AUTOFORMAT_END() +}; + +static const AutoFormatEntry spWallFloorLines[] = +{ + AUTOFORMAT_COLORMOD( 1, 32, THEMED_STYLE_SUBTLE, XML_tx1, XML_tint, 75000 ), + AUTOFORMAT_COLORMOD( 33, 40, THEMED_STYLE_SUBTLE, XML_dk1, XML_tint, 75000 ), + // 41...48: no line, same as Chart2 + AUTOFORMAT_END() +}; + +static const AutoFormatEntry spWallFloorFills[] = +{ + AUTOFORMAT_INVISIBLE( 1, 32 ), + AUTOFORMAT_COLORMOD( 33, 34, THEMED_STYLE_SUBTLE, XML_dk1, XML_tint, 20000 ), + AUTOFORMAT_ACCENTSMOD( 35, THEMED_STYLE_SUBTLE, XML_tint, 20000 ), // tint not documented!? + AUTOFORMAT_COLORMOD( 41, 48, THEMED_STYLE_SUBTLE, XML_dk1, XML_tint, 95000 ), + AUTOFORMAT_END() +}; + +static const AutoFormatEntry spAxisLines[] = +{ + AUTOFORMAT_COLORMOD( 1, 32, THEMED_STYLE_SUBTLE, XML_tx1, XML_tint, 75000 ), // tint not documented!? + AUTOFORMAT_COLORMOD( 33, 48, THEMED_STYLE_SUBTLE, XML_dk1, XML_tint, 75000 ), // tint not documented!? + AUTOFORMAT_END() +}; + +static const AutoFormatEntry spMajorGridLines[] = +{ + AUTOFORMAT_COLORMOD( 1, 32, THEMED_STYLE_SUBTLE, XML_tx1, XML_tint, 75000 ), // tint not documented!? + AUTOFORMAT_COLORMOD( 33, 48, THEMED_STYLE_SUBTLE, XML_dk1, XML_tint, 75000 ), // tint not documented!? + AUTOFORMAT_END() +}; + +static const AutoFormatEntry spMinorGridLines[] = +{ + AUTOFORMAT_COLORMOD( 1, 40, THEMED_STYLE_SUBTLE, XML_tx1, XML_tint, 50000 ), + AUTOFORMAT_COLORMOD( 41, 48, THEMED_STYLE_SUBTLE, XML_tx1, XML_tint, 90000 ), + AUTOFORMAT_END() +}; + +static const AutoFormatEntry spOtherLines[] = +{ + AUTOFORMAT_COLOR( 1, 32, THEMED_STYLE_SUBTLE, XML_tx1 ), + AUTOFORMAT_COLOR( 33, 34, THEMED_STYLE_SUBTLE, XML_dk1 ), + AUTOFORMAT_COLORMOD( 35, 40, THEMED_STYLE_SUBTLE, XML_dk1, XML_shade, 25000 ), + AUTOFORMAT_COLOR( 41, 48, THEMED_STYLE_SUBTLE, XML_lt1 ), + AUTOFORMAT_END() +}; + +static const AutoFormatEntry spLinearSeriesLines[] = +{ + AUTOFORMAT_PATTERN( 1, 1, THEMED_STYLE_SUBTLE, 300, spAutoFormatPattern1 ), + AUTOFORMAT_PATTERN( 2, 2, THEMED_STYLE_SUBTLE, 300, spAutoFormatPattern2 ), + AUTOFORMAT_FADEDACCENTS( 3, THEMED_STYLE_SUBTLE, 300 ), + AUTOFORMAT_PATTERN( 9, 9, THEMED_STYLE_SUBTLE, 500, spAutoFormatPattern1 ), + AUTOFORMAT_PATTERN( 10, 10, THEMED_STYLE_SUBTLE, 500, spAutoFormatPattern2 ), + AUTOFORMAT_FADEDACCENTS( 11, THEMED_STYLE_SUBTLE, 500 ), + AUTOFORMAT_PATTERN( 17, 17, THEMED_STYLE_SUBTLE, 500, spAutoFormatPattern1 ), + AUTOFORMAT_PATTERN( 18, 18, THEMED_STYLE_SUBTLE, 500, spAutoFormatPattern2 ), + AUTOFORMAT_FADEDACCENTS( 19, THEMED_STYLE_SUBTLE, 500 ), + AUTOFORMAT_PATTERN( 25, 25, THEMED_STYLE_SUBTLE, 700, spAutoFormatPattern1 ), + AUTOFORMAT_PATTERN( 26, 26, THEMED_STYLE_SUBTLE, 700, spAutoFormatPattern2 ), + AUTOFORMAT_FADEDACCENTS( 27, THEMED_STYLE_SUBTLE, 700 ), + AUTOFORMAT_PATTERN( 33, 33, THEMED_STYLE_SUBTLE, 500, spAutoFormatPattern1 ), + AUTOFORMAT_PATTERN( 34, 34, THEMED_STYLE_SUBTLE, 500, spAutoFormatPattern2 ), + AUTOFORMAT_FADEDACCENTS( 35, THEMED_STYLE_SUBTLE, 500 ), + AUTOFORMAT_PATTERN( 41, 42, THEMED_STYLE_SUBTLE, 500, spAutoFormatPattern4 ), + AUTOFORMAT_PATTERN( 42, 42, THEMED_STYLE_SUBTLE, 500, spAutoFormatPattern2 ), + AUTOFORMAT_FADEDACCENTS( 43, THEMED_STYLE_SUBTLE, 500 ), + AUTOFORMAT_END() +}; + +static const AutoFormatEntry spFilledSeriesLines[] = +{ + AUTOFORMAT_INVISIBLE( 1, 8 ), + AUTOFORMAT_COLOR( 9, 16, THEMED_STYLE_SUBTLE, XML_lt1 ), + AUTOFORMAT_INVISIBLE( 17, 32 ), + AUTOFORMAT_COLORMOD( 33, 33, THEMED_STYLE_SUBTLE, XML_dk1, XML_shade, 50000 ), + AUTOFORMAT_PATTERN( 34, 34, THEMED_STYLE_SUBTLE, 100, spAutoFormatPattern3 ), + AUTOFORMAT_ACCENTSMOD( 35, THEMED_STYLE_SUBTLE, XML_shade, 50000 ), + AUTOFORMAT_INVISIBLE( 41, 48 ), + AUTOFORMAT_END() +}; + +static const AutoFormatEntry spFilledSeries2dFills[] = +{ + AUTOFORMAT_PATTERN( 1, 1, THEMED_STYLE_SUBTLE, 100, spAutoFormatPattern1 ), + AUTOFORMAT_PATTERN( 2, 2, THEMED_STYLE_SUBTLE, 100, spAutoFormatPattern2 ), + AUTOFORMAT_FADEDACCENTS( 3, THEMED_STYLE_SUBTLE, 100 ), + AUTOFORMAT_PATTERN( 9, 9, THEMED_STYLE_SUBTLE, 100, spAutoFormatPattern1 ), + AUTOFORMAT_PATTERN( 10, 10, THEMED_STYLE_SUBTLE, 100, spAutoFormatPattern2 ), + AUTOFORMAT_FADEDACCENTS( 11, THEMED_STYLE_SUBTLE, 100 ), + AUTOFORMAT_PATTERN( 17, 17, THEMED_STYLE_INTENSE, 100, spAutoFormatPattern1 ), + AUTOFORMAT_PATTERN( 18, 18, THEMED_STYLE_INTENSE, 100, spAutoFormatPattern2 ), + AUTOFORMAT_FADEDACCENTS( 19, THEMED_STYLE_INTENSE, 100 ), + AUTOFORMAT_PATTERN( 25, 25, THEMED_STYLE_INTENSE, 100, spAutoFormatPattern1 ), + AUTOFORMAT_PATTERN( 26, 26, THEMED_STYLE_INTENSE, 100, spAutoFormatPattern2 ), + AUTOFORMAT_FADEDACCENTS( 27, THEMED_STYLE_INTENSE, 100 ), + AUTOFORMAT_PATTERN( 33, 33, THEMED_STYLE_SUBTLE, 100, spAutoFormatPattern1 ), + AUTOFORMAT_PATTERN( 34, 34, THEMED_STYLE_SUBTLE, 100, spAutoFormatPattern2 ), + AUTOFORMAT_FADEDACCENTS( 35, THEMED_STYLE_SUBTLE, 100 ), + AUTOFORMAT_PATTERN( 41, 42, THEMED_STYLE_INTENSE, 100, spAutoFormatPattern4 ), + AUTOFORMAT_PATTERN( 42, 42, THEMED_STYLE_INTENSE, 100, spAutoFormatPattern2 ), + AUTOFORMAT_FADEDACCENTS( 43, THEMED_STYLE_INTENSE, 100 ), + AUTOFORMAT_END() +}; + +static const AutoFormatEntry spFilledSeries3dFills[] = +{ + AUTOFORMAT_PATTERN( 1, 1, THEMED_STYLE_SUBTLE, 100, spAutoFormatPattern1 ), + AUTOFORMAT_PATTERN( 2, 2, THEMED_STYLE_SUBTLE, 100, spAutoFormatPattern2 ), + AUTOFORMAT_FADEDACCENTS( 3, THEMED_STYLE_SUBTLE, 100 ), + AUTOFORMAT_PATTERN( 9, 9, THEMED_STYLE_SUBTLE, 100, spAutoFormatPattern1 ), + AUTOFORMAT_PATTERN( 10, 10, THEMED_STYLE_SUBTLE, 100, spAutoFormatPattern2 ), + AUTOFORMAT_FADEDACCENTS( 11, THEMED_STYLE_SUBTLE, 100 ), + AUTOFORMAT_PATTERN( 17, 17, THEMED_STYLE_SUBTLE, 100, spAutoFormatPattern1 ), + AUTOFORMAT_PATTERN( 18, 18, THEMED_STYLE_INTENSE, 100, spAutoFormatPattern2 ), + AUTOFORMAT_FADEDACCENTS( 19, THEMED_STYLE_SUBTLE, 100 ), + AUTOFORMAT_PATTERN( 25, 25, THEMED_STYLE_SUBTLE, 100, spAutoFormatPattern1 ), + AUTOFORMAT_PATTERN( 26, 26, THEMED_STYLE_INTENSE, 100, spAutoFormatPattern2 ), + AUTOFORMAT_FADEDACCENTS( 27, THEMED_STYLE_SUBTLE, 100 ), + AUTOFORMAT_PATTERN( 33, 33, THEMED_STYLE_SUBTLE, 100, spAutoFormatPattern1 ), + AUTOFORMAT_PATTERN( 34, 34, THEMED_STYLE_SUBTLE, 100, spAutoFormatPattern2 ), + AUTOFORMAT_FADEDACCENTS( 35, THEMED_STYLE_SUBTLE, 100 ), + AUTOFORMAT_PATTERN( 41, 42, THEMED_STYLE_SUBTLE, 100, spAutoFormatPattern4 ), + AUTOFORMAT_PATTERN( 42, 42, THEMED_STYLE_INTENSE, 100, spAutoFormatPattern2 ), + AUTOFORMAT_FADEDACCENTS( 43, THEMED_STYLE_SUBTLE, 100 ), + AUTOFORMAT_END() +}; + +static const AutoFormatEntry spUpDownBarLines[] = +{ + AUTOFORMAT_COLOR( 1, 16, THEMED_STYLE_SUBTLE, XML_tx1 ), + AUTOFORMAT_INVISIBLE( 17, 32 ), + AUTOFORMAT_COLOR( 33, 34, THEMED_STYLE_SUBTLE, XML_dk1 ), + AUTOFORMAT_ACCENTSMOD( 35, THEMED_STYLE_SUBTLE, XML_shade, 25000 ), + AUTOFORMAT_INVISIBLE( 41, 48 ), + AUTOFORMAT_END() +}; + +static const AutoFormatEntry spUpBarFills[] = +{ + AUTOFORMAT_COLORMOD( 1, 1, THEMED_STYLE_SUBTLE, XML_dk1, XML_tint, 25000 ), + AUTOFORMAT_COLORMOD( 2, 2, THEMED_STYLE_SUBTLE, XML_dk1, XML_tint, 5000 ), + AUTOFORMAT_ACCENTSMOD( 3, THEMED_STYLE_SUBTLE, XML_tint, 25000 ), + AUTOFORMAT_COLORMOD( 9, 9, THEMED_STYLE_SUBTLE, XML_dk1, XML_tint, 25000 ), + AUTOFORMAT_COLORMOD( 10, 10, THEMED_STYLE_SUBTLE, XML_dk1, XML_tint, 5000 ), + AUTOFORMAT_ACCENTSMOD( 11, THEMED_STYLE_SUBTLE, XML_tint, 25000 ), + AUTOFORMAT_COLORMOD( 17, 17, THEMED_STYLE_INTENSE, XML_dk1, XML_tint, 25000 ), + AUTOFORMAT_COLORMOD( 18, 18, THEMED_STYLE_INTENSE, XML_dk1, XML_tint, 5000 ), + AUTOFORMAT_ACCENTSMOD( 19, THEMED_STYLE_INTENSE, XML_tint, 25000 ), + AUTOFORMAT_COLORMOD( 25, 25, THEMED_STYLE_INTENSE, XML_dk1, XML_tint, 25000 ), + AUTOFORMAT_COLORMOD( 26, 26, THEMED_STYLE_INTENSE, XML_dk1, XML_tint, 5000 ), + AUTOFORMAT_ACCENTSMOD( 27, THEMED_STYLE_INTENSE, XML_tint, 25000 ), + AUTOFORMAT_COLOR( 33, 40, THEMED_STYLE_SUBTLE, XML_lt1 ), + AUTOFORMAT_COLORMOD( 41, 41, THEMED_STYLE_INTENSE, XML_dk1, XML_tint, 25000 ), + AUTOFORMAT_COLOR( 42, 42, THEMED_STYLE_INTENSE, XML_lt1 ), + AUTOFORMAT_ACCENTSMOD( 43, THEMED_STYLE_INTENSE, XML_tint, 25000 ), + AUTOFORMAT_END() +}; + +static const AutoFormatEntry spDownBarFills[] = +{ + AUTOFORMAT_COLORMOD( 1, 1, THEMED_STYLE_SUBTLE, XML_dk1, XML_tint, 85000 ), + AUTOFORMAT_COLORMOD( 2, 2, THEMED_STYLE_SUBTLE, XML_dk1, XML_tint, 95000 ), + AUTOFORMAT_ACCENTSMOD( 3, THEMED_STYLE_SUBTLE, XML_shade, 25000 ), + AUTOFORMAT_COLORMOD( 9, 9, THEMED_STYLE_SUBTLE, XML_dk1, XML_tint, 85000 ), + AUTOFORMAT_COLORMOD( 10, 10, THEMED_STYLE_SUBTLE, XML_dk1, XML_tint, 95000 ), + AUTOFORMAT_ACCENTSMOD( 11, THEMED_STYLE_SUBTLE, XML_shade, 25000 ), + AUTOFORMAT_COLORMOD( 17, 17, THEMED_STYLE_INTENSE, XML_dk1, XML_tint, 85000 ), + AUTOFORMAT_COLORMOD( 18, 18, THEMED_STYLE_INTENSE, XML_dk1, XML_tint, 95000 ), + AUTOFORMAT_ACCENTSMOD( 19, THEMED_STYLE_INTENSE, XML_shade, 25000 ), + AUTOFORMAT_COLORMOD( 25, 25, THEMED_STYLE_INTENSE, XML_dk1, XML_tint, 85000 ), + AUTOFORMAT_COLORMOD( 26, 26, THEMED_STYLE_INTENSE, XML_dk1, XML_tint, 95000 ), + AUTOFORMAT_ACCENTSMOD( 27, THEMED_STYLE_INTENSE, XML_shade, 25000 ), + AUTOFORMAT_COLORMOD( 33, 33, THEMED_STYLE_SUBTLE, XML_dk1, XML_tint, 85000 ), + AUTOFORMAT_COLORMOD( 34, 34, THEMED_STYLE_SUBTLE, XML_dk1, XML_tint, 95000 ), + AUTOFORMAT_ACCENTSMOD( 35, THEMED_STYLE_SUBTLE, XML_shade, 25000 ), + AUTOFORMAT_COLORMOD( 41, 41, THEMED_STYLE_INTENSE, XML_dk1, XML_tint, 85000 ), + AUTOFORMAT_COLOR( 42, 42, THEMED_STYLE_INTENSE, XML_dk1 ), + AUTOFORMAT_ACCENTSMOD( 43, THEMED_STYLE_INTENSE, XML_shade, 25000 ), + AUTOFORMAT_END() +}; + +#undef AUTOFORMAT_COLOR +#undef AUTOFORMAT_COLORMOD +#undef AUTOFORMAT_ACCENTSMOD +#undef AUTOFORMAT_PATTERN +#undef AUTOFORMAT_FADED +#undef AUTOFORMAT_FADEDACCENTS +#undef AUTOFORMAT_INVISIBLE +#undef AUTOFORMAT_END + +const AutoFormatEntry* lclGetAutoFormatEntry( const AutoFormatEntry* pEntries, sal_Int32 nStyle ) +{ + for( ; pEntries && (pEntries->mnFirstStyleIdx >= 0); ++pEntries ) + if( (pEntries->mnFirstStyleIdx <= nStyle) && (nStyle <= pEntries->mnLastStyleIdx) ) + return pEntries; + return nullptr; +} + +struct AutoTextEntry +{ + sal_Int32 mnFirstStyleIdx; /// First chart style index. + sal_Int32 mnLastStyleIdx; /// Last chart style index. + sal_Int32 mnThemedFont; /// Themed font (minor/major). + sal_Int32 mnColorToken; /// Theme color token. + sal_Int32 mnDefFontSize; /// Default font size (1/100 points). + sal_Int32 mnRelFontSize; /// Font size relative to chart global font (percent). + bool mbBold; /// True = bold font. +}; + +#define AUTOTEXT_COLOR( first, last, themed_font, color_token, def_font_size, rel_font_size, bold ) \ + { first, last, themed_font, color_token, def_font_size, rel_font_size, bold } + +#define AUTOTEXT_END() \ + AUTOTEXT_COLOR( -1, -1, XML_none, XML_TOKEN_INVALID, 1000, 100, false ) + +static const AutoTextEntry spChartTitleTexts[] = +{ + AUTOTEXT_COLOR( 1, 40, XML_minor, XML_tx1, 1800, 120, true ), + AUTOTEXT_COLOR( 41, 48, XML_minor, XML_lt1, 1800, 120, true ), + AUTOTEXT_END() +}; + +static const AutoTextEntry spAxisTitleTexts[] = +{ + AUTOTEXT_COLOR( 1, 40, XML_minor, XML_tx1, 1000, 100, true ), + AUTOTEXT_COLOR( 41, 48, XML_minor, XML_lt1, 1000, 100, true ), + AUTOTEXT_END() +}; + +static const AutoTextEntry spOtherTexts[] = +{ + AUTOTEXT_COLOR( 1, 40, XML_minor, XML_tx1, 1000, 100, false ), + AUTOTEXT_COLOR( 41, 48, XML_minor, XML_lt1, 1000, 100, false ), + AUTOTEXT_END() +}; + +#undef AUTOTEXT_COLOR +#undef AUTOTEXT_END + +const AutoTextEntry* lclGetAutoTextEntry( const AutoTextEntry* pEntries, sal_Int32 nStyle ) +{ + for( ; pEntries && (pEntries->mnFirstStyleIdx >= 0); ++pEntries ) + if( (pEntries->mnFirstStyleIdx <= nStyle) && (nStyle <= pEntries->mnLastStyleIdx) ) + return pEntries; + return nullptr; +} + +// These PropIds arrays will be indexed into using a ShapeProperty enum + +static const ShapePropertyIds spnCommonPropIds = +{ + PROP_LineStyle, PROP_LineWidth, PROP_LineColor, PROP_LineTransparence, PROP_LineDashName, + PROP_LineCap, PROP_INVALID, PROP_INVALID, PROP_INVALID, PROP_INVALID, PROP_INVALID, PROP_INVALID, PROP_INVALID, + PROP_FillStyle, PROP_FillColor, PROP_FillTransparence, PROP_INVALID, PROP_FillGradientName, + PROP_FillBitmapName, PROP_FillBitmapMode, PROP_FillBitmapSizeX, PROP_FillBitmapSizeY, + PROP_FillBitmapPositionOffsetX, PROP_FillBitmapPositionOffsetY, PROP_FillBitmapRectanglePoint, + PROP_FillHatchName, PROP_FillBackground +}; + +static const ShapePropertyIds spnLinearPropIds = +{ + PROP_LineStyle, PROP_LineWidth, PROP_Color, PROP_Transparency, PROP_LineDashName, + PROP_LineCap, PROP_INVALID, PROP_INVALID, PROP_INVALID, PROP_INVALID, PROP_INVALID, PROP_INVALID, PROP_INVALID, + PROP_INVALID, PROP_INVALID, PROP_INVALID, PROP_INVALID, PROP_INVALID, + PROP_INVALID, PROP_INVALID, PROP_INVALID, PROP_INVALID, + PROP_INVALID, PROP_INVALID, PROP_INVALID, + PROP_INVALID, PROP_INVALID +}; + +static const ShapePropertyIds spnFilledPropIds = +{ + PROP_BorderStyle, + PROP_BorderWidth, + PROP_BorderColor, + PROP_BorderTransparency, + PROP_BorderDashName, + PROP_LineCap, + PROP_INVALID, + PROP_INVALID, + PROP_INVALID, + PROP_INVALID, + PROP_INVALID, + PROP_INVALID, + PROP_INVALID, + PROP_FillStyle, + PROP_Color, + PROP_Transparency, + PROP_FillTransparenceGradientName, + PROP_GradientName, + PROP_FillBitmapName, + PROP_FillBitmapMode, + PROP_FillBitmapSizeX, + PROP_FillBitmapSizeY, + PROP_FillBitmapPositionOffsetX, + PROP_FillBitmapPositionOffsetY, + PROP_FillBitmapRectanglePoint, + PROP_HatchName, + PROP_FillBackground +}; + +/** Property info for common chart objects, to be used in ShapePropertyMap. */ +static const ShapePropertyInfo saCommonPropInfo( spnCommonPropIds, false, true, true, true, true ); +/** Property info for linear data series, to be used in ShapePropertyMap. */ +static const ShapePropertyInfo saLinearPropInfo( spnLinearPropIds, false, true, true, true, true ); +/** Property info for filled data series, to be used in ShapePropertyMap. */ +static const ShapePropertyInfo saFilledPropInfo( spnFilledPropIds, false, true, true, true, true ); + +/** Contains information about formatting of a specific chart object type. */ +struct ObjectTypeFormatEntry +{ + ObjectType meObjType; /// Object type for automatic format. + const ShapePropertyInfo& mrPropInfo; /// Property info for the ShapePropertyMap class. + const AutoFormatEntry* mpAutoLines; /// Automatic line formatting for all chart styles. + const AutoFormatEntry* mpAutoFills; /// Automatic fill formatting for all chart styles. + const AutoTextEntry* mpAutoTexts; /// Automatic text attributes for all chart styles. + bool mbIsFrame; /// True = object is a frame, false = object is a line. + ObjectTypeFormatEntry(ObjectType eObjType, const ShapePropertyInfo& rPropInfo, + const AutoFormatEntry* pAutoLines, + const AutoFormatEntry* pAutoFills, + const AutoTextEntry* pAutoTexts, + bool bIsFrame) + :meObjType(eObjType), mrPropInfo(rPropInfo), mpAutoLines(pAutoLines) + ,mpAutoFills(pAutoFills), mpAutoTexts(pAutoTexts), mbIsFrame(bIsFrame) + {} // prevent creation of implicit default ctor which fails in MSVC +}; + +#define TYPEFORMAT_FRAME( obj_type, prop_type, auto_texts, auto_lines, auto_fills ) \ + { obj_type, prop_type, auto_lines, auto_fills, auto_texts, true } + +#define TYPEFORMAT_LINE( obj_type, prop_type, auto_texts, auto_lines ) \ + { obj_type, prop_type, auto_lines, nullptr, auto_texts, false } + +static const ObjectTypeFormatEntry spObjTypeFormatEntries[] = +{ + // object type property info auto text auto line auto fill + TYPEFORMAT_FRAME( OBJECTTYPE_CHARTSPACE, saCommonPropInfo, nullptr, spNoFormats, spChartSpaceFill ), + TYPEFORMAT_FRAME( OBJECTTYPE_CHARTTITLE, saCommonPropInfo, spChartTitleTexts, nullptr /* eq to Ch2 */, nullptr /* eq to Ch2 */), + TYPEFORMAT_FRAME( OBJECTTYPE_LEGEND, saCommonPropInfo, spOtherTexts, spNoFormats, spNoFormats ), + TYPEFORMAT_FRAME( OBJECTTYPE_PLOTAREA2D, saCommonPropInfo, nullptr, nullptr /* eq to Ch2 */, spPlotArea2dFills ), + TYPEFORMAT_FRAME( OBJECTTYPE_PLOTAREA3D, saCommonPropInfo, nullptr, nullptr /* eq to Ch2 */, nullptr /* eq to Ch2 */ ), + TYPEFORMAT_FRAME( OBJECTTYPE_WALL, saCommonPropInfo, nullptr, spWallFloorLines, spWallFloorFills ), + TYPEFORMAT_FRAME( OBJECTTYPE_FLOOR, saCommonPropInfo, nullptr, spWallFloorLines, spWallFloorFills ), + TYPEFORMAT_LINE( OBJECTTYPE_AXIS, saCommonPropInfo, spOtherTexts, spAxisLines ), + TYPEFORMAT_FRAME( OBJECTTYPE_AXISTITLE, saCommonPropInfo, spAxisTitleTexts, nullptr /* eq to Ch2 */, nullptr /* eq to Ch2 */ ), + TYPEFORMAT_FRAME( OBJECTTYPE_AXISUNIT, saCommonPropInfo, spAxisTitleTexts, nullptr /* eq in Ch2 */, nullptr /* eq in Ch2 */ ), + TYPEFORMAT_LINE( OBJECTTYPE_MAJORGRIDLINE, saCommonPropInfo, nullptr, spMajorGridLines ), + TYPEFORMAT_LINE( OBJECTTYPE_MINORGRIDLINE, saCommonPropInfo, nullptr, spMinorGridLines ), + TYPEFORMAT_LINE( OBJECTTYPE_LINEARSERIES2D, saLinearPropInfo, nullptr, spLinearSeriesLines ), + TYPEFORMAT_FRAME( OBJECTTYPE_FILLEDSERIES2D, saFilledPropInfo, nullptr, spFilledSeriesLines, spFilledSeries2dFills ), + TYPEFORMAT_FRAME( OBJECTTYPE_FILLEDSERIES3D, saFilledPropInfo, nullptr, spFilledSeriesLines, spFilledSeries3dFills ), + TYPEFORMAT_FRAME( OBJECTTYPE_DATALABEL, saCommonPropInfo, spOtherTexts, nullptr /* eq to Ch2 */, nullptr /* eq to Ch2 */ ), + TYPEFORMAT_LINE( OBJECTTYPE_TRENDLINE, saCommonPropInfo, nullptr, spOtherLines ), + TYPEFORMAT_FRAME( OBJECTTYPE_TRENDLINELABEL, saCommonPropInfo, spOtherTexts, nullptr /* eq to Ch2 */, nullptr /* eq to Ch2 */ ), + TYPEFORMAT_LINE( OBJECTTYPE_ERRORBAR, saCommonPropInfo, nullptr, spOtherLines ), + TYPEFORMAT_LINE( OBJECTTYPE_SERLINE, saCommonPropInfo, nullptr, spOtherLines ), + TYPEFORMAT_LINE( OBJECTTYPE_LEADERLINE, saCommonPropInfo, nullptr, spOtherLines ), + TYPEFORMAT_LINE( OBJECTTYPE_DROPLINE, saCommonPropInfo, nullptr, spOtherLines ), + TYPEFORMAT_LINE( OBJECTTYPE_HILOLINE, saLinearPropInfo, nullptr, spOtherLines ), + TYPEFORMAT_FRAME( OBJECTTYPE_UPBAR, saCommonPropInfo, nullptr, spUpDownBarLines, spUpBarFills ), + TYPEFORMAT_FRAME( OBJECTTYPE_DOWNBAR, saCommonPropInfo, nullptr, spUpDownBarLines, spDownBarFills ), + TYPEFORMAT_LINE( OBJECTTYPE_DATATABLE, saCommonPropInfo, spOtherTexts, spDataTableLines ) +}; + +#undef TYPEFORMAT_FRAME +#undef TYPEFORMAT_LINE + +void lclConvertPictureOptions( FillProperties& orFillProps, const PictureOptionsModel& rPicOptions ) +{ + bool bStacked = (rPicOptions.mnPictureFormat == XML_stack) || (rPicOptions.mnPictureFormat == XML_stackScale); + orFillProps.maBlipProps.moBitmapMode = bStacked ? XML_tile : XML_stretch; +} + +} // namespace + +struct ObjectFormatterData; + +namespace { + +class DetailFormatterBase +{ +public: + explicit DetailFormatterBase( + ObjectFormatterData& rData, + const AutoFormatEntry* pAutoFormatEntry ); + explicit DetailFormatterBase( + ObjectFormatterData& rData, + const AutoTextEntry* pAutoTextEntry ); + +protected: + /** Returns the placeholder color which may depend on the passed series index. */ + ::Color getPhColor( sal_Int32 nSeriesIdx ) const; + +private: + /** Resolves and returns the scheme color with the passed transformation. */ + ::Color getSchemeColor( sal_Int32 nColorToken, sal_Int32 nModToken, sal_Int32 nModValue ) const; + +protected: + typedef ::std::vector< ::Color > ColorPatternVec; + + ObjectFormatterData& mrData; /// Shared formatter data. + ::Color mnPhClr; /// RGB placeholder color for themed style. + ColorPatternVec maColorPattern; /// Different cycling colors for data series. +}; + +class LineFormatter : public DetailFormatterBase +{ +public: + explicit LineFormatter( + ObjectFormatterData& rData, + const AutoFormatEntry* pAutoFormatEntry, + const ObjectType eObjType ); + + /** Converts line formatting to the passed property set. */ + void convertFormatting( + ShapePropertyMap& rPropMap, + const ModelRef< Shape >& rxShapeProp, + sal_Int32 nSeriesIdx ); + +private: + LinePropertiesPtr mxAutoLine; /// Automatic line properties. +}; + +class FillFormatter : public DetailFormatterBase +{ +public: + explicit FillFormatter( + ObjectFormatterData& rData, + const AutoFormatEntry* pAutoFormatEntry, + const ObjectType eObjType ); + + /** Converts area formatting to the passed property set. */ + void convertFormatting( + ShapePropertyMap& rPropMap, + const ModelRef< Shape >& rxShapeProp, + const PictureOptionsModel* pPicOptions, + sal_Int32 nSeriesIdx ); + +private: + FillPropertiesPtr mxAutoFill; /// Automatic fill properties. +}; + +class TextFormatter : public DetailFormatterBase +{ +public: + explicit TextFormatter( + ObjectFormatterData& rData, + const AutoTextEntry* pAutoTextEntry, + const ModelRef< TextBody >& rxGlobalTextProp ); + + /** Converts text formatting to the passed property set. */ + void convertFormatting( + PropertySet& rPropSet, + const TextCharacterProperties* pTextProps ); + /** Converts text formatting to the passed property set. */ + void convertFormatting( + PropertySet& rPropSet, + const ModelRef< TextBody >& rxTextProp ); + +private: + TextCharacterPropertiesPtr mxAutoText; /// Automatic text properties. +}; + +/** Formatter for a specific object type. */ +class ObjectTypeFormatter +{ +public: + explicit ObjectTypeFormatter( + ObjectFormatterData& rData, + const ObjectTypeFormatEntry& rEntry, + const ChartSpaceModel& rChartSpace, + const ObjectType eObjType ); + + /** Sets frame formatting properties to the passed property set. */ + void convertFrameFormatting( + PropertySet& rPropSet, + const ModelRef< Shape >& rxShapeProp, + const PictureOptionsModel* pPicOptions, + sal_Int32 nSeriesIdx ); + + /** Sets text formatting properties to the passed property set. */ + void convertTextFormatting( + PropertySet& rPropSet, + const ModelRef< TextBody >& rxTextProp ); + + /** Sets frame/text formatting properties to the passed property set. */ + void convertFormatting( + PropertySet& rPropSet, + const ModelRef< Shape >& rxShapeProp, + const ModelRef< TextBody >& rxTextProp ); + + /** Sets text formatting properties to the passed property set. */ + void convertTextFormatting( + PropertySet& rPropSet, + const TextCharacterProperties& rTextProps ); + + /** Sets automatic fill properties to the passed property set. */ + void convertAutomaticFill( + PropertySet& rPropSet, + sal_Int32 nSeriesIdx ); + +private: + LineFormatter maLineFormatter; /// Converter for line formatting. + FillFormatter maFillFormatter; /// Converter for fill formatting. + TextFormatter maTextFormatter; /// Converter for text formatting. + ModelObjectHelper& mrModelObjHelper; /// Helper for named drawing formatting. + const ObjectTypeFormatEntry& mrEntry; /// Additional settings. +}; + +} + +struct ObjectFormatterData +{ + typedef RefMap< ObjectType, ObjectTypeFormatter > ObjectTypeFormatterMap; + + const XmlFilterBase& mrFilter; /// Base filter object. + ObjectTypeFormatterMap maTypeFormatters; /// Formatters for all types of objects in a chart. + ModelObjectHelper maModelObjHelper; /// Helper for named drawing formatting (dashes, gradients, bitmaps). + Reference< XNumberFormats > mxNumFmts; /// Number formats collection of container document. + Reference< XNumberFormatTypes > mxNumTypes; /// Number format types collection of container document. + Locale maEnUsLocale; /// Locale struct containing en-US. + Locale maFromLocale; /// Empty locale struct. + sal_Int32 mnMaxSeriesIdx; /// Maximum series index used for color cycling/fading. + + explicit ObjectFormatterData( + const XmlFilterBase& rFilter, + const Reference< XChartDocument >& rxChartDoc, + const ChartSpaceModel& rChartSpace ); + + ObjectTypeFormatter* getTypeFormatter( ObjectType eObjType ); +}; + +DetailFormatterBase::DetailFormatterBase( ObjectFormatterData& rData, const AutoFormatEntry* pAutoFormatEntry ) : + mrData( rData ), + mnPhClr( 0xffffffff ) +{ + if( !pAutoFormatEntry ) + return; + + if( pAutoFormatEntry->mpPattern ) + { + // prepare multi-color pattern + for( const AutoFormatPatternEntry* pPatternEntry = pAutoFormatEntry->mpPattern; pPatternEntry->mnColorToken != XML_TOKEN_INVALID; ++pPatternEntry ) + maColorPattern.push_back( getSchemeColor( pPatternEntry->mnColorToken, pPatternEntry->mnModToken, pPatternEntry->mnModValue ) ); + } + else if( pAutoFormatEntry->mnColorToken != XML_TOKEN_INVALID ) + { + // prepare color or single-color pattern (color fading) + mnPhClr = getSchemeColor( pAutoFormatEntry->mnColorToken, pAutoFormatEntry->mnModToken, pAutoFormatEntry->mnModValue ); + if( pAutoFormatEntry->mbFadedColor ) + maColorPattern.push_back( mnPhClr ); + } +} + +DetailFormatterBase::DetailFormatterBase( ObjectFormatterData& rData, const AutoTextEntry* pAutoTextEntry ) : + mrData( rData ), + mnPhClr( 0xffffffff ) +{ + if( pAutoTextEntry && (pAutoTextEntry->mnColorToken != XML_TOKEN_INVALID) ) + mnPhClr = getSchemeColor( pAutoTextEntry->mnColorToken, XML_TOKEN_INVALID, 0 ); +} + +::Color DetailFormatterBase::getPhColor( sal_Int32 nSeriesIdx ) const +{ + if( maColorPattern.empty() || (mrData.mnMaxSeriesIdx < 0) || (nSeriesIdx < 0) ) + return mnPhClr; + + /* Apply tint/shade depending on the cycle index. The colors of leading + series are darkened (color shade), the colors of trailing series are + lightened (color tint). Shade/tint is applied in an exclusive range of + -70% to 70%. + + Example 1: 3 data series using single-color shading with accent color 1 + (e.g. automatic chart style #3). Shade/tint is applied per series. + Shade/tint changes in steps of 140%/(<series_count+1) = 140%/4 = 35%, + starting at -70%: + Step 1: -70% -> Not used. + Step 2: -35% -> Series 1 has 35% shade of accent color 1. + Step 3: 0% -> Series 2 has pure accent color 1. + Step 4: 35% -> Series 3 has 35% tint of accent color 1. + Step 5: 70% -> Not used. + + Example 2: 20 data series using accent color pattern (e.g. automatic + chart style #2). Each color cycle has a size of 6 series (accent colors + 1 to 6). Shade/tint is applied per color cycle. + Cycle #1: Series 1...6 are based on accent colors 1 to 6. + Cycle #2: Series 7...12 are based on accent colors 1 to 6. + Cycle #3: Series 13...18 are based on accent colors 1 to 6. + Cycle #4: Series 19...20 are based on accent colors 1 to 2. + Shade/tint changes in steps of 140%/(cycle_count+1) = 140%/5 = 28%, + starting at -70%: + Step 1: -70% -> Not used. + Step 2: -42% -> Cycle #1 has 42% shade of accent colors 1...6 + step 3: -14% -> Cycle #2 has 14% shade of accent colors 1...6 + step 4: 14% -> Cycle #3 has 14% tint of accent colors 1...6 + step 5: 42% -> Cycle #4 has 42% tint of accent colors 1...6 + step 6: 70% -> Not used. + */ + ::Color nPhClr = maColorPattern[ static_cast< size_t >( nSeriesIdx % maColorPattern.size() ) ]; + size_t nCycleIdx = static_cast< size_t >( nSeriesIdx / maColorPattern.size() ); + size_t nMaxCycleIdx = static_cast< size_t >( mrData.mnMaxSeriesIdx / maColorPattern.size() ); + double fShadeTint = static_cast< double >( nCycleIdx + 1 ) / (nMaxCycleIdx + 2) * 1.4 - 0.7; + if( fShadeTint != 0.0 ) + { + Color aColor; + aColor.setSrgbClr( nPhClr ); + aColor.addChartTintTransformation( fShadeTint ); + nPhClr = aColor.getColor( mrData.mrFilter.getGraphicHelper() ); + } + + return nPhClr; +} + +::Color DetailFormatterBase::getSchemeColor( sal_Int32 nColorToken, sal_Int32 nModToken, sal_Int32 nModValue ) const +{ + Color aColor; + aColor.setSchemeClr( nColorToken ); + if( nModToken != XML_TOKEN_INVALID ) + aColor.addTransformation( nModToken, nModValue ); + return aColor.getColor( mrData.mrFilter.getGraphicHelper() ); +} + +LineFormatter::LineFormatter( ObjectFormatterData& rData, const AutoFormatEntry* pAutoFormatEntry, const ObjectType eObjType ) : + DetailFormatterBase(rData, pAutoFormatEntry) +{ + if( !pAutoFormatEntry ) + return; + + mxAutoLine = std::make_shared<LineProperties>(); + mxAutoLine->maLineFill.moFillType = XML_noFill; + if( const Theme* pTheme = mrData.mrFilter.getCurrentTheme() ) + if( const LineProperties* pLineProps = pTheme->getLineStyle( pAutoFormatEntry->mnThemedIdx ) ) + *mxAutoLine = *pLineProps; + // set automatic border property for chartarea, because of tdf#81437 and tdf#82217 + if ( eObjType == OBJECTTYPE_CHARTSPACE ) + { + mxAutoLine->maLineFill.moFillType = oox::GraphicHelper::getDefaultChartAreaLineStyle(); + mxAutoLine->moLineWidth = oox::GraphicHelper::getDefaultChartAreaLineWidth(); + // this value is what MSO 2016 use as a default color for chartspace border + mxAutoLine->maLineFill.maFillColor.setSrgbClr( 0xD9D9D9 ); + } + // change line width according to chart auto style + if( mxAutoLine->moLineWidth.has() ) + mxAutoLine->moLineWidth = mxAutoLine->moLineWidth.get() * pAutoFormatEntry->mnRelLineWidth / 100; +} + +void LineFormatter::convertFormatting( ShapePropertyMap& rPropMap, const ModelRef< Shape >& rxShapeProp, sal_Int32 nSeriesIdx ) +{ + LineProperties aLineProps; + if( mxAutoLine ) + aLineProps.assignUsed( *mxAutoLine ); + if( rxShapeProp.is() ) + aLineProps.assignUsed( rxShapeProp->getLineProperties() ); + aLineProps.pushToPropMap( rPropMap, mrData.mrFilter.getGraphicHelper(), getPhColor( nSeriesIdx ) ); +} + +FillFormatter::FillFormatter( ObjectFormatterData& rData, const AutoFormatEntry* pAutoFormatEntry, const ObjectType eObjType ) : + DetailFormatterBase( rData, pAutoFormatEntry ) +{ + if( !pAutoFormatEntry ) + return; + + mxAutoFill = std::make_shared<FillProperties>(); + if( eObjType != OBJECTTYPE_CHARTSPACE ) + mxAutoFill->moFillType = XML_noFill; + if( const Theme* pTheme = mrData.mrFilter.getCurrentTheme() ) + if( const FillProperties* pFillProps = pTheme->getFillStyle( pAutoFormatEntry->mnThemedIdx ) ) + *mxAutoFill = *pFillProps; + + if (eObjType == OBJECTTYPE_CHARTSPACE) + { + mxAutoFill->moFillType = rData.mrFilter.getGraphicHelper().getDefaultChartAreaFillStyle(); + } +} + +void FillFormatter::convertFormatting( ShapePropertyMap& rPropMap, const ModelRef< Shape >& rxShapeProp, const PictureOptionsModel* pPicOptions, sal_Int32 nSeriesIdx ) +{ + FillProperties aFillProps; + if( mxAutoFill ) + aFillProps.assignUsed( *mxAutoFill ); + if( rxShapeProp.is() ) + aFillProps.assignUsed( rxShapeProp->getFillProperties() ); + if( pPicOptions ) + lclConvertPictureOptions( aFillProps, *pPicOptions ); + aFillProps.pushToPropMap( rPropMap, mrData.mrFilter.getGraphicHelper(), 0, getPhColor( nSeriesIdx ) ); +} + +namespace { + +const TextCharacterProperties* lclGetTextProperties( const ModelRef< TextBody >& rxTextProp ) +{ + return (rxTextProp.is() && !rxTextProp->getParagraphs().empty()) ? + &rxTextProp->getParagraphs().front()->getProperties().getTextCharacterProperties() : nullptr; +} + +} // namespace + +TextFormatter::TextFormatter( ObjectFormatterData& rData, const AutoTextEntry* pAutoTextEntry, const ModelRef< TextBody >& rxGlobalTextProp ) : + DetailFormatterBase( rData, pAutoTextEntry ) +{ + if( !pAutoTextEntry ) + return; + + mxAutoText = std::make_shared<TextCharacterProperties>(); + if( const Theme* pTheme = mrData.mrFilter.getCurrentTheme() ) + if( const TextCharacterProperties* pTextProps = pTheme->getFontStyle( pAutoTextEntry->mnThemedFont ) ) + *mxAutoText = *pTextProps; + ::Color nTextColor = getPhColor( -1 ); + if( sal_Int32(nTextColor) >= 0 ) { + mxAutoText->maFillProperties.maFillColor.setSrgbClr( nTextColor ); + mxAutoText->maFillProperties.moFillType.set(XML_solidFill); + } + mxAutoText->moHeight = pAutoTextEntry->mnDefFontSize; + mxAutoText->moBold = pAutoTextEntry->mbBold; + + if( const TextCharacterProperties* pTextProps = lclGetTextProperties( rxGlobalTextProp ) ) + { + mxAutoText->assignUsed( *pTextProps ); + if( pTextProps->moHeight.has() ) + mxAutoText->moHeight = pTextProps->moHeight.get() * pAutoTextEntry->mnRelFontSize / 100; + } +} + +void TextFormatter::convertFormatting( PropertySet& rPropSet, const TextCharacterProperties* pTextProps ) +{ + TextCharacterProperties aTextProps; + if( mxAutoText ) + aTextProps.assignUsed( *mxAutoText ); + if( pTextProps ) + aTextProps.assignUsed( *pTextProps ); + aTextProps.pushToPropSet( rPropSet, mrData.mrFilter ); +} + +void TextFormatter::convertFormatting( PropertySet& rPropSet, const ModelRef< TextBody >& rxTextProp ) +{ + convertFormatting( rPropSet, lclGetTextProperties( rxTextProp ) ); +} + +ObjectTypeFormatter::ObjectTypeFormatter( ObjectFormatterData& rData, const ObjectTypeFormatEntry& rEntry, const ChartSpaceModel& rChartSpace, const ObjectType eObjType ) : + maLineFormatter( rData, lclGetAutoFormatEntry( rEntry.mpAutoLines, rChartSpace.mnStyle ), eObjType ), + maFillFormatter( rData, lclGetAutoFormatEntry( rEntry.mpAutoFills, rChartSpace.mnStyle ), eObjType ), + maTextFormatter( rData, lclGetAutoTextEntry( rEntry.mpAutoTexts, rChartSpace.mnStyle ), rChartSpace.mxTextProp ), + mrModelObjHelper( rData.maModelObjHelper ), + mrEntry( rEntry ) +{ +} + +void ObjectTypeFormatter::convertFrameFormatting( PropertySet& rPropSet, const ModelRef< Shape >& rxShapeProp, const PictureOptionsModel* pPicOptions, sal_Int32 nSeriesIdx ) +{ + ShapePropertyMap aPropMap( mrModelObjHelper, mrEntry.mrPropInfo ); + maLineFormatter.convertFormatting( aPropMap, rxShapeProp, nSeriesIdx ); + if( mrEntry.mbIsFrame ) + maFillFormatter.convertFormatting( aPropMap, rxShapeProp, pPicOptions, nSeriesIdx ); + rPropSet.setProperties( aPropMap ); +} + +void ObjectTypeFormatter::convertTextFormatting( PropertySet& rPropSet, const ModelRef< TextBody >& rxTextProp ) +{ + maTextFormatter.convertFormatting( rPropSet, rxTextProp ); +} + +void ObjectTypeFormatter::convertFormatting( PropertySet& rPropSet, const ModelRef< Shape >& rxShapeProp, const ModelRef< TextBody >& rxTextProp ) +{ + convertFrameFormatting( rPropSet, rxShapeProp, nullptr, -1 ); + convertTextFormatting( rPropSet, rxTextProp ); +} + +void ObjectTypeFormatter::convertTextFormatting( PropertySet& rPropSet, const TextCharacterProperties& rTextProps ) +{ + maTextFormatter.convertFormatting( rPropSet, &rTextProps ); +} + +void ObjectTypeFormatter::convertAutomaticFill( PropertySet& rPropSet, sal_Int32 nSeriesIdx ) +{ + ShapePropertyMap aPropMap( mrModelObjHelper, mrEntry.mrPropInfo ); + ModelRef< Shape > xShapeProp; + maFillFormatter.convertFormatting( aPropMap, xShapeProp, nullptr, nSeriesIdx ); + rPropSet.setProperties( aPropMap ); +} + +ObjectFormatterData::ObjectFormatterData( const XmlFilterBase& rFilter, const Reference< XChartDocument >& rxChartDoc, const ChartSpaceModel& rChartSpace ) : + mrFilter( rFilter ), + maModelObjHelper( Reference< XMultiServiceFactory >( rxChartDoc, UNO_QUERY ) ), + maEnUsLocale( "en", "US", OUString() ), + mnMaxSeriesIdx( -1 ) +{ + for(auto const &rEntry : spObjTypeFormatEntries) + maTypeFormatters[ rEntry.meObjType ] = std::make_shared<ObjectTypeFormatter>( *this, rEntry, rChartSpace, rEntry.meObjType ); + + try + { + Reference< XNumberFormatsSupplier > xNumFmtsSupp( rxChartDoc, UNO_QUERY_THROW ); + mxNumFmts = xNumFmtsSupp->getNumberFormats(); + mxNumTypes.set( mxNumFmts, UNO_QUERY ); + } + catch( Exception& ) + { + } + OSL_ENSURE( mxNumFmts.is() && mxNumTypes.is(), "ObjectFormatterData::ObjectFormatterData - cannot get number formats" ); +} + +ObjectTypeFormatter* ObjectFormatterData::getTypeFormatter( ObjectType eObjType ) +{ + OSL_ENSURE( maTypeFormatters.has( eObjType ), "ObjectFormatterData::getTypeFormatter - unknown object type" ); + return maTypeFormatters.get( eObjType ).get(); +} + +ObjectFormatter::ObjectFormatter( const XmlFilterBase& rFilter, const Reference< XChartDocument >& rxChartDoc, const ChartSpaceModel& rChartSpace ) : + mxData( std::make_shared<ObjectFormatterData>( rFilter, rxChartDoc, rChartSpace ) ) +{ +} + +ObjectFormatter::~ObjectFormatter() +{ +} + +void ObjectFormatter::setMaxSeriesIndex( sal_Int32 nMaxSeriesIdx ) +{ + mxData->mnMaxSeriesIdx = nMaxSeriesIdx; +} + +sal_Int32 ObjectFormatter::getMaxSeriesIndex() const +{ + return mxData->mnMaxSeriesIdx; +} + +void ObjectFormatter::convertFrameFormatting( PropertySet& rPropSet, const ModelRef< Shape >& rxShapeProp, ObjectType eObjType, sal_Int32 nSeriesIdx ) +{ + if( ObjectTypeFormatter* pFormat = mxData->getTypeFormatter( eObjType ) ) + pFormat->convertFrameFormatting( rPropSet, rxShapeProp, nullptr, nSeriesIdx ); +} + +void ObjectFormatter::convertFrameFormatting( PropertySet& rPropSet, const ModelRef< Shape >& rxShapeProp, const PictureOptionsModel& rPicOptions, ObjectType eObjType, sal_Int32 nSeriesIdx ) +{ + if( ObjectTypeFormatter* pFormat = mxData->getTypeFormatter( eObjType ) ) + pFormat->convertFrameFormatting( rPropSet, rxShapeProp, &rPicOptions, nSeriesIdx ); +} + +void ObjectFormatter::convertTextFormatting( PropertySet& rPropSet, const ModelRef< TextBody >& rxTextProp, ObjectType eObjType ) +{ + if( ObjectTypeFormatter* pFormat = mxData->getTypeFormatter( eObjType ) ) + pFormat->convertTextFormatting( rPropSet, rxTextProp ); +} + +void ObjectFormatter::convertFormatting( PropertySet& rPropSet, const ModelRef< Shape >& rxShapeProp, const ModelRef< TextBody >& rxTextProp, ObjectType eObjType ) +{ + if( ObjectTypeFormatter* pFormat = mxData->getTypeFormatter( eObjType ) ) + pFormat->convertFormatting( rPropSet, rxShapeProp, rxTextProp ); +} + +void ObjectFormatter::convertTextFormatting( PropertySet& rPropSet, const TextCharacterProperties& rTextProps, ObjectType eObjType ) +{ + if( ObjectTypeFormatter* pFormat = mxData->getTypeFormatter( eObjType ) ) + pFormat->convertTextFormatting( rPropSet, rTextProps ); +} + +void ObjectFormatter::convertTextRotation( PropertySet& rPropSet, const ModelRef< TextBody >& rxTextProp, bool bSupportsStacked, sal_Int32 nDefaultRotation ) +{ + if( !rxTextProp.is() ) + return; + + bool bStacked = false; + if( bSupportsStacked ) + { + sal_Int32 nVert = rxTextProp->getTextProperties().moVert.get( XML_horz ); + bStacked = (nVert == XML_wordArtVert) || (nVert == XML_wordArtVertRtl); + rPropSet.setProperty( PROP_StackCharacters, bStacked ); + } + + /* Chart2 expects rotation angle as double value in range of [0,360). + OOXML counts clockwise, Chart2 counts counterclockwise. */ + double fAngle = static_cast< double >( bStacked ? 0 : rxTextProp->getTextProperties().moRotation.get( nDefaultRotation ) ); + // MS Office UI allows values only in range of [-90,90]. + if ( fAngle < -5400000.0 || fAngle > 5400000.0 ) + { + fAngle = 0.0; + } + fAngle = getDoubleIntervalValue< double >( -fAngle / 60000.0, 0.0, 360.0 ); + rPropSet.setProperty( PROP_TextRotation, fAngle ); +} + +void ObjectFormatter::convertTextWrap( PropertySet& rPropSet, const ModelRef< TextBody >& rxTextProp ) +{ + if( !rxTextProp.is() ) + return; + + PropertyMap& aPropMap = rxTextProp->getTextProperties().maPropertyMap; + if( aPropMap.hasProperty(PROP_TextWordWrap) ) + { + Any aValue = aPropMap.getProperty( PROP_TextWordWrap ); + if( aValue.hasValue() ) + { + bool bValue = false; + aValue >>= bValue; + rPropSet.setProperty( PROP_TextWordWrap, bValue ); + } + } +} + +void ObjectFormatter::convertNumberFormat( PropertySet& rPropSet, const NumberFormat& rNumberFormat, bool bAxis, bool bShowPercent ) +{ + if( !mxData->mxNumFmts.is() ) + return; + + const bool bGeneral = rNumberFormat.maFormatCode.equalsIgnoreAsciiCase("general"); + const bool bPercent = !bAxis && bShowPercent && !rNumberFormat.mbSourceLinked; + sal_Int32 nPropId = bPercent ? PROP_PercentageNumberFormat : PROP_NumberFormat; + OUString sFormatCode(rNumberFormat.maFormatCode); + if (bPercent && bGeneral) + sFormatCode = "0%"; + try + { + sal_Int32 nIndex = bGeneral && !bPercent ? + mxData->mxNumTypes->getStandardIndex( mxData->maFromLocale ) : + mxData->mxNumFmts->addNewConverted( sFormatCode, mxData->maEnUsLocale, mxData->maFromLocale ); + if( nIndex >= 0 ) + rPropSet.setProperty( nPropId, nIndex ); + } + catch( Exception& ) + { + OSL_FAIL( OStringBuffer( "ObjectFormatter::convertNumberFormat - cannot create number format '" ). + append( OUStringToOString( rNumberFormat.maFormatCode, osl_getThreadTextEncoding() ) ).append( '\'' ).getStr() ); + } + + // Setting "LinkNumberFormatToSource" does not really work, at least not for axis :-/ + if (!bAxis) + rPropSet.setProperty(PROP_LinkNumberFormatToSource, makeAny(rNumberFormat.mbSourceLinked)); + else + rPropSet.setProperty(PROP_LinkNumberFormatToSource, makeAny(rNumberFormat.maFormatCode.isEmpty())); +} + +void ObjectFormatter::convertAutomaticFill( PropertySet& rPropSet, ObjectType eObjType, sal_Int32 nSeriesIdx ) +{ + if( ObjectTypeFormatter* pFormat = mxData->getTypeFormatter( eObjType ) ) + pFormat->convertAutomaticFill( rPropSet, nSeriesIdx ); +} + +bool ObjectFormatter::isAutomaticFill( const ModelRef< Shape >& rxShapeProp ) +{ + return !rxShapeProp || !rxShapeProp->getFillProperties().moFillType.has(); +} + +bool ObjectFormatter::getTextRotation( const ModelRef< TextBody >& rxTextProp, sal_Int32 nDefaultRotation ) +{ + if( rxTextProp.is() ) + { + double fAnglevalue = static_cast< double >( rxTextProp->getTextProperties().moRotation.get( nDefaultRotation ) ); + if( fAnglevalue < -5400000.0 || fAnglevalue > 5400000.0 || fAnglevalue == 0.0 ) + { + return true; + } + else + { + return false; + } + } + else + { + return false; + } +} + +} // namespace oox + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/oox/source/drawingml/chart/plotareacontext.cxx b/oox/source/drawingml/chart/plotareacontext.cxx new file mode 100644 index 000000000..76f7c7ef1 --- /dev/null +++ b/oox/source/drawingml/chart/plotareacontext.cxx @@ -0,0 +1,205 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <drawingml/chart/plotareacontext.hxx> + +#include <drawingml/shapepropertiescontext.hxx> +#include <drawingml/chart/axiscontext.hxx> +#include <drawingml/chart/plotareamodel.hxx> +#include <drawingml/chart/seriescontext.hxx> +#include <drawingml/chart/typegroupcontext.hxx> +#include <oox/core/xmlfilterbase.hxx> +#include <oox/helper/attributelist.hxx> +#include <oox/token/namespaces.hxx> +#include <oox/token/tokens.hxx> + +namespace oox::drawingml::chart { + +using ::oox::core::ContextHandler2Helper; +using ::oox::core::ContextHandlerRef; + +View3DContext::View3DContext( ContextHandler2Helper& rParent, View3DModel& rModel ) : + ContextBase< View3DModel >( rParent, rModel ) +{ +} + +View3DContext::~View3DContext() +{ +} + +ContextHandlerRef View3DContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) +{ + bool bMSO2007Doc = getFilter().isMSO2007Document(); + switch( getCurrentElement() ) + { + case C_TOKEN( view3D ): + switch( nElement ) + { + case C_TOKEN( depthPercent ): + mrModel.mnDepthPercent = rAttribs.getInteger( XML_val, 100 ); + return nullptr; + case C_TOKEN( hPercent ): + mrModel.monHeightPercent = rAttribs.getInteger( XML_val, 100 ); + return nullptr; + case C_TOKEN( perspective ): + mrModel.mnPerspective = rAttribs.getInteger( XML_val, 30 ); + return nullptr; + case C_TOKEN( rAngAx ): + mrModel.mbRightAngled = rAttribs.getBool( XML_val, !bMSO2007Doc ); + return nullptr; + case C_TOKEN( rotX ): + // default value dependent on chart type + mrModel.monRotationX = rAttribs.getInteger( XML_val ); + return nullptr; + case C_TOKEN( rotY ): + // default value dependent on chart type + mrModel.monRotationY = rAttribs.getInteger( XML_val ); + return nullptr; + } + break; + } + return nullptr; +} + +WallFloorContext::WallFloorContext( ContextHandler2Helper& rParent, WallFloorModel& rModel ) : + ContextBase< WallFloorModel >( rParent, rModel ) +{ +} + +WallFloorContext::~WallFloorContext() +{ +} + +ContextHandlerRef WallFloorContext::onCreateContext( sal_Int32 nElement, const AttributeList& ) +{ + bool bMSO2007Doc = getFilter().isMSO2007Document(); + switch( getCurrentElement() ) + { + case C_TOKEN( backWall ): + case C_TOKEN( floor ): + case C_TOKEN( sideWall ): + switch( nElement ) + { + case C_TOKEN( pictureOptions ): + return new PictureOptionsContext( *this, mrModel.mxPicOptions.create(bMSO2007Doc) ); + case C_TOKEN( spPr ): + return new ShapePropertiesContext( *this, mrModel.mxShapeProp.create() ); + } + break; + } + return nullptr; +} + +DataTableContext::DataTableContext( ContextHandler2Helper& rParent, DataTableModel& rModel ) : + ContextBase< DataTableModel >( rParent, rModel ) +{ +} + +DataTableContext::~DataTableContext() +{ +} + +ContextHandlerRef DataTableContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs) +{ + switch( getCurrentElement() ) + { + case C_TOKEN( dTable ): + switch( nElement ) + { + case C_TOKEN( showHorzBorder ): + mrModel.mbShowHBorder = rAttribs.getBool( XML_val, false ); + break; + case C_TOKEN( showVertBorder ): + mrModel.mbShowVBorder = rAttribs.getBool( XML_val, false ); + break; + case C_TOKEN( showOutline ): + mrModel.mbShowOutline = rAttribs.getBool( XML_val, false ); + break; + } + break; + } + return nullptr; +} + +PlotAreaContext::PlotAreaContext( ContextHandler2Helper& rParent, PlotAreaModel& rModel ) : + ContextBase< PlotAreaModel >( rParent, rModel ) +{ +} + +PlotAreaContext::~PlotAreaContext() +{ +} + +ContextHandlerRef PlotAreaContext::onCreateContext( sal_Int32 nElement, const AttributeList& ) +{ + bool bMSO2007Doc = getFilter().isMSO2007Document(); + switch( getCurrentElement() ) + { + case C_TOKEN( plotArea ): + switch( nElement ) + { + case C_TOKEN( area3DChart ): + case C_TOKEN( areaChart ): + return new AreaTypeGroupContext( *this, mrModel.maTypeGroups.create( nElement, bMSO2007Doc ) ); + case C_TOKEN( bar3DChart ): + case C_TOKEN( barChart ): + return new BarTypeGroupContext( *this, mrModel.maTypeGroups.create( nElement, bMSO2007Doc ) ); + case C_TOKEN( bubbleChart ): + return new BubbleTypeGroupContext( *this, mrModel.maTypeGroups.create( nElement, bMSO2007Doc ) ); + case C_TOKEN( line3DChart ): + 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 ): + case C_TOKEN( pie3DChart ): + case C_TOKEN( pieChart ): + return new PieTypeGroupContext( *this, mrModel.maTypeGroups.create( nElement, bMSO2007Doc ) ); + case C_TOKEN( radarChart ): + return new RadarTypeGroupContext( *this, mrModel.maTypeGroups.create( nElement, bMSO2007Doc ) ); + case C_TOKEN( scatterChart ): + return new ScatterTypeGroupContext( *this, mrModel.maTypeGroups.create( nElement, bMSO2007Doc ) ); + case C_TOKEN( surface3DChart ): + case C_TOKEN( surfaceChart ): + return new SurfaceTypeGroupContext( *this, mrModel.maTypeGroups.create( nElement, bMSO2007Doc ) ); + + case C_TOKEN( catAx ): + return new CatAxisContext( *this, mrModel.maAxes.create( nElement, bMSO2007Doc ) ); + case C_TOKEN( dateAx ): + return new DateAxisContext( *this, mrModel.maAxes.create( nElement, bMSO2007Doc ) ); + case C_TOKEN( serAx ): + return new SerAxisContext( *this, mrModel.maAxes.create( nElement, bMSO2007Doc ) ); + case C_TOKEN( valAx ): + return new ValAxisContext( *this, mrModel.maAxes.create( nElement, bMSO2007Doc ) ); + + case C_TOKEN( layout ): + return new LayoutContext( *this, mrModel.mxLayout.create() ); + case C_TOKEN( spPr ): + return new ShapePropertiesContext( *this, mrModel.mxShapeProp.create() ); + case C_TOKEN(dTable): + return new DataTableContext( *this, mrModel.mxDataTable.create() ); + } + break; + } + return nullptr; +} + +} // namespace oox::drawingml::chart + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/oox/source/drawingml/chart/plotareaconverter.cxx b/oox/source/drawingml/chart/plotareaconverter.cxx new file mode 100644 index 000000000..8a8a721a1 --- /dev/null +++ b/oox/source/drawingml/chart/plotareaconverter.cxx @@ -0,0 +1,485 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <drawingml/chart/plotareaconverter.hxx> + +#include <com/sun/star/chart/XChartDocument.hpp> +#include <com/sun/star/chart/XDiagramPositioning.hpp> +#include <com/sun/star/chart2/XChartDocument.hpp> +#include <com/sun/star/chart2/XCoordinateSystemContainer.hpp> +#include <com/sun/star/chart2/XDiagram.hpp> +#include <com/sun/star/drawing/Direction3D.hpp> +#include <com/sun/star/drawing/ProjectionMode.hpp> +#include <com/sun/star/drawing/ShadeMode.hpp> +#include <osl/diagnose.h> +#include <drawingml/chart/axisconverter.hxx> +#include <drawingml/chart/plotareamodel.hxx> +#include <drawingml/chart/typegroupconverter.hxx> +#include <oox/core/xmlfilterbase.hxx> +#include <oox/token/namespaces.hxx> +#include <oox/token/properties.hxx> +#include <oox/token/tokens.hxx> +#include <tools/helpers.hxx> + +namespace oox::drawingml::chart { + +using namespace ::com::sun::star; +using namespace ::com::sun::star::chart2; +using namespace ::com::sun::star::uno; + +namespace { + +/** Axes set model. This is a helper for the plot area converter collecting all + type groups and axes of the primary or secondary axes set. */ +struct AxesSetModel +{ + typedef ModelVector< TypeGroupModel > TypeGroupVector; + typedef ModelMap< sal_Int32, AxisModel > AxisMap; + + TypeGroupVector maTypeGroups; /// All type groups containing data series. + AxisMap maAxes; /// All axes mapped by API axis type. + + explicit AxesSetModel() {} +}; + +/** Axes set converter. This is a helper class for the plot area converter. */ +class AxesSetConverter : public ConverterBase< AxesSetModel > +{ +public: + explicit AxesSetConverter( const ConverterRoot& rParent, AxesSetModel& rModel ); + + /** Converts the axes set model to a chart2 diagram. Returns an automatic + chart title from a single series title, if possible. */ + void convertFromModel( + const Reference< XDiagram >& rxDiagram, + View3DModel& rView3DModel, + sal_Int32 nAxesSetIdx, + bool bSupportsVaryColorsByPoint ); + + /** Returns the automatic chart title if the axes set contains only one series. */ + const OUString& getAutomaticTitle() const { return maAutoTitle; } + /** Returns true, if the chart is three-dimensional. */ + bool is3dChart() const { return mb3dChart; } + /** Returns true, if chart type supports wall and floor format in 3D mode. */ + bool isWall3dChart() const { return mbWall3dChart; } + /** Returns true, if chart is a pie chart or doughnut chart. */ + bool isPieChart() const { return mbPieChart; } + +private: + OUString maAutoTitle; + bool mb3dChart; + bool mbWall3dChart; + bool mbPieChart; +}; + +AxesSetConverter::AxesSetConverter( const ConverterRoot& rParent, AxesSetModel& rModel ) : + ConverterBase< AxesSetModel >( rParent, rModel ), + mb3dChart( false ), + mbWall3dChart( false ), + mbPieChart( false ) +{ +} + +ModelRef< AxisModel > lclGetOrCreateAxis( const AxesSetModel::AxisMap& rFromAxes, sal_Int32 nAxisIdx, sal_Int32 nDefTypeId, bool bMSO2007Doc ) +{ + ModelRef< AxisModel > xAxis = rFromAxes.get( nAxisIdx ); + if( !xAxis ) + xAxis.create( nDefTypeId, bMSO2007Doc ).mbDeleted = true; // missing axis is invisible + return xAxis; +} + +void AxesSetConverter::convertFromModel( const Reference< XDiagram >& rxDiagram, + View3DModel& rView3DModel, sal_Int32 nAxesSetIdx, bool bSupportsVaryColorsByPoint ) +{ + // create type group converter objects for all type groups + typedef RefVector< TypeGroupConverter > TypeGroupConvVector; + TypeGroupConvVector aTypeGroups; + for (auto const& typeGroup : mrModel.maTypeGroups) + aTypeGroups.push_back( std::make_shared<TypeGroupConverter>( *this, *typeGroup ) ); + + OSL_ENSURE( !aTypeGroups.empty(), "AxesSetConverter::convertFromModel - no type groups in axes set" ); + if( aTypeGroups.empty() ) + return; + + try + { + // first type group needed for coordinate system and axis conversion + TypeGroupConverter& rFirstTypeGroup = *aTypeGroups.front(); + + // get automatic chart title, if there is only one type group + if( aTypeGroups.size() == 1 ) + maAutoTitle = rFirstTypeGroup.getSingleSeriesTitle(); + + /* Create a coordinate system. For now, all type groups from all axes sets + have to be inserted into one coordinate system. Later, chart2 should + support using one coordinate system for each axes set. */ + Reference< XCoordinateSystem > xCoordSystem; + Reference< XCoordinateSystemContainer > xCoordSystemCont( rxDiagram, UNO_QUERY_THROW ); + Sequence< Reference< XCoordinateSystem > > aCoordSystems = xCoordSystemCont->getCoordinateSystems(); + if( aCoordSystems.hasElements() ) + { + OSL_ENSURE( aCoordSystems.getLength() == 1, "AxesSetConverter::convertFromModel - too many coordinate systems" ); + xCoordSystem = aCoordSystems[ 0 ]; + OSL_ENSURE( xCoordSystem.is(), "AxesSetConverter::convertFromModel - invalid coordinate system" ); + } + else + { + xCoordSystem = rFirstTypeGroup.createCoordinateSystem(); + if( xCoordSystem.is() ) + xCoordSystemCont->addCoordinateSystem( xCoordSystem ); + } + + // 3D view settings + mb3dChart = rFirstTypeGroup.is3dChart(); + mbWall3dChart = rFirstTypeGroup.isWall3dChart(); + mbPieChart = rFirstTypeGroup.getTypeInfo().meTypeCategory == TYPECATEGORY_PIE; + if( mb3dChart ) + { + View3DConverter aView3DConv( *this, rView3DModel ); + aView3DConv.convertFromModel( rxDiagram, rFirstTypeGroup ); + } + + /* Convert all chart type groups. Each type group will add its series + to the data provider attached to the chart document. */ + if( xCoordSystem.is() ) + { + bool bMSO2007Doc = getFilter().isMSO2007Document(); + // convert all axes (create missing axis models) + ModelRef< AxisModel > xXAxis = lclGetOrCreateAxis( mrModel.maAxes, API_X_AXIS, rFirstTypeGroup.getTypeInfo().mbCategoryAxis ? C_TOKEN( catAx ) : C_TOKEN( valAx ), bMSO2007Doc ); + ModelRef< AxisModel > xYAxis = lclGetOrCreateAxis( mrModel.maAxes, API_Y_AXIS, C_TOKEN( valAx ), bMSO2007Doc ); + + AxisConverter aXAxisConv( *this, *xXAxis ); + aXAxisConv.convertFromModel( xCoordSystem, aTypeGroups, xYAxis.get(), nAxesSetIdx, API_X_AXIS ); + AxisConverter aYAxisConv( *this, *xYAxis ); + aYAxisConv.convertFromModel( xCoordSystem, aTypeGroups, xXAxis.get(), nAxesSetIdx, API_Y_AXIS ); + + if( rFirstTypeGroup.isDeep3dChart() ) + { + ModelRef< AxisModel > xZAxis = lclGetOrCreateAxis( mrModel.maAxes, API_Z_AXIS, C_TOKEN( serAx ), bMSO2007Doc ); + AxisConverter aZAxisConv( *this, *xZAxis ); + aZAxisConv.convertFromModel( xCoordSystem, aTypeGroups, nullptr, nAxesSetIdx, API_Z_AXIS ); + } + + // convert all chart type groups, this converts all series data and formatting + for (auto const& typeGroup : aTypeGroups) + typeGroup->convertFromModel( rxDiagram, xCoordSystem, nAxesSetIdx, bSupportsVaryColorsByPoint ); + } + } + catch( Exception& ) + { + } +} + +} // namespace + +View3DConverter::View3DConverter( const ConverterRoot& rParent, View3DModel& rModel ) : + ConverterBase< View3DModel >( rParent, rModel ) +{ +} + +View3DConverter::~View3DConverter() +{ +} + +void View3DConverter::convertFromModel( const Reference< XDiagram >& rxDiagram, TypeGroupConverter const & rTypeGroup ) +{ + namespace cssd = ::com::sun::star::drawing; + PropertySet aPropSet( rxDiagram ); + + sal_Int32 nRotationY = 0; + sal_Int32 nRotationX = 0; + bool bRightAngled = false; + sal_Int32 nAmbientColor = 0; + sal_Int32 nLightColor = 0; + + if( rTypeGroup.getTypeInfo().meTypeCategory == TYPECATEGORY_PIE ) + { + // Y rotation used as 'first pie slice angle' in 3D pie charts + rTypeGroup.convertPieRotation( aPropSet, mrModel.monRotationY.get( 0 ) ); + // X rotation a.k.a. elevation (map OOXML [0..90] to Chart2 [-90,0]) + nRotationX = getLimitedValue< sal_Int32, sal_Int32 >( mrModel.monRotationX.get( 15 ), 0, 90 ) - 90; + // no right-angled axes in pie charts + bRightAngled = false; + // ambient color (Gray 30%) + nAmbientColor = 0xB3B3B3; + // light color (Gray 70%) + nLightColor = 0x4C4C4C; + } + else // 3D bar/area/line charts + { + // Y rotation (OOXML [0..359], Chart2 [-179,180]) + nRotationY = mrModel.monRotationY.get( 20 ); + // X rotation a.k.a. elevation (OOXML [-90..90], Chart2 [-179,180]) + nRotationX = getLimitedValue< sal_Int32, sal_Int32 >( mrModel.monRotationX.get( 15 ), -90, 90 ); + // right-angled axes + bRightAngled = mrModel.mbRightAngled; + // ambient color (Gray 20%) + nAmbientColor = 0xCCCCCC; + // light color (Gray 60%) + nLightColor = 0x666666; + } + + // Y rotation (map OOXML [0..359] to Chart2 [-179,180]) + nRotationY = NormAngle180(nRotationY); + /* Perspective (map OOXML [0..200] to Chart2 [0,100]). Seems that MSO 2007 is + buggy here, the XML plugin of MSO 2003 writes the correct perspective in + the range from 0 to 100. We will emulate the wrong behaviour of MSO 2007. */ + sal_Int32 nPerspective = getLimitedValue< sal_Int32, sal_Int32 >( mrModel.mnPerspective / 2, 0, 100 ); + // projection mode (parallel axes, if right-angled, #i90360# or if perspective is at 0%) + bool bParallel = bRightAngled || (nPerspective == 0); + cssd::ProjectionMode eProjMode = bParallel ? cssd::ProjectionMode_PARALLEL : cssd::ProjectionMode_PERSPECTIVE; + + // set rotation properties + aPropSet.setProperty( PROP_RightAngledAxes, bRightAngled ); + aPropSet.setProperty( PROP_RotationVertical, nRotationY ); + aPropSet.setProperty( PROP_RotationHorizontal, nRotationX ); + aPropSet.setProperty( PROP_Perspective, nPerspective ); + aPropSet.setProperty( PROP_D3DScenePerspective, eProjMode ); + + // set light settings + aPropSet.setProperty( PROP_D3DSceneShadeMode, cssd::ShadeMode_FLAT ); + aPropSet.setProperty( PROP_D3DSceneAmbientColor, nAmbientColor ); + aPropSet.setProperty( PROP_D3DSceneLightOn1, false ); + aPropSet.setProperty( PROP_D3DSceneLightOn2, true ); + aPropSet.setProperty( PROP_D3DSceneLightColor2, nLightColor ); + aPropSet.setProperty( PROP_D3DSceneLightDirection2, cssd::Direction3D( 0.2, 0.4, 1.0 ) ); +} + +WallFloorConverter::WallFloorConverter( const ConverterRoot& rParent, WallFloorModel& rModel ) : + ConverterBase< WallFloorModel >( rParent, rModel ) +{ +} + +WallFloorConverter::~WallFloorConverter() +{ +} + +void WallFloorConverter::convertFromModel( const Reference< XDiagram >& rxDiagram, ObjectType eObjType ) +{ + bool bMSO2007Doc = getFilter().isMSO2007Document(); + if( rxDiagram.is() ) + { + PropertySet aPropSet; + switch( eObjType ) + { + case OBJECTTYPE_FLOOR: aPropSet.set( rxDiagram->getFloor() ); break; + case OBJECTTYPE_WALL: aPropSet.set( rxDiagram->getWall() ); break; + default: OSL_FAIL( "WallFloorConverter::convertFromModel - invalid object type" ); + } + if( aPropSet.is() ) + getFormatter().convertFrameFormatting( aPropSet, mrModel.mxShapeProp, mrModel.mxPicOptions.getOrCreate(bMSO2007Doc), eObjType ); + } +} + +DataTableConverter::DataTableConverter( const ConverterRoot& rParent, DataTableModel& rModel ) : + ConverterBase< DataTableModel >( rParent, rModel ) +{ +} + +DataTableConverter::~DataTableConverter() +{ +} + +void DataTableConverter::convertFromModel( const Reference< XDiagram >& rxDiagram ) +{ + PropertySet aPropSet( rxDiagram ); + if (mrModel.mbShowHBorder) + aPropSet.setProperty( PROP_DataTableHBorder, mrModel.mbShowHBorder ); + if (mrModel.mbShowVBorder) + aPropSet.setProperty( PROP_DataTableVBorder, mrModel.mbShowVBorder); + if (mrModel.mbShowOutline) + aPropSet.setProperty( PROP_DataTableOutline, mrModel.mbShowOutline ); +} + +PlotAreaConverter::PlotAreaConverter( const ConverterRoot& rParent, PlotAreaModel& rModel ) : + ConverterBase< PlotAreaModel >( rParent, rModel ), + mb3dChart( false ), + mbWall3dChart( false ), + mbPieChart( false ) +{ +} + +PlotAreaConverter::~PlotAreaConverter() +{ +} + +void PlotAreaConverter::convertFromModel( View3DModel& rView3DModel ) +{ + /* Create the diagram object and attach it to the chart document. One + diagram is used to carry all coordinate systems and data series. */ + Reference< XDiagram > xDiagram; + try + { + xDiagram.set( createInstance( "com.sun.star.chart2.Diagram" ), UNO_QUERY_THROW ); + getChartDocument()->setFirstDiagram( xDiagram ); + } + catch( Exception& ) + { + } + + // store all axis models in a map, keyed by axis identifier + typedef ModelMap< sal_Int32, AxisModel > AxisMap; + AxisMap aAxisMap; + std::vector<sal_Int32>rValAxisIds; + std::vector<sal_Int32>rRealValAxisIds; + + for (auto const& atypeGroup : mrModel.maTypeGroups) + { + if (atypeGroup->maAxisIds.size() > 1) + { + // let's collect which axId belongs to the Y Axis according to maTypeGroups + rRealValAxisIds.push_back(atypeGroup->maAxisIds[1]); + } + } + + for (auto const& axis : mrModel.maAxes) + { + OSL_ENSURE( axis->mnAxisId >= 0, "PlotAreaConverter::convertFromModel - invalid axis identifier" ); + OSL_ENSURE( !aAxisMap.has( axis->mnAxisId ), "PlotAreaConverter::convertFromModel - axis identifiers not unique" ); + if( axis->mnAxisId != -1 ) + aAxisMap[ axis->mnAxisId ] = axis; + + if ( axis->mnAxisId != -1 && axis->mnTypeId == C_TOKEN(valAx) ) + { + for (size_t i = 0; i < rRealValAxisIds.size(); i++) + { + if (axis->mnAxisId == rRealValAxisIds[i]) + { + // let's collect which axId belongs to the Y Axis according to maAxes + rValAxisIds.push_back(axis->mnAxisId); + } + } + } + } + + // group the type group models into different axes sets + typedef ModelVector< AxesSetModel > AxesSetVector; + AxesSetVector aAxesSets; + sal_Int32 nMaxSeriesIdx = -1; + for (auto const& typeGroup : mrModel.maTypeGroups) + { + if( !typeGroup->maSeries.empty() ) + { + // try to find a compatible axes set for the type group + AxesSetModel* pAxesSet = nullptr; + for (auto const& axesSet : aAxesSets) + { + if( axesSet->maTypeGroups.front()->maAxisIds == typeGroup->maAxisIds ) + { + pAxesSet = axesSet.get(); + if (pAxesSet) + break; + } + } + + // not possible to insert into an existing axes set -> start a new axes set + if( !pAxesSet ) + { + pAxesSet = &aAxesSets.create(); + // find axis models used by the type group + const std::vector<sal_Int32>& rAxisIds = typeGroup->maAxisIds; + if( !rAxisIds.empty() ) + pAxesSet->maAxes[ API_X_AXIS ] = aAxisMap.get( rAxisIds[ 0 ] ); + if( rAxisIds.size() >= 2 ) + pAxesSet->maAxes[ API_Y_AXIS ] = aAxisMap.get( rAxisIds[ 1 ] ); + if( rAxisIds.size() >= 3 ) + pAxesSet->maAxes[ API_Z_AXIS ] = aAxisMap.get( rAxisIds[ 2 ] ); + } + + // insert the type group model + pAxesSet->maTypeGroups.push_back( typeGroup ); + + // collect the maximum series index for automatic series formatting + for (auto const& elemSeries : typeGroup->maSeries) + nMaxSeriesIdx = ::std::max( nMaxSeriesIdx, elemSeries->mnIndex ); + } + } + getFormatter().setMaxSeriesIndex( nMaxSeriesIdx ); + + // varying point colors only for single series in single chart type + bool bSupportsVaryColorsByPoint = mrModel.maTypeGroups.size() == 1; + + // convert all axes sets, and check which axis is attached to the first maTypeGroups + sal_Int32 nStartAxesSetIdx = (rValAxisIds.size() > 1 && aAxesSets.size() > 0 && aAxesSets[0]->maAxes.count( API_Y_AXIS ) + && aAxesSets[0]->maAxes[ API_Y_AXIS ]->mnAxisId != rValAxisIds[0] ) ? 1 : 0; + sal_Int32 nAxesSetIdx = nStartAxesSetIdx; + + for (auto const& axesSet : aAxesSets) + { + AxesSetConverter aAxesSetConv(*this, *axesSet); + aAxesSetConv.convertFromModel( xDiagram, rView3DModel, nAxesSetIdx, bSupportsVaryColorsByPoint ); + if(nAxesSetIdx == nStartAxesSetIdx) + { + maAutoTitle = aAxesSetConv.getAutomaticTitle(); + mb3dChart = aAxesSetConv.is3dChart(); + mbWall3dChart = aAxesSetConv.isWall3dChart(); + mbPieChart = aAxesSetConv.isPieChart(); + } + else + { + maAutoTitle.clear(); + } + nAxesSetIdx = 1 - nAxesSetIdx; + } + + DataTableConverter dataTableConverter (*this, mrModel.mxDataTable.getOrCreate()); + dataTableConverter.convertFromModel(xDiagram); + // plot area formatting + if( xDiagram.is() && !mb3dChart ) + { + PropertySet aPropSet( xDiagram->getWall() ); + getFormatter().convertFrameFormatting( aPropSet, mrModel.mxShapeProp, OBJECTTYPE_PLOTAREA2D ); + } +} + +void PlotAreaConverter::convertPositionFromModel() +{ + LayoutModel& rLayout = mrModel.mxLayout.getOrCreate(); + LayoutConverter aLayoutConv( *this, rLayout ); + awt::Rectangle aDiagramRect; + if( !aLayoutConv.calcAbsRectangle( aDiagramRect ) ) + return; + + try + { + namespace cssc = ::com::sun::star::chart; + Reference< cssc::XChartDocument > xChart1Doc( getChartDocument(), UNO_QUERY_THROW ); + Reference< cssc::XDiagramPositioning > xPositioning( xChart1Doc->getDiagram(), UNO_QUERY_THROW ); + // for pie charts, always set inner plot area size to exclude the data labels as Excel does + sal_Int32 nTarget = (mbPieChart && (rLayout.mnTarget == XML_outer)) ? XML_inner : rLayout.mnTarget; + switch( nTarget ) + { + case XML_inner: + xPositioning->setDiagramPositionExcludingAxes( aDiagramRect ); + break; + case XML_outer: + xPositioning->setDiagramPositionIncludingAxes( aDiagramRect ); + break; + default: + OSL_FAIL( "PlotAreaConverter::convertPositionFromModel - unknown positioning target" ); + } + } + catch( Exception& ) + { + } +} + +} // namespace oox + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/oox/source/drawingml/chart/plotareamodel.cxx b/oox/source/drawingml/chart/plotareamodel.cxx new file mode 100644 index 000000000..72abacc20 --- /dev/null +++ b/oox/source/drawingml/chart/plotareamodel.cxx @@ -0,0 +1,64 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <drawingml/chart/plotareamodel.hxx> + +namespace oox::drawingml::chart { + +View3DModel::View3DModel(bool bMSO2007Doc) : + mnDepthPercent( 100 ), + mnPerspective( 30 ), + mbRightAngled( !bMSO2007Doc ) +{ +} + +View3DModel::~View3DModel() +{ +} + +WallFloorModel::WallFloorModel() +{ +} + +WallFloorModel::~WallFloorModel() +{ +} + +DataTableModel::DataTableModel() : + mbShowHBorder(false), + mbShowVBorder(false), + mbShowOutline(false) +{ +} + +DataTableModel::~DataTableModel() +{ +} + +PlotAreaModel::PlotAreaModel() +{ +} + +PlotAreaModel::~PlotAreaModel() +{ +} + +} // namespace oox::drawingml::chart + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/oox/source/drawingml/chart/seriescontext.cxx b/oox/source/drawingml/chart/seriescontext.cxx new file mode 100644 index 000000000..912b7252e --- /dev/null +++ b/oox/source/drawingml/chart/seriescontext.cxx @@ -0,0 +1,708 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <drawingml/chart/seriescontext.hxx> + +#include <drawingml/shapepropertiescontext.hxx> +#include <drawingml/textbodycontext.hxx> +#include <drawingml/chart/datasourcecontext.hxx> +#include <drawingml/chart/seriesmodel.hxx> +#include <drawingml/chart/titlecontext.hxx> +#include <oox/core/xmlfilterbase.hxx> +#include <oox/helper/attributelist.hxx> +#include <oox/token/namespaces.hxx> +#include <oox/token/tokens.hxx> + +namespace oox::drawingml::chart { + +using ::oox::core::ContextHandler2; +using ::oox::core::ContextHandler2Helper; +using ::oox::core::ContextHandlerRef; + +namespace { + +ContextHandlerRef lclDataLabelSharedCreateContext( ContextHandler2& rContext, + sal_Int32 nElement, const AttributeList& rAttribs, DataLabelModelBase& orModel, bool bMSO2007 ) +{ + if( rContext.isRootElement() ) switch( nElement ) + { + case C_TOKEN( delete ): + orModel.mbDeleted = rAttribs.getBool( XML_val, !bMSO2007 ); + return nullptr; + case C_TOKEN( dLblPos ): + orModel.monLabelPos = rAttribs.getToken( XML_val, XML_TOKEN_INVALID ); + return nullptr; + case C_TOKEN( numFmt ): + orModel.maNumberFormat.setAttributes( rAttribs ); + return nullptr; + case C_TOKEN( showBubbleSize ): + orModel.mobShowBubbleSize = rAttribs.getBool( XML_val ); + return nullptr; + case C_TOKEN( showCatName ): + orModel.mobShowCatName = rAttribs.getBool( XML_val ); + return nullptr; + case C_TOKEN( showLegendKey ): + orModel.mobShowLegendKey = rAttribs.getBool( XML_val ); + return nullptr; + case C_TOKEN( showPercent ): + orModel.mobShowPercent = rAttribs.getBool( XML_val ); + return nullptr; + case C_TOKEN( showSerName ): + orModel.mobShowSerName = rAttribs.getBool( XML_val ); + return nullptr; + case C_TOKEN( showVal ): + orModel.mobShowVal = rAttribs.getBool( XML_val ); + return nullptr; + case C_TOKEN( separator ): + // collect separator text in onCharacters() + return &rContext; + case C_TOKEN( spPr ): + return new ShapePropertiesContext( rContext, orModel.mxShapeProp.create() ); + case C_TOKEN( txPr ): + return new TextBodyContext( rContext, orModel.mxTextProp.create() ); + } + return nullptr; +} + +void lclDataLabelSharedCharacters( ContextHandler2 const & rContext, const OUString& rChars, DataLabelModelBase& orModel ) +{ + if( rContext.isCurrentElement( C_TOKEN( separator ) ) ) + orModel.moaSeparator = rChars; +} + +} // namespace + +DataLabelContext::DataLabelContext( ContextHandler2Helper& rParent, DataLabelModel& rModel ) : + ContextBase< DataLabelModel >( rParent, rModel ) +{ + mrModel.mbDeleted = false; +} + +DataLabelContext::~DataLabelContext() +{ +} + +ContextHandlerRef DataLabelContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) +{ + if( isRootElement() ) switch( nElement ) + { + case C_TOKEN( idx ): + mrModel.mnIndex = rAttribs.getInteger( XML_val, -1 ); + return nullptr; + case C_TOKEN( layout ): + return new LayoutContext( *this, mrModel.mxLayout.create() ); + case C_TOKEN( tx ): + return new TextContext( *this, mrModel.mxText.create() ); + } + bool bMSO2007 = getFilter().isMSO2007Document(); + return lclDataLabelSharedCreateContext( *this, nElement, rAttribs, mrModel, bMSO2007 ); +} + +void DataLabelContext::onCharacters( const OUString& rChars ) +{ + lclDataLabelSharedCharacters( *this, rChars, mrModel ); +} + +DataLabelsContext::DataLabelsContext( ContextHandler2Helper& rParent, DataLabelsModel& rModel ) : + ContextBase< DataLabelsModel >( rParent, rModel ) +{ + mrModel.mbDeleted = false; +} + +DataLabelsContext::~DataLabelsContext() +{ +} + +ContextHandlerRef DataLabelsContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) +{ + bool bMSO2007Doc = getFilter().isMSO2007Document(); + if( isRootElement() ) switch( nElement ) + { + case C_TOKEN( dLbl ): + return new DataLabelContext( *this, mrModel.maPointLabels.create(bMSO2007Doc) ); + case C_TOKEN( leaderLines ): + return new ShapePrWrapperContext( *this, mrModel.mxLeaderLines.create() ); + case C_TOKEN( showLeaderLines ): + mrModel.mbShowLeaderLines = rAttribs.getBool( XML_val, !bMSO2007Doc ); + return nullptr; + } + return lclDataLabelSharedCreateContext( *this, nElement, rAttribs, mrModel, bMSO2007Doc ); +} + +void DataLabelsContext::onCharacters( const OUString& rChars ) +{ + lclDataLabelSharedCharacters( *this, rChars, mrModel ); +} + +PictureOptionsContext::PictureOptionsContext( ContextHandler2Helper& rParent, PictureOptionsModel& rModel ) : + ContextBase< PictureOptionsModel >( rParent, rModel ) +{ +} + +PictureOptionsContext::~PictureOptionsContext() +{ +} + +ContextHandlerRef PictureOptionsContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) +{ + bool bMSO2007Doc = getFilter().isMSO2007Document(); + if( isRootElement() ) switch( nElement ) + { + case C_TOKEN( applyToEnd ): + mrModel.mbApplyToEnd = rAttribs.getBool( XML_val, !bMSO2007Doc ); + return nullptr; + case C_TOKEN( applyToFront ): + mrModel.mbApplyToFront = rAttribs.getBool( XML_val, !bMSO2007Doc ); + return nullptr; + case C_TOKEN( applyToSides ): + mrModel.mbApplyToSides = rAttribs.getBool( XML_val, !bMSO2007Doc ); + return nullptr; + case C_TOKEN( pictureFormat ): + mrModel.mnPictureFormat = rAttribs.getToken( XML_val, XML_stretch ); + return nullptr; + case C_TOKEN( pictureStackUnit ): + mrModel.mfStackUnit = rAttribs.getDouble( XML_val, 1.0 ); + return nullptr; + } + return nullptr; +} + +ErrorBarContext::ErrorBarContext( ContextHandler2Helper& rParent, ErrorBarModel& rModel ) : + ContextBase< ErrorBarModel >( rParent, rModel ) +{ +} + +ErrorBarContext::~ErrorBarContext() +{ +} + +ContextHandlerRef ErrorBarContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) +{ + bool bMSO2007Doc = getFilter().isMSO2007Document(); + if( isRootElement() ) switch( nElement ) + { + case C_TOKEN( errBarType ): + mrModel.mnTypeId = rAttribs.getToken( XML_val, XML_both ); + return nullptr; + case C_TOKEN( errDir ): + mrModel.mnDirection = rAttribs.getToken( XML_val, XML_TOKEN_INVALID ); + return nullptr; + case C_TOKEN( errValType ): + mrModel.mnValueType = rAttribs.getToken( XML_val, XML_fixedVal ); + return nullptr; + case C_TOKEN( minus ): + return new DataSourceContext( *this, mrModel.maSources.create( ErrorBarModel::MINUS ) ); + case C_TOKEN( noEndCap ): + mrModel.mbNoEndCap = rAttribs.getBool( XML_val, !bMSO2007Doc ); + return nullptr; + case C_TOKEN( plus ): + return new DataSourceContext( *this, mrModel.maSources.create( ErrorBarModel::PLUS ) ); + case C_TOKEN( spPr ): + return new ShapePropertiesContext( *this, mrModel.mxShapeProp.create() ); + case C_TOKEN( val ): + mrModel.mfValue = rAttribs.getDouble( XML_val, 0.0 ); + return nullptr; + } + return nullptr; +} + +TrendlineLabelContext::TrendlineLabelContext( ContextHandler2Helper& rParent, TrendlineLabelModel& rModel ) : + ContextBase< TrendlineLabelModel >( rParent, rModel ) +{ +} + +TrendlineLabelContext::~TrendlineLabelContext() +{ +} + +ContextHandlerRef TrendlineLabelContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) +{ + if( isRootElement() ) switch( nElement ) + { + case C_TOKEN( layout ): + return new LayoutContext( *this, mrModel.mxLayout.create() ); + case C_TOKEN( numFmt ): + mrModel.maNumberFormat.setAttributes( rAttribs ); + return nullptr; + case C_TOKEN( spPr ): + return new ShapePropertiesContext( *this, mrModel.mxShapeProp.create() ); + case C_TOKEN( tx ): + return new TextContext( *this, mrModel.mxText.create() ); + case C_TOKEN( txPr ): + return new TextBodyContext( *this, mrModel.mxTextProp.create() ); + } + return nullptr; +} + +TrendlineContext::TrendlineContext( ContextHandler2Helper& rParent, TrendlineModel& rModel ) : + ContextBase< TrendlineModel >( rParent, rModel ) +{ +} + +TrendlineContext::~TrendlineContext() +{ +} + +ContextHandlerRef TrendlineContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) +{ + bool bMSO2007Doc = getFilter().isMSO2007Document(); + if( isRootElement() ) switch( nElement ) + { + case C_TOKEN( backward ): + mrModel.mfBackward = rAttribs.getDouble( XML_val, 0.0 ); + return nullptr; + case C_TOKEN( dispEq ): + mrModel.mbDispEquation = rAttribs.getBool( XML_val, !bMSO2007Doc ); + return nullptr; + case C_TOKEN( dispRSqr ): + mrModel.mbDispRSquared = rAttribs.getBool( XML_val, !bMSO2007Doc ); + return nullptr; + case C_TOKEN( forward ): + mrModel.mfForward = rAttribs.getDouble( XML_val, 0.0 ); + return nullptr; + case C_TOKEN( intercept ): + mrModel.mfIntercept = rAttribs.getDouble( XML_val, 0.0 ); + return nullptr; + case C_TOKEN( name ): + return this; // collect name in onCharacters() + case C_TOKEN( order ): + mrModel.mnOrder = rAttribs.getInteger( XML_val, 2 ); + return nullptr; + case C_TOKEN( period ): + mrModel.mnPeriod = rAttribs.getInteger( XML_val, 2 ); + return nullptr; + case C_TOKEN( spPr ): + return new ShapePropertiesContext( *this, mrModel.mxShapeProp.create() ); + case C_TOKEN( trendlineLbl ): + return new TrendlineLabelContext( *this, mrModel.mxLabel.create() ); + case C_TOKEN( trendlineType ): + mrModel.mnTypeId = rAttribs.getToken( XML_val, XML_linear ); + return nullptr; + } + return nullptr; +} + +void TrendlineContext::onCharacters( const OUString& rChars ) +{ + if( isCurrentElement( C_TOKEN( name ) ) ) + mrModel.maName = rChars; +} + +DataPointContext::DataPointContext( ContextHandler2Helper& rParent, DataPointModel& rModel ) : + ContextBase< DataPointModel >( rParent, rModel ) +{ +} + +DataPointContext::~DataPointContext() +{ +} + +ContextHandlerRef DataPointContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) +{ + bool bMSO2007Doc = getFilter().isMSO2007Document(); + switch( getCurrentElement() ) + { + case C_TOKEN( dPt ): + switch( nElement ) + { + case C_TOKEN( bubble3D ): + mrModel.mobBubble3d = rAttribs.getBool( XML_val ); + return nullptr; + case C_TOKEN( explosion ): + // if the 'val' attribute is missing, series explosion remains unchanged + mrModel.monExplosion = rAttribs.getInteger( XML_val ); + return nullptr; + case C_TOKEN( idx ): + mrModel.mnIndex = rAttribs.getInteger( XML_val, -1 ); + return nullptr; + case C_TOKEN( invertIfNegative ): + mrModel.mbInvertNeg = rAttribs.getBool( XML_val, !bMSO2007Doc ); + return nullptr; + case C_TOKEN( marker ): + return this; + case C_TOKEN( pictureOptions ): + return new PictureOptionsContext( *this, mrModel.mxPicOptions.create(bMSO2007Doc) ); + case C_TOKEN( spPr ): + return new ShapePropertiesContext( *this, mrModel.mxShapeProp.create() ); + } + break; + + case C_TOKEN( marker ): + switch( nElement ) + { + case C_TOKEN( size ): + mrModel.monMarkerSize = rAttribs.getInteger( XML_val, 5 ); + return nullptr; + case C_TOKEN( spPr ): + return new ShapePropertiesContext( *this, mrModel.mxMarkerProp.create() ); + case C_TOKEN( symbol ): + mrModel.monMarkerSymbol = rAttribs.getToken( XML_val, XML_none ); + return nullptr; + } + break; + } + return nullptr; +} + +SeriesContextBase::SeriesContextBase( ContextHandler2Helper& rParent, SeriesModel& rModel ) : + ContextBase< SeriesModel >( rParent, rModel ) +{ +} + +SeriesContextBase::~SeriesContextBase() +{ +} + +ContextHandlerRef SeriesContextBase::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) +{ + switch( getCurrentElement() ) + { + case C_TOKEN( ser ): + switch( nElement ) + { + case C_TOKEN( idx ): + mrModel.mnIndex = rAttribs.getInteger( XML_val, -1 ); + return nullptr; + case C_TOKEN( order ): + mrModel.mnOrder = rAttribs.getInteger( XML_val, -1 ); + return nullptr; + case C_TOKEN( spPr ): + return new ShapePropertiesContext( *this, mrModel.mxShapeProp.create() ); + case C_TOKEN( tx ): + return new TextContext( *this, mrModel.mxText.create() ); + } + break; + + case C_TOKEN( marker ): + switch( nElement ) + { + case C_TOKEN( size ): + mrModel.mnMarkerSize = rAttribs.getInteger( XML_val, 5 ); + return nullptr; + case C_TOKEN( spPr ): + return new ShapePropertiesContext( *this, mrModel.mxMarkerProp.create() ); + case C_TOKEN( symbol ): + mrModel.mnMarkerSymbol = rAttribs.getToken( XML_val, XML_none ); + return nullptr; + } + break; + } + return nullptr; +} + +AreaSeriesContext::AreaSeriesContext( ContextHandler2Helper& rParent, SeriesModel& rModel ) : + SeriesContextBase( rParent, rModel ) +{ +} + +AreaSeriesContext::~AreaSeriesContext() +{ +} + +ContextHandlerRef AreaSeriesContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) +{ + bool bMSO2007Doc = getFilter().isMSO2007Document(); + switch( getCurrentElement() ) + { + case C_TOKEN( ser ): + switch( nElement ) + { + case C_TOKEN( cat ): + return new DataSourceContext( *this, mrModel.maSources.create( SeriesModel::CATEGORIES ) ); + case C_TOKEN( errBars ): + return new ErrorBarContext( *this, mrModel.maErrorBars.create(bMSO2007Doc) ); + case C_TOKEN( dLbls ): + return new DataLabelsContext( *this, mrModel.mxLabels.create(bMSO2007Doc) ); + case C_TOKEN( dPt ): + return new DataPointContext( *this, mrModel.maPoints.create(bMSO2007Doc) ); + case C_TOKEN( trendline ): + return new TrendlineContext( *this, mrModel.maTrendlines.create(bMSO2007Doc) ); + case C_TOKEN( val ): + return new DataSourceContext( *this, mrModel.maSources.create( SeriesModel::VALUES ) ); + } + break; + } + return SeriesContextBase::onCreateContext( nElement, rAttribs ); +} + +BarSeriesContext::BarSeriesContext( ContextHandler2Helper& rParent, SeriesModel& rModel ) : + SeriesContextBase( rParent, rModel ) +{ +} + +BarSeriesContext::~BarSeriesContext() +{ +} + +ContextHandlerRef BarSeriesContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) +{ + bool bMSO2007Doc = getFilter().isMSO2007Document(); + switch( getCurrentElement() ) + { + case C_TOKEN( ser ): + switch( nElement ) + { + case C_TOKEN( cat ): + return new DataSourceContext( *this, mrModel.maSources.create( SeriesModel::CATEGORIES ) ); + case C_TOKEN( dLbls ): + return new DataLabelsContext( *this, mrModel.mxLabels.create(bMSO2007Doc) ); + case C_TOKEN( dPt ): + return new DataPointContext( *this, mrModel.maPoints.create(bMSO2007Doc) ); + case C_TOKEN( errBars ): + return new ErrorBarContext( *this, mrModel.maErrorBars.create(bMSO2007Doc) ); + case C_TOKEN( invertIfNegative ): + mrModel.mbInvertNeg = rAttribs.getBool( XML_val, !bMSO2007Doc ); + return nullptr; + case C_TOKEN( pictureOptions ): + return new PictureOptionsContext( *this, mrModel.mxPicOptions.create(bMSO2007Doc) ); + case C_TOKEN( shape ): + mrModel.monShape = rAttribs.getToken(XML_val); + return nullptr; + case C_TOKEN( trendline ): + return new TrendlineContext( *this, mrModel.maTrendlines.create(bMSO2007Doc) ); + case C_TOKEN( val ): + return new DataSourceContext( *this, mrModel.maSources.create( SeriesModel::VALUES ) ); + } + break; + } + return SeriesContextBase::onCreateContext( nElement, rAttribs ); +} + +BubbleSeriesContext::BubbleSeriesContext( ContextHandler2Helper& rParent, SeriesModel& rModel ) : + SeriesContextBase( rParent, rModel ) +{ +} + +BubbleSeriesContext::~BubbleSeriesContext() +{ +} + +ContextHandlerRef BubbleSeriesContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) +{ + bool bMSO2007Doc = getFilter().isMSO2007Document(); + switch( getCurrentElement() ) + { + case C_TOKEN( ser ): + switch( nElement ) + { + case C_TOKEN( bubble3D ): + mrModel.mbBubble3d = rAttribs.getBool( XML_val, !bMSO2007Doc ); + return nullptr; + case C_TOKEN( bubbleSize ): + return new DataSourceContext( *this, mrModel.maSources.create( SeriesModel::POINTS ) ); + case C_TOKEN( dLbls ): + return new DataLabelsContext( *this, mrModel.mxLabels.create(bMSO2007Doc) ); + case C_TOKEN( dPt ): + return new DataPointContext( *this, mrModel.maPoints.create(bMSO2007Doc) ); + case C_TOKEN( errBars ): + return new ErrorBarContext( *this, mrModel.maErrorBars.create(bMSO2007Doc) ); + case C_TOKEN( invertIfNegative ): + mrModel.mbInvertNeg = rAttribs.getBool( XML_val, !bMSO2007Doc ); + return nullptr; + case C_TOKEN( trendline ): + return new TrendlineContext( *this, mrModel.maTrendlines.create(bMSO2007Doc) ); + case C_TOKEN( xVal ): + return new DataSourceContext( *this, mrModel.maSources.create( SeriesModel::CATEGORIES ) ); + case C_TOKEN( yVal ): + return new DataSourceContext( *this, mrModel.maSources.create( SeriesModel::VALUES ) ); + } + break; + } + return SeriesContextBase::onCreateContext( nElement, rAttribs ); +} + +LineSeriesContext::LineSeriesContext( ContextHandler2Helper& rParent, SeriesModel& rModel ) : + SeriesContextBase( rParent, rModel ) +{ +} + +LineSeriesContext::~LineSeriesContext() +{ +} + +ContextHandlerRef LineSeriesContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) +{ + bool bMSO2007Doc = getFilter().isMSO2007Document(); + switch( getCurrentElement() ) + { + case C_TOKEN( ser ): + switch( nElement ) + { + case C_TOKEN( cat ): + return new DataSourceContext( *this, mrModel.maSources.create( SeriesModel::CATEGORIES ) ); + case C_TOKEN( dLbls ): + return new DataLabelsContext( *this, mrModel.mxLabels.create(bMSO2007Doc) ); + case C_TOKEN( dPt ): + return new DataPointContext( *this, mrModel.maPoints.create(bMSO2007Doc) ); + case C_TOKEN( errBars ): + return new ErrorBarContext( *this, mrModel.maErrorBars.create(bMSO2007Doc) ); + case C_TOKEN( marker ): + return this; + case C_TOKEN( smooth ): + mrModel.mbSmooth = rAttribs.getBool( XML_val, !bMSO2007Doc ); + return nullptr; + case C_TOKEN( trendline ): + return new TrendlineContext( *this, mrModel.maTrendlines.create(bMSO2007Doc) ); + case C_TOKEN( val ): + return new DataSourceContext( *this, mrModel.maSources.create( SeriesModel::VALUES ) ); + } + break; + } + return SeriesContextBase::onCreateContext( nElement, rAttribs ); +} + +PieSeriesContext::PieSeriesContext( ContextHandler2Helper& rParent, SeriesModel& rModel ) : + SeriesContextBase( rParent, rModel ) +{ +} + +PieSeriesContext::~PieSeriesContext() +{ +} + +ContextHandlerRef PieSeriesContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) +{ + bool bMSO2007Doc = getFilter().isMSO2007Document(); + switch( getCurrentElement() ) + { + case C_TOKEN( ser ): + switch( nElement ) + { + case C_TOKEN( cat ): + return new DataSourceContext( *this, mrModel.maSources.create( SeriesModel::CATEGORIES ) ); + case C_TOKEN( dLbls ): + return new DataLabelsContext( *this, mrModel.mxLabels.create(bMSO2007Doc) ); + case C_TOKEN( dPt ): + return new DataPointContext( *this, mrModel.maPoints.create(bMSO2007Doc) ); + case C_TOKEN( explosion ): + mrModel.mnExplosion = rAttribs.getInteger( XML_val, 0 ); + return nullptr; + case C_TOKEN( val ): + return new DataSourceContext( *this, mrModel.maSources.create( SeriesModel::VALUES ) ); + } + break; + } + return SeriesContextBase::onCreateContext( nElement, rAttribs ); +} + +RadarSeriesContext::RadarSeriesContext( ContextHandler2Helper& rParent, SeriesModel& rModel ) : + SeriesContextBase( rParent, rModel ) +{ +} + +RadarSeriesContext::~RadarSeriesContext() +{ +} + +ContextHandlerRef RadarSeriesContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) +{ + bool bMSO2007Doc = getFilter().isMSO2007Document(); + switch( getCurrentElement() ) + { + case C_TOKEN( ser ): + switch( nElement ) + { + case C_TOKEN( cat ): + return new DataSourceContext( *this, mrModel.maSources.create( SeriesModel::CATEGORIES ) ); + case C_TOKEN( dLbls ): + return new DataLabelsContext( *this, mrModel.mxLabels.create(bMSO2007Doc) ); + case C_TOKEN( dPt ): + return new DataPointContext( *this, mrModel.maPoints.create(bMSO2007Doc) ); + case C_TOKEN( marker ): + return this; + case C_TOKEN( smooth ): + mrModel.mbSmooth = rAttribs.getBool( XML_val, bMSO2007Doc ); + return nullptr; + case C_TOKEN( val ): + return new DataSourceContext( *this, mrModel.maSources.create( SeriesModel::VALUES ) ); + } + break; + } + return SeriesContextBase::onCreateContext( nElement, rAttribs ); +} + +ScatterSeriesContext::ScatterSeriesContext( ContextHandler2Helper& rParent, SeriesModel& rModel ) : + SeriesContextBase( rParent, rModel ) +{ +} + +ScatterSeriesContext::~ScatterSeriesContext() +{ +} + +ContextHandlerRef ScatterSeriesContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) +{ + bool bMSO2007Doc = getFilter().isMSO2007Document(); + switch( getCurrentElement() ) + { + case C_TOKEN( ser ): + switch( nElement ) + { + case C_TOKEN( dLbls ): + return new DataLabelsContext( *this, mrModel.mxLabels.create(bMSO2007Doc) ); + case C_TOKEN( dPt ): + return new DataPointContext( *this, mrModel.maPoints.create(bMSO2007Doc) ); + case C_TOKEN( errBars ): + return new ErrorBarContext( *this, mrModel.maErrorBars.create(bMSO2007Doc) ); + case C_TOKEN( marker ): + return this; + case C_TOKEN( smooth ): + mrModel.mbSmooth = rAttribs.getBool( XML_val, !bMSO2007Doc ); + return nullptr; + case C_TOKEN( trendline ): + return new TrendlineContext( *this, mrModel.maTrendlines.create(bMSO2007Doc) ); + case C_TOKEN( xVal ): + return new DataSourceContext( *this, mrModel.maSources.create( SeriesModel::CATEGORIES ) ); + case C_TOKEN( yVal ): + return new DataSourceContext( *this, mrModel.maSources.create( SeriesModel::VALUES ) ); + } + break; + } + return SeriesContextBase::onCreateContext( nElement, rAttribs ); +} + +SurfaceSeriesContext::SurfaceSeriesContext( ContextHandler2Helper& rParent, SeriesModel& rModel ) : + SeriesContextBase( rParent, rModel ) +{ +} + +SurfaceSeriesContext::~SurfaceSeriesContext() +{ +} + +ContextHandlerRef SurfaceSeriesContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) +{ + switch( getCurrentElement() ) + { + case C_TOKEN( ser ): + switch( nElement ) + { + case C_TOKEN( cat ): + return new DataSourceContext( *this, mrModel.maSources.create( SeriesModel::CATEGORIES ) ); + case C_TOKEN( val ): + return new DataSourceContext( *this, mrModel.maSources.create( SeriesModel::VALUES ) ); + } + break; + } + return SeriesContextBase::onCreateContext( nElement, rAttribs ); +} + +} // namespace oox + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/oox/source/drawingml/chart/seriesconverter.cxx b/oox/source/drawingml/chart/seriesconverter.cxx new file mode 100644 index 000000000..32ee4fbd2 --- /dev/null +++ b/oox/source/drawingml/chart/seriesconverter.cxx @@ -0,0 +1,884 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <drawingml/chart/seriesconverter.hxx> + +#include <com/sun/star/chart/DataLabelPlacement.hpp> +#include <com/sun/star/chart2/RelativePosition.hpp> +#include <com/sun/star/chart/ErrorBarStyle.hpp> +#include <com/sun/star/chart2/DataPointLabel.hpp> +#include <com/sun/star/drawing/Hatch.hpp> +#include <com/sun/star/chart2/XChartDocument.hpp> +#include <com/sun/star/chart2/XDataPointCustomLabelField.hpp> +#include <com/sun/star/chart2/DataPointCustomLabelField.hpp> +#include <com/sun/star/chart2/DataPointCustomLabelFieldType.hpp> +#include <com/sun/star/chart2/XDataSeries.hpp> +#include <com/sun/star/chart2/XRegressionCurve.hpp> +#include <com/sun/star/chart2/XRegressionCurveContainer.hpp> +#include <com/sun/star/chart2/data/XDataSink.hpp> +#include <com/sun/star/chart2/data/LabeledDataSequence.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/drawing/FillStyle.hpp> +#include <osl/diagnose.h> +#include <drawingml/chart/datasourceconverter.hxx> +#include <drawingml/chart/seriesmodel.hxx> +#include <drawingml/chart/titleconverter.hxx> +#include <drawingml/chart/typegroupconverter.hxx> +#include <drawingml/chart/typegroupmodel.hxx> +#include <drawingml/fillproperties.hxx> +#include <oox/core/xmlfilterbase.hxx> +#include <oox/helper/containerhelper.hxx> +#include <oox/helper/modelobjecthelper.hxx> +#include <oox/token/properties.hxx> +#include <oox/token/tokens.hxx> +#include <drawingml/lineproperties.hxx> +#include <drawingml/textparagraph.hxx> +#include <drawingml/textrun.hxx> +#include <drawingml/textfield.hxx> +#include <drawingml/textbody.hxx> +#include <drawingml/hatchmap.hxx> + +namespace oox::drawingml::chart { + +using namespace com::sun::star; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::chart2; +using namespace ::com::sun::star::chart2::data; +using namespace ::com::sun::star::uno; + +namespace { + +Reference< XLabeledDataSequence > lclCreateLabeledDataSequence( + const ConverterRoot& rParent, + DataSourceModel* pValues, const OUString& rRole, + TextModel* pTitle = nullptr ) +{ + // create data sequence for values + Reference< XDataSequence > xValueSeq; + if( pValues ) + { + DataSourceConverter aSourceConv( rParent, *pValues ); + xValueSeq = aSourceConv.createDataSequence( rRole ); + } + + // create data sequence for title + Reference< XDataSequence > xTitleSeq; + if( pTitle ) + { + TextConverter aTextConv( rParent, *pTitle ); + xTitleSeq = aTextConv.createDataSequence( "label" ); + } + + // create the labeled data sequence, if values or title are present + Reference< XLabeledDataSequence > xLabeledSeq; + if( xValueSeq.is() || xTitleSeq.is() ) + { + xLabeledSeq = LabeledDataSequence::create(rParent.getComponentContext()); + if( xLabeledSeq.is() ) + { + xLabeledSeq->setValues( xValueSeq ); + xLabeledSeq->setLabel( xTitleSeq ); + } + } + return xLabeledSeq; +} + +void convertTextProperty(PropertySet& rPropSet, ObjectFormatter& rFormatter, + DataLabelModelBase::TextBodyRef xTextProps) +{ + rFormatter.convertTextFormatting( rPropSet, xTextProps, OBJECTTYPE_DATALABEL ); + ObjectFormatter::convertTextRotation( rPropSet, xTextProps, false ); + ObjectFormatter::convertTextWrap( rPropSet, xTextProps ); +} + +void lclConvertLabelFormatting( PropertySet& rPropSet, ObjectFormatter& rFormatter, + DataLabelModelBase& rDataLabel, const TypeGroupConverter& rTypeGroup, + bool bDataSeriesLabel, bool bHasInternalData, bool bMSO2007Doc ) +{ + const TypeGroupInfo& rTypeInfo = rTypeGroup.getTypeInfo(); + + /* Excel 2007 does not change the series setting for a single data point, + if none of some specific elements occur. But only one existing element + in a data point will reset most other of these elements from the series + (e.g.: series has <c:showVal>, data point has <c:showCatName>, this + will reset <c:showVal> for this point, unless <c:showVal> is repeated + in the data point). The elements <c:layout>, <c:numberFormat>, + <c:spPr>, <c:tx>, and <c:txPr> are not affected at all. */ + bool bHasAnyElement = true; + if (bMSO2007Doc) + { + bHasAnyElement = rDataLabel.moaSeparator.has() || rDataLabel.monLabelPos.has() || + rDataLabel.mobShowCatName.has() || rDataLabel.mobShowLegendKey.has() || + rDataLabel.mobShowPercent.has() || rDataLabel.mobShowSerName.has() || + rDataLabel.mobShowVal.has(); + } + + bool bShowValue = !rDataLabel.mbDeleted && rDataLabel.mobShowVal.get( !bMSO2007Doc ); + bool bShowPercent = !rDataLabel.mbDeleted && rDataLabel.mobShowPercent.get( !bMSO2007Doc ) && (rTypeInfo.meTypeCategory == TYPECATEGORY_PIE); + bool bShowCateg = !rDataLabel.mbDeleted && rDataLabel.mobShowCatName.get( !bMSO2007Doc ); + bool bShowSymbol = !rDataLabel.mbDeleted && rDataLabel.mobShowLegendKey.get( !bMSO2007Doc ); + + // tdf#132174, tdf#136650: the inner data table has no own cell number format. + if( bHasInternalData && bShowValue && !bShowPercent ) + rDataLabel.maNumberFormat.mbSourceLinked = false; + + // type of attached label + if( bHasAnyElement || rDataLabel.mbDeleted ) + { + DataPointLabel aPointLabel( bShowValue, bShowPercent, bShowCateg, bShowSymbol ); + rPropSet.setProperty( PROP_Label, aPointLabel ); + } + + if( rDataLabel.mbDeleted ) + return; + + // data label number format (percentage format wins over value format) + rFormatter.convertNumberFormat( rPropSet, rDataLabel.maNumberFormat, false, bShowPercent ); + + // data label text formatting (frame formatting not supported by Chart2) + if( bDataSeriesLabel || (rDataLabel.mxTextProp.is() && !rDataLabel.mxTextProp->getParagraphs().empty()) ) + convertTextProperty(rPropSet, rFormatter, rDataLabel.mxTextProp); + + // data label separator (do not overwrite series separator, if no explicit point separator is present) + // Set the data label separator to "new line" if the value is shown as percentage with a category name, + // just like in MS-Office. In any other case the default separator will be a semicolon. + if( bShowPercent && !bShowValue && ( bDataSeriesLabel || rDataLabel.moaSeparator.has() ) ) + rPropSet.setProperty( PROP_LabelSeparator, rDataLabel.moaSeparator.get( "\n" ) ); + else if( bDataSeriesLabel || rDataLabel.moaSeparator.has() ) + rPropSet.setProperty( PROP_LabelSeparator, rDataLabel.moaSeparator.get( "; " ) ); + + // data label placement (do not overwrite series placement, if no explicit point placement is present) + if( !(bDataSeriesLabel || rDataLabel.monLabelPos.has()) ) + return; + + namespace csscd = ::com::sun::star::chart::DataLabelPlacement; + sal_Int32 nPlacement = -1; + switch( rDataLabel.monLabelPos.get( XML_TOKEN_INVALID ) ) + { + case XML_outEnd: nPlacement = csscd::OUTSIDE; break; + case XML_inEnd: nPlacement = csscd::INSIDE; break; + case XML_ctr: nPlacement = csscd::CENTER; break; + case XML_inBase: nPlacement = csscd::NEAR_ORIGIN; break; + case XML_t: nPlacement = csscd::TOP; break; + case XML_b: nPlacement = csscd::BOTTOM; break; + case XML_l: nPlacement = csscd::LEFT; break; + case XML_r: nPlacement = csscd::RIGHT; break; + case XML_bestFit: nPlacement = csscd::AVOID_OVERLAP; break; + } + + if( !bDataSeriesLabel && nPlacement == -1 ) + return; + + if( nPlacement == -1 ) + nPlacement = rTypeInfo.mnDefLabelPos; + + rPropSet.setProperty( PROP_LabelPlacement, nPlacement ); +} + +void importBorderProperties( PropertySet& rPropSet, Shape& rShape, const GraphicHelper& rGraphicHelper ) +{ + LineProperties& rLP = rShape.getLineProperties(); + // no fill has the same effect as no border so skip it + if (rLP.maLineFill.moFillType.get() == XML_noFill) + return; + + if (rLP.moLineWidth.has()) + { + sal_Int32 nWidth = convertEmuToHmm(rLP.moLineWidth.get()); + rPropSet.setProperty(PROP_LabelBorderWidth, uno::makeAny(nWidth)); + rPropSet.setProperty(PROP_LabelBorderStyle, uno::makeAny(drawing::LineStyle_SOLID)); + } + const Color& aColor = rLP.maLineFill.maFillColor; + ::Color nColor = aColor.getColor(rGraphicHelper); + rPropSet.setProperty(PROP_LabelBorderColor, uno::makeAny(nColor)); +} + +void importFillProperties( PropertySet& rPropSet, Shape& rShape, const GraphicHelper& rGraphicHelper, ModelObjectHelper& rModelObjHelper ) +{ + FillProperties& rFP = rShape.getFillProperties(); + + if (rFP.moFillType.has() && rFP.moFillType.get() == XML_solidFill) + { + rPropSet.setProperty(PROP_LabelFillStyle, drawing::FillStyle_SOLID); + + const Color& aColor = rFP.maFillColor; + ::Color nColor = aColor.getColor(rGraphicHelper); + rPropSet.setProperty(PROP_LabelFillColor, uno::makeAny(nColor)); + } + else if(rFP.moFillType.has() && rFP.moFillType.get() == XML_pattFill) + { + rPropSet.setProperty(PROP_LabelFillStyle, drawing::FillStyle_HATCH); + rPropSet.setProperty(PROP_LabelFillBackground, true); + + Color aHatchColor( rFP.maPatternProps.maPattFgColor ); + drawing::Hatch aHatch = createHatch(rFP.maPatternProps.moPattPreset.get(), aHatchColor.getColor(rGraphicHelper, 0)); + + OUString sHatchName = rModelObjHelper.insertFillHatch(aHatch); + rPropSet.setProperty(PROP_LabelFillHatchName, sHatchName); + + const Color& aColor = rFP.maPatternProps.maPattBgColor; + ::Color nColor = aColor.getColor(rGraphicHelper); + rPropSet.setProperty(PROP_LabelFillColor, uno::makeAny(nColor)); + } + +} + +DataPointCustomLabelFieldType lcl_ConvertFieldNameToFieldEnum( const OUString& rField ) +{ + if (rField == "VALUE") + return DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_VALUE; + else if (rField == "SERIESNAME") + return DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_SERIESNAME; + else if (rField == "CATEGORYNAME") + return DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_CATEGORYNAME; + else if (rField == "CELLREF") + return DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_CELLREF; + else if (rField == "PERCENTAGE") + return DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_PERCENTAGE; + else + return DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_TEXT; +} + +} // namespace + +DataLabelConverter::DataLabelConverter( const ConverterRoot& rParent, DataLabelModel& rModel ) : + ConverterBase< DataLabelModel >( rParent, rModel ) +{ +} + +DataLabelConverter::~DataLabelConverter() +{ +} + +void DataLabelConverter::convertFromModel( const Reference< XDataSeries >& rxDataSeries, const TypeGroupConverter& rTypeGroup ) +{ + if (!rxDataSeries.is()) + return; + + try + { + bool bMSO2007Doc = getFilter().isMSO2007Document(); + bool bHasInternalData = getChartDocument()->hasInternalDataProvider(); + PropertySet aPropSet( rxDataSeries->getDataPointByIndex( mrModel.mnIndex ) ); + + lclConvertLabelFormatting( aPropSet, getFormatter(), mrModel, rTypeGroup, false, bHasInternalData, bMSO2007Doc ); + + const TypeGroupInfo& rTypeInfo = rTypeGroup.getTypeInfo(); + bool bIsPie = rTypeInfo.meTypeCategory == TYPECATEGORY_PIE; + + if( mrModel.mxLayout && !mrModel.mxLayout->mbAutoLayout && !bIsPie ) + { + RelativePosition aPos(mrModel.mxLayout->mfX, mrModel.mxLayout->mfY, css::drawing::Alignment_TOP_LEFT); + aPropSet.setProperty(PROP_CustomLabelPosition, aPos); + } + + if (mrModel.mxShapeProp) + { + importBorderProperties(aPropSet, *mrModel.mxShapeProp, getFilter().getGraphicHelper()); + uno::Reference<lang::XMultiServiceFactory> xFactory(getChartDocument(), uno::UNO_QUERY); + ModelObjectHelper& rHelper = getFilter().getModelObjectHelperForModel(xFactory); + importFillProperties(aPropSet, *mrModel.mxShapeProp, getFilter().getGraphicHelper(), + rHelper); + } + if( mrModel.mxText && mrModel.mxText->mxTextBody && !mrModel.mxText->mxTextBody->getParagraphs().empty() ) + { + css::uno::Reference< XComponentContext > xContext = getComponentContext(); + uno::Sequence< css::uno::Reference< XDataPointCustomLabelField > > aSequence; + + auto& rParagraphs = mrModel.mxText->mxTextBody->getParagraphs(); + + int nSequenceSize = 0; + for( auto& pParagraph : rParagraphs ) + nSequenceSize += pParagraph->getRuns().size(); + + int nParagraphs = rParagraphs.size(); + if( nParagraphs > 1 ) + nSequenceSize += nParagraphs - 1; + + aSequence.realloc( nSequenceSize ); + + int nPos = 0; + for( auto& pParagraph : rParagraphs ) + { + for( auto& pRun : pParagraph->getRuns() ) + { + css::uno::Reference< XDataPointCustomLabelField > xCustomLabel = DataPointCustomLabelField::create( xContext ); + + // Store properties + oox::PropertySet aPropertySet( xCustomLabel ); + pRun->getTextCharacterProperties().pushToPropSet( aPropertySet, getFilter() ); + + TextField* pField = nullptr; + if( ( pField = dynamic_cast< TextField* >( pRun.get() ) ) ) + { + xCustomLabel->setString( pField->getText() ); + xCustomLabel->setFieldType( lcl_ConvertFieldNameToFieldEnum( pField->getType() ) ); + xCustomLabel->setGuid( pField->getUuid() ); + } + else if( pRun ) + { + xCustomLabel->setString( pRun->getText() ); + xCustomLabel->setFieldType( DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_TEXT ); + } + aSequence[ nPos++ ] = xCustomLabel; + } + + if( nParagraphs > 1 && nPos < nSequenceSize ) + { + css::uno::Reference< XDataPointCustomLabelField > xCustomLabel = DataPointCustomLabelField::create( xContext ); + xCustomLabel->setFieldType( DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_NEWLINE ); + xCustomLabel->setString("\n"); + aSequence[ nPos++ ] = xCustomLabel; + } + } + + aPropSet.setProperty( PROP_CustomLabelFields, makeAny( aSequence ) ); + convertTextProperty(aPropSet, getFormatter(), mrModel.mxText->mxTextBody); + } + } + catch( Exception& ) + { + } +} + +DataLabelsConverter::DataLabelsConverter( const ConverterRoot& rParent, DataLabelsModel& rModel ) : + ConverterBase< DataLabelsModel >( rParent, rModel ) +{ +} + +DataLabelsConverter::~DataLabelsConverter() +{ +} + +namespace +{ +/// Inherit <c:dLbl> text props (if not set) from <c:dLbls> text props (if set). +void InheritFromDataLabelsTextProps(const DataLabelsModel& rLabels, const DataLabelModel& rLabel) +{ + // See if <c:dLbls> contains text properties to inherit. + if (!rLabels.mxTextProp.is() || rLabels.mxTextProp->getParagraphs().empty()) + { + return; + } + + const std::shared_ptr<TextParagraph>& rLabelsParagraph = rLabels.mxTextProp->getParagraphs()[0]; + + // See if <c:dLbl> lacks text properties. + if (rLabel.mxTextProp.is()) + { + return; + } + + if (!rLabel.mxText || !rLabel.mxText->mxTextBody + || rLabel.mxText->mxTextBody->getParagraphs().empty()) + { + return; + } + + const std::shared_ptr<TextParagraph>& rLabelParagraph + = rLabel.mxText->mxTextBody->getParagraphs()[0]; + + // Inherit rLabel.mxText's char props from rLabels.mxTextProp's char props. + TextCharacterProperties aCharProps; + aCharProps.assignUsed(rLabelsParagraph->getProperties().getTextCharacterProperties()); + aCharProps.assignUsed(rLabelParagraph->getProperties().getTextCharacterProperties()); + rLabelParagraph->getProperties().getTextCharacterProperties().assignUsed(aCharProps); +} +} + +void DataLabelsConverter::convertFromModel( const Reference< XDataSeries >& rxDataSeries, const TypeGroupConverter& rTypeGroup ) +{ + PropertySet aPropSet( rxDataSeries ); + if( !mrModel.mbDeleted ) + { + bool bMSO2007Doc = getFilter().isMSO2007Document(); + bool bHasInternalData = getChartDocument()->hasInternalDataProvider(); + + lclConvertLabelFormatting( aPropSet, getFormatter(), mrModel, rTypeGroup, true, bHasInternalData, bMSO2007Doc ); + + if (mrModel.mxShapeProp) + { + // Import baseline border properties for these data labels. + importBorderProperties(aPropSet, *mrModel.mxShapeProp, getFilter().getGraphicHelper()); + uno::Reference<lang::XMultiServiceFactory> xFactory(getChartDocument(), uno::UNO_QUERY); + ModelObjectHelper& rHelper = getFilter().getModelObjectHelperForModel(xFactory); + importFillProperties(aPropSet, *mrModel.mxShapeProp, getFilter().getGraphicHelper(), + rHelper); + } + } + // import leaderline of data labels + if( !mrModel.mbShowLeaderLines ) + aPropSet.setProperty( PROP_ShowLeaderLines, false ); + + // data point label settings + for (auto const& pointLabel : mrModel.maPointLabels) + { + if (pointLabel->maNumberFormat.maFormatCode.isEmpty()) + pointLabel->maNumberFormat = mrModel.maNumberFormat; + InheritFromDataLabelsTextProps(mrModel, *pointLabel); + + DataLabelConverter aLabelConv(*this, *pointLabel); + aLabelConv.convertFromModel( rxDataSeries, rTypeGroup ); + } +} + +ErrorBarConverter::ErrorBarConverter( const ConverterRoot& rParent, ErrorBarModel& rModel ) : + ConverterBase< ErrorBarModel >( rParent, rModel ) +{ +} + +ErrorBarConverter::~ErrorBarConverter() +{ +} + +void ErrorBarConverter::convertFromModel( const Reference< XDataSeries >& rxDataSeries ) +{ + bool bShowPos = (mrModel.mnTypeId == XML_plus) || (mrModel.mnTypeId == XML_both); + bool bShowNeg = (mrModel.mnTypeId == XML_minus) || (mrModel.mnTypeId == XML_both); + if( !(bShowPos || bShowNeg) ) + return; + + try + { + Reference< XPropertySet > xErrorBar( createInstance( "com.sun.star.chart2.ErrorBar" ), UNO_QUERY_THROW ); + PropertySet aBarProp( xErrorBar ); + + // plus/minus bars + aBarProp.setProperty( PROP_ShowPositiveError, bShowPos ); + aBarProp.setProperty( PROP_ShowNegativeError, bShowNeg ); + + // type of displayed error + namespace cssc = ::com::sun::star::chart; + switch( mrModel.mnValueType ) + { + case XML_cust: + { + // #i87806# manual error bars + aBarProp.setProperty( PROP_ErrorBarStyle, cssc::ErrorBarStyle::FROM_DATA ); + // attach data sequences to error bar + Reference< XDataSink > xDataSink( xErrorBar, UNO_QUERY ); + if( xDataSink.is() ) + { + // create vector of all value sequences + ::std::vector< Reference< XLabeledDataSequence > > aLabeledSeqVec; + // add positive values + if( bShowPos ) + { + Reference< XLabeledDataSequence > xValueSeq = createLabeledDataSequence( ErrorBarModel::PLUS ); + if( xValueSeq.is() ) + aLabeledSeqVec.push_back( xValueSeq ); + } + // add negative values + if( bShowNeg ) + { + Reference< XLabeledDataSequence > xValueSeq = createLabeledDataSequence( ErrorBarModel::MINUS ); + if( xValueSeq.is() ) + aLabeledSeqVec.push_back( xValueSeq ); + } + // attach labeled data sequences to series + if( aLabeledSeqVec.empty() ) + xErrorBar.clear(); + else + xDataSink->setData( ContainerHelper::vectorToSequence( aLabeledSeqVec ) ); + } + } + break; + case XML_fixedVal: + aBarProp.setProperty( PROP_ErrorBarStyle, cssc::ErrorBarStyle::ABSOLUTE ); + aBarProp.setProperty( PROP_PositiveError, mrModel.mfValue ); + aBarProp.setProperty( PROP_NegativeError, mrModel.mfValue ); + break; + case XML_percentage: + aBarProp.setProperty( PROP_ErrorBarStyle, cssc::ErrorBarStyle::RELATIVE ); + aBarProp.setProperty( PROP_PositiveError, mrModel.mfValue ); + aBarProp.setProperty( PROP_NegativeError, mrModel.mfValue ); + break; + case XML_stdDev: + aBarProp.setProperty( PROP_ErrorBarStyle, cssc::ErrorBarStyle::STANDARD_DEVIATION ); + aBarProp.setProperty( PROP_Weight, mrModel.mfValue ); + break; + case XML_stdErr: + aBarProp.setProperty( PROP_ErrorBarStyle, cssc::ErrorBarStyle::STANDARD_ERROR ); + break; + default: + OSL_FAIL( "ErrorBarConverter::convertFromModel - unknown error bar type" ); + xErrorBar.clear(); + } + + // error bar formatting + getFormatter().convertFrameFormatting( aBarProp, mrModel.mxShapeProp, OBJECTTYPE_ERRORBAR ); + + if( xErrorBar.is() ) + { + PropertySet aSeriesProp( rxDataSeries ); + switch( mrModel.mnDirection ) + { + case XML_x: aSeriesProp.setProperty( PROP_ErrorBarX, xErrorBar ); break; + case XML_y: aSeriesProp.setProperty( PROP_ErrorBarY, xErrorBar ); break; + default: OSL_FAIL( "ErrorBarConverter::convertFromModel - invalid error bar direction" ); + } + } + } + catch( Exception& ) + { + OSL_FAIL( "ErrorBarConverter::convertFromModel - error while creating error bars" ); + } +} + +Reference< XLabeledDataSequence > ErrorBarConverter::createLabeledDataSequence( ErrorBarModel::SourceType eSourceType ) +{ + OUString aRole; + switch( eSourceType ) + { + case ErrorBarModel::PLUS: + switch( mrModel.mnDirection ) + { + case XML_x: aRole = "error-bars-x-positive"; break; + case XML_y: aRole = "error-bars-y-positive"; break; + } + break; + case ErrorBarModel::MINUS: + switch( mrModel.mnDirection ) + { + case XML_x: aRole = "error-bars-x-negative"; break; + case XML_y: aRole = "error-bars-y-negative"; break; + } + break; + } + OSL_ENSURE( !aRole.isEmpty(), "ErrorBarConverter::createLabeledDataSequence - invalid error bar direction" ); + return lclCreateLabeledDataSequence( *this, mrModel.maSources.get( eSourceType ).get(), aRole ); +} + +TrendlineLabelConverter::TrendlineLabelConverter( const ConverterRoot& rParent, TrendlineLabelModel& rModel ) : + ConverterBase< TrendlineLabelModel >( rParent, rModel ) +{ +} + +TrendlineLabelConverter::~TrendlineLabelConverter() +{ +} + +void TrendlineLabelConverter::convertFromModel( PropertySet& rPropSet ) +{ + // formatting + getFormatter().convertFormatting( rPropSet, mrModel.mxShapeProp, mrModel.mxTextProp, OBJECTTYPE_TRENDLINELABEL ); +} + +TrendlineConverter::TrendlineConverter( const ConverterRoot& rParent, TrendlineModel& rModel ) : + ConverterBase< TrendlineModel >( rParent, rModel ) +{ +} + +TrendlineConverter::~TrendlineConverter() +{ +} + +void TrendlineConverter::convertFromModel( const Reference< XDataSeries >& rxDataSeries ) +{ + try + { + // trend line type + OUString aServiceName; + switch( mrModel.mnTypeId ) + { + case XML_exp: + aServiceName = "com.sun.star.chart2.ExponentialRegressionCurve"; + break; + case XML_linear: + aServiceName = "com.sun.star.chart2.LinearRegressionCurve"; + break; + case XML_log: + aServiceName = "com.sun.star.chart2.LogarithmicRegressionCurve"; + break; + case XML_movingAvg: + aServiceName = "com.sun.star.chart2.MovingAverageRegressionCurve"; + break; + case XML_poly: + aServiceName = "com.sun.star.chart2.PolynomialRegressionCurve"; + break; + case XML_power: + aServiceName = "com.sun.star.chart2.PotentialRegressionCurve"; + break; + default: + OSL_FAIL( "TrendlineConverter::convertFromModel - unknown trendline type" ); + } + if( !aServiceName.isEmpty() ) + { + Reference< XRegressionCurve > xRegCurve( createInstance( aServiceName ), UNO_QUERY_THROW ); + PropertySet aPropSet( xRegCurve ); + + // Name + aPropSet.setProperty( PROP_CurveName, mrModel.maName ); + aPropSet.setProperty( PROP_PolynomialDegree, mrModel.mnOrder ); + aPropSet.setProperty( PROP_MovingAveragePeriod, mrModel.mnPeriod ); + + // Intercept + bool hasIntercept = mrModel.mfIntercept.has(); + aPropSet.setProperty( PROP_ForceIntercept, hasIntercept); + if (hasIntercept) + aPropSet.setProperty( PROP_InterceptValue, mrModel.mfIntercept.get()); + + // Extrapolation + if (mrModel.mfForward.has()) + aPropSet.setProperty( PROP_ExtrapolateForward, mrModel.mfForward.get() ); + if (mrModel.mfBackward.has()) + aPropSet.setProperty( PROP_ExtrapolateBackward, mrModel.mfBackward.get() ); + + // trendline formatting + getFormatter().convertFrameFormatting( aPropSet, mrModel.mxShapeProp, OBJECTTYPE_TRENDLINE ); + + // #i83100# show equation and correlation coefficient + PropertySet aLabelProp( xRegCurve->getEquationProperties() ); + aLabelProp.setProperty( PROP_ShowEquation, mrModel.mbDispEquation ); + aLabelProp.setProperty( PROP_ShowCorrelationCoefficient, mrModel.mbDispRSquared ); + + // #i83100# formatting of the equation text box + if( mrModel.mbDispEquation || mrModel.mbDispRSquared ) + { + TrendlineLabelConverter aLabelConv( *this, mrModel.mxLabel.getOrCreate() ); + aLabelConv.convertFromModel( aLabelProp ); + } + + // unsupported: #i5085# manual trendline size + // unsupported: #i34093# manual crossing point + + Reference< XRegressionCurveContainer > xRegCurveCont( rxDataSeries, UNO_QUERY_THROW ); + xRegCurveCont->addRegressionCurve( xRegCurve ); + } + } + catch( Exception& ) + { + OSL_FAIL( "TrendlineConverter::convertFromModel - error while creating trendline" ); + } +} + +DataPointConverter::DataPointConverter( const ConverterRoot& rParent, DataPointModel& rModel ) : + ConverterBase< DataPointModel >( rParent, rModel ) +{ +} + +DataPointConverter::~DataPointConverter() +{ +} + +void DataPointConverter::convertFromModel( const Reference< XDataSeries >& rxDataSeries, + const TypeGroupConverter& rTypeGroup, const SeriesModel& rSeries ) +{ + bool bMSO2007Doc = getFilter().isMSO2007Document(); + try + { + PropertySet aPropSet( rxDataSeries->getDataPointByIndex( mrModel.mnIndex ) ); + + // data point marker + if( mrModel.monMarkerSymbol.differsFrom( rSeries.mnMarkerSymbol ) || mrModel.monMarkerSize.differsFrom( rSeries.mnMarkerSize ) ) + rTypeGroup.convertMarker( aPropSet, mrModel.monMarkerSymbol.get( rSeries.mnMarkerSymbol ), + mrModel.monMarkerSize.get( rSeries.mnMarkerSize ), mrModel.mxMarkerProp ); + + // data point pie explosion + if( mrModel.monExplosion.differsFrom( rSeries.mnExplosion ) ) + rTypeGroup.convertPieExplosion( aPropSet, mrModel.monExplosion.get() ); + + // point formatting + if( mrModel.mxShapeProp.is() ) + { + if( rTypeGroup.getTypeInfo().mbPictureOptions ) + getFormatter().convertFrameFormatting( aPropSet, mrModel.mxShapeProp, mrModel.mxPicOptions.getOrCreate(bMSO2007Doc), rTypeGroup.getSeriesObjectType(), rSeries.mnIndex ); + else + getFormatter().convertFrameFormatting( aPropSet, mrModel.mxShapeProp, rTypeGroup.getSeriesObjectType(), rSeries.mnIndex ); + } + else if (rSeries.mxShapeProp.is()) + { + getFormatter().convertFrameFormatting( aPropSet, rSeries.mxShapeProp, rTypeGroup.getSeriesObjectType(), rSeries.mnIndex ); + } + } + catch( Exception& ) + { + } +} + +SeriesConverter::SeriesConverter( const ConverterRoot& rParent, SeriesModel& rModel ) : + ConverterBase< SeriesModel >( rParent, rModel ) +{ +} + +SeriesConverter::~SeriesConverter() +{ +} + +Reference< XLabeledDataSequence > SeriesConverter::createCategorySequence( const OUString& rRole ) +{ + return createLabeledDataSequence(SeriesModel::CATEGORIES, rRole, false); +} + +Reference< XLabeledDataSequence > SeriesConverter::createValueSequence( const OUString& rRole ) +{ + return createLabeledDataSequence( SeriesModel::VALUES, rRole, true ); +} + +Reference< XDataSeries > SeriesConverter::createDataSeries( const TypeGroupConverter& rTypeGroup, bool bVaryColorsByPoint ) +{ + const TypeGroupInfo& rTypeInfo = rTypeGroup.getTypeInfo(); + + // create the data series object + Reference< XDataSeries > xDataSeries( createInstance( "com.sun.star.chart2.DataSeries" ), UNO_QUERY ); + PropertySet aSeriesProp( xDataSeries ); + + // attach data and title sequences to series + sal_Int32 nDataPointCount = 0; + Reference< XDataSink > xDataSink( xDataSeries, UNO_QUERY ); + if( xDataSink.is() ) + { + // create vector of all value sequences + ::std::vector< Reference< XLabeledDataSequence > > aLabeledSeqVec; + // add Y values + Reference< XLabeledDataSequence > xYValueSeq = createValueSequence( "values-y" ); + if( xYValueSeq.is() ) + { + aLabeledSeqVec.push_back( xYValueSeq ); + Reference< XDataSequence > xValues = xYValueSeq->getValues(); + if( xValues.is() ) + nDataPointCount = xValues->getData().getLength(); + + if (!nDataPointCount) + // No values present. Don't create a data series. + return Reference<XDataSeries>(); + } + // add X values of scatter and bubble charts + if( !rTypeInfo.mbCategoryAxis ) + { + Reference< XLabeledDataSequence > xXValueSeq = createCategorySequence( "values-x" ); + if( xXValueSeq.is() ) + aLabeledSeqVec.push_back( xXValueSeq ); + // add size values of bubble charts + if( rTypeInfo.meTypeId == TYPEID_BUBBLE ) + { + Reference< XLabeledDataSequence > xSizeValueSeq = createLabeledDataSequence( SeriesModel::POINTS, "values-size", true ); + if( xSizeValueSeq.is() ) + aLabeledSeqVec.push_back( xSizeValueSeq ); + } + } + // attach labeled data sequences to series + if( !aLabeledSeqVec.empty() ) + xDataSink->setData( ContainerHelper::vectorToSequence( aLabeledSeqVec ) ); + } + + // error bars + for (auto const& errorBar : mrModel.maErrorBars) + { + ErrorBarConverter aErrorBarConv(*this, *errorBar); + aErrorBarConv.convertFromModel( xDataSeries ); + } + + // trendlines + for (auto const& trendLine : mrModel.maTrendlines) + { + TrendlineConverter aTrendlineConv(*this, *trendLine); + aTrendlineConv.convertFromModel( xDataSeries ); + } + + // data point markers + rTypeGroup.convertMarker( aSeriesProp, mrModel.mnMarkerSymbol, mrModel.mnMarkerSize, mrModel.mxMarkerProp ); +#if OOX_CHART_SMOOTHED_PER_SERIES + // #i66858# smoothed series lines + rTypeGroup.convertLineSmooth( aSeriesProp, mrModel.mbSmooth ); +#endif + // 3D bar style (not possible to set at chart type -> set at all series) + rTypeGroup.convertBarGeometry( aSeriesProp, mrModel.monShape.get( rTypeGroup.getModel().mnShape ) ); + // pie explosion (restricted to [0%,100%] in Chart2) + rTypeGroup.convertPieExplosion( aSeriesProp, mrModel.mnExplosion ); + + // series formatting + ObjectFormatter& rFormatter = getFormatter(); + ObjectType eObjType = rTypeGroup.getSeriesObjectType(); + bool bMSO2007Doc = getFilter().isMSO2007Document(); + if( rTypeInfo.mbPictureOptions ) + rFormatter.convertFrameFormatting( aSeriesProp, mrModel.mxShapeProp, mrModel.mxPicOptions.getOrCreate(bMSO2007Doc), eObjType, mrModel.mnIndex ); + else + rFormatter.convertFrameFormatting( aSeriesProp, mrModel.mxShapeProp, eObjType, mrModel.mnIndex ); + + // set the (unused) property default value used by the Chart2 templates (true for pie/doughnut charts) + bool bIsPie = rTypeInfo.meTypeCategory == TYPECATEGORY_PIE; + aSeriesProp.setProperty( PROP_VaryColorsByPoint, bVaryColorsByPoint ); + + // own area formatting for every data point (TODO: varying line color not supported) + // #i91271# always set area formatting for every point in pie/doughnut charts to override their automatic point formatting + if( bIsPie || (bVaryColorsByPoint && rTypeGroup.isSeriesFrameFormat() && ObjectFormatter::isAutomaticFill( mrModel.mxShapeProp )) ) + { + /* Set the series point number as color cycle size at the object + formatter to get correct start-shade/end-tint. TODO: in doughnut + charts, the sizes of the series may vary, need to use the maximum + point count of all series. */ + sal_Int32 nOldMax = rFormatter.getMaxSeriesIndex(); + if( bVaryColorsByPoint ) + rFormatter.setMaxSeriesIndex( nDataPointCount - 1 ); + for( sal_Int32 nIndex = 0; nIndex < nDataPointCount; ++nIndex ) + { + try + { + PropertySet aPointProp( xDataSeries->getDataPointByIndex( nIndex ) ); + rFormatter.convertAutomaticFill( aPointProp, eObjType, bVaryColorsByPoint ? nIndex : mrModel.mnIndex ); + } + catch( Exception& ) + { + } + } + rFormatter.setMaxSeriesIndex( nOldMax ); + } + + // data point settings + for (auto const& point : mrModel.maPoints) + { + DataPointConverter aPointConv(*this, *point); + aPointConv.convertFromModel( xDataSeries, rTypeGroup, mrModel ); + } + + /* Series data label settings. If and only if the series does not contain + a c:dLbls element, then the c:dLbls element of the parent chart type is + used (data label settings of the parent chart type are *not* merged + into own existing data label settings). */ + ModelRef< DataLabelsModel > xLabels = mrModel.mxLabels.is() ? mrModel.mxLabels : rTypeGroup.getModel().mxLabels; + if( xLabels.is() ) + { + if( xLabels->maNumberFormat.maFormatCode.isEmpty() ) + { + // Use number format code from Value series + DataSourceModel* pValues = mrModel.maSources.get( SeriesModel::VALUES ).get(); + if( pValues ) + xLabels->maNumberFormat.maFormatCode = pValues->mxDataSeq->maFormatCode; + } + DataLabelsConverter aLabelsConv( *this, *xLabels ); + aLabelsConv.convertFromModel( xDataSeries, rTypeGroup ); + } + + return xDataSeries; +} + +// private -------------------------------------------------------------------- + +Reference< XLabeledDataSequence > SeriesConverter::createLabeledDataSequence( + SeriesModel::SourceType eSourceType, const OUString& rRole, bool bUseTextLabel ) +{ + DataSourceModel* pValues = mrModel.maSources.get( eSourceType ).get(); + TextModel* pTitle = bUseTextLabel ? mrModel.mxText.get() : nullptr; + return lclCreateLabeledDataSequence( *this, pValues, rRole, pTitle ); +} + +} // namespace oox + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/oox/source/drawingml/chart/seriesmodel.cxx b/oox/source/drawingml/chart/seriesmodel.cxx new file mode 100644 index 000000000..563e0e48e --- /dev/null +++ b/oox/source/drawingml/chart/seriesmodel.cxx @@ -0,0 +1,129 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <drawingml/chart/seriesmodel.hxx> +#include <oox/token/tokens.hxx> + +namespace oox::drawingml::chart { + +DataLabelModelBase::DataLabelModelBase(bool bMSO2007Doc) : + mbDeleted( !bMSO2007Doc ) +{ +} + +DataLabelModelBase::~DataLabelModelBase() +{ +} + +DataLabelModel::DataLabelModel(bool bMSO2007Doc) : + DataLabelModelBase(bMSO2007Doc), + mnIndex( -1 ) +{ +} + +DataLabelModel::~DataLabelModel() +{ +} + +DataLabelsModel::DataLabelsModel(bool bMSO2007Doc) : + DataLabelModelBase(bMSO2007Doc), + mbShowLeaderLines( !bMSO2007Doc ) +{ +} + +DataLabelsModel::~DataLabelsModel() +{ +} + +PictureOptionsModel::PictureOptionsModel(bool bMSO2007Doc) : + mfStackUnit( 1.0 ), + mnPictureFormat( XML_stretch ), + mbApplyToFront( !bMSO2007Doc ), + mbApplyToSides( !bMSO2007Doc ), + mbApplyToEnd( !bMSO2007Doc ) +{ +} + +PictureOptionsModel::~PictureOptionsModel() +{ +} + +ErrorBarModel::ErrorBarModel(bool bMSO2007Doc) : + mfValue( 0.0 ), + mnDirection( XML_y ), + mnTypeId( XML_both ), + mnValueType( XML_fixedVal ), + mbNoEndCap( !bMSO2007Doc ) +{ +} + +ErrorBarModel::~ErrorBarModel() +{ +} + +TrendlineLabelModel::TrendlineLabelModel() +{ +} + +TrendlineLabelModel::~TrendlineLabelModel() +{ +} + +TrendlineModel::TrendlineModel(bool bMSO2007Doc) : + mnOrder( 2 ), + mnPeriod( 2 ), + mnTypeId( XML_linear ), + mbDispEquation( !bMSO2007Doc ), + mbDispRSquared( !bMSO2007Doc ) +{ +} + +TrendlineModel::~TrendlineModel() +{ +} + +DataPointModel::DataPointModel(bool bMSO2007Doc) : + mnIndex( -1 ), + mbInvertNeg( !bMSO2007Doc ) +{ +} + +DataPointModel::~DataPointModel() +{ +} + +SeriesModel::SeriesModel(bool bMSO2007Doc) : + mnExplosion( 0 ), + mnIndex( -1 ), + mnMarkerSize( 5 ), + mnMarkerSymbol( XML_auto ), + mnOrder( -1 ), + mbBubble3d( !bMSO2007Doc ), + mbInvertNeg( !bMSO2007Doc ), + mbSmooth( !bMSO2007Doc ) +{ +} + +SeriesModel::~SeriesModel() +{ +} + +} // namespace oox::drawingml::chart + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/oox/source/drawingml/chart/titlecontext.cxx b/oox/source/drawingml/chart/titlecontext.cxx new file mode 100644 index 000000000..35ba44cf6 --- /dev/null +++ b/oox/source/drawingml/chart/titlecontext.cxx @@ -0,0 +1,177 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <drawingml/chart/titlecontext.hxx> + +#include <drawingml/shapepropertiescontext.hxx> +#include <drawingml/textbodycontext.hxx> +#include <drawingml/chart/datasourcecontext.hxx> +#include <drawingml/chart/titlemodel.hxx> +#include <oox/core/xmlfilterbase.hxx> +#include <oox/helper/attributelist.hxx> +#include <oox/token/namespaces.hxx> +#include <oox/token/tokens.hxx> + +#include <osl/diagnose.h> + + +namespace oox::drawingml::chart { + +using ::oox::core::ContextHandler2Helper; +using ::oox::core::ContextHandlerRef; + +TextContext::TextContext( ContextHandler2Helper& rParent, TextModel& rModel ) : + ContextBase< TextModel >( rParent, rModel ) +{ +} + +TextContext::~TextContext() +{ +} + +ContextHandlerRef TextContext::onCreateContext( sal_Int32 nElement, const AttributeList& ) +{ + // this context handler is used for <c:tx> and embedded <c:v> elements + if( isCurrentElement( C_TOKEN( tx ) ) ) switch( nElement ) + { + case C_TOKEN( rich ): + return new TextBodyContext( *this, mrModel.mxTextBody.create() ); + + case C_TOKEN( strRef ): + OSL_ENSURE( !mrModel.mxDataSeq, "TextContext::onCreateContext - multiple data sequences" ); + return new StringSequenceContext( *this, mrModel.mxDataSeq.create() ); + + case C_TOKEN( v ): + OSL_ENSURE( !mrModel.mxDataSeq, "TextContext::onCreateContext - multiple data sequences" ); + return this; // collect value in onCharacters() + } + return nullptr; +} + +void TextContext::onCharacters( const OUString& rChars ) +{ + if( isCurrentElement( C_TOKEN( v ) ) ) + { + // Static text is stored as a single string formula token for Excel document. + mrModel.mxDataSeq.create().maFormula = "\"" + rChars + "\""; + + // Also store it as a single element type for non-Excel document. + mrModel.mxDataSeq->maData[0] <<= rChars; + mrModel.mxDataSeq->mnPointCount = 1; + } +} + +TitleContext::TitleContext( ContextHandler2Helper& rParent, TitleModel& rModel ) : + ContextBase< TitleModel >( rParent, rModel ) +{ +} + +TitleContext::~TitleContext() +{ +} + +ContextHandlerRef TitleContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) +{ + // this context handler is used for <c:title> only + switch( nElement ) + { + case C_TOKEN( layout ): + return new LayoutContext( *this, mrModel.mxLayout.create() ); + + case C_TOKEN( overlay ): + mrModel.mbOverlay = rAttribs.getBool( XML_val, true ); + return nullptr; + + case C_TOKEN( spPr ): + return new ShapePropertiesContext( *this, mrModel.mxShapeProp.create() ); + + case C_TOKEN( tx ): + return new TextContext( *this, mrModel.mxText.create() ); + + case C_TOKEN( txPr ): + return new TextBodyContext( *this, mrModel.mxTextProp.create() ); + } + return nullptr; +} + +LegendEntryContext::LegendEntryContext( ContextHandler2Helper& rParent, LegendEntryModel& rModel ) : + ContextBase< LegendEntryModel >( rParent, rModel ) +{ +} + +LegendEntryContext::~LegendEntryContext() +{ +} + +ContextHandlerRef LegendEntryContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) +{ + // this context handler is used for <c:legendEntry> only + switch( nElement ) + { + case C_TOKEN( idx ): + mrModel.mnLegendEntryIdx = rAttribs.getInteger( XML_val, -1 ); + return nullptr; + + case C_TOKEN( delete ): + mrModel.mbLabelDeleted = rAttribs.getBool( XML_val, true ); + return nullptr; + } + return nullptr; +} + +LegendContext::LegendContext( ContextHandler2Helper& rParent, LegendModel& rModel ) : + ContextBase< LegendModel >( rParent, rModel ) +{ +} + +LegendContext::~LegendContext() +{ +} + +ContextHandlerRef LegendContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) +{ + // this context handler is used for <c:legend> only + switch( nElement ) + { + case C_TOKEN( layout ): + return new LayoutContext( *this, mrModel.mxLayout.create() ); + + case C_TOKEN( legendPos ): + mrModel.mnPosition = rAttribs.getToken( XML_val, XML_r ); + return nullptr; + + case C_TOKEN( legendEntry ): + return new LegendEntryContext( *this, mrModel.maLegendEntries.create() ); + + case C_TOKEN( overlay ): + mrModel.mbOverlay = rAttribs.getBool( XML_val, true ); + return nullptr; + + case C_TOKEN( spPr ): + return new ShapePropertiesContext( *this, mrModel.mxShapeProp.create() ); + + case C_TOKEN( txPr ): + return new TextBodyContext( *this, mrModel.mxTextProp.create() ); + } + return nullptr; +} + +} // namespace oox::drawingml::chart + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/oox/source/drawingml/chart/titleconverter.cxx b/oox/source/drawingml/chart/titleconverter.cxx new file mode 100644 index 000000000..a4a2d9c1e --- /dev/null +++ b/oox/source/drawingml/chart/titleconverter.cxx @@ -0,0 +1,355 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <drawingml/chart/titleconverter.hxx> + +#include <com/sun/star/chart/ChartLegendExpansion.hpp> +#include <com/sun/star/chart2/FormattedString.hpp> +#include <com/sun/star/chart2/LegendPosition.hpp> +#include <com/sun/star/chart2/XDiagram.hpp> +#include <com/sun/star/chart2/XLegend.hpp> +#include <com/sun/star/chart2/XTitle.hpp> +#include <com/sun/star/chart2/XTitled.hpp> +#include <com/sun/star/chart2/XChartTypeContainer.hpp> +#include <com/sun/star/chart2/XCoordinateSystemContainer.hpp> +#include <com/sun/star/chart2/XDataSeriesContainer.hpp> +#include <osl/diagnose.h> +#include <drawingml/textbody.hxx> +#include <drawingml/textparagraph.hxx> +#include <drawingml/chart/datasourceconverter.hxx> +#include <drawingml/chart/titlemodel.hxx> +#include <oox/helper/containerhelper.hxx> +#include <oox/token/properties.hxx> +#include <oox/token/tokens.hxx> +#include <com/sun/star/chart2/RelativePosition.hpp> +#include <com/sun/star/drawing/Alignment.hpp> + +#include <oox/drawingml/chart/modelbase.hxx> +namespace oox::drawingml::chart { + +using namespace ::com::sun::star::awt; +using namespace ::com::sun::star::chart2; +using namespace ::com::sun::star::chart2::data; +using namespace ::com::sun::star::drawing; +using namespace ::com::sun::star::uno; + + +TextConverter::TextConverter( const ConverterRoot& rParent, TextModel& rModel ) : + ConverterBase< TextModel >( rParent, rModel ) +{ +} + +TextConverter::~TextConverter() +{ +} + +Reference< XDataSequence > TextConverter::createDataSequence( const OUString& rRole ) +{ + Reference< XDataSequence > xDataSeq; + if( mrModel.mxDataSeq.is() ) + { + DataSequenceConverter aDataSeqConv( *this, *mrModel.mxDataSeq ); + xDataSeq = aDataSeqConv.createDataSequence( rRole ); + } + return xDataSeq; +} + +Sequence< Reference< XFormattedString > > TextConverter::createStringSequence( + const OUString& rDefaultText, const ModelRef< TextBody >& rxTextProp, ObjectType eObjType ) +{ + OSL_ENSURE( !mrModel.mxDataSeq || !mrModel.mxTextBody, "TextConverter::createStringSequence - linked string and rich text found" ); + ::std::vector< Reference< XFormattedString > > aStringVec; + if( mrModel.mxTextBody.is() ) + { + // rich-formatted text objects can be created, but currently Chart2 is not able to show them + const TextParagraphVector& rTextParas = mrModel.mxTextBody->getParagraphs(); + for( TextParagraphVector::const_iterator aPIt = rTextParas.begin(), aPEnd = rTextParas.end(); aPIt != aPEnd; ++aPIt ) + { + const TextParagraph& rTextPara = **aPIt; + const TextCharacterProperties& rParaProps = rTextPara.getProperties().getTextCharacterProperties(); + for( TextRunVector::const_iterator aRIt = rTextPara.getRuns().begin(), aREnd = rTextPara.getRuns().end(); aRIt != aREnd; ++aRIt ) + { + const TextRun& rTextRun = **aRIt; + bool bAddNewLine = ((aRIt + 1 == aREnd) && (aPIt + 1 != aPEnd)) || rTextRun.isLineBreak(); + Reference< XFormattedString > xFmtStr = appendFormattedString( aStringVec, rTextRun.getText(), bAddNewLine ); + PropertySet aPropSet( xFmtStr ); + TextCharacterProperties aRunProps( rParaProps ); + aRunProps.assignUsed( rTextRun.getTextCharacterProperties() ); + getFormatter().convertTextFormatting( aPropSet, aRunProps, eObjType ); + } + } + } + else + { + OUString aString; + // try to create string from linked data + if( mrModel.mxDataSeq.is() && !mrModel.mxDataSeq->maData.empty() ) + mrModel.mxDataSeq->maData.begin()->second >>= aString; + // no linked string -> fall back to default string + if( aString.isEmpty() ) + aString = rDefaultText; + + // create formatted string object + if( !aString.isEmpty() ) + { + Reference< XFormattedString > xFmtStr = appendFormattedString( aStringVec, aString, false ); + PropertySet aPropSet( xFmtStr ); + getFormatter().convertTextFormatting( aPropSet, rxTextProp, eObjType ); + } + } + + return ContainerHelper::vectorToSequence( aStringVec ); +} + +Reference< XFormattedString > TextConverter::appendFormattedString( + ::std::vector< Reference< XFormattedString > >& orStringVec, const OUString& rString, bool bAddNewLine ) const +{ + Reference< XFormattedString2 > xFmtStr; + try + { + xFmtStr = FormattedString::create( ConverterRoot::getComponentContext() ); + xFmtStr->setString( bAddNewLine ? (rString + "\n") : rString ); + orStringVec.emplace_back(xFmtStr ); + } + catch( Exception& ) + { + } + return xFmtStr; +} + +TitleConverter::TitleConverter( const ConverterRoot& rParent, TitleModel& rModel ) : + ConverterBase< TitleModel >( rParent, rModel ) +{ +} + +TitleConverter::~TitleConverter() +{ +} + +void TitleConverter::convertFromModel( const Reference< XTitled >& rxTitled, const OUString& rAutoTitle, ObjectType eObjType, sal_Int32 nMainIdx, sal_Int32 nSubIdx ) +{ + if( !rxTitled.is() ) + return; + + // create the formatted strings + TextModel& rText = mrModel.mxText.getOrCreate(); + TextConverter aTextConv( *this, rText ); + Sequence< Reference< XFormattedString > > aStringSeq = aTextConv.createStringSequence( rAutoTitle, mrModel.mxTextProp, eObjType ); + if( !aStringSeq.hasElements() ) + return; + + try + { + // create the title object and set the string data + Reference< XTitle > xTitle( createInstance( "com.sun.star.chart2.Title" ), UNO_QUERY_THROW ); + xTitle->setText( aStringSeq ); + rxTitled->setTitleObject( xTitle ); + + // frame formatting (text formatting already done in TextConverter::createStringSequence()) + PropertySet aPropSet( xTitle ); + getFormatter().convertFrameFormatting( aPropSet, mrModel.mxShapeProp, eObjType ); + + // frame rotation + OSL_ENSURE( !mrModel.mxTextProp || !rText.mxTextBody, "TitleConverter::convertFromModel - multiple text properties" ); + ModelRef< TextBody > xTextProp = mrModel.mxTextProp.is() ? mrModel.mxTextProp : rText.mxTextBody; + ObjectFormatter::convertTextRotation( aPropSet, xTextProp, true, mrModel.mnDefaultRotation ); + + // register the title and layout data for conversion of position + registerTitleLayout( xTitle, mrModel.mxLayout, eObjType, nMainIdx, nSubIdx ); + } + catch( Exception& ) + { + } +} + +LegendConverter::LegendConverter( const ConverterRoot& rParent, LegendModel& rModel ) : + ConverterBase< LegendModel >( rParent, rModel ) +{ +} + +LegendConverter::~LegendConverter() +{ +} + +void LegendConverter::convertFromModel( const Reference< XDiagram >& rxDiagram ) +{ + if( !rxDiagram.is() ) + return; + + try + { + namespace cssc = ::com::sun::star::chart; + namespace cssc2 = ::com::sun::star::chart2; + + // create the legend + Reference< XLegend > xLegend( createInstance( "com.sun.star.chart2.Legend" ), UNO_QUERY_THROW ); + rxDiagram->setLegend( xLegend ); + PropertySet aPropSet( xLegend ); + aPropSet.setProperty( PROP_Show, true ); + + // legend formatting + getFormatter().convertFormatting( aPropSet, mrModel.mxShapeProp, mrModel.mxTextProp, OBJECTTYPE_LEGEND ); + + // predefined legend position and expansion + cssc2::LegendPosition eLegendPos = cssc2::LegendPosition_LINE_END; + cssc::ChartLegendExpansion eLegendExpand = cssc::ChartLegendExpansion_CUSTOM; + RelativePosition eRelPos; + bool bTopRight=false; + switch( mrModel.mnPosition ) + { + case XML_l: + eLegendPos = cssc2::LegendPosition_LINE_START; + eLegendExpand = cssc::ChartLegendExpansion_HIGH; + break; + case XML_r: + eLegendPos = cssc2::LegendPosition_LINE_END; + eLegendExpand = cssc::ChartLegendExpansion_HIGH; + break; + case XML_tr: // top-right not supported + eRelPos.Primary = 1; + eRelPos.Secondary =0; + eRelPos.Anchor = Alignment_TOP_RIGHT; + bTopRight=true; + break; + case XML_t: + eLegendPos = cssc2::LegendPosition_PAGE_START; + eLegendExpand = cssc::ChartLegendExpansion_WIDE; + break; + case XML_b: + eLegendPos = cssc2::LegendPosition_PAGE_END; + eLegendExpand = cssc::ChartLegendExpansion_WIDE; + break; + } + bool bManualLayout=false; + // manual positioning and size + if( mrModel.mxLayout.get() ) + { + LayoutConverter aLayoutConv( *this, *mrModel.mxLayout ); + // manual size needs ChartLegendExpansion_CUSTOM + if( aLayoutConv.convertFromModel( aPropSet ) ) + { + eLegendExpand = cssc::ChartLegendExpansion_CUSTOM; + } + bManualLayout = !aLayoutConv.getAutoLayout(); + } + + // set position and expansion properties + aPropSet.setProperty( PROP_AnchorPosition, eLegendPos ); + aPropSet.setProperty( PROP_Expansion, eLegendExpand ); + + if (bTopRight && !bManualLayout) + aPropSet.setProperty( PROP_RelativePosition , makeAny(eRelPos)); + + aPropSet.setProperty(PROP_Overlay, mrModel.mbOverlay); + + if (mrModel.maLegendEntries.size() > 0) + legendEntriesFormatting(rxDiagram); + } + catch( Exception& ) + { + } +} + +void LegendConverter::legendEntriesFormatting(const Reference<XDiagram>& rxDiagram) +{ + Reference<XCoordinateSystemContainer> xCooSysContainer(rxDiagram, UNO_QUERY_THROW); + const Sequence<Reference<XCoordinateSystem>> xCooSysSequence(xCooSysContainer->getCoordinateSystems()); + if (!xCooSysSequence.hasElements()) + return; + + sal_Int32 nIndex = 0; + for (const auto& rCooSys : xCooSysSequence) + { + PropertySet aCooSysProp(rCooSys); + bool bSwapXAndY = aCooSysProp.getBoolProperty(PROP_SwapXAndYAxis); + + Reference<XChartTypeContainer> xChartTypeContainer(rCooSys, UNO_QUERY_THROW); + const Sequence<Reference<XChartType>> xChartTypeSequence(xChartTypeContainer->getChartTypes()); + if (!xChartTypeSequence.hasElements()) + continue; + + for (const auto& rCT : xChartTypeSequence) + { + Reference<XDataSeriesContainer> xDSCont(rCT, UNO_QUERY); + if (!xDSCont.is()) + continue; + + const Sequence<Reference<XDataSeries>> aDataSeriesSeq = xDSCont->getDataSeries(); + if (bSwapXAndY) + nIndex += aDataSeriesSeq.getLength() - 1; + for (const auto& rDataSeries : aDataSeriesSeq) + { + PropertySet aSeriesProp(rDataSeries); + bool bVaryColorsByPoint = aSeriesProp.getBoolProperty(PROP_VaryColorsByPoint); + + if (bVaryColorsByPoint) + { + Reference<XDataSource> xDSrc(rDataSeries, UNO_QUERY); + if (!xDSrc.is()) + continue; + + const Sequence<Reference<XLabeledDataSequence> > aDataSeqs = xDSrc->getDataSequences(); + std::vector<sal_Int32> deletedLegendEntries; + sal_Int32 j = 0; + for (const auto& rDataSeq : aDataSeqs) + { + Reference<XDataSequence> xValues = rDataSeq->getValues(); + if (!xValues.is()) + continue; + + sal_Int32 nDataSeqSize = xValues->getData().getLength(); + for (sal_Int32 i = 0; i < nDataSeqSize; ++i) + { + for (const auto& rLegendEntry : mrModel.maLegendEntries) + { + if (nIndex == rLegendEntry->mnLegendEntryIdx && rLegendEntry->mbLabelDeleted) + { + deletedLegendEntries.push_back(j + i); + break; + } + } + nIndex++; + } + j += nDataSeqSize; + } + if (deletedLegendEntries.size() > 0) + aSeriesProp.setProperty(PROP_DeletedLegendEntries, ContainerHelper::vectorToSequence(deletedLegendEntries)); + } + else + { + for (const auto& rLegendEntry : mrModel.maLegendEntries) + { + if (nIndex == rLegendEntry->mnLegendEntryIdx) + { + aSeriesProp.setProperty(PROP_ShowLegendEntry, !rLegendEntry->mbLabelDeleted); + break; + } + } + bSwapXAndY ? nIndex-- : nIndex++; + } + } + if (bSwapXAndY) + nIndex += aDataSeriesSeq.getLength() + 1; + } + } +} + +} // namespace oox::drawingml::chart + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/oox/source/drawingml/chart/titlemodel.cxx b/oox/source/drawingml/chart/titlemodel.cxx new file mode 100644 index 000000000..f28520573 --- /dev/null +++ b/oox/source/drawingml/chart/titlemodel.cxx @@ -0,0 +1,65 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <drawingml/chart/titlemodel.hxx> +#include <oox/token/tokens.hxx> + +namespace oox::drawingml::chart { + +TextModel::TextModel() +{ +} + +TextModel::~TextModel() +{ +} + +TitleModel::TitleModel(sal_Int32 nDefaultRotation) : + mbOverlay( false ), + mnDefaultRotation(nDefaultRotation) +{ +} + +TitleModel::~TitleModel() +{ +} + +LegendEntryModel::LegendEntryModel() : + mnLegendEntryIdx( -1 ), + mbLabelDeleted( false ) +{ +} + +LegendEntryModel::~LegendEntryModel() +{ +} + +LegendModel::LegendModel() : + mnPosition( XML_r ), + mbOverlay( false ) +{ +} + +LegendModel::~LegendModel() +{ +} + +} // namespace oox::drawingml::chart + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/oox/source/drawingml/chart/typegroupcontext.cxx b/oox/source/drawingml/chart/typegroupcontext.cxx new file mode 100644 index 000000000..96c4d6fc2 --- /dev/null +++ b/oox/source/drawingml/chart/typegroupcontext.cxx @@ -0,0 +1,371 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <drawingml/chart/typegroupcontext.hxx> + +#include <drawingml/chart/seriescontext.hxx> +#include <drawingml/chart/typegroupmodel.hxx> +#include <oox/core/xmlfilterbase.hxx> +#include <oox/helper/attributelist.hxx> +#include <oox/token/namespaces.hxx> +#include <oox/token/tokens.hxx> + +namespace oox::drawingml::chart { + +using ::oox::core::ContextHandler2Helper; +using ::oox::core::ContextHandlerRef; + +UpDownBarsContext::UpDownBarsContext( ContextHandler2Helper& rParent, UpDownBarsModel& rModel ) : + ContextBase< UpDownBarsModel >( rParent, rModel ) +{ +} + +UpDownBarsContext::~UpDownBarsContext() +{ +} + +ContextHandlerRef UpDownBarsContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) +{ + switch( getCurrentElement() ) + { + case C_TOKEN( upDownBars ): + switch( nElement ) + { + case C_TOKEN( downBars ): + return new ShapePrWrapperContext( *this, mrModel.mxDownBars.create() ); + case C_TOKEN( gapWidth ): + mrModel.mnGapWidth = rAttribs.getInteger( XML_val, 150 ); + return nullptr; + case C_TOKEN( upBars ): + return new ShapePrWrapperContext( *this, mrModel.mxUpBars.create() ); + } + break; + } + return nullptr; +} + +AreaTypeGroupContext::AreaTypeGroupContext( ContextHandler2Helper& rParent, TypeGroupModel& rModel ) : + TypeGroupContextBase( rParent, rModel ) +{ +} + +AreaTypeGroupContext::~AreaTypeGroupContext() +{ +} + +ContextHandlerRef AreaTypeGroupContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) +{ + bool bMSO2007Doc = getFilter().isMSO2007Document(); + if( isRootElement() ) switch( nElement ) + { + case C_TOKEN( axId ): + mrModel.maAxisIds.push_back( rAttribs.getInteger( XML_val, -1 ) ); + return nullptr; + case C_TOKEN( dLbls ): + return new DataLabelsContext( *this, mrModel.mxLabels.create(bMSO2007Doc) ); + case C_TOKEN( dropLines ): + return new ShapePrWrapperContext( *this, mrModel.mxDropLines.create() ); + case C_TOKEN( gapDepth ): + mrModel.mnGapDepth = rAttribs.getInteger( XML_val, 150 ); + return nullptr; + case C_TOKEN( grouping ): + mrModel.mnGrouping = rAttribs.getToken( XML_val, bMSO2007Doc ? XML_standard : XML_clustered ); + return nullptr; + case C_TOKEN( ser ): + return new AreaSeriesContext( *this, mrModel.maSeries.create(bMSO2007Doc) ); + case C_TOKEN( varyColors ): + mrModel.mbVaryColors = rAttribs.getBool( XML_val, !bMSO2007Doc ); + return nullptr; + } + return nullptr; +} + +BarTypeGroupContext::BarTypeGroupContext( ContextHandler2Helper& rParent, TypeGroupModel& rModel ) : + TypeGroupContextBase( rParent, rModel ) +{ +} + +BarTypeGroupContext::~BarTypeGroupContext() +{ +} + +ContextHandlerRef BarTypeGroupContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) +{ + bool bMSO2007Doc = getFilter().isMSO2007Document(); + if( isRootElement() ) switch( nElement ) + { + case C_TOKEN( axId ): + mrModel.maAxisIds.push_back( rAttribs.getInteger( XML_val, -1 ) ); + return nullptr; + case C_TOKEN( barDir ): + mrModel.mnBarDir = rAttribs.getToken( XML_val, XML_col ); + return nullptr; + case C_TOKEN( dLbls ): + return new DataLabelsContext( *this, mrModel.mxLabels.create(bMSO2007Doc) ); + case C_TOKEN( gapDepth ): + mrModel.mnGapDepth = rAttribs.getInteger( XML_val, 150 ); + return nullptr; + case C_TOKEN( gapWidth ): + mrModel.mnGapWidth = rAttribs.getInteger( XML_val, 150 ); + return nullptr; + case C_TOKEN( grouping ): + mrModel.mnGrouping = rAttribs.getToken( XML_val, bMSO2007Doc ? XML_standard : XML_clustered ); + return nullptr; + case C_TOKEN( overlap ): + mrModel.mnOverlap = rAttribs.getInteger( XML_val, 0 ); + return nullptr; + case C_TOKEN( ser ): + return new BarSeriesContext( *this, mrModel.maSeries.create(bMSO2007Doc) ); + case C_TOKEN( serLines ): + return new ShapePrWrapperContext( *this, mrModel.mxSerLines.create() ); + case C_TOKEN( shape ): + mrModel.mnShape = rAttribs.getToken( XML_val, XML_box ); + return nullptr; + case C_TOKEN( varyColors ): + mrModel.mbVaryColors = rAttribs.getBool( XML_val, !bMSO2007Doc ); + return nullptr; + } + return nullptr; +} + +BubbleTypeGroupContext::BubbleTypeGroupContext( ContextHandler2Helper& rParent, TypeGroupModel& rModel ) : + TypeGroupContextBase( rParent, rModel ) +{ +} + +BubbleTypeGroupContext::~BubbleTypeGroupContext() +{ +} + +ContextHandlerRef BubbleTypeGroupContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) +{ + bool bMSO2007Doc = getFilter().isMSO2007Document(); + if( isRootElement() ) switch( nElement ) + { + case C_TOKEN( axId ): + mrModel.maAxisIds.push_back( rAttribs.getInteger( XML_val, -1 ) ); + return nullptr; + case C_TOKEN( bubble3D ): + mrModel.mbBubble3d = rAttribs.getBool( XML_val, !bMSO2007Doc ); + return nullptr; + case C_TOKEN( bubbleScale ): + mrModel.mnBubbleScale = rAttribs.getInteger( XML_val, 100 ); + return nullptr; + case C_TOKEN( dLbls ): + return new DataLabelsContext( *this, mrModel.mxLabels.create(bMSO2007Doc) ); + case C_TOKEN( ser ): + return new BubbleSeriesContext( *this, mrModel.maSeries.create(bMSO2007Doc) ); + case C_TOKEN( showNegBubbles ): + mrModel.mbShowNegBubbles = rAttribs.getBool( XML_val, !bMSO2007Doc ); + return nullptr; + case C_TOKEN( sizeRepresents ): + mrModel.mnSizeRepresents = rAttribs.getToken( XML_val, XML_area ); + return nullptr; + case C_TOKEN( varyColors ): + mrModel.mbVaryColors = rAttribs.getBool( XML_val, !bMSO2007Doc ); + return nullptr; + } + return nullptr; +} + +LineTypeGroupContext::LineTypeGroupContext( ContextHandler2Helper& rParent, TypeGroupModel& rModel ) : + TypeGroupContextBase( rParent, rModel ) +{ +} + +LineTypeGroupContext::~LineTypeGroupContext() +{ +} + +ContextHandlerRef LineTypeGroupContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) +{ + bool bMSO2007Doc = getFilter().isMSO2007Document(); + if( isRootElement() ) switch( nElement ) + { + case C_TOKEN( axId ): + mrModel.maAxisIds.push_back( rAttribs.getInteger( XML_val, -1 ) ); + return nullptr; + case C_TOKEN( dLbls ): + return new DataLabelsContext( *this, mrModel.mxLabels.create(bMSO2007Doc) ); + case C_TOKEN( dropLines ): + return new ShapePrWrapperContext( *this, mrModel.mxDropLines.create() ); + case C_TOKEN( gapDepth ): + mrModel.mnGapDepth = rAttribs.getInteger( XML_val, 150 ); + return nullptr; + case C_TOKEN( grouping ): + mrModel.mnGrouping = rAttribs.getToken( XML_val, bMSO2007Doc ? XML_standard : XML_clustered ); + return nullptr; + case C_TOKEN( hiLowLines ): + return new ShapePrWrapperContext( *this, mrModel.mxHiLowLines.create() ); + case C_TOKEN( marker ): + mrModel.mbShowMarker = rAttribs.getBool( XML_val, !bMSO2007Doc ); + return nullptr; + case C_TOKEN( ser ): + return new LineSeriesContext( *this, mrModel.maSeries.create(bMSO2007Doc) ); + case C_TOKEN( smooth ): + mrModel.mbSmooth = rAttribs.getBool( XML_val, !bMSO2007Doc ); + return nullptr; + case C_TOKEN( upDownBars ): + return new UpDownBarsContext( *this, mrModel.mxUpDownBars.create() ); + case C_TOKEN( varyColors ): + mrModel.mbVaryColors = rAttribs.getBool( XML_val, !bMSO2007Doc ); + return nullptr; + } + return nullptr; +} + +PieTypeGroupContext::PieTypeGroupContext( ContextHandler2Helper& rParent, TypeGroupModel& rModel ) : + TypeGroupContextBase( rParent, rModel ) +{ +} + +PieTypeGroupContext::~PieTypeGroupContext() +{ +} + +ContextHandlerRef PieTypeGroupContext::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( firstSliceAng ): + mrModel.mnFirstAngle = rAttribs.getInteger( XML_val, 0 ); + return nullptr; + case C_TOKEN( gapWidth ): + mrModel.mnGapWidth = rAttribs.getInteger( XML_val, 150 ); + return nullptr; + case C_TOKEN( holeSize ): + mrModel.mnHoleSize = rAttribs.getInteger( XML_val, 10 ); + return nullptr; + case C_TOKEN( ofPieType ): + mrModel.mnOfPieType = rAttribs.getToken( XML_val, XML_pie ); + return nullptr; + case C_TOKEN( secondPieSize ): + mrModel.mnSecondPieSize = rAttribs.getInteger( XML_val, 75 ); + 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( splitPos ): + mrModel.mfSplitPos = rAttribs.getDouble( XML_val, 0.0 ); + return nullptr; + case C_TOKEN( splitType ): + mrModel.mnSplitType = rAttribs.getToken( XML_val, XML_auto ); + return nullptr; + case C_TOKEN( varyColors ): + mrModel.mbVaryColors = rAttribs.getBool( XML_val, !bMSO2007Doc ); + return nullptr; + } + return nullptr; +} + +RadarTypeGroupContext::RadarTypeGroupContext( ContextHandler2Helper& rParent, TypeGroupModel& rModel ) : + TypeGroupContextBase( rParent, rModel ) +{ +} + +RadarTypeGroupContext::~RadarTypeGroupContext() +{ +} + +ContextHandlerRef RadarTypeGroupContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) +{ + bool bMSO2007Doc = getFilter().isMSO2007Document(); + if( isRootElement() ) switch( nElement ) + { + case C_TOKEN( axId ): + mrModel.maAxisIds.push_back( rAttribs.getInteger( XML_val, -1 ) ); + return nullptr; + case C_TOKEN( dLbls ): + return new DataLabelsContext( *this, mrModel.mxLabels.create(bMSO2007Doc) ); + case C_TOKEN( radarStyle ): + mrModel.mnRadarStyle = rAttribs.getToken( XML_val, XML_standard ); + return nullptr; + case C_TOKEN( ser ): + return new RadarSeriesContext( *this, mrModel.maSeries.create(bMSO2007Doc) ); + case C_TOKEN( varyColors ): + mrModel.mbVaryColors = rAttribs.getBool( XML_val, !bMSO2007Doc ); + return nullptr; + } + return nullptr; +} + +ScatterTypeGroupContext::ScatterTypeGroupContext( ContextHandler2Helper& rParent, TypeGroupModel& rModel ) : + TypeGroupContextBase( rParent, rModel ) +{ +} + +ScatterTypeGroupContext::~ScatterTypeGroupContext() +{ +} + +ContextHandlerRef ScatterTypeGroupContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) +{ + bool bMSO2007Doc = getFilter().isMSO2007Document(); + if( isRootElement() ) switch( nElement ) + { + case C_TOKEN( axId ): + mrModel.maAxisIds.push_back( rAttribs.getInteger( XML_val, -1 ) ); + return nullptr; + case C_TOKEN( dLbls ): + return new DataLabelsContext( *this, mrModel.mxLabels.create(bMSO2007Doc) ); + case C_TOKEN( scatterStyle ): + mrModel.mnScatterStyle = rAttribs.getInteger( XML_val, XML_marker ); + return nullptr; + case C_TOKEN( ser ): + return new ScatterSeriesContext( *this, mrModel.maSeries.create(bMSO2007Doc) ); + case C_TOKEN( varyColors ): + mrModel.mbVaryColors = rAttribs.getBool( XML_val, !bMSO2007Doc ); + return nullptr; + } + return nullptr; +} + +SurfaceTypeGroupContext::SurfaceTypeGroupContext( ContextHandler2Helper& rParent, TypeGroupModel& rModel ) : + TypeGroupContextBase( rParent, rModel ) +{ +} + +SurfaceTypeGroupContext::~SurfaceTypeGroupContext() +{ +} + +ContextHandlerRef SurfaceTypeGroupContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) +{ + bool bMSO2007Doc = getFilter().isMSO2007Document(); + if( isRootElement() ) switch( nElement ) + { + case C_TOKEN( axId ): + mrModel.maAxisIds.push_back( rAttribs.getInteger( XML_val, -1 ) ); + return nullptr; + case C_TOKEN( ser ): + return new SurfaceSeriesContext( *this, mrModel.maSeries.create(bMSO2007Doc) ); + case C_TOKEN( wireframe ): + mrModel.mbWireframe = rAttribs.getBool( XML_val, !bMSO2007Doc ); + return nullptr; + } + return nullptr; +} + +} // namespace oox::drawingml::chart + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/oox/source/drawingml/chart/typegroupconverter.cxx b/oox/source/drawingml/chart/typegroupconverter.cxx new file mode 100644 index 000000000..9953d4380 --- /dev/null +++ b/oox/source/drawingml/chart/typegroupconverter.cxx @@ -0,0 +1,601 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <drawingml/chart/typegroupconverter.hxx> + +#include <com/sun/star/chart/DataLabelPlacement.hpp> +#include <com/sun/star/chart2/CartesianCoordinateSystem2d.hpp> +#include <com/sun/star/chart2/CartesianCoordinateSystem3d.hpp> +#include <com/sun/star/chart2/PolarCoordinateSystem2d.hpp> +#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/StackingDirection.hpp> +#include <com/sun/star/chart2/Symbol.hpp> +#include <com/sun/star/chart2/XChartTypeContainer.hpp> +#include <com/sun/star/chart2/XCoordinateSystem.hpp> +#include <com/sun/star/chart2/XDataSeriesContainer.hpp> +#include <com/sun/star/chart2/XDiagram.hpp> +#include <com/sun/star/chart2/data/XDataSink.hpp> +#include <com/sun/star/drawing/LineStyle.hpp> +#include <osl/diagnose.h> +#include <drawingml/lineproperties.hxx> +#include <drawingml/chart/seriesconverter.hxx> +#include <drawingml/chart/typegroupmodel.hxx> +#include <oox/core/xmlfilterbase.hxx> +#include <oox/helper/containerhelper.hxx> +#include <oox/token/namespaces.hxx> +#include <oox/token/properties.hxx> +#include <oox/token/tokens.hxx> + +namespace oox::drawingml::chart { + +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::chart2; +using namespace ::com::sun::star::chart2::data; +using namespace ::com::sun::star::uno; + +namespace { + +// chart type service names +const char SERVICE_CHART2_AREA[] = "com.sun.star.chart2.AreaChartType"; +const char SERVICE_CHART2_CANDLE[] = "com.sun.star.chart2.CandleStickChartType"; +const char SERVICE_CHART2_COLUMN[] = "com.sun.star.chart2.ColumnChartType"; +const char SERVICE_CHART2_LINE[] = "com.sun.star.chart2.LineChartType"; +const char SERVICE_CHART2_NET[] = "com.sun.star.chart2.NetChartType"; +const char SERVICE_CHART2_FILLEDNET[] = "com.sun.star.chart2.FilledNetChartType"; +const char SERVICE_CHART2_PIE[] = "com.sun.star.chart2.PieChartType"; +const char SERVICE_CHART2_SCATTER[] = "com.sun.star.chart2.ScatterChartType"; +const char SERVICE_CHART2_BUBBLE[] = "com.sun.star.chart2.BubbleChartType"; +const char SERVICE_CHART2_SURFACE[] = "com.sun.star.chart2.ColumnChartType"; // Todo + +namespace csscd = ::com::sun::star::chart::DataLabelPlacement; + +static const TypeGroupInfo spTypeInfos[] = +{ + // type-id type-category service varied-point-color default label pos polar area2d 1stvis xcateg swap stack picopt + { TYPEID_BAR, TYPECATEGORY_BAR, SERVICE_CHART2_COLUMN, VARPOINTMODE_SINGLE, csscd::OUTSIDE, false, true, false, true, false, true, true }, + { TYPEID_HORBAR, TYPECATEGORY_BAR, SERVICE_CHART2_COLUMN, VARPOINTMODE_SINGLE, csscd::OUTSIDE, false, true, false, true, true, true, true }, + { TYPEID_LINE, TYPECATEGORY_LINE, SERVICE_CHART2_LINE, VARPOINTMODE_SINGLE, csscd::RIGHT, false, false, false, true, false, true, false }, + { TYPEID_AREA, TYPECATEGORY_LINE, SERVICE_CHART2_AREA, VARPOINTMODE_NONE, csscd::CENTER, false, true, false, true, false, true, false }, + { TYPEID_STOCK, TYPECATEGORY_LINE, SERVICE_CHART2_CANDLE, VARPOINTMODE_NONE, csscd::RIGHT, false, false, false, true, false, true, false }, + { TYPEID_RADARLINE, TYPECATEGORY_RADAR, SERVICE_CHART2_NET, VARPOINTMODE_SINGLE, csscd::OUTSIDE, true, false, false, true, false, false, false }, + { TYPEID_RADARAREA, TYPECATEGORY_RADAR, SERVICE_CHART2_FILLEDNET, VARPOINTMODE_NONE, csscd::OUTSIDE, true, true, false, true, false, false, false }, + { TYPEID_PIE, TYPECATEGORY_PIE, SERVICE_CHART2_PIE, VARPOINTMODE_MULTI, csscd::AVOID_OVERLAP, true, true, true, true, false, false, false }, + { TYPEID_DOUGHNUT, TYPECATEGORY_PIE, SERVICE_CHART2_PIE, VARPOINTMODE_MULTI, csscd::AVOID_OVERLAP, true, true, false, true, false, false, false }, + { TYPEID_OFPIE, TYPECATEGORY_PIE, SERVICE_CHART2_PIE, VARPOINTMODE_MULTI, csscd::AVOID_OVERLAP, true, true, true, true, false, false, false }, + { TYPEID_SCATTER, TYPECATEGORY_SCATTER, SERVICE_CHART2_SCATTER, VARPOINTMODE_SINGLE, csscd::RIGHT, false, false, false, false, false, false, false }, + { TYPEID_BUBBLE, TYPECATEGORY_SCATTER, SERVICE_CHART2_BUBBLE, VARPOINTMODE_SINGLE, csscd::RIGHT, false, true, false, false, false, false, false }, + { TYPEID_SURFACE, TYPECATEGORY_SURFACE, SERVICE_CHART2_SURFACE, VARPOINTMODE_NONE, csscd::RIGHT, false, true, false, true, false, false, false } +}; + +static const TypeGroupInfo saUnknownTypeInfo = + { TYPEID_UNKNOWN, TYPECATEGORY_BAR, SERVICE_CHART2_COLUMN, VARPOINTMODE_SINGLE, csscd::OUTSIDE, false, true, false, true, false, true, true }; + +const TypeGroupInfo& lclGetTypeInfoFromTypeId( TypeId eTypeId ) +{ + for( auto const &rIt : spTypeInfos) + { + if( rIt.meTypeId == eTypeId ) + return rIt; + } + OSL_ENSURE( eTypeId == TYPEID_UNKNOWN, "lclGetTypeInfoFromTypeId - unexpected chart type identifier" ); + return saUnknownTypeInfo; +} + +} // namespace + +const TypeGroupInfo& GetTypeGroupInfo( TypeId eType ) +{ + return lclGetTypeInfoFromTypeId(eType); +} + +UpDownBarsConverter::UpDownBarsConverter( const ConverterRoot& rParent, UpDownBarsModel& rModel ) : + ConverterBase< UpDownBarsModel >( rParent, rModel ) +{ +} + +UpDownBarsConverter::~UpDownBarsConverter() +{ +} + +void UpDownBarsConverter::convertFromModel( const Reference< XChartType >& rxChartType ) +{ + PropertySet aTypeProp( rxChartType ); + + // upbar format + Reference< XPropertySet > xWhitePropSet; + if( aTypeProp.getProperty( xWhitePropSet, PROP_WhiteDay ) ) + { + PropertySet aPropSet( xWhitePropSet ); + getFormatter().convertFrameFormatting( aPropSet, mrModel.mxUpBars, OBJECTTYPE_UPBAR ); + } + + // downbar format + Reference< XPropertySet > xBlackPropSet; + if( aTypeProp.getProperty( xBlackPropSet, PROP_BlackDay ) ) + { + PropertySet aPropSet( xBlackPropSet ); + getFormatter().convertFrameFormatting( aPropSet, mrModel.mxDownBars, OBJECTTYPE_DOWNBAR ); + } +} + +TypeGroupConverter::TypeGroupConverter( const ConverterRoot& rParent, TypeGroupModel& rModel ) : + ConverterBase< TypeGroupModel >( rParent, rModel ), + mb3dChart( false ) +{ + TypeId eTypeId = TYPEID_UNKNOWN; + switch( mrModel.mnTypeId ) + { +#define ENSURE_AXESCOUNT( min, max ) OSL_ENSURE( (min <= static_cast<int>(mrModel.maAxisIds.size())) && (static_cast<int>(mrModel.maAxisIds.size()) <= max), "TypeGroupConverter::TypeGroupConverter - invalid axes count" ) + case C_TOKEN( area3DChart ): ENSURE_AXESCOUNT( 2, 3 ); eTypeId = TYPEID_AREA; mb3dChart = true; break; + case C_TOKEN( areaChart ): ENSURE_AXESCOUNT( 2, 2 ); eTypeId = TYPEID_AREA; mb3dChart = false; break; + case C_TOKEN( bar3DChart ): ENSURE_AXESCOUNT( 2, 3 ); eTypeId = TYPEID_BAR; mb3dChart = true; break; + case C_TOKEN( barChart ): ENSURE_AXESCOUNT( 2, 2 ); eTypeId = TYPEID_BAR; mb3dChart = false; break; + case C_TOKEN( bubbleChart ): ENSURE_AXESCOUNT( 2, 2 ); eTypeId = TYPEID_BUBBLE; mb3dChart = false; break; + case C_TOKEN( doughnutChart ): ENSURE_AXESCOUNT( 0, 0 ); eTypeId = TYPEID_DOUGHNUT; mb3dChart = false; break; + case C_TOKEN( line3DChart ): ENSURE_AXESCOUNT( 3, 3 ); eTypeId = TYPEID_LINE; mb3dChart = true; break; + case C_TOKEN( lineChart ): ENSURE_AXESCOUNT( 2, 2 ); eTypeId = TYPEID_LINE; mb3dChart = false; break; + case C_TOKEN( ofPieChart ): ENSURE_AXESCOUNT( 0, 0 ); eTypeId = TYPEID_OFPIE; mb3dChart = false; break; + case C_TOKEN( pie3DChart ): ENSURE_AXESCOUNT( 0, 0 ); eTypeId = TYPEID_PIE; mb3dChart = true; break; + case C_TOKEN( pieChart ): ENSURE_AXESCOUNT( 0, 0 ); eTypeId = TYPEID_PIE; mb3dChart = false; break; + case C_TOKEN( radarChart ): ENSURE_AXESCOUNT( 2, 2 ); eTypeId = TYPEID_RADARLINE; mb3dChart = false; break; + case C_TOKEN( scatterChart ): ENSURE_AXESCOUNT( 2, 2 ); eTypeId = TYPEID_SCATTER; mb3dChart = false; break; + case C_TOKEN( stockChart ): ENSURE_AXESCOUNT( 2, 2 ); eTypeId = TYPEID_STOCK; mb3dChart = false; break; + case C_TOKEN( surface3DChart ): ENSURE_AXESCOUNT( 3, 3 ); eTypeId = TYPEID_SURFACE; mb3dChart = true; break; + case C_TOKEN( surfaceChart ): ENSURE_AXESCOUNT( 2, 3 ); eTypeId = TYPEID_SURFACE; mb3dChart = true; break; // 3D bar chart from all surface charts + default: OSL_FAIL( "TypeGroupConverter::TypeGroupConverter - unknown chart type" ); +#undef ENSURE_AXESCOUNT + } + + // special handling for some chart types + switch( eTypeId ) + { + case TYPEID_BAR: + if( mrModel.mnBarDir == XML_bar ) + eTypeId = TYPEID_HORBAR; + break; + case TYPEID_RADARLINE: + if( mrModel.mnRadarStyle == XML_filled ) + eTypeId = TYPEID_RADARAREA; + break; + case TYPEID_SURFACE: + // create a deep 3D bar chart from surface charts + mrModel.mnGrouping = XML_standard; + break; + default:; + } + + // set the chart type info struct for the current chart type + maTypeInfo = lclGetTypeInfoFromTypeId( eTypeId ); +} + +TypeGroupConverter::~TypeGroupConverter() +{ +} + +bool TypeGroupConverter::isStacked() const +{ + return maTypeInfo.mbSupportsStacking && (mrModel.mnGrouping == XML_stacked); +} + +bool TypeGroupConverter::isPercent() const +{ + return maTypeInfo.mbSupportsStacking && (mrModel.mnGrouping == XML_percentStacked); +} + +bool TypeGroupConverter::isWall3dChart() const +{ + return mb3dChart && (maTypeInfo.meTypeCategory != TYPECATEGORY_PIE); +} + +bool TypeGroupConverter::isDeep3dChart() const +{ + return isWall3dChart() && (mrModel.mnGrouping == XML_standard); +} + +bool TypeGroupConverter::isSeriesFrameFormat() const +{ + return mb3dChart || maTypeInfo.mbSeriesIsFrame2d; +} + +ObjectType TypeGroupConverter::getSeriesObjectType() const +{ + return mb3dChart ? OBJECTTYPE_FILLEDSERIES3D : + (maTypeInfo.mbSeriesIsFrame2d ? OBJECTTYPE_FILLEDSERIES2D : OBJECTTYPE_LINEARSERIES2D); +} + +OUString TypeGroupConverter::getSingleSeriesTitle() const +{ + OUString aSeriesTitle; + if( !mrModel.maSeries.empty() && (maTypeInfo.mbSingleSeriesVis || (mrModel.maSeries.size() == 1)) ) + if( const TextModel* pText = mrModel.maSeries.front()->mxText.get() ) + if( const DataSequenceModel* pDataSeq = pText->mxDataSeq.get() ) + if( !pDataSeq->maData.empty() ) + pDataSeq->maData.begin()->second >>= aSeriesTitle; + return aSeriesTitle; +} + +Reference< XCoordinateSystem > TypeGroupConverter::createCoordinateSystem() +{ + // create the coordinate system object + Reference< css::uno::XComponentContext > xContext = getComponentContext(); + Reference< XCoordinateSystem > xCoordSystem; + if( maTypeInfo.mbPolarCoordSystem ) + { + if( mb3dChart ) + xCoordSystem = css::chart2::PolarCoordinateSystem3d::create(xContext); + else + xCoordSystem = css::chart2::PolarCoordinateSystem2d::create(xContext); + } + else + { + if( mb3dChart ) + xCoordSystem = css::chart2::CartesianCoordinateSystem3d::create(xContext); + else + xCoordSystem = css::chart2::CartesianCoordinateSystem2d::create(xContext); + } + + // swap X and Y axis + if( maTypeInfo.mbSwappedAxesSet ) + { + PropertySet aPropSet( xCoordSystem ); + aPropSet.setProperty( PROP_SwapXAndYAxis, true ); + } + + return xCoordSystem; +} + +Reference< XLabeledDataSequence > TypeGroupConverter::createCategorySequence() +{ + sal_Int32 nMaxValues = 0; + Reference< XLabeledDataSequence > xLabeledSeq; + /* Find first existing category sequence. The behaviour of Excel 2007 is + different to Excel 2003, which always used the category sequence of the + first series, even if it was empty. */ + for (auto const& elem : mrModel.maSeries) + { + if( elem->maSources.has( SeriesModel::CATEGORIES ) ) + { + SeriesConverter aSeriesConv(*this, *elem); + xLabeledSeq = aSeriesConv.createCategorySequence( "categories" ); + if (xLabeledSeq.is()) + break; + } + else if( nMaxValues <= 0 && elem->maSources.has( SeriesModel::VALUES ) ) + { + DataSourceModel *pValues = elem->maSources.get( SeriesModel::VALUES ).get(); + if( pValues->mxDataSeq.is() ) + nMaxValues = pValues->mxDataSeq->maData.size(); + } + } + /* n#839727 Create Category Sequence when none are found */ + if( !xLabeledSeq.is() && !mrModel.maSeries.empty() ) { + if( nMaxValues < 0 ) + nMaxValues = 2; + SeriesModel &aModel = *mrModel.maSeries.get(0); + DataSourceModel &aSrc = aModel.maSources.create( SeriesModel::CATEGORIES ); + DataSequenceModel &aSeq = aSrc.mxDataSeq.create(); + aSeq.mnPointCount = nMaxValues; + for( sal_Int32 i = 0; i < nMaxValues; i++ ) + aSeq.maData[ i ] <<= OUString::number( i + 1 ); + SeriesConverter aSeriesConv( *this, aModel ); + xLabeledSeq = aSeriesConv.createCategorySequence( "categories" ); + } + return xLabeledSeq; +} + +void TypeGroupConverter::convertFromModel( const Reference< XDiagram >& rxDiagram, + const Reference< XCoordinateSystem >& rxCoordSystem, + sal_Int32 nAxesSetIdx, bool bSupportsVaryColorsByPoint ) +{ + try + { + // create the chart type object + OUString aService = OUString::createFromAscii( maTypeInfo.mpcServiceName ); + Reference< XChartType > xChartType( createInstance( aService ), UNO_QUERY_THROW ); + + Reference< XChartTypeContainer > xChartTypeContOld( rxCoordSystem, UNO_QUERY_THROW ); + Sequence< Reference< XChartType > > xOldChartTypes( xChartTypeContOld->getChartTypes() ); + sal_Int32 nOldChartTypeIdx = -1; + + // additional properties + PropertySet aDiaProp( rxDiagram ); + PropertySet aTypeProp( xChartType ); + switch( maTypeInfo.meTypeCategory ) + { + case TYPECATEGORY_BAR: + { + Sequence< sal_Int32 > aInt32Seq( 2 ); + aInt32Seq[ 0 ] = aInt32Seq[ 1 ] = mrModel.mnOverlap; + aTypeProp.setProperty( PROP_OverlapSequence, aInt32Seq ); + aInt32Seq[ 0 ] = aInt32Seq[ 1 ] = mrModel.mnGapWidth; + aTypeProp.setProperty( PROP_GapwidthSequence, aInt32Seq ); + } + break; + case TYPECATEGORY_PIE: + { + aTypeProp.setProperty( PROP_UseRings, maTypeInfo.meTypeId == TYPEID_DOUGHNUT ); + /* #i85166# starting angle of first pie slice. 3D pie charts + use Y rotation setting in view3D element. Of-pie charts do + not support pie rotation. */ + if( !is3dChart() && (maTypeInfo.meTypeId != TYPEID_OFPIE) ) + convertPieRotation( aDiaProp, mrModel.mnFirstAngle ); + } + break; + default:; + } + + // create converter objects for all series models + typedef RefVector< SeriesConverter > SeriesConvVector; + SeriesConvVector aSeries; + for (auto const& elemSeries : mrModel.maSeries) + aSeries.push_back( std::make_shared<SeriesConverter>(*this, *elemSeries) ); + + // decide whether to use varying colors for each data point + bool bVaryColorsByPoint = bSupportsVaryColorsByPoint && mrModel.mbVaryColors; + switch( maTypeInfo.meVarPointMode ) + { + case VARPOINTMODE_NONE: bVaryColorsByPoint = false; break; + case VARPOINTMODE_SINGLE: bVaryColorsByPoint &= (mrModel.maSeries.size() == 1); break; + case VARPOINTMODE_MULTI: break; + } + + /* Stock chart needs special processing. Create one 'big' series with + data sequences of different roles. */ + if( maTypeInfo.meTypeId == TYPEID_STOCK ) + { + // create the data series object + Reference< XDataSeries > xDataSeries( createInstance( "com.sun.star.chart2.DataSeries" ), UNO_QUERY ); + Reference< XDataSink > xDataSink( xDataSeries, UNO_QUERY ); + if( xDataSink.is() ) + { + // create a list of data sequences from all series + ::std::vector< Reference< XLabeledDataSequence > > aLabeledSeqVec; + OSL_ENSURE( aSeries.size() >= 3, "TypeGroupConverter::convertFromModel - too few stock chart series" ); + int nRoleIdx = (aSeries.size() == 3) ? 1 : 0; + for( auto& rxSeriesConv : aSeries ) + { + // create a data sequence with a specific role + OUString aRole; + switch( nRoleIdx ) + { + case 0: aRole = "values-first"; break; + case 1: aRole = "values-max"; break; + case 2: aRole = "values-min"; break; + case 3: aRole = "values-last"; break; + } + Reference< XLabeledDataSequence > xDataSeq = rxSeriesConv->createValueSequence( aRole ); + if( xDataSeq.is() ) + aLabeledSeqVec.push_back( xDataSeq ); + + ++nRoleIdx; + if (nRoleIdx >= 4) + break; + } + + // attach labeled data sequences to series and insert series into chart type + xDataSink->setData( ContainerHelper::vectorToSequence( aLabeledSeqVec ) ); + + // formatting of high/low lines + aTypeProp.setProperty( PROP_ShowHighLow, true ); + PropertySet aSeriesProp( xDataSeries ); + if( mrModel.mxHiLowLines.is() ) + getFormatter().convertFrameFormatting( aSeriesProp, mrModel.mxHiLowLines, OBJECTTYPE_HILOLINE ); + else + // hi/low-lines cannot be switched off via "ShowHighLow" property (?) + aSeriesProp.setProperty( PROP_LineStyle, css::drawing::LineStyle_NONE ); + + // formatting of up/down bars + bool bUpDownBars = mrModel.mxUpDownBars.is(); + aTypeProp.setProperty( PROP_Japanese, bUpDownBars ); + aTypeProp.setProperty( PROP_ShowFirst, bUpDownBars ); + if( bUpDownBars ) + { + UpDownBarsConverter aUpDownConv( *this, *mrModel.mxUpDownBars ); + aUpDownConv.convertFromModel( xChartType ); + } + + // insert the series into the chart type object + insertDataSeries( xChartType, xDataSeries, nAxesSetIdx ); + } + } + else + { + for( sal_Int32 nCTIdx=0; nCTIdx<xOldChartTypes.getLength(); ++nCTIdx ) + { + if ( xChartType->getChartType() == xOldChartTypes[nCTIdx]->getChartType() ) + { + nOldChartTypeIdx = nCTIdx; + } + } + + for (auto const& elem : aSeries) + { + SeriesConverter& rSeriesConv = *elem; + Reference< XDataSeries > xDataSeries = rSeriesConv.createDataSeries( *this, bVaryColorsByPoint ); + insertDataSeries( nOldChartTypeIdx == -1 ? xChartType : xOldChartTypes[nOldChartTypeIdx], xDataSeries, nAxesSetIdx ); + + /* Excel does not use the value of the c:smooth element of the + chart type to set a default line smoothing for the data + series. Line smoothing is always controlled by the c:smooth + element of the respective data series. If the element in the + data series is missing, line smoothing is off, regardless of + the c:smooth element of the chart type. */ +#if !OOX_CHART_SMOOTHED_PER_SERIES + if( rSeriesConv.getModel().mbSmooth ) + convertLineSmooth( aTypeProp, true ); +#endif + } + } + + // add chart type object to coordinate system + Reference< XChartTypeContainer > xChartTypeCont( rxCoordSystem, UNO_QUERY_THROW ); + if (nOldChartTypeIdx == -1) + { + xChartTypeCont->addChartType(xChartType); + } + + // set existence of bar connector lines at diagram (only in stacked 2D bar charts) + if( mrModel.mxSerLines.is() && !mb3dChart && (maTypeInfo.meTypeCategory == TYPECATEGORY_BAR) && (isStacked() || isPercent()) ) + aDiaProp.setProperty( PROP_ConnectBars, true ); + } + catch( Exception& ) + { + OSL_FAIL( "TypeGroupConverter::convertFromModel - cannot add chart type" ); + } +} + +void TypeGroupConverter::convertMarker( PropertySet& rPropSet, sal_Int32 nOoxSymbol, sal_Int32 nOoxSize, + const ModelRef< Shape >& xShapeProps ) const +{ + if( isSeriesFrameFormat() ) + return; + + namespace cssc = ::com::sun::star::chart2; + + // symbol style + cssc::Symbol aSymbol; + aSymbol.Style = cssc::SymbolStyle_STANDARD; + switch( nOoxSymbol ) // compare with XclChPropSetHelper::WriteMarkerProperties in xlchart.cxx + { + case XML_auto: aSymbol.Style = cssc::SymbolStyle_AUTO; break; + case XML_none: aSymbol.Style = cssc::SymbolStyle_NONE; break; + case XML_square: aSymbol.StandardSymbol = 0; break; // square + case XML_diamond: aSymbol.StandardSymbol = 1; break; // diamond + case XML_triangle: aSymbol.StandardSymbol = 3; break; // arrow up + case XML_x: aSymbol.StandardSymbol = 10; break; // X, legacy bow tie + case XML_star: aSymbol.StandardSymbol = 12; break; // asterisk, legacy sand glass + case XML_dot: aSymbol.StandardSymbol = 4; break; // arrow right + case XML_dash: aSymbol.StandardSymbol = 13; break; // horizontal bar, legacy arrow down + case XML_circle: aSymbol.StandardSymbol = 8; break; // circle, legacy arrow right + case XML_plus: aSymbol.StandardSymbol = 11; break; // plus, legacy arrow left + } + + // symbol size (points in OOXML, 1/100 mm in Chart2) + sal_Int32 nSize = static_cast< sal_Int32 >( nOoxSize * (2540.0 / 72.0) + 0.5 ); + aSymbol.Size.Width = aSymbol.Size.Height = nSize; + + if(xShapeProps.is()) + { + Color aFillColor = xShapeProps->getFillProperties().maFillColor; + aSymbol.FillColor = sal_Int32(aFillColor.getColor(getFilter().getGraphicHelper())); + // tdf#124817: if there is no fill color, use line color of the symbol + if( aSymbol.FillColor < 0 ) + { + Color aLineColor = xShapeProps->getLineProperties().maLineFill.maFillColor; + aSymbol.BorderColor = sal_Int32(aLineColor.getColor(getFilter().getGraphicHelper())); + rPropSet.setProperty(PROP_Color, aSymbol.BorderColor); + } + else + rPropSet.setProperty(PROP_Color, aSymbol.FillColor); + } + + // set the property + rPropSet.setProperty( PROP_Symbol, aSymbol ); +} + +void TypeGroupConverter::convertLineSmooth( PropertySet& rPropSet, bool bOoxSmooth ) const +{ + if( !isSeriesFrameFormat() && (maTypeInfo.meTypeCategory != TYPECATEGORY_RADAR) ) + { + namespace cssc = ::com::sun::star::chart2; + cssc::CurveStyle eCurveStyle = bOoxSmooth ? cssc::CurveStyle_CUBIC_SPLINES : cssc::CurveStyle_LINES; + rPropSet.setProperty( PROP_CurveStyle, eCurveStyle ); + } +} + +void TypeGroupConverter::convertBarGeometry( PropertySet& rPropSet, sal_Int32 nOoxShape ) const +{ + if( !(mb3dChart && (maTypeInfo.meTypeCategory == TYPECATEGORY_BAR)) ) + return; + + namespace cssc = ::com::sun::star::chart2; + + sal_Int32 nGeom3d = cssc::DataPointGeometry3D::CUBOID; + switch( nOoxShape ) + { + case XML_box: nGeom3d = cssc::DataPointGeometry3D::CUBOID; break; + case XML_cone: nGeom3d = cssc::DataPointGeometry3D::CONE; break; + case XML_coneToMax: nGeom3d = cssc::DataPointGeometry3D::CONE; break; + case XML_cylinder: nGeom3d = cssc::DataPointGeometry3D::CYLINDER; break; + case XML_pyramid: nGeom3d = cssc::DataPointGeometry3D::PYRAMID; break; + case XML_pyramidToMax: nGeom3d = cssc::DataPointGeometry3D::PYRAMID; break; + default: OSL_FAIL( "TypeGroupConverter::convertBarGeometry - unknown 3D bar shape type" ); + } + rPropSet.setProperty( PROP_Geometry3D, nGeom3d ); +} + +void TypeGroupConverter::convertPieRotation( PropertySet& rPropSet, sal_Int32 nOoxAngle ) const +{ + if( maTypeInfo.meTypeCategory == TYPECATEGORY_PIE ) + { + // map OOXML [0,360] clockwise (0deg top) to Chart2 counterclockwise (0deg left) + sal_Int32 nAngle = (450 - nOoxAngle) % 360; + rPropSet.setProperty( PROP_StartingAngle, nAngle ); + } +} + +void TypeGroupConverter::convertPieExplosion( PropertySet& rPropSet, sal_Int32 nOoxExplosion ) const +{ + if( maTypeInfo.meTypeCategory == TYPECATEGORY_PIE ) + { + // pie explosion restricted to 100% in Chart2, set as double in range [0,1] + double fOffset = getLimitedValue< double >( nOoxExplosion / 100.0, 0.0, 1.0 ); + rPropSet.setProperty( PROP_Offset, fOffset ); + } +} + +// private -------------------------------------------------------------------- + +void TypeGroupConverter::insertDataSeries( const Reference< XChartType >& rxChartType, const Reference< XDataSeries >& rxSeries, sal_Int32 nAxesSetIdx ) +{ + if( !rxSeries.is() ) + return; + + PropertySet aSeriesProp( rxSeries ); + + // series stacking mode + namespace cssc = ::com::sun::star::chart2; + cssc::StackingDirection eStacking = cssc::StackingDirection_NO_STACKING; + // stacked overrides deep-3d + if( isStacked() || isPercent() ) + eStacking = cssc::StackingDirection_Y_STACKING; + else if( isDeep3dChart() ) + eStacking = cssc::StackingDirection_Z_STACKING; + aSeriesProp.setProperty( PROP_StackingDirection, eStacking ); + + // additional series properties + aSeriesProp.setProperty( PROP_AttachedAxisIndex, nAxesSetIdx ); + + // insert series into container + try + { + Reference< XDataSeriesContainer > xSeriesCont( rxChartType, UNO_QUERY_THROW ); + xSeriesCont->addDataSeries( rxSeries ); + } + catch( Exception& ) + { + OSL_FAIL( "TypeGroupConverter::insertDataSeries - cannot add data series" ); + } +} + +} // namespace oox + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/oox/source/drawingml/chart/typegroupmodel.cxx b/oox/source/drawingml/chart/typegroupmodel.cxx new file mode 100644 index 000000000..cc106a5de --- /dev/null +++ b/oox/source/drawingml/chart/typegroupmodel.cxx @@ -0,0 +1,67 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <drawingml/chart/typegroupmodel.hxx> +#include <oox/token/tokens.hxx> + +namespace oox::drawingml::chart { + +UpDownBarsModel::UpDownBarsModel() : + mnGapWidth( 150 ) +{ +} + +UpDownBarsModel::~UpDownBarsModel() +{ +} + +TypeGroupModel::TypeGroupModel( sal_Int32 nTypeId, bool bMSO2007Doc ) : + mfSplitPos( 0.0 ), + mnBarDir( XML_col ), + mnBubbleScale( 100 ), + mnFirstAngle( 0 ), + mnGapDepth( 150 ), + mnGapWidth( 150 ), + mnGrouping( bMSO2007Doc ? XML_standard : XML_clustered ), + mnHoleSize( 10 ), + mnOfPieType( XML_pie ), + mnOverlap( 0 ), + mnRadarStyle( XML_standard ), + mnScatterStyle( XML_marker ), + mnSecondPieSize( 75 ), + mnShape( XML_box ), + mnSizeRepresents( XML_area ), + mnSplitType( XML_auto ), + mnTypeId( nTypeId ), + mbBubble3d( !bMSO2007Doc ), + mbShowMarker( !bMSO2007Doc ), + mbShowNegBubbles( !bMSO2007Doc ), + mbSmooth( !bMSO2007Doc ), + mbVaryColors( !bMSO2007Doc ), + mbWireframe( !bMSO2007Doc ) +{ +} + +TypeGroupModel::~TypeGroupModel() +{ +} + +} // namespace oox::drawingml::chart + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |