diff options
-rw-r--r-- | chart2/qa/extras/chart2import.cxx | 31 | ||||
-rw-r--r-- | chart2/qa/extras/data/pptx/bnc889755.pptx | bin | 0 -> 34771 bytes | |||
-rw-r--r-- | chart2/source/controller/chartapiwrapper/AxisWrapper.cxx | 13 | ||||
-rw-r--r-- | chart2/source/model/main/Axis.cxx | 15 | ||||
-rw-r--r-- | chart2/source/view/axes/VAxisProperties.cxx | 7 | ||||
-rw-r--r-- | chart2/source/view/axes/VAxisProperties.hxx | 5 | ||||
-rw-r--r-- | chart2/source/view/axes/VCartesianAxis.cxx | 23 | ||||
-rw-r--r-- | include/xmloff/xmltoken.hxx | 1 | ||||
-rw-r--r-- | offapi/com/sun/star/chart2/Axis.idl | 7 | ||||
-rw-r--r-- | oox/inc/drawingml/chart/datasourcecontext.hxx | 5 | ||||
-rw-r--r-- | oox/source/drawingml/chart/datasourcecontext.cxx | 62 | ||||
-rw-r--r-- | xmloff/source/chart/PropertyMap.hxx | 1 | ||||
-rw-r--r-- | xmloff/source/chart/SchXMLAxisContext.cxx | 7 | ||||
-rw-r--r-- | xmloff/source/core/xmltoken.cxx | 1 |
14 files changed, 165 insertions, 13 deletions
diff --git a/chart2/qa/extras/chart2import.cxx b/chart2/qa/extras/chart2import.cxx index 3ab06008ab47..593f3c82969b 100644 --- a/chart2/qa/extras/chart2import.cxx +++ b/chart2/qa/extras/chart2import.cxx @@ -52,6 +52,7 @@ public: void testODPChartSeries(); void testBnc864396(); void testBnc882383(); + void testBnc889755(); void testSimpleStrictXLSX(); void testDelayedCellImport(); // chart range referencing content on later sheets void testFlatODSStackedColumnChart(); @@ -108,6 +109,7 @@ public: CPPUNIT_TEST(testODPChartSeries); CPPUNIT_TEST(testBnc864396); CPPUNIT_TEST(testBnc882383); + CPPUNIT_TEST(testBnc889755); CPPUNIT_TEST(testSimpleStrictXLSX); CPPUNIT_TEST(testDelayedCellImport); CPPUNIT_TEST(testFlatODSStackedColumnChart); @@ -580,6 +582,35 @@ void Chart2ImportTest::testBnc864396() } } +void Chart2ImportTest::testBnc889755() +{ + load("/chart2/qa/extras/data/pptx/", "bnc889755.pptx"); + uno::Reference<chart2::XChartDocument> xChartDoc(getChartDocFromDrawImpress(0, 6), uno::UNO_QUERY_THROW); + CPPUNIT_ASSERT(xChartDoc.is()); + CPPUNIT_ASSERT(xChartDoc->hasInternalDataProvider()); + + uno::Reference< chart2::XInternalDataProvider > xDataProvider( xChartDoc->getDataProvider(), uno::UNO_QUERY_THROW ); + uno::Reference< chart::XChartDataArray > xChartDataArray(xDataProvider, uno::UNO_QUERY_THROW); + uno::Sequence< OUString > aRowLabels = xChartDataArray->getRowDescriptions(); + CPPUNIT_ASSERT_EQUAL( aRowLabels.getLength(), sal_Int32(16) ); + CPPUNIT_ASSERT_EQUAL(OUString("Oct-12"), aRowLabels[0]); + CPPUNIT_ASSERT_EQUAL(OUString("Nov-12"), aRowLabels[1]); + CPPUNIT_ASSERT_EQUAL(OUString("Dec-12"), aRowLabels[2]); + CPPUNIT_ASSERT_EQUAL(OUString("Jan-13"), aRowLabels[3]); + CPPUNIT_ASSERT_EQUAL(OUString("Feb-13"), aRowLabels[4]); + CPPUNIT_ASSERT_EQUAL(OUString("Mar-13"), aRowLabels[5]); + CPPUNIT_ASSERT_EQUAL(OUString("Apr-13"), aRowLabels[6]); + CPPUNIT_ASSERT_EQUAL(OUString("May-13"), aRowLabels[7]); + CPPUNIT_ASSERT_EQUAL(OUString("Jun-13"), aRowLabels[8]); + CPPUNIT_ASSERT_EQUAL(OUString("Jul-13"), aRowLabels[9]); + CPPUNIT_ASSERT_EQUAL(OUString("Aug-13"), aRowLabels[10]); + CPPUNIT_ASSERT_EQUAL(OUString("Sep-13"), aRowLabels[11]); + CPPUNIT_ASSERT_EQUAL(OUString("Oct-13"), aRowLabels[12]); + CPPUNIT_ASSERT_EQUAL(OUString("Nov-13"), aRowLabels[13]); + CPPUNIT_ASSERT_EQUAL(OUString("Dec-13"), aRowLabels[14]); + CPPUNIT_ASSERT_EQUAL(OUString("Jan-14"), aRowLabels[15]); +} + void Chart2ImportTest::testBnc882383() { load("/chart2/qa/extras/data/pptx/", "bnc882383.pptx"); diff --git a/chart2/qa/extras/data/pptx/bnc889755.pptx b/chart2/qa/extras/data/pptx/bnc889755.pptx Binary files differnew file mode 100644 index 000000000000..f3af67765677 --- /dev/null +++ b/chart2/qa/extras/data/pptx/bnc889755.pptx diff --git a/chart2/source/controller/chartapiwrapper/AxisWrapper.cxx b/chart2/source/controller/chartapiwrapper/AxisWrapper.cxx index 6abfbf48f429..2cc97cebc91d 100644 --- a/chart2/source/controller/chartapiwrapper/AxisWrapper.cxx +++ b/chart2/source/controller/chartapiwrapper/AxisWrapper.cxx @@ -102,7 +102,8 @@ enum PROP_AXIS_OVERLAP, PROP_AXIS_GAP_WIDTH, PROP_AXIS_DISPLAY_UNITS, - PROP_AXIS_BUILTINUNIT + PROP_AXIS_BUILTINUNIT, + PROP_AXIS_TRY_STAGGERING_FIRST }; void lcl_AddPropertiesToVector( @@ -356,6 +357,15 @@ void lcl_AddPropertiesToVector( cppu::UnoType<OUString>::get(), beans::PropertyAttribute::BOUND | beans::PropertyAttribute::MAYBEDEFAULT )); + + // Compatibility option: starting from LibreOffice 5.1 the rotated + // layout is preferred to staggering for axis labels. + rOutProperties.push_back( + Property( "TryStaggeringFirst", + PROP_AXIS_TRY_STAGGERING_FIRST, + cppu::UnoType<bool>::get(), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); } struct StaticAxisWrapperPropertyArray_Initializer @@ -656,6 +666,7 @@ const std::vector< WrappedProperty* > AxisWrapper::createWrappedProperties() aWrappedProperties.push_back( new WrappedProperty("ArrangeOrder","ArrangeOrder") ); aWrappedProperties.push_back( new WrappedProperty("Visible","Show") ); aWrappedProperties.push_back( new WrappedDirectStateProperty("DisplayLabels","DisplayLabels") ); + aWrappedProperties.push_back( new WrappedDirectStateProperty("TryStaggeringFirst","TryStaggeringFirst") ); aWrappedProperties.push_back( new WrappedDirectStateProperty("TextBreak","TextBreak") ); aWrappedProperties.push_back( new WrappedNumberFormatProperty(m_spChart2ModelContact) ); aWrappedProperties.push_back( new WrappedLinkNumberFormatProperty(m_spChart2ModelContact) ); diff --git a/chart2/source/model/main/Axis.cxx b/chart2/source/model/main/Axis.cxx index 7fcaaec81eef..79855d68ac44 100644 --- a/chart2/source/model/main/Axis.cxx +++ b/chart2/source/model/main/Axis.cxx @@ -83,7 +83,9 @@ enum PROP_AXIS_MARK_POSITION, PROP_AXIS_DISPLAY_UNITS, - PROP_AXIS_BUILTINUNIT + PROP_AXIS_BUILTINUNIT, + + PROP_AXIS_TRY_STAGGERING_FIRST }; void lcl_AddPropertiesToVector( @@ -210,6 +212,16 @@ void lcl_AddPropertiesToVector( cppu::UnoType<OUString>::get(), beans::PropertyAttribute::BOUND | beans::PropertyAttribute::MAYBEDEFAULT )); + + // Compatibility option: starting from LibreOffice 5.1 the rotated + // layout is preferred to staggering for axis labels. + rOutProperties.push_back( + Property( "TryStaggeringFirst", + PROP_AXIS_TRY_STAGGERING_FIRST, + cppu::UnoType<bool>::get(), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); + } struct StaticAxisDefaults_Initializer @@ -246,6 +258,7 @@ private: ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_AXIS_MINOR_TICKMARKS, 0 /* CHAXIS_MARK_NONE */ ); ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_AXIS_MARK_POSITION, ::com::sun::star::chart::ChartAxisMarkPosition_AT_LABELS_AND_AXIS ); ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_AXIS_DISPLAY_UNITS, false ); + ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_AXIS_TRY_STAGGERING_FIRST, false ); } }; diff --git a/chart2/source/view/axes/VAxisProperties.cxx b/chart2/source/view/axes/VAxisProperties.cxx index 3db365d5b04f..85721ada8309 100644 --- a/chart2/source/view/axes/VAxisProperties.cxx +++ b/chart2/source/view/axes/VAxisProperties.cxx @@ -164,6 +164,7 @@ AxisProperties::AxisProperties( const uno::Reference< XAxis >& xAxisModel , m_bCrossingAxisHasReverseDirection(false) , m_bCrossingAxisIsCategoryAxes(false) , m_bDisplayLabels( true ) + , m_bTryStaggeringFirst( false ) , m_nNumberFormatKey(0) , m_nMajorTickmarks(1) , m_nMinorTickmarks(1) @@ -189,6 +190,7 @@ AxisProperties::AxisProperties( const AxisProperties& rAxisProperties ) , m_bCrossingAxisIsCategoryAxes( rAxisProperties.m_bCrossingAxisIsCategoryAxes ) , maLabelAlignment( rAxisProperties.maLabelAlignment ) , m_bDisplayLabels( rAxisProperties.m_bDisplayLabels ) + , m_bTryStaggeringFirst( rAxisProperties.m_bTryStaggeringFirst ) , m_nNumberFormatKey( rAxisProperties.m_nNumberFormatKey ) , m_nMajorTickmarks( rAxisProperties.m_nMajorTickmarks ) , m_nMinorTickmarks( rAxisProperties.m_nMinorTickmarks ) @@ -331,6 +333,11 @@ void AxisProperties::init( bool bCartesian ) //init display labels xProp->getPropertyValue( "DisplayLabels" ) >>= m_bDisplayLabels; + // Init layout strategy hint for axis labels. + // Compatibility option: starting from LibreOffice 5.1 the rotated + // layout is preferred to staggering for axis labels. + xProp->getPropertyValue( "TryStaggeringFirst" ) >>= m_bTryStaggeringFirst; + //init TickmarkProperties xProp->getPropertyValue( "MajorTickmarks" ) >>= m_nMajorTickmarks; xProp->getPropertyValue( "MinorTickmarks" ) >>= m_nMinorTickmarks; diff --git a/chart2/source/view/axes/VAxisProperties.hxx b/chart2/source/view/axes/VAxisProperties.hxx index 1eadf707d8bd..039bd1cb1166 100644 --- a/chart2/source/view/axes/VAxisProperties.hxx +++ b/chart2/source/view/axes/VAxisProperties.hxx @@ -118,6 +118,11 @@ struct AxisProperties SAL_FINAL bool m_bDisplayLabels; + // Compatibility option: starting from LibreOffice 5.1 the rotated + // layout is preferred to staggering for axis labels. + // So the default value of this flag for new documents is `false`. + bool m_bTryStaggeringFirst; + sal_Int32 m_nNumberFormatKey; /* diff --git a/chart2/source/view/axes/VCartesianAxis.cxx b/chart2/source/view/axes/VCartesianAxis.cxx index a8022b355812..46feff4866d9 100644 --- a/chart2/source/view/axes/VCartesianAxis.cxx +++ b/chart2/source/view/axes/VCartesianAxis.cxx @@ -825,15 +825,20 @@ bool VCartesianAxis::createTextShapes( bool bOverlapsAfterAutoStagger = true; if( !bIsStaggered && isAutoStaggeringOfLabelsAllowed( rAxisLabelProperties, bIsHorizontalAxis, bIsVerticalAxis ) ) { - bIsStaggered = true; - rAxisLabelProperties.eStaggering = STAGGER_EVEN; - pLastVisibleNeighbourTickInfo = pPREPreviousVisibleTickInfo; - if( !pLastVisibleNeighbourTickInfo || - !lcl_doesShapeOverlapWithTickmark( pLastVisibleNeighbourTickInfo->xTextShape - , rAxisLabelProperties.fRotationAngleDegree - , pTickInfo->aTickScreenPosition - , bIsHorizontalAxis, bIsVerticalAxis ) ) - bOverlapsAfterAutoStagger = false; + // Compatibility option: starting from LibreOffice 5.1 the rotated + // layout is preferred to staggering for axis labels. + if( m_aAxisProperties.m_bTryStaggeringFirst || !(::rtl::math::approxEqual( rAxisLabelProperties.fRotationAngleDegree, 0.0 ) ) ) + { + bIsStaggered = true; + rAxisLabelProperties.eStaggering = STAGGER_EVEN; + pLastVisibleNeighbourTickInfo = pPREPreviousVisibleTickInfo; + if( !pLastVisibleNeighbourTickInfo || + !lcl_doesShapeOverlapWithTickmark( pLastVisibleNeighbourTickInfo->xTextShape + , rAxisLabelProperties.fRotationAngleDegree + , pTickInfo->aTickScreenPosition + , bIsHorizontalAxis, bIsVerticalAxis ) ) + bOverlapsAfterAutoStagger = false; + } } if (bOverlapsAfterAutoStagger) diff --git a/include/xmloff/xmltoken.hxx b/include/xmloff/xmltoken.hxx index 1eea8c17fcb6..29af403b6d3e 100644 --- a/include/xmloff/xmltoken.hxx +++ b/include/xmloff/xmltoken.hxx @@ -1909,6 +1909,7 @@ namespace xmloff { namespace token { XML_TRANSPOSE, XML_TRUE, XML_TRUNCATE_ON_OVERFLOW, + XML_TRY_STAGGERING_FIRST, XML_TTB, XML_TYPE, XML_DOT_DASH, diff --git a/offapi/com/sun/star/chart2/Axis.idl b/offapi/com/sun/star/chart2/Axis.idl index c27bf8aec6be..28f5c1928301 100644 --- a/offapi/com/sun/star/chart2/Axis.idl +++ b/offapi/com/sun/star/chart2/Axis.idl @@ -134,6 +134,13 @@ service Axis @since LibreOffice 4.3 */ [optional, property] string BuiltInUnit; + + /** Compatibility option: determines which strategy should be tried first for fixing axis labels overlapping issues + + @since LibreOffice 5.1 + */ + [optional, property] boolean TryStaggeringFirst; + }; } ; // chart2 diff --git a/oox/inc/drawingml/chart/datasourcecontext.hxx b/oox/inc/drawingml/chart/datasourcecontext.hxx index 82aa38e2f2ac..ef3298c89fde 100644 --- a/oox/inc/drawingml/chart/datasourcecontext.hxx +++ b/oox/inc/drawingml/chart/datasourcecontext.hxx @@ -21,6 +21,7 @@ #define INCLUDED_OOX_DRAWINGML_CHART_DATASOURCECONTEXT_HXX #include <drawingml/chart/chartcontextbase.hxx> +#include <svl/zforlist.hxx> namespace oox { namespace drawingml { @@ -46,7 +47,11 @@ public: virtual void onCharacters( const OUString& rChars ) SAL_OVERRIDE; private: + SvNumberFormatter* getNumberFormatter(); + +private: sal_Int32 mnPtIndex; /// Current data point index. + SvNumberFormatter* mpNumberFormatter; }; diff --git a/oox/source/drawingml/chart/datasourcecontext.cxx b/oox/source/drawingml/chart/datasourcecontext.cxx index 946b5bdb00d1..10ac7c652015 100644 --- a/oox/source/drawingml/chart/datasourcecontext.cxx +++ b/oox/source/drawingml/chart/datasourcecontext.cxx @@ -21,6 +21,9 @@ #include "oox/drawingml/chart/datasourcemodel.hxx" +#include <comphelper/processfactory.hxx> +#include <oox/core/xmlfilterbase.hxx> +#include <svl/zforlist.hxx> #include <osl/diagnose.h> namespace oox { @@ -30,14 +33,21 @@ namespace 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 ) + mnPtIndex( -1 ), + mpNumberFormatter( NULL ) { } DoubleSequenceContext::~DoubleSequenceContext() { + if( mpNumberFormatter != NULL ) + { + delete mpNumberFormatter; + } } ContextHandlerRef DoubleSequenceContext::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) @@ -98,14 +108,62 @@ void DoubleSequenceContext::onCharacters( const OUString& rChars ) * TODO: NumberFormat conversion, remove the check then. */ if( isParentElement( C_TOKEN( cat ), 4 ) ) - mrModel.maData[ mnPtIndex ] <<= rChars; + { + // 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; + short nType; + pNumFrmt->PutEntry( aFormatCode, nCheckPos, nType, nKey ); + bNoKey = (nCheckPos != 0); + } + if( bNoKey ) + { + mrModel.maData[ mnPtIndex ] <<= rChars; + } + else + { + double fValue = rChars.toDouble(); + Color* pColor = NULL; + OUString aFormattedValue; + 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 == NULL ) + { + uno::Reference<uno::XComponentContext> rContext = + this->getFilter().getComponentContext(); + mpNumberFormatter = + new SvNumberFormatter(rContext, LANGUAGE_DONTKNOW); + } + return mpNumberFormatter; +} + + StringSequenceContext::StringSequenceContext( ContextHandler2Helper& rParent, DataSequenceModel& rModel ) : DataSequenceContextBase( rParent, rModel ) , mnPtIndex(-1) diff --git a/xmloff/source/chart/PropertyMap.hxx b/xmloff/source/chart/PropertyMap.hxx index 0145bde7cbe9..4a22c479ab7c 100644 --- a/xmloff/source/chart/PropertyMap.hxx +++ b/xmloff/source/chart/PropertyMap.hxx @@ -184,6 +184,7 @@ const XMLPropertyMapEntry aXMLChartPropMap[] = MAP_ENTRY( "TextCanOverlap", CHART, XML_TEXT_OVERLAP, XML_TYPE_BOOL ), MAP_ENTRY_ODF12( "ReverseDirection", CHART, XML_REVERSE_DIRECTION, XML_TYPE_BOOL ), MAP_ENTRY( "TextBreak", TEXT, XML_LINE_BREAK, XML_TYPE_BOOL ), + MAP_ENTRY_ODF_EXT( "TryStaggeringFirst", LO_EXT, XML_TRY_STAGGERING_FIRST, XML_TYPE_BOOL ), MAP_ENTRY( "ArrangeOrder", CHART, XML_LABEL_ARRANGEMENT, XML_SCH_TYPE_AXIS_ARRANGEMENT ), MAP_SPECIAL( "NumberFormat", STYLE, XML_DATA_STYLE_NAME, XML_TYPE_NUMBER, XML_SCH_CONTEXT_SPECIAL_NUMBER_FORMAT ), MAP_ENTRY( "LinkNumberFormatToSource", CHART, XML_LINK_DATA_STYLE_TO_SOURCE, XML_TYPE_BOOL ), diff --git a/xmloff/source/chart/SchXMLAxisContext.cxx b/xmloff/source/chart/SchXMLAxisContext.cxx index 8377650bf221..37709e0b4af1 100644 --- a/xmloff/source/chart/SchXMLAxisContext.cxx +++ b/xmloff/source/chart/SchXMLAxisContext.cxx @@ -459,6 +459,13 @@ void SchXMLAxisContext::CreateAxis() m_xAxisProps->setPropertyValue("DisplayLabels", aFalseBool ); + // Compatibility option: starting from LibreOffice 5.1 the rotated + // layout is preferred to staggering for axis labels. + // So the import default value for having compatibility with ODF + // documents created with erlier LibreOffice versions is `true`. + if( GetImport().getGeneratorVersion() != SvXMLImport::ProductVersionUnknown ) + m_xAxisProps->setPropertyValue("TryStaggeringFirst", aTrueBool ); + // #88077# AutoOrigin 'on' is default m_xAxisProps->setPropertyValue("AutoOrigin", aTrueBool ); diff --git a/xmloff/source/core/xmltoken.cxx b/xmloff/source/core/xmltoken.cxx index 63e4aff8703c..0d4ed2dd5577 100644 --- a/xmloff/source/core/xmltoken.cxx +++ b/xmloff/source/core/xmltoken.cxx @@ -1914,6 +1914,7 @@ namespace xmloff { namespace token { TOKEN( "transpose", XML_TRANSPOSE ), TOKEN( "true", XML_TRUE ), TOKEN( "truncate-on-overflow", XML_TRUNCATE_ON_OVERFLOW ), + TOKEN( "try-staggering-first", XML_TRY_STAGGERING_FIRST ), TOKEN( "ttb", XML_TTB ), TOKEN( "type", XML_TYPE ), TOKEN( "dot-dash", XML_DOT_DASH ), |