Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / sc / source / filter / excel / xechart.cxx
blobeab70437bcef6a2423ecbfd4556f6bccb5c758a3
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <xechart.hxx>
22 #include <com/sun/star/i18n/XBreakIterator.hpp>
23 #include <com/sun/star/i18n/ScriptType.hpp>
24 #include <com/sun/star/drawing/FillStyle.hpp>
25 #include <com/sun/star/drawing/XShapes.hpp>
26 #include <com/sun/star/chart/XChartDocument.hpp>
27 #include <com/sun/star/chart/ChartAxisLabelPosition.hpp>
28 #include <com/sun/star/chart/ChartAxisPosition.hpp>
29 #include <com/sun/star/chart/ChartLegendExpansion.hpp>
30 #include <com/sun/star/chart/DataLabelPlacement.hpp>
31 #include <com/sun/star/chart/ErrorBarStyle.hpp>
32 #include <com/sun/star/chart/MissingValueTreatment.hpp>
33 #include <com/sun/star/chart/TimeInterval.hpp>
34 #include <com/sun/star/chart/TimeUnit.hpp>
35 #include <com/sun/star/chart/XAxisSupplier.hpp>
36 #include <com/sun/star/chart/XDiagramPositioning.hpp>
37 #include <com/sun/star/chart2/XChartDocument.hpp>
38 #include <com/sun/star/chart2/XDiagram.hpp>
39 #include <com/sun/star/chart2/XCoordinateSystemContainer.hpp>
40 #include <com/sun/star/chart2/XChartTypeContainer.hpp>
41 #include <com/sun/star/chart2/XDataSeriesContainer.hpp>
42 #include <com/sun/star/chart2/XRegressionCurveContainer.hpp>
43 #include <com/sun/star/chart2/XTitled.hpp>
44 #include <com/sun/star/chart2/XColorScheme.hpp>
45 #include <com/sun/star/chart2/data/XDataSource.hpp>
46 #include <com/sun/star/chart2/AxisType.hpp>
47 #include <com/sun/star/chart2/CurveStyle.hpp>
48 #include <com/sun/star/chart2/DataPointGeometry3D.hpp>
49 #include <com/sun/star/chart2/DataPointLabel.hpp>
50 #include <com/sun/star/chart2/LegendPosition.hpp>
51 #include <com/sun/star/chart2/RelativePosition.hpp>
52 #include <com/sun/star/chart2/RelativeSize.hpp>
53 #include <com/sun/star/chart2/StackingDirection.hpp>
54 #include <com/sun/star/chart2/TickmarkStyle.hpp>
56 #include <tools/gen.hxx>
57 #include <vcl/outdev.hxx>
58 #include <filter/msfilter/escherex.hxx>
60 #include <document.hxx>
61 #include <compiler.hxx>
62 #include <tokenarray.hxx>
63 #include <xeescher.hxx>
64 #include <xeformula.hxx>
65 #include <xehelper.hxx>
66 #include <xepage.hxx>
67 #include <xestyle.hxx>
68 #include <xltools.hxx>
70 #include <memory>
72 using ::com::sun::star::uno::Any;
73 using ::com::sun::star::uno::Reference;
74 using ::com::sun::star::uno::Sequence;
75 using ::com::sun::star::uno::UNO_QUERY;
76 using ::com::sun::star::uno::UNO_QUERY_THROW;
77 using ::com::sun::star::uno::UNO_SET_THROW;
78 using ::com::sun::star::uno::Exception;
79 using ::com::sun::star::beans::XPropertySet;
80 using ::com::sun::star::i18n::XBreakIterator;
81 using ::com::sun::star::frame::XModel;
82 using ::com::sun::star::drawing::XShape;
83 using ::com::sun::star::drawing::XShapes;
85 using ::com::sun::star::chart2::IncrementData;
86 using ::com::sun::star::chart2::RelativePosition;
87 using ::com::sun::star::chart2::RelativeSize;
88 using ::com::sun::star::chart2::ScaleData;
89 using ::com::sun::star::chart2::SubIncrement;
90 using ::com::sun::star::chart2::XAxis;
91 using ::com::sun::star::chart2::XChartDocument;
92 using ::com::sun::star::chart2::XChartTypeContainer;
93 using ::com::sun::star::chart2::XColorScheme;
94 using ::com::sun::star::chart2::XCoordinateSystem;
95 using ::com::sun::star::chart2::XCoordinateSystemContainer;
96 using ::com::sun::star::chart2::XChartType;
97 using ::com::sun::star::chart2::XDataSeries;
98 using ::com::sun::star::chart2::XDataSeriesContainer;
99 using ::com::sun::star::chart2::XDiagram;
100 using ::com::sun::star::chart2::XFormattedString;
101 using ::com::sun::star::chart2::XLegend;
102 using ::com::sun::star::chart2::XRegressionCurve;
103 using ::com::sun::star::chart2::XRegressionCurveContainer;
104 using ::com::sun::star::chart2::XTitle;
105 using ::com::sun::star::chart2::XTitled;
107 using ::com::sun::star::chart2::data::XDataSequence;
108 using ::com::sun::star::chart2::data::XDataSource;
109 using ::com::sun::star::chart2::data::XLabeledDataSequence;
111 using ::formula::FormulaToken;
112 using ::formula::FormulaTokenArrayPlainIterator;
114 namespace cssc = ::com::sun::star::chart;
115 namespace cssc2 = ::com::sun::star::chart2;
117 // Helpers ====================================================================
119 namespace {
121 XclExpStream& operator<<( XclExpStream& rStrm, const XclChRectangle& rRect )
123 return rStrm << rRect.mnX << rRect.mnY << rRect.mnWidth << rRect.mnHeight;
126 void lclSaveRecord( XclExpStream& rStrm, XclExpRecordRef const & xRec )
128 if( xRec )
129 xRec->Save( rStrm );
132 /** Saves the passed record (group) together with a leading value record. */
133 template< typename Type >
134 void lclSaveRecord( XclExpStream& rStrm, XclExpRecordRef const & xRec, sal_uInt16 nRecId, Type nValue )
136 if( xRec )
138 XclExpValueRecord< Type >( nRecId, nValue ).Save( rStrm );
139 xRec->Save( rStrm );
143 template<typename ValueType, typename KeyType>
144 void lclSaveRecord(XclExpStream& rStrm, ValueType* pRec, sal_uInt16 nRecId, KeyType nValue)
146 if (pRec)
148 XclExpValueRecord<KeyType>(nRecId, nValue).Save(rStrm);
149 pRec->Save(rStrm);
153 void lclWriteChFrBlockRecord( XclExpStream& rStrm, const XclChFrBlock& rFrBlock, bool bBegin )
155 sal_uInt16 nRecId = bBegin ? EXC_ID_CHFRBLOCKBEGIN : EXC_ID_CHFRBLOCKEND;
156 rStrm.StartRecord( nRecId, 12 );
157 rStrm << nRecId << EXC_FUTUREREC_EMPTYFLAGS << rFrBlock.mnType << rFrBlock.mnContext << rFrBlock.mnValue1 << rFrBlock.mnValue2;
158 rStrm.EndRecord();
161 template< typename Type >
162 bool lclIsAutoAnyOrGetValue( Type& rValue, const Any& rAny )
164 return !rAny.hasValue() || !(rAny >>= rValue);
167 bool lclIsAutoAnyOrGetScaledValue( double& rfValue, const Any& rAny, bool bLogScale )
169 bool bIsAuto = lclIsAutoAnyOrGetValue( rfValue, rAny );
170 if( !bIsAuto && bLogScale )
171 rfValue = log( rfValue ) / log( 10.0 );
172 return bIsAuto;
175 sal_uInt16 lclGetTimeValue( const XclExpRoot& rRoot, double fSerialDate, sal_uInt16 nTimeUnit )
177 DateTime aDateTime = rRoot.GetDateTimeFromDouble( fSerialDate );
178 switch( nTimeUnit )
180 case EXC_CHDATERANGE_DAYS:
181 return ::limit_cast< sal_uInt16, double >( fSerialDate, 0, SAL_MAX_UINT16 );
182 case EXC_CHDATERANGE_MONTHS:
183 return ::limit_cast< sal_uInt16, sal_uInt16 >( 12 * (aDateTime.GetYear() - rRoot.GetBaseYear()) + aDateTime.GetMonth() - 1, 0, SAL_MAX_INT16 );
184 case EXC_CHDATERANGE_YEARS:
185 return ::limit_cast< sal_uInt16, sal_uInt16 >( aDateTime.GetYear() - rRoot.GetBaseYear(), 0, SAL_MAX_INT16 );
186 default:
187 OSL_ENSURE( false, "lclGetTimeValue - unexpected time unit" );
189 return ::limit_cast< sal_uInt16, double >( fSerialDate, 0, SAL_MAX_UINT16 );
192 bool lclConvertTimeValue( const XclExpRoot& rRoot, sal_uInt16& rnValue, const Any& rAny, sal_uInt16 nTimeUnit )
194 double fSerialDate = 0;
195 bool bAuto = lclIsAutoAnyOrGetValue( fSerialDate, rAny );
196 if( !bAuto )
197 rnValue = lclGetTimeValue( rRoot, fSerialDate, nTimeUnit );
198 return bAuto;
201 sal_uInt16 lclGetTimeUnit( sal_Int32 nApiTimeUnit )
203 switch( nApiTimeUnit )
205 case cssc::TimeUnit::DAY: return EXC_CHDATERANGE_DAYS;
206 case cssc::TimeUnit::MONTH: return EXC_CHDATERANGE_MONTHS;
207 case cssc::TimeUnit::YEAR: return EXC_CHDATERANGE_YEARS;
208 default: OSL_ENSURE( false, "lclGetTimeUnit - unexpected time unit" );
210 return EXC_CHDATERANGE_DAYS;
213 bool lclConvertTimeInterval( sal_uInt16& rnValue, sal_uInt16& rnTimeUnit, const Any& rAny )
215 cssc::TimeInterval aInterval;
216 bool bAuto = lclIsAutoAnyOrGetValue( aInterval, rAny );
217 if( !bAuto )
219 rnValue = ::limit_cast< sal_uInt16, sal_Int32 >( aInterval.Number, 1, SAL_MAX_UINT16 );
220 rnTimeUnit = lclGetTimeUnit( aInterval.TimeUnit );
222 return bAuto;
225 } // namespace
227 // Common =====================================================================
229 /** Stores global data needed in various classes of the Chart export filter. */
230 struct XclExpChRootData : public XclChRootData
232 typedef ::std::vector< XclChFrBlock > XclChFrBlockVector;
234 XclExpChChart& mrChartData; /// The chart data object.
235 XclChFrBlockVector maWrittenFrBlocks; /// Stack of future record levels already written out.
236 XclChFrBlockVector maUnwrittenFrBlocks; /// Stack of future record levels not yet written out.
238 explicit XclExpChRootData( XclExpChChart& rChartData ) : mrChartData( rChartData ) {}
240 /** Registers a new future record level. */
241 void RegisterFutureRecBlock( const XclChFrBlock& rFrBlock );
242 /** Initializes the current future record level (writes all unwritten CHFRBLOCKBEGIN records). */
243 void InitializeFutureRecBlock( XclExpStream& rStrm );
244 /** Finalizes the current future record level (writes CHFRBLOCKEND record if needed). */
245 void FinalizeFutureRecBlock( XclExpStream& rStrm );
248 void XclExpChRootData::RegisterFutureRecBlock( const XclChFrBlock& rFrBlock )
250 maUnwrittenFrBlocks.push_back( rFrBlock );
253 void XclExpChRootData::InitializeFutureRecBlock( XclExpStream& rStrm )
255 // first call from a future record writes all missing CHFRBLOCKBEGIN records
256 if( !maUnwrittenFrBlocks.empty() )
258 // write the leading CHFRINFO record
259 if( maWrittenFrBlocks.empty() )
261 rStrm.StartRecord( EXC_ID_CHFRINFO, 20 );
262 rStrm << EXC_ID_CHFRINFO << EXC_FUTUREREC_EMPTYFLAGS << EXC_CHFRINFO_EXCELXP2003 << EXC_CHFRINFO_EXCELXP2003 << sal_uInt16( 3 );
263 rStrm << sal_uInt16( 0x0850 ) << sal_uInt16( 0x085A ) << sal_uInt16( 0x0861 ) << sal_uInt16( 0x0861 ) << sal_uInt16( 0x086A ) << sal_uInt16( 0x086B );
264 rStrm.EndRecord();
266 // write all unwritten CHFRBLOCKBEGIN records
267 for( const auto& rUnwrittenFrBlock : maUnwrittenFrBlocks )
269 OSL_ENSURE( rUnwrittenFrBlock.mnType != EXC_CHFRBLOCK_TYPE_UNKNOWN, "XclExpChRootData::InitializeFutureRecBlock - unknown future record block type" );
270 lclWriteChFrBlockRecord( rStrm, rUnwrittenFrBlock, true );
272 // move all record infos to vector of written blocks
273 maWrittenFrBlocks.insert( maWrittenFrBlocks.end(), maUnwrittenFrBlocks.begin(), maUnwrittenFrBlocks.end() );
274 maUnwrittenFrBlocks.clear();
278 void XclExpChRootData::FinalizeFutureRecBlock( XclExpStream& rStrm )
280 OSL_ENSURE( !maUnwrittenFrBlocks.empty() || !maWrittenFrBlocks.empty(), "XclExpChRootData::FinalizeFutureRecBlock - no future record level found" );
281 if( !maUnwrittenFrBlocks.empty() )
283 // no future record has been written, just forget the topmost level
284 maUnwrittenFrBlocks.pop_back();
286 else if( !maWrittenFrBlocks.empty() )
288 // write the CHFRBLOCKEND record for the topmost block and delete it
289 lclWriteChFrBlockRecord( rStrm, maWrittenFrBlocks.back(), false );
290 maWrittenFrBlocks.pop_back();
294 XclExpChRoot::XclExpChRoot( const XclExpRoot& rRoot, XclExpChChart& rChartData ) :
295 XclExpRoot( rRoot ),
296 mxChData( new XclExpChRootData( rChartData ) )
300 XclExpChRoot::~XclExpChRoot()
304 Reference< XChartDocument > const & XclExpChRoot::GetChartDocument() const
306 return mxChData->mxChartDoc;
309 XclExpChChart& XclExpChRoot::GetChartData() const
311 return mxChData->mrChartData;
314 const XclChTypeInfo& XclExpChRoot::GetChartTypeInfo( XclChTypeId eType ) const
316 return mxChData->mxTypeInfoProv->GetTypeInfo( eType );
319 const XclChTypeInfo& XclExpChRoot::GetChartTypeInfo( const OUString& rServiceName ) const
321 return mxChData->mxTypeInfoProv->GetTypeInfoFromService( rServiceName );
324 const XclChFormatInfo& XclExpChRoot::GetFormatInfo( XclChObjectType eObjType ) const
326 return mxChData->mxFmtInfoProv->GetFormatInfo( eObjType );
329 void XclExpChRoot::InitConversion( css::uno::Reference< css::chart2::XChartDocument > const & xChartDoc, const tools::Rectangle& rChartRect ) const
331 mxChData->InitConversion( GetRoot(), xChartDoc, rChartRect );
334 void XclExpChRoot::FinishConversion() const
336 mxChData->FinishConversion();
339 bool XclExpChRoot::IsSystemColor( const Color& rColor, sal_uInt16 nSysColorIdx ) const
341 XclExpPalette& rPal = GetPalette();
342 return rPal.IsSystemColor( nSysColorIdx ) && (rColor == rPal.GetDefColor( nSysColorIdx ));
345 void XclExpChRoot::SetSystemColor( Color& rColor, sal_uInt32& rnColorId, sal_uInt16 nSysColorIdx ) const
347 OSL_ENSURE( GetPalette().IsSystemColor( nSysColorIdx ), "XclExpChRoot::SetSystemColor - invalid color index" );
348 rColor = GetPalette().GetDefColor( nSysColorIdx );
349 rnColorId = XclExpPalette::GetColorIdFromIndex( nSysColorIdx );
352 sal_Int32 XclExpChRoot::CalcChartXFromHmm( sal_Int32 nPosX ) const
354 return ::limit_cast< sal_Int32, double >( (nPosX - mxChData->mnBorderGapX) / mxChData->mfUnitSizeX, 0, EXC_CHART_TOTALUNITS );
357 sal_Int32 XclExpChRoot::CalcChartYFromHmm( sal_Int32 nPosY ) const
359 return ::limit_cast< sal_Int32, double >( (nPosY - mxChData->mnBorderGapY) / mxChData->mfUnitSizeY, 0, EXC_CHART_TOTALUNITS );
362 XclChRectangle XclExpChRoot::CalcChartRectFromHmm( const css::awt::Rectangle& rRect ) const
364 XclChRectangle aRect;
365 aRect.mnX = CalcChartXFromHmm( rRect.X );
366 aRect.mnY = CalcChartYFromHmm( rRect.Y );
367 aRect.mnWidth = CalcChartXFromHmm( rRect.Width );
368 aRect.mnHeight = CalcChartYFromHmm( rRect.Height );
369 return aRect;
372 void XclExpChRoot::ConvertLineFormat( XclChLineFormat& rLineFmt,
373 const ScfPropertySet& rPropSet, XclChPropertyMode ePropMode ) const
375 GetChartPropSetHelper().ReadLineProperties(
376 rLineFmt, *mxChData->mxLineDashTable, rPropSet, ePropMode );
379 bool XclExpChRoot::ConvertAreaFormat( XclChAreaFormat& rAreaFmt,
380 const ScfPropertySet& rPropSet, XclChPropertyMode ePropMode ) const
382 return GetChartPropSetHelper().ReadAreaProperties( rAreaFmt, rPropSet, ePropMode );
385 void XclExpChRoot::ConvertEscherFormat(
386 XclChEscherFormat& rEscherFmt, XclChPicFormat& rPicFmt,
387 const ScfPropertySet& rPropSet, XclChPropertyMode ePropMode ) const
389 GetChartPropSetHelper().ReadEscherProperties( rEscherFmt, rPicFmt,
390 *mxChData->mxGradientTable, *mxChData->mxHatchTable, *mxChData->mxBitmapTable, rPropSet, ePropMode );
393 sal_uInt16 XclExpChRoot::ConvertFont( const ScfPropertySet& rPropSet, sal_Int16 nScript ) const
395 XclFontData aFontData;
396 GetFontPropSetHelper().ReadFontProperties( aFontData, rPropSet, EXC_FONTPROPSET_CHART, nScript );
397 return GetFontBuffer().Insert( aFontData, EXC_COLOR_CHARTTEXT );
400 sal_uInt16 XclExpChRoot::ConvertPieRotation( const ScfPropertySet& rPropSet )
402 sal_Int32 nApiRot = 0;
403 rPropSet.GetProperty( nApiRot, EXC_CHPROP_STARTINGANGLE );
404 return static_cast< sal_uInt16 >( (450 - (nApiRot % 360)) % 360 );
407 void XclExpChRoot::RegisterFutureRecBlock( const XclChFrBlock& rFrBlock )
409 mxChData->RegisterFutureRecBlock( rFrBlock );
412 void XclExpChRoot::InitializeFutureRecBlock( XclExpStream& rStrm )
414 mxChData->InitializeFutureRecBlock( rStrm );
417 void XclExpChRoot::FinalizeFutureRecBlock( XclExpStream& rStrm )
419 mxChData->FinalizeFutureRecBlock( rStrm );
422 XclExpChGroupBase::XclExpChGroupBase( const XclExpChRoot& rRoot,
423 sal_uInt16 nFrType, sal_uInt16 nRecId, std::size_t nRecSize ) :
424 XclExpRecord( nRecId, nRecSize ),
425 XclExpChRoot( rRoot ),
426 maFrBlock( nFrType )
430 XclExpChGroupBase::~XclExpChGroupBase()
434 void XclExpChGroupBase::Save( XclExpStream& rStrm )
436 // header record
437 XclExpRecord::Save( rStrm );
438 // group records
439 if( HasSubRecords() )
441 // register the future record context corresponding to this record group
442 RegisterFutureRecBlock( maFrBlock );
443 // CHBEGIN record
444 XclExpEmptyRecord( EXC_ID_CHBEGIN ).Save( rStrm );
445 // embedded records
446 WriteSubRecords( rStrm );
447 // finalize the future records, must be done before the closing CHEND
448 FinalizeFutureRecBlock( rStrm );
449 // CHEND record
450 XclExpEmptyRecord( EXC_ID_CHEND ).Save( rStrm );
454 bool XclExpChGroupBase::HasSubRecords() const
456 return true;
459 void XclExpChGroupBase::SetFutureRecordContext( sal_uInt16 nFrContext, sal_uInt16 nFrValue1, sal_uInt16 nFrValue2 )
461 maFrBlock.mnContext = nFrContext;
462 maFrBlock.mnValue1 = nFrValue1;
463 maFrBlock.mnValue2 = nFrValue2;
466 XclExpChFutureRecordBase::XclExpChFutureRecordBase( const XclExpChRoot& rRoot,
467 XclFutureRecType eRecType, sal_uInt16 nRecId, std::size_t nRecSize ) :
468 XclExpFutureRecord( eRecType, nRecId, nRecSize ),
469 XclExpChRoot( rRoot )
473 void XclExpChFutureRecordBase::Save( XclExpStream& rStrm )
475 InitializeFutureRecBlock( rStrm );
476 XclExpFutureRecord::Save( rStrm );
479 // Frame formatting ===========================================================
481 XclExpChFramePos::XclExpChFramePos( sal_uInt16 nTLMode ) :
482 XclExpRecord( EXC_ID_CHFRAMEPOS, 20 )
484 maData.mnTLMode = nTLMode;
485 maData.mnBRMode = EXC_CHFRAMEPOS_PARENT;
488 void XclExpChFramePos::WriteBody( XclExpStream& rStrm )
490 rStrm << maData.mnTLMode << maData.mnBRMode << maData.maRect;
493 XclExpChLineFormat::XclExpChLineFormat( const XclExpChRoot& rRoot ) :
494 XclExpRecord( EXC_ID_CHLINEFORMAT, (rRoot.GetBiff() == EXC_BIFF8) ? 12 : 10 ),
495 mnColorId( XclExpPalette::GetColorIdFromIndex( EXC_COLOR_CHWINDOWTEXT ) )
499 void XclExpChLineFormat::SetDefault( XclChFrameType eDefFrameType )
501 switch( eDefFrameType )
503 case EXC_CHFRAMETYPE_AUTO:
504 SetAuto( true );
505 break;
506 case EXC_CHFRAMETYPE_INVISIBLE:
507 SetAuto( false );
508 maData.mnPattern = EXC_CHLINEFORMAT_NONE;
509 break;
510 default:
511 OSL_FAIL( "XclExpChLineFormat::SetDefault - unknown frame type" );
515 void XclExpChLineFormat::Convert( const XclExpChRoot& rRoot,
516 const ScfPropertySet& rPropSet, XclChObjectType eObjType )
518 const XclChFormatInfo& rFmtInfo = rRoot.GetFormatInfo( eObjType );
519 rRoot.ConvertLineFormat( maData, rPropSet, rFmtInfo.mePropMode );
520 if( HasLine() )
522 // detect system color, set color identifier (TODO: detect automatic series line)
523 if( (eObjType != EXC_CHOBJTYPE_LINEARSERIES) && rRoot.IsSystemColor( maData.maColor, rFmtInfo.mnAutoLineColorIdx ) )
525 // store color index from automatic format data
526 mnColorId = XclExpPalette::GetColorIdFromIndex( rFmtInfo.mnAutoLineColorIdx );
527 // try to set automatic mode
528 bool bAuto = (maData.mnPattern == EXC_CHLINEFORMAT_SOLID) && (maData.mnWeight == rFmtInfo.mnAutoLineWeight);
529 ::set_flag( maData.mnFlags, EXC_CHLINEFORMAT_AUTO, bAuto );
531 else
533 // user defined color - register in palette
534 mnColorId = rRoot.GetPalette().InsertColor( maData.maColor, EXC_COLOR_CHARTLINE );
537 else
539 // no line - set default system color
540 rRoot.SetSystemColor( maData.maColor, mnColorId, EXC_COLOR_CHWINDOWTEXT );
544 bool XclExpChLineFormat::IsDefault( XclChFrameType eDefFrameType ) const
546 return
547 ((eDefFrameType == EXC_CHFRAMETYPE_INVISIBLE) && !HasLine()) ||
548 ((eDefFrameType == EXC_CHFRAMETYPE_AUTO) && IsAuto());
551 void XclExpChLineFormat::WriteBody( XclExpStream& rStrm )
553 rStrm << maData.maColor << maData.mnPattern << maData.mnWeight << maData.mnFlags;
554 if( rStrm.GetRoot().GetBiff() == EXC_BIFF8 )
555 rStrm << rStrm.GetRoot().GetPalette().GetColorIndex( mnColorId );
558 namespace {
560 /** Creates a CHLINEFORMAT record from the passed property set. */
561 XclExpChLineFormatRef lclCreateLineFormat( const XclExpChRoot& rRoot,
562 const ScfPropertySet& rPropSet, XclChObjectType eObjType )
564 XclExpChLineFormatRef xLineFmt( new XclExpChLineFormat( rRoot ) );
565 xLineFmt->Convert( rRoot, rPropSet, eObjType );
566 const XclChFormatInfo& rFmtInfo = rRoot.GetFormatInfo( eObjType );
567 if( rFmtInfo.mbDeleteDefFrame && xLineFmt->IsDefault( rFmtInfo.meDefFrameType ) )
568 xLineFmt.reset();
569 return xLineFmt;
572 } // namespace
574 XclExpChAreaFormat::XclExpChAreaFormat( const XclExpChRoot& rRoot ) :
575 XclExpRecord( EXC_ID_CHAREAFORMAT, (rRoot.GetBiff() == EXC_BIFF8) ? 16 : 12 ),
576 mnPattColorId( XclExpPalette::GetColorIdFromIndex( EXC_COLOR_CHWINDOWBACK ) ),
577 mnBackColorId( XclExpPalette::GetColorIdFromIndex( EXC_COLOR_CHWINDOWTEXT ) )
581 bool XclExpChAreaFormat::Convert( const XclExpChRoot& rRoot,
582 const ScfPropertySet& rPropSet, XclChObjectType eObjType )
584 const XclChFormatInfo& rFmtInfo = rRoot.GetFormatInfo( eObjType );
585 bool bComplexFill = rRoot.ConvertAreaFormat( maData, rPropSet, rFmtInfo.mePropMode );
586 if( HasArea() )
588 bool bSolid = maData.mnPattern == EXC_PATT_SOLID;
589 // detect system color, set color identifier (TODO: detect automatic series area)
590 if( (eObjType != EXC_CHOBJTYPE_FILLEDSERIES) && rRoot.IsSystemColor( maData.maPattColor, rFmtInfo.mnAutoPattColorIdx ) )
592 // store color index from automatic format data
593 mnPattColorId = XclExpPalette::GetColorIdFromIndex( rFmtInfo.mnAutoPattColorIdx );
594 // set automatic mode
595 ::set_flag( maData.mnFlags, EXC_CHAREAFORMAT_AUTO, bSolid );
597 else
599 // user defined color - register color in palette
600 mnPattColorId = rRoot.GetPalette().InsertColor( maData.maPattColor, EXC_COLOR_CHARTAREA );
602 // background color (default system color for solid fills)
603 if( bSolid )
604 rRoot.SetSystemColor( maData.maBackColor, mnBackColorId, EXC_COLOR_CHWINDOWTEXT );
605 else
606 mnBackColorId = rRoot.GetPalette().InsertColor( maData.maBackColor, EXC_COLOR_CHARTAREA );
608 else
610 // no area - set default system colors
611 rRoot.SetSystemColor( maData.maPattColor, mnPattColorId, EXC_COLOR_CHWINDOWBACK );
612 rRoot.SetSystemColor( maData.maBackColor, mnBackColorId, EXC_COLOR_CHWINDOWTEXT );
614 return bComplexFill;
617 void XclExpChAreaFormat::SetDefault( XclChFrameType eDefFrameType )
619 switch( eDefFrameType )
621 case EXC_CHFRAMETYPE_AUTO:
622 SetAuto( true );
623 break;
624 case EXC_CHFRAMETYPE_INVISIBLE:
625 SetAuto( false );
626 maData.mnPattern = EXC_PATT_NONE;
627 break;
628 default:
629 OSL_FAIL( "XclExpChAreaFormat::SetDefault - unknown frame type" );
633 bool XclExpChAreaFormat::IsDefault( XclChFrameType eDefFrameType ) const
635 return
636 ((eDefFrameType == EXC_CHFRAMETYPE_INVISIBLE) && !HasArea()) ||
637 ((eDefFrameType == EXC_CHFRAMETYPE_AUTO) && IsAuto());
640 void XclExpChAreaFormat::WriteBody( XclExpStream& rStrm )
642 rStrm << maData.maPattColor << maData.maBackColor << maData.mnPattern << maData.mnFlags;
643 if( rStrm.GetRoot().GetBiff() == EXC_BIFF8 )
645 const XclExpPalette& rPal = rStrm.GetRoot().GetPalette();
646 rStrm << rPal.GetColorIndex( mnPattColorId ) << rPal.GetColorIndex( mnBackColorId );
650 XclExpChEscherFormat::XclExpChEscherFormat( const XclExpChRoot& rRoot ) :
651 XclExpChGroupBase( rRoot, EXC_CHFRBLOCK_TYPE_UNKNOWN, EXC_ID_CHESCHERFORMAT ),
652 mnColor1Id( XclExpPalette::GetColorIdFromIndex( EXC_COLOR_CHWINDOWBACK ) ),
653 mnColor2Id( XclExpPalette::GetColorIdFromIndex( EXC_COLOR_CHWINDOWBACK ) )
655 OSL_ENSURE_BIFF( GetBiff() == EXC_BIFF8 );
658 void XclExpChEscherFormat::Convert( const ScfPropertySet& rPropSet, XclChObjectType eObjType )
660 const XclChFormatInfo& rFmtInfo = GetFormatInfo( eObjType );
661 ConvertEscherFormat( maData, maPicFmt, rPropSet, rFmtInfo.mePropMode );
662 // register colors in palette
663 mnColor1Id = RegisterColor( ESCHER_Prop_fillColor );
664 mnColor2Id = RegisterColor( ESCHER_Prop_fillBackColor );
667 bool XclExpChEscherFormat::IsValid() const
669 return static_cast< bool >(maData.mxEscherSet);
672 void XclExpChEscherFormat::Save( XclExpStream& rStrm )
674 if( maData.mxEscherSet )
676 // replace RGB colors with palette indexes in the Escher container
677 const XclExpPalette& rPal = GetPalette();
678 maData.mxEscherSet->AddOpt( ESCHER_Prop_fillColor, 0x08000000 | rPal.GetColorIndex( mnColor1Id ) );
679 maData.mxEscherSet->AddOpt( ESCHER_Prop_fillBackColor, 0x08000000 | rPal.GetColorIndex( mnColor2Id ) );
681 // save the record group
682 XclExpChGroupBase::Save( rStrm );
686 bool XclExpChEscherFormat::HasSubRecords() const
688 // no subrecords for gradients
689 return maPicFmt.mnBmpMode != EXC_CHPICFORMAT_NONE;
692 void XclExpChEscherFormat::WriteSubRecords( XclExpStream& rStrm )
694 rStrm.StartRecord( EXC_ID_CHPICFORMAT, 14 );
695 rStrm << maPicFmt.mnBmpMode << sal_uInt16( 0 ) << maPicFmt.mnFlags << maPicFmt.mfScale;
696 rStrm.EndRecord();
699 sal_uInt32 XclExpChEscherFormat::RegisterColor( sal_uInt16 nPropId )
701 sal_uInt32 nBGRValue;
702 if( maData.mxEscherSet && maData.mxEscherSet->GetOpt( nPropId, nBGRValue ) )
704 // swap red and blue
705 Color aColor( nBGRValue & 0xff, (nBGRValue >> 8) & 0xff, (nBGRValue >> 16) & 0xff );
706 return GetPalette().InsertColor( aColor, EXC_COLOR_CHARTAREA );
708 return XclExpPalette::GetColorIdFromIndex( EXC_COLOR_CHWINDOWBACK );
711 void XclExpChEscherFormat::WriteBody( XclExpStream& rStrm )
713 OSL_ENSURE( maData.mxEscherSet, "XclExpChEscherFormat::WriteBody - missing property container" );
714 // write Escher property container via temporary memory stream
715 SvMemoryStream aMemStrm;
716 maData.mxEscherSet->Commit( aMemStrm );
717 aMemStrm.Flush();
718 aMemStrm.Seek( STREAM_SEEK_TO_BEGIN );
719 rStrm.CopyFromStream( aMemStrm );
722 XclExpChFrameBase::XclExpChFrameBase()
726 XclExpChFrameBase::~XclExpChFrameBase()
730 void XclExpChFrameBase::ConvertFrameBase( const XclExpChRoot& rRoot,
731 const ScfPropertySet& rPropSet, XclChObjectType eObjType )
733 // line format
734 mxLineFmt.reset( new XclExpChLineFormat( rRoot ) );
735 mxLineFmt->Convert( rRoot, rPropSet, eObjType );
736 // area format (only for frame objects)
737 if( rRoot.GetFormatInfo( eObjType ).mbIsFrame )
739 mxAreaFmt.reset( new XclExpChAreaFormat( rRoot ) );
740 bool bComplexFill = mxAreaFmt->Convert( rRoot, rPropSet, eObjType );
741 if( (rRoot.GetBiff() == EXC_BIFF8) && bComplexFill )
743 mxEscherFmt.reset( new XclExpChEscherFormat( rRoot ) );
744 mxEscherFmt->Convert( rPropSet, eObjType );
745 if( mxEscherFmt->IsValid() )
746 mxAreaFmt->SetAuto( false );
747 else
748 mxEscherFmt.reset();
753 void XclExpChFrameBase::SetDefaultFrameBase( const XclExpChRoot& rRoot,
754 XclChFrameType eDefFrameType, bool bIsFrame )
756 // line format
757 mxLineFmt.reset( new XclExpChLineFormat( rRoot ) );
758 mxLineFmt->SetDefault( eDefFrameType );
759 // area format (only for frame objects)
760 if( bIsFrame )
762 mxAreaFmt.reset( new XclExpChAreaFormat( rRoot ) );
763 mxAreaFmt->SetDefault( eDefFrameType );
764 mxEscherFmt.reset();
768 bool XclExpChFrameBase::IsDefaultFrameBase( XclChFrameType eDefFrameType ) const
770 return
771 (!mxLineFmt || mxLineFmt->IsDefault( eDefFrameType )) &&
772 (!mxAreaFmt || mxAreaFmt->IsDefault( eDefFrameType ));
775 void XclExpChFrameBase::WriteFrameRecords( XclExpStream& rStrm )
777 lclSaveRecord( rStrm, mxLineFmt );
778 lclSaveRecord( rStrm, mxAreaFmt );
779 lclSaveRecord( rStrm, mxEscherFmt );
782 XclExpChFrame::XclExpChFrame( const XclExpChRoot& rRoot, XclChObjectType eObjType ) :
783 XclExpChGroupBase( rRoot, EXC_CHFRBLOCK_TYPE_FRAME, EXC_ID_CHFRAME, 4 ),
784 meObjType( eObjType )
788 void XclExpChFrame::Convert( const ScfPropertySet& rPropSet )
790 ConvertFrameBase( GetChRoot(), rPropSet, meObjType );
793 void XclExpChFrame::SetAutoFlags( bool bAutoPos, bool bAutoSize )
795 ::set_flag( maData.mnFlags, EXC_CHFRAME_AUTOPOS, bAutoPos );
796 ::set_flag( maData.mnFlags, EXC_CHFRAME_AUTOSIZE, bAutoSize );
799 bool XclExpChFrame::IsDefault() const
801 return IsDefaultFrameBase( GetFormatInfo( meObjType ).meDefFrameType );
804 bool XclExpChFrame::IsDeleteable() const
806 return IsDefault() && GetFormatInfo( meObjType ).mbDeleteDefFrame;
809 void XclExpChFrame::Save( XclExpStream& rStrm )
811 switch( meObjType )
813 // wall/floor frame without CHFRAME header record
814 case EXC_CHOBJTYPE_WALL3D:
815 case EXC_CHOBJTYPE_FLOOR3D:
816 WriteFrameRecords( rStrm );
817 break;
818 default:
819 XclExpChGroupBase::Save( rStrm );
823 void XclExpChFrame::WriteSubRecords( XclExpStream& rStrm )
825 WriteFrameRecords( rStrm );
828 void XclExpChFrame::WriteBody( XclExpStream& rStrm )
830 rStrm << maData.mnFormat << maData.mnFlags;
833 namespace {
835 /** Creates a CHFRAME record from the passed property set. */
836 XclExpChFrameRef lclCreateFrame( const XclExpChRoot& rRoot,
837 const ScfPropertySet& rPropSet, XclChObjectType eObjType )
839 XclExpChFrameRef xFrame( new XclExpChFrame( rRoot, eObjType ) );
840 xFrame->Convert( rPropSet );
841 if( xFrame->IsDeleteable() )
842 xFrame.reset();
843 return xFrame;
846 } // namespace
848 // Source links ===============================================================
850 namespace {
852 void lclAddDoubleRefData(
853 ScTokenArray& orArray, const FormulaToken& rToken,
854 SCTAB nScTab1, SCCOL nScCol1, SCROW nScRow1,
855 SCTAB nScTab2, SCCOL nScCol2, SCROW nScRow2 )
857 ScComplexRefData aComplexRef;
858 aComplexRef.InitRange(ScRange(nScCol1,nScRow1,nScTab1,nScCol2,nScRow2,nScTab2));
859 aComplexRef.Ref1.SetFlag3D( true );
861 if( orArray.GetLen() > 0 )
862 orArray.AddOpCode( ocUnion );
864 OSL_ENSURE( (rToken.GetType() == ::formula::svDoubleRef) || (rToken.GetType() == ::formula::svExternalDoubleRef),
865 "lclAddDoubleRefData - double reference token expected");
866 if( rToken.GetType() == ::formula::svExternalDoubleRef )
867 orArray.AddExternalDoubleReference(
868 rToken.GetIndex(), rToken.GetString(), aComplexRef);
869 else
870 orArray.AddDoubleReference( aComplexRef );
873 } // namespace
875 XclExpChSourceLink::XclExpChSourceLink( const XclExpChRoot& rRoot, sal_uInt8 nDestType ) :
876 XclExpRecord( EXC_ID_CHSOURCELINK ),
877 XclExpChRoot( rRoot )
879 maData.mnDestType = nDestType;
880 maData.mnLinkType = EXC_CHSRCLINK_DIRECTLY;
883 sal_uInt16 XclExpChSourceLink::ConvertDataSequence( Reference< XDataSequence > const & xDataSeq, bool bSplitToColumns, sal_uInt16 nDefCount )
885 mxLinkFmla.reset();
886 maData.mnLinkType = EXC_CHSRCLINK_DEFAULT;
888 if( !xDataSeq.is() )
889 return nDefCount;
891 // Compile the range representation string into token array. Note that the
892 // source range text depends on the current grammar.
893 OUString aRangeRepr = xDataSeq->getSourceRangeRepresentation();
894 ScCompiler aComp( &GetDoc(), ScAddress(), GetDoc().GetGrammar() );
895 std::unique_ptr<ScTokenArray> pArray(aComp.CompileString(aRangeRepr));
896 if( !pArray )
897 return nDefCount;
899 ScTokenArray aArray;
900 sal_uInt32 nValueCount = 0;
901 FormulaTokenArrayPlainIterator aIter(*pArray);
902 for( const FormulaToken* pToken = aIter.First(); pToken; pToken = aIter.Next() )
904 switch( pToken->GetType() )
906 case ::formula::svSingleRef:
907 case ::formula::svExternalSingleRef:
908 // for a single ref token, just add it to the new token array as is
909 if( aArray.GetLen() > 0 )
910 aArray.AddOpCode( ocUnion );
911 aArray.AddToken( *pToken );
912 ++nValueCount;
913 break;
915 case ::formula::svDoubleRef:
916 case ::formula::svExternalDoubleRef:
918 // split 3-dimensional ranges into single sheets
919 const ScComplexRefData& rComplexRef = *pToken->GetDoubleRef();
920 ScAddress aAbs1 = rComplexRef.Ref1.toAbs(ScAddress());
921 ScAddress aAbs2 = rComplexRef.Ref2.toAbs(ScAddress());
922 for (SCTAB nScTab = aAbs1.Tab(); nScTab <= aAbs2.Tab(); ++nScTab)
924 // split 2-dimensional ranges into single columns
925 if (bSplitToColumns && (aAbs1.Col() < aAbs2.Col()) && (aAbs1.Row() < aAbs2.Row()))
926 for (SCCOL nScCol = aAbs1.Col(); nScCol <= aAbs2.Col(); ++nScCol)
927 lclAddDoubleRefData(aArray, *pToken, nScTab, nScCol, aAbs1.Row(), nScTab, nScCol, aAbs2.Row());
928 else
929 lclAddDoubleRefData(aArray, *pToken, nScTab, aAbs1.Col(), aAbs1.Row(), nScTab, aAbs2.Col(), aAbs2.Row());
931 sal_uInt32 nTabs = static_cast<sal_uInt32>(aAbs2.Tab() - aAbs1.Tab() + 1);
932 sal_uInt32 nCols = static_cast<sal_uInt32>(aAbs2.Col() - aAbs1.Col() + 1);
933 sal_uInt32 nRows = static_cast<sal_uInt32>(aAbs2.Row() - aAbs1.Row() + 1);
934 nValueCount += nCols * nRows * nTabs;
936 break;
938 default:;
942 const ScAddress aBaseCell;
943 mxLinkFmla = GetFormulaCompiler().CreateFormula( EXC_FMLATYPE_CHART, aArray, &aBaseCell );
944 maData.mnLinkType = EXC_CHSRCLINK_WORKSHEET;
945 return ulimit_cast< sal_uInt16 >( nValueCount, EXC_CHDATAFORMAT_MAXPOINTCOUNT );
948 void XclExpChSourceLink::ConvertString( const OUString& aString )
950 mxString = XclExpStringHelper::CreateString( GetRoot(), aString, XclStrFlags::ForceUnicode | XclStrFlags::EightBitLength | XclStrFlags::SeparateFormats );
953 sal_uInt16 XclExpChSourceLink::ConvertStringSequence( const Sequence< Reference< XFormattedString > >& rStringSeq )
955 mxString.reset();
956 sal_uInt16 nFontIdx = EXC_FONT_APP;
957 if( rStringSeq.hasElements() )
959 mxString = XclExpStringHelper::CreateString( GetRoot(), OUString(), XclStrFlags::ForceUnicode | XclStrFlags::EightBitLength | XclStrFlags::SeparateFormats );
960 Reference< XBreakIterator > xBreakIt = GetDoc().GetBreakIterator();
961 namespace ApiScriptType = ::com::sun::star::i18n::ScriptType;
963 // convert all formatted string entries from the sequence
964 for( const Reference< XFormattedString >& rString : rStringSeq )
966 if( rString.is() )
968 sal_uInt16 nWstrnFontIdx = EXC_FONT_NOTFOUND;
969 sal_uInt16 nAsianFontIdx = EXC_FONT_NOTFOUND;
970 sal_uInt16 nCmplxFontIdx = EXC_FONT_NOTFOUND;
971 OUString aText = rString->getString();
972 ScfPropertySet aStrProp( rString );
974 // #i63255# get script type for leading weak characters
975 sal_Int16 nLastScript = XclExpStringHelper::GetLeadingScriptType( GetRoot(), aText );
977 // process all script portions
978 sal_Int32 nPortionPos = 0;
979 sal_Int32 nTextLen = aText.getLength();
980 while( nPortionPos < nTextLen )
982 // get script type and end position of next script portion
983 sal_Int16 nScript = xBreakIt->getScriptType( aText, nPortionPos );
984 sal_Int32 nPortionEnd = xBreakIt->endOfScript( aText, nPortionPos, nScript );
986 // reuse previous script for following weak portions
987 if( nScript == ApiScriptType::WEAK )
988 nScript = nLastScript;
990 // Excel start position of this portion
991 sal_uInt16 nXclPortionStart = mxString->Len();
992 // add portion text to Excel string
993 XclExpStringHelper::AppendString( *mxString, GetRoot(), aText.copy( nPortionPos, nPortionEnd - nPortionPos ) );
994 if( nXclPortionStart < mxString->Len() )
996 // find font index variable dependent on script type
997 sal_uInt16& rnFontIdx = (nScript == ApiScriptType::COMPLEX) ? nCmplxFontIdx :
998 ((nScript == ApiScriptType::ASIAN) ? nAsianFontIdx : nWstrnFontIdx);
1000 // insert font into buffer (if not yet done)
1001 if( rnFontIdx == EXC_FONT_NOTFOUND )
1002 rnFontIdx = ConvertFont( aStrProp, nScript );
1004 // insert font index into format run vector
1005 mxString->AppendFormat( nXclPortionStart, rnFontIdx );
1008 // go to next script portion
1009 nLastScript = nScript;
1010 nPortionPos = nPortionEnd;
1014 if( !mxString->IsEmpty() )
1016 // get leading font index
1017 const XclFormatRunVec& rFormats = mxString->GetFormats();
1018 OSL_ENSURE( !rFormats.empty() && (rFormats.front().mnChar == 0),
1019 "XclExpChSourceLink::ConvertStringSequenc - missing leading format" );
1020 // remove leading format run, if entire string is equally formatted
1021 if( rFormats.size() == 1 )
1022 nFontIdx = mxString->RemoveLeadingFont();
1023 else if( !rFormats.empty() )
1024 nFontIdx = rFormats.front().mnFontIdx;
1025 // add trailing format run, if string is rich-formatted
1026 if( mxString->IsRich() )
1027 mxString->AppendTrailingFormat( EXC_FONT_APP );
1030 return nFontIdx;
1033 void XclExpChSourceLink::ConvertNumFmt( const ScfPropertySet& rPropSet, bool bPercent )
1035 sal_Int32 nApiNumFmt = 0;
1036 if( bPercent ? rPropSet.GetProperty( nApiNumFmt, EXC_CHPROP_PERCENTAGENUMFMT ) : rPropSet.GetProperty( nApiNumFmt, EXC_CHPROP_NUMBERFORMAT ) )
1038 ::set_flag( maData.mnFlags, EXC_CHSRCLINK_NUMFMT );
1039 maData.mnNumFmtIdx = GetNumFmtBuffer().Insert( static_cast< sal_uInt32 >( nApiNumFmt ) );
1043 void XclExpChSourceLink::AppendString( const OUString& rStr )
1045 if (!mxString)
1046 return;
1047 XclExpStringHelper::AppendString( *mxString, GetRoot(), rStr );
1050 void XclExpChSourceLink::Save( XclExpStream& rStrm )
1052 // CHFORMATRUNS record
1053 if( mxString && mxString->IsRich() )
1055 std::size_t nRecSize = (1 + mxString->GetFormatsCount()) * ((GetBiff() == EXC_BIFF8) ? 2 : 1);
1056 rStrm.StartRecord( EXC_ID_CHFORMATRUNS, nRecSize );
1057 mxString->WriteFormats( rStrm, true );
1058 rStrm.EndRecord();
1060 // CHSOURCELINK record
1061 XclExpRecord::Save( rStrm );
1062 // CHSTRING record
1063 if( mxString && !mxString->IsEmpty() )
1065 rStrm.StartRecord( EXC_ID_CHSTRING, 2 + mxString->GetSize() );
1066 rStrm << sal_uInt16( 0 ) << *mxString;
1067 rStrm.EndRecord();
1071 void XclExpChSourceLink::WriteBody( XclExpStream& rStrm )
1073 rStrm << maData.mnDestType
1074 << maData.mnLinkType
1075 << maData.mnFlags
1076 << maData.mnNumFmtIdx
1077 << mxLinkFmla;
1080 // Text =======================================================================
1082 XclExpChFont::XclExpChFont( sal_uInt16 nFontIdx ) :
1083 XclExpUInt16Record( EXC_ID_CHFONT, nFontIdx )
1087 XclExpChObjectLink::XclExpChObjectLink( sal_uInt16 nLinkTarget, const XclChDataPointPos& rPointPos ) :
1088 XclExpRecord( EXC_ID_CHOBJECTLINK, 6 )
1090 maData.mnTarget = nLinkTarget;
1091 maData.maPointPos = rPointPos;
1094 void XclExpChObjectLink::WriteBody( XclExpStream& rStrm )
1096 rStrm << maData.mnTarget << maData.maPointPos.mnSeriesIdx << maData.maPointPos.mnPointIdx;
1099 XclExpChFrLabelProps::XclExpChFrLabelProps( const XclExpChRoot& rRoot ) :
1100 XclExpChFutureRecordBase( rRoot, EXC_FUTUREREC_UNUSEDREF, EXC_ID_CHFRLABELPROPS, 4 )
1104 void XclExpChFrLabelProps::Convert( const ScfPropertySet& rPropSet,
1105 bool bShowCateg, bool bShowValue, bool bShowPercent, bool bShowBubble )
1107 // label value flags
1108 ::set_flag( maData.mnFlags, EXC_CHFRLABELPROPS_SHOWSERIES, false );
1109 ::set_flag( maData.mnFlags, EXC_CHFRLABELPROPS_SHOWCATEG, bShowCateg );
1110 ::set_flag( maData.mnFlags, EXC_CHFRLABELPROPS_SHOWVALUE, bShowValue );
1111 ::set_flag( maData.mnFlags, EXC_CHFRLABELPROPS_SHOWPERCENT, bShowPercent );
1112 ::set_flag( maData.mnFlags, EXC_CHFRLABELPROPS_SHOWBUBBLE, bShowBubble );
1114 // label value separator
1115 maData.maSeparator = rPropSet.GetStringProperty( EXC_CHPROP_LABELSEPARATOR );
1116 if( maData.maSeparator.isEmpty() )
1117 maData.maSeparator = " ";
1120 void XclExpChFrLabelProps::WriteBody( XclExpStream& rStrm )
1122 XclExpString aXclSep( maData.maSeparator, XclStrFlags::ForceUnicode | XclStrFlags::SmartFlags );
1123 rStrm << maData.mnFlags << aXclSep;
1126 XclExpChFontBase::~XclExpChFontBase()
1130 void XclExpChFontBase::ConvertFontBase( const XclExpChRoot& rRoot, sal_uInt16 nFontIdx )
1132 if( const XclExpFont* pFont = rRoot.GetFontBuffer().GetFont( nFontIdx ) )
1134 XclExpChFontRef xFont( new XclExpChFont( nFontIdx ) );
1135 SetFont( xFont, pFont->GetFontData().maColor, pFont->GetFontColorId() );
1139 void XclExpChFontBase::ConvertFontBase( const XclExpChRoot& rRoot, const ScfPropertySet& rPropSet )
1141 ConvertFontBase( rRoot, rRoot.ConvertFont( rPropSet, rRoot.GetDefApiScript() ) );
1144 void XclExpChFontBase::ConvertRotationBase(const ScfPropertySet& rPropSet, bool bSupportsStacked )
1146 sal_uInt16 nRotation = XclChPropSetHelper::ReadRotationProperties( rPropSet, bSupportsStacked );
1147 SetRotation( nRotation );
1150 XclExpChText::XclExpChText( const XclExpChRoot& rRoot ) :
1151 XclExpChGroupBase( rRoot, EXC_CHFRBLOCK_TYPE_TEXT, EXC_ID_CHTEXT, (rRoot.GetBiff() == EXC_BIFF8) ? 32 : 26 ),
1152 mnTextColorId( XclExpPalette::GetColorIdFromIndex( EXC_COLOR_CHWINDOWTEXT ) )
1156 void XclExpChText::SetFont( XclExpChFontRef xFont, const Color& rColor, sal_uInt32 nColorId )
1158 mxFont = xFont;
1159 maData.maTextColor = rColor;
1160 ::set_flag( maData.mnFlags, EXC_CHTEXT_AUTOCOLOR, rColor == COL_AUTO );
1161 mnTextColorId = nColorId;
1164 void XclExpChText::SetRotation( sal_uInt16 nRotation )
1166 maData.mnRotation = nRotation;
1167 ::insert_value( maData.mnFlags, XclTools::GetXclOrientFromRot( nRotation ), 8, 3 );
1170 void XclExpChText::ConvertTitle( Reference< XTitle > const & xTitle, sal_uInt16 nTarget, const OUString* pSubTitle )
1172 switch( nTarget )
1174 case EXC_CHOBJLINK_TITLE: SetFutureRecordContext( EXC_CHFRBLOCK_TEXT_TITLE ); break;
1175 case EXC_CHOBJLINK_YAXIS: SetFutureRecordContext( EXC_CHFRBLOCK_TEXT_AXISTITLE, 1 ); break;
1176 case EXC_CHOBJLINK_XAXIS: SetFutureRecordContext( EXC_CHFRBLOCK_TEXT_AXISTITLE ); break;
1177 case EXC_CHOBJLINK_ZAXIS: SetFutureRecordContext( EXC_CHFRBLOCK_TEXT_AXISTITLE, 2 ); break;
1180 mxSrcLink.reset();
1181 mxObjLink.reset( new XclExpChObjectLink( nTarget, XclChDataPointPos( 0, 0 ) ) );
1183 if( xTitle.is() )
1185 // title frame formatting
1186 ScfPropertySet aTitleProp( xTitle );
1187 mxFrame = lclCreateFrame( GetChRoot(), aTitleProp, EXC_CHOBJTYPE_TEXT );
1189 // string sequence
1190 mxSrcLink.reset( new XclExpChSourceLink( GetChRoot(), EXC_CHSRCLINK_TITLE ) );
1191 sal_uInt16 nFontIdx = mxSrcLink->ConvertStringSequence( xTitle->getText() );
1192 if (pSubTitle)
1194 // append subtitle as the 2nd line of the title.
1195 OUString aSubTitle = "\n" + *pSubTitle;
1196 mxSrcLink->AppendString(aSubTitle);
1199 ConvertFontBase( GetChRoot(), nFontIdx );
1201 // rotation
1202 ConvertRotationBase( aTitleProp, true );
1204 // manual text position - only for main title
1205 mxFramePos.reset( new XclExpChFramePos( EXC_CHFRAMEPOS_PARENT ) );
1206 if( nTarget == EXC_CHOBJLINK_TITLE )
1208 Any aRelPos;
1209 if( aTitleProp.GetAnyProperty( aRelPos, EXC_CHPROP_RELATIVEPOSITION ) && aRelPos.has< RelativePosition >() ) try
1211 // calculate absolute position for CHTEXT record
1212 Reference< cssc::XChartDocument > xChart1Doc( GetChartDocument(), UNO_QUERY_THROW );
1213 Reference< XShape > xTitleShape( xChart1Doc->getTitle(), UNO_SET_THROW );
1214 css::awt::Point aPos = xTitleShape->getPosition();
1215 css::awt::Size aSize = xTitleShape->getSize();
1216 css::awt::Rectangle aRect( aPos.X, aPos.Y, aSize.Width, aSize.Height );
1217 maData.maRect = CalcChartRectFromHmm( aRect );
1218 ::insert_value( maData.mnFlags2, EXC_CHTEXT_POS_MOVED, 0, 4 );
1219 // manual title position implies manual plot area
1220 GetChartData().SetManualPlotArea();
1221 // calculate the default title position in chart units
1222 sal_Int32 nDefPosX = ::std::max< sal_Int32 >( (EXC_CHART_TOTALUNITS - maData.maRect.mnWidth) / 2, 0 );
1223 sal_Int32 nDefPosY = 85;
1224 // set the position relative to the standard position
1225 XclChRectangle& rFrameRect = mxFramePos->GetFramePosData().maRect;
1226 rFrameRect.mnX = maData.maRect.mnX - nDefPosX;
1227 rFrameRect.mnY = maData.maRect.mnY - nDefPosY;
1229 catch( Exception& )
1234 else
1236 ::set_flag( maData.mnFlags, EXC_CHTEXT_DELETED );
1240 void XclExpChText::ConvertLegend( const ScfPropertySet& rPropSet )
1242 ::set_flag( maData.mnFlags, EXC_CHTEXT_AUTOTEXT );
1243 ::set_flag( maData.mnFlags, EXC_CHTEXT_AUTOGEN );
1244 ConvertFontBase( GetChRoot(), rPropSet );
1247 bool XclExpChText::ConvertDataLabel( const ScfPropertySet& rPropSet,
1248 const XclChTypeInfo& rTypeInfo, const XclChDataPointPos& rPointPos )
1250 SetFutureRecordContext( EXC_CHFRBLOCK_TEXT_DATALABEL, rPointPos.mnPointIdx, rPointPos.mnSeriesIdx );
1252 cssc2::DataPointLabel aPointLabel;
1253 if( !rPropSet.GetProperty( aPointLabel, EXC_CHPROP_LABEL ) )
1254 return false;
1256 // percentage only allowed in pie and donut charts
1257 bool bIsPie = rTypeInfo.meTypeCateg == EXC_CHTYPECATEG_PIE;
1258 // bubble sizes only allowed in bubble charts
1259 bool bIsBubble = rTypeInfo.meTypeId == EXC_CHTYPEID_BUBBLES;
1260 OSL_ENSURE( (GetBiff() == EXC_BIFF8) || !bIsBubble, "XclExpChText::ConvertDataLabel - bubble charts only in BIFF8" );
1262 // raw show flags
1263 bool bShowValue = !bIsBubble && aPointLabel.ShowNumber; // Chart2 uses 'ShowNumber' for bubble size
1264 bool bShowPercent = bIsPie && aPointLabel.ShowNumberInPercent; // percentage only in pie/donut charts
1265 bool bShowCateg = aPointLabel.ShowCategoryName;
1266 bool bShowBubble = bIsBubble && aPointLabel.ShowNumber; // Chart2 uses 'ShowNumber' for bubble size
1267 bool bShowAny = bShowValue || bShowPercent || bShowCateg || bShowBubble;
1269 // create the CHFRLABELPROPS record for extended settings in BIFF8
1270 if( bShowAny && (GetBiff() == EXC_BIFF8) )
1272 mxLabelProps.reset( new XclExpChFrLabelProps( GetChRoot() ) );
1273 mxLabelProps->Convert( rPropSet, bShowCateg, bShowValue, bShowPercent, bShowBubble );
1276 // restrict to combinations allowed in CHTEXT
1277 if( bShowPercent ) bShowValue = false; // percent wins over value
1278 if( bShowValue ) bShowCateg = false; // value wins over category
1279 if( bShowValue || bShowCateg ) bShowBubble = false; // value or category wins over bubble size
1281 // set all flags
1282 ::set_flag( maData.mnFlags, EXC_CHTEXT_AUTOTEXT );
1283 ::set_flag( maData.mnFlags, EXC_CHTEXT_SHOWVALUE, bShowValue );
1284 ::set_flag( maData.mnFlags, EXC_CHTEXT_SHOWPERCENT, bShowPercent );
1285 ::set_flag( maData.mnFlags, EXC_CHTEXT_SHOWCATEG, bShowCateg );
1286 ::set_flag( maData.mnFlags, EXC_CHTEXT_SHOWCATEGPERC, bShowPercent && bShowCateg );
1287 ::set_flag( maData.mnFlags, EXC_CHTEXT_SHOWBUBBLE, bShowBubble );
1288 ::set_flag( maData.mnFlags, EXC_CHTEXT_SHOWSYMBOL, bShowAny && aPointLabel.ShowLegendSymbol );
1289 ::set_flag( maData.mnFlags, EXC_CHTEXT_DELETED, !bShowAny );
1291 if( bShowAny )
1293 // font settings
1294 ConvertFontBase( GetChRoot(), rPropSet );
1295 ConvertRotationBase( rPropSet, false );
1296 // label placement
1297 sal_Int32 nPlacement = 0;
1298 sal_uInt16 nLabelPos = EXC_CHTEXT_POS_AUTO;
1299 if( rPropSet.GetProperty( nPlacement, EXC_CHPROP_LABELPLACEMENT ) )
1301 using namespace cssc::DataLabelPlacement;
1302 if( nPlacement == rTypeInfo.mnDefaultLabelPos )
1304 nLabelPos = EXC_CHTEXT_POS_DEFAULT;
1306 else switch( nPlacement )
1308 case AVOID_OVERLAP: nLabelPos = EXC_CHTEXT_POS_AUTO; break;
1309 case CENTER: nLabelPos = EXC_CHTEXT_POS_CENTER; break;
1310 case TOP: nLabelPos = EXC_CHTEXT_POS_ABOVE; break;
1311 case TOP_LEFT: nLabelPos = EXC_CHTEXT_POS_LEFT; break;
1312 case LEFT: nLabelPos = EXC_CHTEXT_POS_LEFT; break;
1313 case BOTTOM_LEFT: nLabelPos = EXC_CHTEXT_POS_LEFT; break;
1314 case BOTTOM: nLabelPos = EXC_CHTEXT_POS_BELOW; break;
1315 case BOTTOM_RIGHT: nLabelPos = EXC_CHTEXT_POS_RIGHT; break;
1316 case RIGHT: nLabelPos = EXC_CHTEXT_POS_RIGHT; break;
1317 case TOP_RIGHT: nLabelPos = EXC_CHTEXT_POS_RIGHT; break;
1318 case INSIDE: nLabelPos = EXC_CHTEXT_POS_INSIDE; break;
1319 case OUTSIDE: nLabelPos = EXC_CHTEXT_POS_OUTSIDE; break;
1320 case NEAR_ORIGIN: nLabelPos = EXC_CHTEXT_POS_AXIS; break;
1321 default: OSL_FAIL( "XclExpChText::ConvertDataLabel - unknown label placement type" );
1324 ::insert_value( maData.mnFlags2, nLabelPos, 0, 4 );
1325 // source link (contains number format)
1326 mxSrcLink.reset( new XclExpChSourceLink( GetChRoot(), EXC_CHSRCLINK_TITLE ) );
1327 if( bShowValue || bShowPercent )
1328 // percentage format wins over value format
1329 mxSrcLink->ConvertNumFmt( rPropSet, bShowPercent );
1330 // object link
1331 mxObjLink.reset( new XclExpChObjectLink( EXC_CHOBJLINK_DATA, rPointPos ) );
1334 /* Return true to indicate valid label settings:
1335 - for existing labels at entire series
1336 - for any settings at single data point (to be able to delete a point label) */
1337 return bShowAny || (rPointPos.mnPointIdx != EXC_CHDATAFORMAT_ALLPOINTS);
1340 void XclExpChText::ConvertTrendLineEquation( const ScfPropertySet& rPropSet, const XclChDataPointPos& rPointPos )
1342 // required flags
1343 ::set_flag( maData.mnFlags, EXC_CHTEXT_AUTOTEXT );
1344 if( GetBiff() == EXC_BIFF8 )
1345 ::set_flag( maData.mnFlags, EXC_CHTEXT_SHOWCATEG ); // must set this to make equation visible in Excel
1346 // frame formatting
1347 mxFrame = lclCreateFrame( GetChRoot(), rPropSet, EXC_CHOBJTYPE_TEXT );
1348 // font settings
1349 maData.mnHAlign = EXC_CHTEXT_ALIGN_TOPLEFT;
1350 maData.mnVAlign = EXC_CHTEXT_ALIGN_TOPLEFT;
1351 ConvertFontBase( GetChRoot(), rPropSet );
1352 // source link (contains number format)
1353 mxSrcLink.reset( new XclExpChSourceLink( GetChRoot(), EXC_CHSRCLINK_TITLE ) );
1354 mxSrcLink->ConvertNumFmt( rPropSet, false );
1355 // object link
1356 mxObjLink.reset( new XclExpChObjectLink( EXC_CHOBJLINK_DATA, rPointPos ) );
1359 sal_uInt16 XclExpChText::GetAttLabelFlags() const
1361 sal_uInt16 nFlags = 0;
1362 ::set_flag( nFlags, EXC_CHATTLABEL_SHOWVALUE, ::get_flag( maData.mnFlags, EXC_CHTEXT_SHOWVALUE ) );
1363 ::set_flag( nFlags, EXC_CHATTLABEL_SHOWPERCENT, ::get_flag( maData.mnFlags, EXC_CHTEXT_SHOWPERCENT ) );
1364 ::set_flag( nFlags, EXC_CHATTLABEL_SHOWCATEGPERC, ::get_flag( maData.mnFlags, EXC_CHTEXT_SHOWCATEGPERC ) );
1365 ::set_flag( nFlags, EXC_CHATTLABEL_SHOWCATEG, ::get_flag( maData.mnFlags, EXC_CHTEXT_SHOWCATEG ) );
1366 return nFlags;
1369 void XclExpChText::WriteSubRecords( XclExpStream& rStrm )
1371 // CHFRAMEPOS record
1372 lclSaveRecord( rStrm, mxFramePos );
1373 // CHFONT record
1374 lclSaveRecord( rStrm, mxFont );
1375 // CHSOURCELINK group
1376 lclSaveRecord( rStrm, mxSrcLink );
1377 // CHFRAME group
1378 lclSaveRecord( rStrm, mxFrame );
1379 // CHOBJECTLINK record
1380 lclSaveRecord( rStrm, mxObjLink );
1381 // CHFRLABELPROPS record
1382 lclSaveRecord( rStrm, mxLabelProps );
1385 void XclExpChText::WriteBody( XclExpStream& rStrm )
1387 rStrm << maData.mnHAlign
1388 << maData.mnVAlign
1389 << maData.mnBackMode
1390 << maData.maTextColor
1391 << maData.maRect
1392 << maData.mnFlags;
1394 if( GetBiff() == EXC_BIFF8 )
1396 rStrm << GetPalette().GetColorIndex( mnTextColorId )
1397 << maData.mnFlags2
1398 << maData.mnRotation;
1402 namespace {
1404 /** Creates and returns an Excel text object from the passed title. */
1405 XclExpChTextRef lclCreateTitle( const XclExpChRoot& rRoot, Reference< XTitled > const & xTitled, sal_uInt16 nTarget,
1406 const OUString* pSubTitle = nullptr )
1408 Reference< XTitle > xTitle;
1409 if( xTitled.is() )
1410 xTitle = xTitled->getTitleObject();
1412 XclExpChTextRef xText( new XclExpChText( rRoot ) );
1413 xText->ConvertTitle( xTitle, nTarget, pSubTitle );
1414 /* Do not delete the CHTEXT group for the main title. A missing CHTEXT
1415 will be interpreted as auto-generated title showing the series title in
1416 charts that contain exactly one data series. */
1417 if( (nTarget != EXC_CHOBJLINK_TITLE) && !xText->HasString() )
1418 xText.reset();
1420 return xText;
1425 // Data series ================================================================
1427 XclExpChMarkerFormat::XclExpChMarkerFormat( const XclExpChRoot& rRoot ) :
1428 XclExpRecord( EXC_ID_CHMARKERFORMAT, (rRoot.GetBiff() == EXC_BIFF8) ? 20 : 12 ),
1429 mnLineColorId( XclExpPalette::GetColorIdFromIndex( EXC_COLOR_CHWINDOWTEXT ) ),
1430 mnFillColorId( XclExpPalette::GetColorIdFromIndex( EXC_COLOR_CHWINDOWBACK ) )
1434 void XclExpChMarkerFormat::Convert( const XclExpChRoot& rRoot,
1435 const ScfPropertySet& rPropSet, sal_uInt16 nFormatIdx )
1437 XclChPropSetHelper::ReadMarkerProperties( maData, rPropSet, nFormatIdx );
1438 /* Set marker line/fill color to series line color.
1439 TODO: remove this if OOChart supports own colors in markers. */
1440 Color aLineColor;
1441 if( rPropSet.GetColorProperty( aLineColor, EXC_CHPROP_COLOR ) )
1442 maData.maLineColor = maData.maFillColor = aLineColor;
1443 // register colors in palette
1444 RegisterColors( rRoot );
1447 void XclExpChMarkerFormat::ConvertStockSymbol( const XclExpChRoot& rRoot,
1448 const ScfPropertySet& rPropSet, bool bCloseSymbol )
1450 // clear the automatic flag
1451 ::set_flag( maData.mnFlags, EXC_CHMARKERFORMAT_AUTO, false );
1452 // symbol type and color
1453 if( bCloseSymbol )
1455 // set symbol type for the 'close' data series
1456 maData.mnMarkerType = EXC_CHMARKERFORMAT_DOWJ;
1457 maData.mnMarkerSize = EXC_CHMARKERFORMAT_DOUBLESIZE;
1458 // set symbol line/fill color to series line color
1459 Color aLineColor;
1460 if( rPropSet.GetColorProperty( aLineColor, EXC_CHPROP_COLOR ) )
1462 maData.maLineColor = maData.maFillColor = aLineColor;
1463 RegisterColors( rRoot );
1466 else
1468 // set invisible symbol
1469 maData.mnMarkerType = EXC_CHMARKERFORMAT_NOSYMBOL;
1473 void XclExpChMarkerFormat::RegisterColors( const XclExpChRoot& rRoot )
1475 if( HasMarker() )
1477 if( HasLineColor() )
1478 mnLineColorId = rRoot.GetPalette().InsertColor( maData.maLineColor, EXC_COLOR_CHARTLINE );
1479 if( HasFillColor() )
1480 mnFillColorId = rRoot.GetPalette().InsertColor( maData.maFillColor, EXC_COLOR_CHARTAREA );
1484 void XclExpChMarkerFormat::WriteBody( XclExpStream& rStrm )
1486 rStrm << maData.maLineColor << maData.maFillColor << maData.mnMarkerType << maData.mnFlags;
1487 if( rStrm.GetRoot().GetBiff() == EXC_BIFF8 )
1489 const XclExpPalette& rPal = rStrm.GetRoot().GetPalette();
1490 rStrm << rPal.GetColorIndex( mnLineColorId ) << rPal.GetColorIndex( mnFillColorId ) << maData.mnMarkerSize;
1494 XclExpChPieFormat::XclExpChPieFormat() :
1495 XclExpUInt16Record( EXC_ID_CHPIEFORMAT, 0 )
1499 void XclExpChPieFormat::Convert( const ScfPropertySet& rPropSet )
1501 double fApiDist(0.0);
1502 if( rPropSet.GetProperty( fApiDist, EXC_CHPROP_OFFSET ) )
1503 SetValue( limit_cast< sal_uInt16 >( fApiDist * 100.0, 0, 100 ) );
1506 XclExpCh3dDataFormat::XclExpCh3dDataFormat() :
1507 XclExpRecord( EXC_ID_CH3DDATAFORMAT, 2 )
1511 void XclExpCh3dDataFormat::Convert( const ScfPropertySet& rPropSet )
1513 sal_Int32 nApiType(0);
1514 if( rPropSet.GetProperty( nApiType, EXC_CHPROP_GEOMETRY3D ) )
1516 using namespace cssc2::DataPointGeometry3D;
1517 switch( nApiType )
1519 case CUBOID:
1520 maData.mnBase = EXC_CH3DDATAFORMAT_RECT;
1521 maData.mnTop = EXC_CH3DDATAFORMAT_STRAIGHT;
1522 break;
1523 case PYRAMID:
1524 maData.mnBase = EXC_CH3DDATAFORMAT_RECT;
1525 maData.mnTop = EXC_CH3DDATAFORMAT_SHARP;
1526 break;
1527 case CYLINDER:
1528 maData.mnBase = EXC_CH3DDATAFORMAT_CIRC;
1529 maData.mnTop = EXC_CH3DDATAFORMAT_STRAIGHT;
1530 break;
1531 case CONE:
1532 maData.mnBase = EXC_CH3DDATAFORMAT_CIRC;
1533 maData.mnTop = EXC_CH3DDATAFORMAT_SHARP;
1534 break;
1535 default:
1536 OSL_FAIL( "XclExpCh3dDataFormat::Convert - unknown 3D bar format" );
1541 void XclExpCh3dDataFormat::WriteBody( XclExpStream& rStrm )
1543 rStrm << maData.mnBase << maData.mnTop;
1546 XclExpChAttachedLabel::XclExpChAttachedLabel( sal_uInt16 nFlags ) :
1547 XclExpUInt16Record( EXC_ID_CHATTACHEDLABEL, nFlags )
1551 XclExpChDataFormat::XclExpChDataFormat( const XclExpChRoot& rRoot,
1552 const XclChDataPointPos& rPointPos, sal_uInt16 nFormatIdx ) :
1553 XclExpChGroupBase( rRoot, EXC_CHFRBLOCK_TYPE_DATAFORMAT, EXC_ID_CHDATAFORMAT, 8 )
1555 maData.maPointPos = rPointPos;
1556 maData.mnFormatIdx = nFormatIdx;
1559 void XclExpChDataFormat::ConvertDataSeries( const ScfPropertySet& rPropSet, const XclChExtTypeInfo& rTypeInfo )
1561 // line and area formatting
1562 ConvertFrameBase( GetChRoot(), rPropSet, rTypeInfo.GetSeriesObjectType() );
1564 // data point symbols
1565 bool bIsFrame = rTypeInfo.IsSeriesFrameFormat();
1566 if( !bIsFrame )
1568 mxMarkerFmt.reset( new XclExpChMarkerFormat( GetChRoot() ) );
1569 mxMarkerFmt->Convert( GetChRoot(), rPropSet, maData.mnFormatIdx );
1572 // pie segments
1573 if( rTypeInfo.meTypeCateg == EXC_CHTYPECATEG_PIE )
1575 mxPieFmt.reset( new XclExpChPieFormat );
1576 mxPieFmt->Convert( rPropSet );
1579 // 3D bars (only allowed for entire series in BIFF8)
1580 if( IsSeriesFormat() && (GetBiff() == EXC_BIFF8) && rTypeInfo.mb3dChart && (rTypeInfo.meTypeCateg == EXC_CHTYPECATEG_BAR) )
1582 mx3dDataFmt.reset( new XclExpCh3dDataFormat );
1583 mx3dDataFmt->Convert( rPropSet );
1586 // spline
1587 if( IsSeriesFormat() && rTypeInfo.mbSpline && !bIsFrame )
1588 mxSeriesFmt.reset( new XclExpUInt16Record( EXC_ID_CHSERIESFORMAT, EXC_CHSERIESFORMAT_SMOOTHED ) );
1590 // data point labels
1591 XclExpChTextRef xLabel( new XclExpChText( GetChRoot() ) );
1592 if( xLabel->ConvertDataLabel( rPropSet, rTypeInfo, maData.maPointPos ) )
1594 // CHTEXT groups for data labels are stored in global CHCHART group
1595 GetChartData().SetDataLabel( xLabel );
1596 mxAttLabel.reset( new XclExpChAttachedLabel( xLabel->GetAttLabelFlags() ) );
1600 void XclExpChDataFormat::ConvertStockSeries( const ScfPropertySet& rPropSet, bool bCloseSymbol )
1602 // set line format to invisible
1603 SetDefaultFrameBase( GetChRoot(), EXC_CHFRAMETYPE_INVISIBLE, false );
1604 // set symbols to invisible or to 'close' series symbol
1605 mxMarkerFmt.reset( new XclExpChMarkerFormat( GetChRoot() ) );
1606 mxMarkerFmt->ConvertStockSymbol( GetChRoot(), rPropSet, bCloseSymbol );
1609 void XclExpChDataFormat::ConvertLine( const ScfPropertySet& rPropSet, XclChObjectType eObjType )
1611 ConvertFrameBase( GetChRoot(), rPropSet, eObjType );
1614 void XclExpChDataFormat::WriteSubRecords( XclExpStream& rStrm )
1616 lclSaveRecord( rStrm, mx3dDataFmt );
1617 WriteFrameRecords( rStrm );
1618 lclSaveRecord( rStrm, mxPieFmt );
1619 lclSaveRecord( rStrm, mxMarkerFmt );
1620 lclSaveRecord( rStrm, mxSeriesFmt );
1621 lclSaveRecord( rStrm, mxAttLabel );
1624 void XclExpChDataFormat::WriteBody( XclExpStream& rStrm )
1626 rStrm << maData.maPointPos.mnPointIdx
1627 << maData.maPointPos.mnSeriesIdx
1628 << maData.mnFormatIdx
1629 << maData.mnFlags;
1632 XclExpChSerTrendLine::XclExpChSerTrendLine( const XclExpChRoot& rRoot ) :
1633 XclExpRecord( EXC_ID_CHSERTRENDLINE, 28 ),
1634 XclExpChRoot( rRoot )
1638 bool XclExpChSerTrendLine::Convert( Reference< XRegressionCurve > const & xRegCurve, sal_uInt16 nSeriesIdx )
1640 if( !xRegCurve.is() )
1641 return false;
1643 // trend line type
1644 ScfPropertySet aCurveProp( xRegCurve );
1646 OUString aService = aCurveProp.GetServiceName();
1647 if( aService == "com.sun.star.chart2.LinearRegressionCurve" )
1649 maData.mnLineType = EXC_CHSERTREND_POLYNOMIAL;
1650 maData.mnOrder = 1;
1652 else if( aService == "com.sun.star.chart2.ExponentialRegressionCurve" )
1654 maData.mnLineType = EXC_CHSERTREND_EXPONENTIAL;
1656 else if( aService == "com.sun.star.chart2.LogarithmicRegressionCurve" )
1658 maData.mnLineType = EXC_CHSERTREND_LOGARITHMIC;
1660 else if( aService == "com.sun.star.chart2.PotentialRegressionCurve" )
1662 maData.mnLineType = EXC_CHSERTREND_POWER;
1664 else if( aService == "com.sun.star.chart2.PolynomialRegressionCurve" )
1666 maData.mnLineType = EXC_CHSERTREND_POLYNOMIAL;
1667 sal_Int32 aDegree;
1668 aCurveProp.GetProperty(aDegree, EXC_CHPROP_POLYNOMIAL_DEGREE);
1669 maData.mnOrder = static_cast<sal_uInt8> (aDegree);
1671 else if( aService == "com.sun.star.chart2.MovingAverageRegressionCurve" )
1673 maData.mnLineType = EXC_CHSERTREND_MOVING_AVG;
1674 sal_Int32 aPeriod;
1675 aCurveProp.GetProperty(aPeriod, EXC_CHPROP_MOVING_AVERAGE_PERIOD);
1676 maData.mnOrder = static_cast<sal_uInt8> (aPeriod);
1678 else
1680 return false;
1683 aCurveProp.GetProperty(maData.mfForecastFor, EXC_CHPROP_EXTRAPOLATE_FORWARD);
1684 aCurveProp.GetProperty(maData.mfForecastBack, EXC_CHPROP_EXTRAPOLATE_BACKWARD);
1685 bool bIsForceIntercept = false;
1686 aCurveProp.GetProperty(bIsForceIntercept, EXC_CHPROP_FORCE_INTERCEPT);
1687 if (bIsForceIntercept)
1688 aCurveProp.GetProperty(maData.mfIntercept, EXC_CHPROP_INTERCEPT_VALUE);
1690 // line formatting
1691 XclChDataPointPos aPointPos( nSeriesIdx );
1692 mxDataFmt.reset( new XclExpChDataFormat( GetChRoot(), aPointPos, 0 ) );
1693 mxDataFmt->ConvertLine( aCurveProp, EXC_CHOBJTYPE_TRENDLINE );
1695 // #i83100# show equation and correlation coefficient
1696 ScfPropertySet aEquationProp( xRegCurve->getEquationProperties() );
1697 maData.mnShowEquation = aEquationProp.GetBoolProperty( EXC_CHPROP_SHOWEQUATION ) ? 1 : 0;
1698 maData.mnShowRSquared = aEquationProp.GetBoolProperty( EXC_CHPROP_SHOWCORRELATION ) ? 1 : 0;
1700 // #i83100# formatting of the equation text box
1701 if( (maData.mnShowEquation != 0) || (maData.mnShowRSquared != 0) )
1703 mxLabel.reset( new XclExpChText( GetChRoot() ) );
1704 mxLabel->ConvertTrendLineEquation( aEquationProp, aPointPos );
1707 // missing features
1708 // #i5085# manual trend line size
1709 // #i34093# manual crossing point
1710 return true;
1713 void XclExpChSerTrendLine::WriteBody( XclExpStream& rStrm )
1715 rStrm << maData.mnLineType
1716 << maData.mnOrder
1717 << maData.mfIntercept
1718 << maData.mnShowEquation
1719 << maData.mnShowRSquared
1720 << maData.mfForecastFor
1721 << maData.mfForecastBack;
1724 XclExpChSerErrorBar::XclExpChSerErrorBar( const XclExpChRoot& rRoot, sal_uInt8 nBarType ) :
1725 XclExpRecord( EXC_ID_CHSERERRORBAR, 14 ),
1726 XclExpChRoot( rRoot )
1728 maData.mnBarType = nBarType;
1731 bool XclExpChSerErrorBar::Convert( XclExpChSourceLink& rValueLink, sal_uInt16& rnValueCount, const ScfPropertySet& rPropSet )
1733 sal_Int32 nBarStyle = 0;
1734 bool bOk = rPropSet.GetProperty( nBarStyle, EXC_CHPROP_ERRORBARSTYLE );
1735 if( bOk )
1737 switch( nBarStyle )
1739 case cssc::ErrorBarStyle::ABSOLUTE:
1740 maData.mnSourceType = EXC_CHSERERR_FIXED;
1741 rPropSet.GetProperty( maData.mfValue, EXC_CHPROP_POSITIVEERROR );
1742 break;
1743 case cssc::ErrorBarStyle::RELATIVE:
1744 maData.mnSourceType = EXC_CHSERERR_PERCENT;
1745 rPropSet.GetProperty( maData.mfValue, EXC_CHPROP_POSITIVEERROR );
1746 break;
1747 case cssc::ErrorBarStyle::STANDARD_DEVIATION:
1748 maData.mnSourceType = EXC_CHSERERR_STDDEV;
1749 rPropSet.GetProperty( maData.mfValue, EXC_CHPROP_WEIGHT );
1750 break;
1751 case cssc::ErrorBarStyle::STANDARD_ERROR:
1752 maData.mnSourceType = EXC_CHSERERR_STDERR;
1753 break;
1754 case cssc::ErrorBarStyle::FROM_DATA:
1756 bOk = false;
1757 maData.mnSourceType = EXC_CHSERERR_CUSTOM;
1758 Reference< XDataSource > xDataSource( rPropSet.GetApiPropertySet(), UNO_QUERY );
1759 if( xDataSource.is() )
1761 // find first sequence with current role
1762 OUString aRole = XclChartHelper::GetErrorBarValuesRole( maData.mnBarType );
1763 Reference< XDataSequence > xValueSeq;
1765 const Sequence< Reference< XLabeledDataSequence > > aLabeledSeqVec = xDataSource->getDataSequences();
1766 for( const Reference< XLabeledDataSequence >& rLabeledSeq : aLabeledSeqVec )
1768 Reference< XDataSequence > xTmpValueSeq = rLabeledSeq->getValues();
1769 ScfPropertySet aValueProp( xTmpValueSeq );
1770 OUString aCurrRole;
1771 if( aValueProp.GetProperty( aCurrRole, EXC_CHPROP_ROLE ) && (aCurrRole == aRole) )
1773 xValueSeq = xTmpValueSeq;
1774 break;
1777 if( xValueSeq.is() )
1779 // #i86465# pass value count back to series
1780 rnValueCount = maData.mnValueCount = rValueLink.ConvertDataSequence( xValueSeq, true );
1781 bOk = maData.mnValueCount > 0;
1785 break;
1786 default:
1787 bOk = false;
1790 return bOk;
1793 void XclExpChSerErrorBar::WriteBody( XclExpStream& rStrm )
1795 rStrm << maData.mnBarType
1796 << maData.mnSourceType
1797 << maData.mnLineEnd
1798 << sal_uInt8( 1 ) // must be 1 to make line visible
1799 << maData.mfValue
1800 << maData.mnValueCount;
1803 namespace {
1805 /** Returns the property set of the specified data point. */
1806 ScfPropertySet lclGetPointPropSet( Reference< XDataSeries > const & xDataSeries, sal_Int32 nPointIdx )
1808 ScfPropertySet aPropSet;
1811 aPropSet.Set( xDataSeries->getDataPointByIndex( nPointIdx ) );
1813 catch( Exception& )
1815 OSL_FAIL( "lclGetPointPropSet - no data point property set" );
1817 return aPropSet;
1820 } // namespace
1822 XclExpChSeries::XclExpChSeries( const XclExpChRoot& rRoot, sal_uInt16 nSeriesIdx ) :
1823 XclExpChGroupBase( rRoot, EXC_CHFRBLOCK_TYPE_SERIES, EXC_ID_CHSERIES, (rRoot.GetBiff() == EXC_BIFF8) ? 12 : 8 ),
1824 mnGroupIdx( EXC_CHSERGROUP_NONE ),
1825 mnSeriesIdx( nSeriesIdx ),
1826 mnParentIdx( EXC_CHSERIES_INVALID )
1828 // CHSOURCELINK records are always required, even if unused
1829 mxTitleLink.reset( new XclExpChSourceLink( GetChRoot(), EXC_CHSRCLINK_TITLE ) );
1830 mxValueLink.reset( new XclExpChSourceLink( GetChRoot(), EXC_CHSRCLINK_VALUES ) );
1831 mxCategLink.reset( new XclExpChSourceLink( GetChRoot(), EXC_CHSRCLINK_CATEGORY ) );
1832 if( GetBiff() == EXC_BIFF8 )
1833 mxBubbleLink.reset( new XclExpChSourceLink( GetChRoot(), EXC_CHSRCLINK_BUBBLES ) );
1836 bool XclExpChSeries::ConvertDataSeries(
1837 Reference< XDiagram > const & xDiagram, Reference< XDataSeries > const & xDataSeries,
1838 const XclChExtTypeInfo& rTypeInfo, sal_uInt16 nGroupIdx, sal_uInt16 nFormatIdx )
1840 bool bOk = false;
1841 Reference< XDataSource > xDataSource( xDataSeries, UNO_QUERY );
1842 if( xDataSource.is() )
1844 Reference< XDataSequence > xYValueSeq, xTitleSeq, xXValueSeq, xBubbleSeq;
1846 // find first sequence with role 'values-y'
1847 const Sequence< Reference< XLabeledDataSequence > > aLabeledSeqVec = xDataSource->getDataSequences();
1848 for( const Reference< XLabeledDataSequence >& rLabeledSeq : aLabeledSeqVec )
1850 Reference< XDataSequence > xTmpValueSeq = rLabeledSeq->getValues();
1851 ScfPropertySet aValueProp( xTmpValueSeq );
1852 OUString aRole;
1853 if( aValueProp.GetProperty( aRole, EXC_CHPROP_ROLE ) )
1855 if( !xYValueSeq.is() && (aRole == EXC_CHPROP_ROLE_YVALUES) )
1857 xYValueSeq = xTmpValueSeq;
1858 if( !xTitleSeq.is() )
1859 xTitleSeq = rLabeledSeq->getLabel(); // ignore role of label sequence
1861 else if( !xXValueSeq.is() && !rTypeInfo.mbCategoryAxis && (aRole == EXC_CHPROP_ROLE_XVALUES) )
1863 xXValueSeq = xTmpValueSeq;
1865 else if( !xBubbleSeq.is() && (rTypeInfo.meTypeId == EXC_CHTYPEID_BUBBLES) && (aRole == EXC_CHPROP_ROLE_SIZEVALUES) )
1867 xBubbleSeq = xTmpValueSeq;
1868 xTitleSeq = rLabeledSeq->getLabel(); // ignore role of label sequence
1873 bOk = xYValueSeq.is();
1874 if( bOk )
1876 // chart type group index
1877 mnGroupIdx = nGroupIdx;
1879 // convert source links
1880 maData.mnValueCount = mxValueLink->ConvertDataSequence( xYValueSeq, true );
1881 mxTitleLink->ConvertDataSequence( xTitleSeq, true );
1883 // X values of XY charts
1884 maData.mnCategCount = mxCategLink->ConvertDataSequence( xXValueSeq, false, maData.mnValueCount );
1886 // size values of bubble charts
1887 if( mxBubbleLink )
1888 mxBubbleLink->ConvertDataSequence( xBubbleSeq, false, maData.mnValueCount );
1890 // series formatting
1891 XclChDataPointPos aPointPos( mnSeriesIdx );
1892 ScfPropertySet aSeriesProp( xDataSeries );
1893 mxSeriesFmt.reset( new XclExpChDataFormat( GetChRoot(), aPointPos, nFormatIdx ) );
1894 mxSeriesFmt->ConvertDataSeries( aSeriesProp, rTypeInfo );
1896 // trend lines
1897 CreateTrendLines( xDataSeries );
1899 // error bars
1900 CreateErrorBars( aSeriesProp, EXC_CHPROP_ERRORBARX, EXC_CHSERERR_XPLUS, EXC_CHSERERR_XMINUS );
1901 CreateErrorBars( aSeriesProp, EXC_CHPROP_ERRORBARY, EXC_CHSERERR_YPLUS, EXC_CHSERERR_YMINUS );
1903 if( maData.mnValueCount > 0 )
1905 const sal_Int32 nMaxPointCount = maData.mnValueCount;
1907 /* #i91063# Create missing fill properties in pie/doughnut charts.
1908 If freshly created (never saved to ODF), these charts show
1909 varying point colors but do not return these points via API. */
1910 if( xDiagram.is() && (rTypeInfo.meTypeCateg == EXC_CHTYPECATEG_PIE) )
1912 Reference< XColorScheme > xColorScheme = xDiagram->getDefaultColorScheme();
1913 if( xColorScheme.is() )
1915 const OUString aFillStyleName = "FillStyle";
1916 const OUString aColorName = "Color";
1917 namespace cssd = ::com::sun::star::drawing;
1918 for( sal_Int32 nPointIdx = 0; nPointIdx < nMaxPointCount; ++nPointIdx )
1920 aPointPos.mnPointIdx = static_cast< sal_uInt16 >( nPointIdx );
1921 ScfPropertySet aPointProp = lclGetPointPropSet( xDataSeries, nPointIdx );
1922 // test that the point fill style is solid, but no color is set
1923 cssd::FillStyle eFillStyle = cssd::FillStyle_NONE;
1924 if( aPointProp.GetProperty( eFillStyle, aFillStyleName ) &&
1925 (eFillStyle == cssd::FillStyle_SOLID) &&
1926 !aPointProp.HasProperty( aColorName ) )
1928 aPointProp.SetProperty( aColorName, xColorScheme->getColorByIndex( nPointIdx ) );
1934 // data point formatting
1935 Sequence< sal_Int32 > aPointIndexes;
1936 if( aSeriesProp.GetProperty( aPointIndexes, EXC_CHPROP_ATTRIBDATAPOINTS ) && aPointIndexes.hasElements() )
1938 for( const sal_Int32 nPointIndex : aPointIndexes )
1940 if (nPointIndex >= nMaxPointCount)
1941 break;
1942 aPointPos.mnPointIdx = static_cast< sal_uInt16 >( nPointIndex );
1943 ScfPropertySet aPointProp = lclGetPointPropSet( xDataSeries, nPointIndex );
1944 XclExpChDataFormatRef xPointFmt( new XclExpChDataFormat( GetChRoot(), aPointPos, nFormatIdx ) );
1945 xPointFmt->ConvertDataSeries( aPointProp, rTypeInfo );
1946 maPointFmts.AppendRecord( xPointFmt );
1952 return bOk;
1955 bool XclExpChSeries::ConvertStockSeries( css::uno::Reference< css::chart2::XDataSeries > const & xDataSeries,
1956 const OUString& rValueRole, sal_uInt16 nGroupIdx, sal_uInt16 nFormatIdx, bool bCloseSymbol )
1958 bool bOk = false;
1959 Reference< XDataSource > xDataSource( xDataSeries, UNO_QUERY );
1960 if( xDataSource.is() )
1962 Reference< XDataSequence > xYValueSeq, xTitleSeq;
1964 // find first sequence with passed role
1965 const Sequence< Reference< XLabeledDataSequence > > aLabeledSeqVec = xDataSource->getDataSequences();
1966 for( const Reference< XLabeledDataSequence >& rLabeledSeq : aLabeledSeqVec )
1968 Reference< XDataSequence > xTmpValueSeq = rLabeledSeq->getValues();
1969 ScfPropertySet aValueProp( xTmpValueSeq );
1970 OUString aRole;
1971 if( aValueProp.GetProperty( aRole, EXC_CHPROP_ROLE ) && (aRole == rValueRole) )
1973 xYValueSeq = xTmpValueSeq;
1974 xTitleSeq = rLabeledSeq->getLabel(); // ignore role of label sequence
1975 break;
1979 bOk = xYValueSeq.is();
1980 if( bOk )
1982 // chart type group index
1983 mnGroupIdx = nGroupIdx;
1984 // convert source links
1985 maData.mnValueCount = mxValueLink->ConvertDataSequence( xYValueSeq, true );
1986 mxTitleLink->ConvertDataSequence( xTitleSeq, true );
1987 // series formatting
1988 ScfPropertySet aSeriesProp( xDataSeries );
1989 mxSeriesFmt.reset( new XclExpChDataFormat( GetChRoot(), XclChDataPointPos( mnSeriesIdx ), nFormatIdx ) );
1990 mxSeriesFmt->ConvertStockSeries( aSeriesProp, bCloseSymbol );
1993 return bOk;
1996 bool XclExpChSeries::ConvertTrendLine( const XclExpChSeries& rParent, Reference< XRegressionCurve > const & xRegCurve )
1998 InitFromParent( rParent );
2000 mxTrendLine.reset( new XclExpChSerTrendLine( GetChRoot() ) );
2001 bool bOk = mxTrendLine->Convert( xRegCurve, mnSeriesIdx );
2002 if( bOk )
2004 OUString aName;
2005 ScfPropertySet aProperties( xRegCurve );
2006 aProperties.GetProperty(aName, EXC_CHPROP_CURVENAME);
2007 mxTitleLink->ConvertString(aName);
2009 mxSeriesFmt = mxTrendLine->GetDataFormat();
2010 GetChartData().SetDataLabel( mxTrendLine->GetDataLabel() );
2012 return bOk;
2015 bool XclExpChSeries::ConvertErrorBar( const XclExpChSeries& rParent, const ScfPropertySet& rPropSet, sal_uInt8 nBarId )
2017 InitFromParent( rParent );
2018 // error bar settings
2019 mxErrorBar.reset( new XclExpChSerErrorBar( GetChRoot(), nBarId ) );
2020 bool bOk = mxErrorBar->Convert( *mxValueLink, maData.mnValueCount, rPropSet );
2021 if( bOk )
2023 // error bar formatting
2024 mxSeriesFmt.reset( new XclExpChDataFormat( GetChRoot(), XclChDataPointPos( mnSeriesIdx ), 0 ) );
2025 mxSeriesFmt->ConvertLine( rPropSet, EXC_CHOBJTYPE_ERRORBAR );
2027 return bOk;
2030 void XclExpChSeries::ConvertCategSequence( Reference< XLabeledDataSequence > const & xCategSeq )
2032 if( xCategSeq.is() )
2033 maData.mnCategCount = mxCategLink->ConvertDataSequence( xCategSeq->getValues(), false );
2036 void XclExpChSeries::WriteSubRecords( XclExpStream& rStrm )
2038 lclSaveRecord( rStrm, mxTitleLink );
2039 lclSaveRecord( rStrm, mxValueLink );
2040 lclSaveRecord( rStrm, mxCategLink );
2041 lclSaveRecord( rStrm, mxBubbleLink );
2042 lclSaveRecord( rStrm, mxSeriesFmt );
2043 maPointFmts.Save( rStrm );
2044 if( mnGroupIdx != EXC_CHSERGROUP_NONE )
2045 XclExpUInt16Record( EXC_ID_CHSERGROUP, mnGroupIdx ).Save( rStrm );
2046 if( mnParentIdx != EXC_CHSERIES_INVALID )
2047 XclExpUInt16Record( EXC_ID_CHSERPARENT, mnParentIdx ).Save( rStrm );
2048 lclSaveRecord( rStrm, mxTrendLine );
2049 lclSaveRecord( rStrm, mxErrorBar );
2052 void XclExpChSeries::InitFromParent( const XclExpChSeries& rParent )
2054 // index to parent series is stored 1-based
2055 mnParentIdx = rParent.mnSeriesIdx + 1;
2056 /* #i86465# MSO2007 SP1 expects correct point counts in child series
2057 (there was no problem in Excel2003 or Excel2007 without SP1...) */
2058 maData.mnCategCount = rParent.maData.mnCategCount;
2059 maData.mnValueCount = rParent.maData.mnValueCount;
2062 void XclExpChSeries::CreateTrendLines( css::uno::Reference< css::chart2::XDataSeries > const & xDataSeries )
2064 Reference< XRegressionCurveContainer > xRegCurveCont( xDataSeries, UNO_QUERY );
2065 if( xRegCurveCont.is() )
2067 const Sequence< Reference< XRegressionCurve > > aRegCurveSeq = xRegCurveCont->getRegressionCurves();
2068 for( const Reference< XRegressionCurve >& rRegCurve : aRegCurveSeq )
2070 XclExpChSeriesRef xSeries = GetChartData().CreateSeries();
2071 if( xSeries && !xSeries->ConvertTrendLine( *this, rRegCurve ) )
2072 GetChartData().RemoveLastSeries();
2077 void XclExpChSeries::CreateErrorBars( const ScfPropertySet& rPropSet,
2078 const OUString& rBarPropName, sal_uInt8 nPosBarId, sal_uInt8 nNegBarId )
2080 Reference< XPropertySet > xErrorBar;
2081 if( rPropSet.GetProperty( xErrorBar, rBarPropName ) && xErrorBar.is() )
2083 ScfPropertySet aErrorProp( xErrorBar );
2084 CreateErrorBar( aErrorProp, EXC_CHPROP_SHOWPOSITIVEERROR, nPosBarId );
2085 CreateErrorBar( aErrorProp, EXC_CHPROP_SHOWNEGATIVEERROR, nNegBarId );
2089 void XclExpChSeries::CreateErrorBar( const ScfPropertySet& rPropSet,
2090 const OUString& rShowPropName, sal_uInt8 nBarId )
2092 if( rPropSet.GetBoolProperty( rShowPropName ) )
2094 XclExpChSeriesRef xSeries = GetChartData().CreateSeries();
2095 if( xSeries && !xSeries->ConvertErrorBar( *this, rPropSet, nBarId ) )
2096 GetChartData().RemoveLastSeries();
2100 void XclExpChSeries::WriteBody( XclExpStream& rStrm )
2102 rStrm << maData.mnCategType << maData.mnValueType << maData.mnCategCount << maData.mnValueCount;
2103 if( GetBiff() == EXC_BIFF8 )
2104 rStrm << maData.mnBubbleType << maData.mnBubbleCount;
2107 // Chart type groups ==========================================================
2109 XclExpChType::XclExpChType( const XclExpChRoot& rRoot ) :
2110 XclExpRecord( EXC_ID_CHUNKNOWN ),
2111 XclExpChRoot( rRoot ),
2112 maTypeInfo( rRoot.GetChartTypeInfo( EXC_CHTYPEID_UNKNOWN ) )
2116 void XclExpChType::Convert( Reference< XDiagram > const & xDiagram, Reference< XChartType > const & xChartType,
2117 sal_Int32 nApiAxesSetIdx, bool bSwappedAxesSet, bool bHasXLabels )
2119 if( xChartType.is() )
2121 maTypeInfo = GetChartTypeInfo( xChartType->getChartType() );
2122 // special handling for some chart types
2123 switch( maTypeInfo.meTypeCateg )
2125 case EXC_CHTYPECATEG_BAR:
2127 maTypeInfo = GetChartTypeInfo( bSwappedAxesSet ? EXC_CHTYPEID_HORBAR : EXC_CHTYPEID_BAR );
2128 ::set_flag( maData.mnFlags, EXC_CHBAR_HORIZONTAL, bSwappedAxesSet );
2129 ScfPropertySet aTypeProp( xChartType );
2130 Sequence< sal_Int32 > aInt32Seq;
2131 maData.mnOverlap = 0;
2132 if( aTypeProp.GetProperty( aInt32Seq, EXC_CHPROP_OVERLAPSEQ ) && (nApiAxesSetIdx < aInt32Seq.getLength()) )
2133 maData.mnOverlap = limit_cast< sal_Int16 >( -aInt32Seq[ nApiAxesSetIdx ], -100, 100 );
2134 maData.mnGap = 150;
2135 if( aTypeProp.GetProperty( aInt32Seq, EXC_CHPROP_GAPWIDTHSEQ ) && (nApiAxesSetIdx < aInt32Seq.getLength()) )
2136 maData.mnGap = limit_cast< sal_uInt16 >( aInt32Seq[ nApiAxesSetIdx ], 0, 500 );
2138 break;
2139 case EXC_CHTYPECATEG_RADAR:
2140 ::set_flag( maData.mnFlags, EXC_CHRADAR_AXISLABELS, bHasXLabels );
2141 break;
2142 case EXC_CHTYPECATEG_PIE:
2144 ScfPropertySet aTypeProp( xChartType );
2145 bool bDonut = aTypeProp.GetBoolProperty( EXC_CHPROP_USERINGS );
2146 maTypeInfo = GetChartTypeInfo( bDonut ? EXC_CHTYPEID_DONUT : EXC_CHTYPEID_PIE );
2147 maData.mnPieHole = bDonut ? 50 : 0;
2148 // #i85166# starting angle of first pie slice
2149 ScfPropertySet aDiaProp( xDiagram );
2150 maData.mnRotation = XclExpChRoot::ConvertPieRotation( aDiaProp );
2152 break;
2153 case EXC_CHTYPECATEG_SCATTER:
2154 if( GetBiff() == EXC_BIFF8 )
2155 ::set_flag( maData.mnFlags, EXC_CHSCATTER_BUBBLES, maTypeInfo.meTypeId == EXC_CHTYPEID_BUBBLES );
2156 break;
2157 default:;
2159 SetRecId( maTypeInfo.mnRecId );
2163 void XclExpChType::SetStacked( bool bPercent )
2165 switch( maTypeInfo.meTypeCateg )
2167 case EXC_CHTYPECATEG_LINE:
2168 ::set_flag( maData.mnFlags, EXC_CHLINE_STACKED );
2169 ::set_flag( maData.mnFlags, EXC_CHLINE_PERCENT, bPercent );
2170 break;
2171 case EXC_CHTYPECATEG_BAR:
2172 ::set_flag( maData.mnFlags, EXC_CHBAR_STACKED );
2173 ::set_flag( maData.mnFlags, EXC_CHBAR_PERCENT, bPercent );
2174 maData.mnOverlap = -100;
2175 break;
2176 default:;
2180 void XclExpChType::WriteBody( XclExpStream& rStrm )
2182 switch( GetRecId() )
2184 case EXC_ID_CHBAR:
2185 rStrm << maData.mnOverlap << maData.mnGap << maData.mnFlags;
2186 break;
2188 case EXC_ID_CHLINE:
2189 case EXC_ID_CHAREA:
2190 case EXC_ID_CHRADARLINE:
2191 case EXC_ID_CHRADARAREA:
2192 rStrm << maData.mnFlags;
2193 break;
2195 case EXC_ID_CHPIE:
2196 rStrm << maData.mnRotation << maData.mnPieHole;
2197 if( GetBiff() == EXC_BIFF8 )
2198 rStrm << maData.mnFlags;
2199 break;
2201 case EXC_ID_CHSCATTER:
2202 if( GetBiff() == EXC_BIFF8 )
2203 rStrm << maData.mnBubbleSize << maData.mnBubbleType << maData.mnFlags;
2204 break;
2206 default:
2207 OSL_FAIL( "XclExpChType::WriteBody - unknown chart type" );
2211 XclExpChChart3d::XclExpChChart3d() :
2212 XclExpRecord( EXC_ID_CHCHART3D, 14 )
2216 void XclExpChChart3d::Convert( const ScfPropertySet& rPropSet, bool b3dWallChart )
2218 sal_Int32 nRotationY = 0;
2219 rPropSet.GetProperty( nRotationY, EXC_CHPROP_ROTATIONVERTICAL );
2220 sal_Int32 nRotationX = 0;
2221 rPropSet.GetProperty( nRotationX, EXC_CHPROP_ROTATIONHORIZONTAL );
2222 sal_Int32 nPerspective = 15;
2223 rPropSet.GetProperty( nPerspective, EXC_CHPROP_PERSPECTIVE );
2225 if( b3dWallChart )
2227 // Y rotation (Excel [0..359], Chart2 [-179,180])
2228 if( nRotationY < 0 ) nRotationY += 360;
2229 maData.mnRotation = static_cast< sal_uInt16 >( nRotationY );
2230 // X rotation a.k.a. elevation (Excel [-90..90], Chart2 [-179,180])
2231 maData.mnElevation = limit_cast< sal_Int16 >( nRotationX, -90, 90 );
2232 // perspective (Excel and Chart2 [0,100])
2233 maData.mnEyeDist = limit_cast< sal_uInt16 >( nPerspective, 0, 100 );
2234 // flags
2235 maData.mnFlags = 0;
2236 ::set_flag( maData.mnFlags, EXC_CHCHART3D_REAL3D, !rPropSet.GetBoolProperty( EXC_CHPROP_RIGHTANGLEDAXES ) );
2237 ::set_flag( maData.mnFlags, EXC_CHCHART3D_AUTOHEIGHT );
2238 ::set_flag( maData.mnFlags, EXC_CHCHART3D_HASWALLS );
2240 else
2242 // Y rotation not used in pie charts, but 'first pie slice angle'
2243 maData.mnRotation = XclExpChRoot::ConvertPieRotation( rPropSet );
2244 // X rotation a.k.a. elevation (map Chart2 [-80,-10] to Excel [10..80])
2245 maData.mnElevation = limit_cast< sal_Int16 >( (nRotationX + 270) % 180, 10, 80 );
2246 // perspective (Excel and Chart2 [0,100])
2247 maData.mnEyeDist = limit_cast< sal_uInt16 >( nPerspective, 0, 100 );
2248 // flags
2249 maData.mnFlags = 0;
2253 void XclExpChChart3d::WriteBody( XclExpStream& rStrm )
2255 rStrm << maData.mnRotation
2256 << maData.mnElevation
2257 << maData.mnEyeDist
2258 << maData.mnRelHeight
2259 << maData.mnRelDepth
2260 << maData.mnDepthGap
2261 << maData.mnFlags;
2264 XclExpChLegend::XclExpChLegend( const XclExpChRoot& rRoot ) :
2265 XclExpChGroupBase( rRoot, EXC_CHFRBLOCK_TYPE_LEGEND, EXC_ID_CHLEGEND, 20 )
2269 void XclExpChLegend::Convert( const ScfPropertySet& rPropSet )
2271 // frame properties
2272 mxFrame = lclCreateFrame( GetChRoot(), rPropSet, EXC_CHOBJTYPE_LEGEND );
2273 // text properties
2274 mxText.reset( new XclExpChText( GetChRoot() ) );
2275 mxText->ConvertLegend( rPropSet );
2277 // legend position and size
2278 Any aRelPosAny, aRelSizeAny;
2279 rPropSet.GetAnyProperty( aRelPosAny, EXC_CHPROP_RELATIVEPOSITION );
2280 rPropSet.GetAnyProperty( aRelSizeAny, EXC_CHPROP_RELATIVESIZE );
2281 cssc::ChartLegendExpansion eApiExpand = cssc::ChartLegendExpansion_CUSTOM;
2282 rPropSet.GetProperty( eApiExpand, EXC_CHPROP_EXPANSION );
2283 if( aRelPosAny.has< RelativePosition >() || ((eApiExpand == cssc::ChartLegendExpansion_CUSTOM) && aRelSizeAny.has< RelativeSize >()) )
2287 /* The 'RelativePosition' or 'RelativeSize' properties are used as
2288 indicator of manually changed legend position/size, but due to
2289 the different anchor modes used by this property (in the
2290 RelativePosition.Anchor member) it cannot be used to calculate
2291 the position easily. For this, the Chart1 API will be used
2292 instead. */
2293 Reference< cssc::XChartDocument > xChart1Doc( GetChartDocument(), UNO_QUERY_THROW );
2294 Reference< XShape > xChart1Legend( xChart1Doc->getLegend(), UNO_SET_THROW );
2295 // coordinates in CHLEGEND record written but not used by Excel
2296 mxFramePos.reset( new XclExpChFramePos( EXC_CHFRAMEPOS_CHARTSIZE ) );
2297 XclChFramePos& rFramePos = mxFramePos->GetFramePosData();
2298 rFramePos.mnTLMode = EXC_CHFRAMEPOS_CHARTSIZE;
2299 css::awt::Point aLegendPos = xChart1Legend->getPosition();
2300 rFramePos.maRect.mnX = maData.maRect.mnX = CalcChartXFromHmm( aLegendPos.X );
2301 rFramePos.maRect.mnY = maData.maRect.mnY = CalcChartYFromHmm( aLegendPos.Y );
2302 // legend size, Excel expects points in CHFRAMEPOS record
2303 rFramePos.mnBRMode = EXC_CHFRAMEPOS_ABSSIZE_POINTS;
2304 css::awt::Size aLegendSize = xChart1Legend->getSize();
2305 rFramePos.maRect.mnWidth = static_cast< sal_uInt16 >( aLegendSize.Width * EXC_POINTS_PER_HMM + 0.5 );
2306 rFramePos.maRect.mnHeight = static_cast< sal_uInt16 >( aLegendSize.Height * EXC_POINTS_PER_HMM + 0.5 );
2307 maData.maRect.mnWidth = CalcChartXFromHmm( aLegendSize.Width );
2308 maData.maRect.mnHeight = CalcChartYFromHmm( aLegendSize.Height );
2309 eApiExpand = cssc::ChartLegendExpansion_CUSTOM;
2310 // manual legend position implies manual plot area
2311 GetChartData().SetManualPlotArea();
2312 maData.mnDockMode = EXC_CHLEGEND_NOTDOCKED;
2313 // a CHFRAME record with cleared auto flags is needed
2314 if( !mxFrame )
2315 mxFrame.reset( new XclExpChFrame( GetChRoot(), EXC_CHOBJTYPE_LEGEND ) );
2316 mxFrame->SetAutoFlags( false, false );
2318 catch( Exception& )
2320 OSL_FAIL( "XclExpChLegend::Convert - cannot get legend shape" );
2321 maData.mnDockMode = EXC_CHLEGEND_RIGHT;
2322 eApiExpand = cssc::ChartLegendExpansion_HIGH;
2325 else
2327 cssc2::LegendPosition eApiPos = cssc2::LegendPosition_CUSTOM;
2328 rPropSet.GetProperty( eApiPos, EXC_CHPROP_ANCHORPOSITION );
2329 switch( eApiPos )
2331 case cssc2::LegendPosition_LINE_START: maData.mnDockMode = EXC_CHLEGEND_LEFT; break;
2332 case cssc2::LegendPosition_LINE_END: maData.mnDockMode = EXC_CHLEGEND_RIGHT; break;
2333 case cssc2::LegendPosition_PAGE_START: maData.mnDockMode = EXC_CHLEGEND_TOP; break;
2334 case cssc2::LegendPosition_PAGE_END: maData.mnDockMode = EXC_CHLEGEND_BOTTOM; break;
2335 default:
2336 OSL_FAIL( "XclExpChLegend::Convert - unrecognized legend position" );
2337 maData.mnDockMode = EXC_CHLEGEND_RIGHT;
2338 eApiExpand = cssc::ChartLegendExpansion_HIGH;
2341 ::set_flag( maData.mnFlags, EXC_CHLEGEND_STACKED, eApiExpand == cssc::ChartLegendExpansion_HIGH );
2343 // other flags
2344 ::set_flag( maData.mnFlags, EXC_CHLEGEND_AUTOSERIES );
2345 const sal_uInt16 nAutoFlags = EXC_CHLEGEND_DOCKED | EXC_CHLEGEND_AUTOPOSX | EXC_CHLEGEND_AUTOPOSY;
2346 ::set_flag( maData.mnFlags, nAutoFlags, maData.mnDockMode != EXC_CHLEGEND_NOTDOCKED );
2349 void XclExpChLegend::WriteSubRecords( XclExpStream& rStrm )
2351 lclSaveRecord( rStrm, mxFramePos );
2352 lclSaveRecord( rStrm, mxText );
2353 lclSaveRecord( rStrm, mxFrame );
2356 void XclExpChLegend::WriteBody( XclExpStream& rStrm )
2358 rStrm << maData.maRect << maData.mnDockMode << maData.mnSpacing << maData.mnFlags;
2361 XclExpChDropBar::XclExpChDropBar( const XclExpChRoot& rRoot, XclChObjectType eObjType ) :
2362 XclExpChGroupBase( rRoot, EXC_CHFRBLOCK_TYPE_DROPBAR, EXC_ID_CHDROPBAR, 2 ),
2363 meObjType( eObjType )
2367 void XclExpChDropBar::Convert( const ScfPropertySet& rPropSet )
2369 if( rPropSet.Is() )
2370 ConvertFrameBase( GetChRoot(), rPropSet, meObjType );
2371 else
2372 SetDefaultFrameBase( GetChRoot(), EXC_CHFRAMETYPE_INVISIBLE, true );
2375 void XclExpChDropBar::WriteSubRecords( XclExpStream& rStrm )
2377 WriteFrameRecords( rStrm );
2380 void XclExpChDropBar::WriteBody( XclExpStream& rStrm )
2382 rStrm << sal_uInt16(100); // Distance between bars (CHDROPBAR record).
2385 XclExpChTypeGroup::XclExpChTypeGroup( const XclExpChRoot& rRoot, sal_uInt16 nGroupIdx ) :
2386 XclExpChGroupBase( rRoot, EXC_CHFRBLOCK_TYPE_TYPEGROUP, EXC_ID_CHTYPEGROUP, 20 ),
2387 maType( rRoot ),
2388 maTypeInfo( maType.GetTypeInfo() )
2390 maData.mnGroupIdx = nGroupIdx;
2393 void XclExpChTypeGroup::ConvertType(
2394 Reference< XDiagram > const & xDiagram, Reference< XChartType > const & xChartType,
2395 sal_Int32 nApiAxesSetIdx, bool b3dChart, bool bSwappedAxesSet, bool bHasXLabels )
2397 // chart type settings
2398 maType.Convert( xDiagram, xChartType, nApiAxesSetIdx, bSwappedAxesSet, bHasXLabels );
2400 // spline - TODO: get from single series (#i66858#)
2401 ScfPropertySet aTypeProp( xChartType );
2402 cssc2::CurveStyle eCurveStyle;
2403 bool bSpline = aTypeProp.GetProperty( eCurveStyle, EXC_CHPROP_CURVESTYLE ) &&
2404 (eCurveStyle != cssc2::CurveStyle_LINES);
2406 // extended type info
2407 maTypeInfo.Set( maType.GetTypeInfo(), b3dChart, bSpline );
2409 // 3d chart settings
2410 if( maTypeInfo.mb3dChart ) // only true, if Excel chart supports 3d mode
2412 mxChart3d.reset( new XclExpChChart3d );
2413 ScfPropertySet aDiaProp( xDiagram );
2414 mxChart3d->Convert( aDiaProp, Is3dWallChart() );
2418 void XclExpChTypeGroup::ConvertSeries(
2419 Reference< XDiagram > const & xDiagram, Reference< XChartType > const & xChartType,
2420 sal_Int32 nGroupAxesSetIdx, bool bPercent, bool bConnectBars )
2422 Reference< XDataSeriesContainer > xSeriesCont( xChartType, UNO_QUERY );
2423 if( xSeriesCont.is() )
2425 typedef ::std::vector< Reference< XDataSeries > > XDataSeriesVec;
2426 XDataSeriesVec aSeriesVec;
2428 // copy data series attached to the current axes set to the vector
2429 const Sequence< Reference< XDataSeries > > aSeriesSeq = xSeriesCont->getDataSeries();
2430 for( const Reference< XDataSeries >& rSeries : aSeriesSeq )
2432 ScfPropertySet aSeriesProp( rSeries );
2433 sal_Int32 nSeriesAxesSetIdx(0);
2434 if( aSeriesProp.GetProperty( nSeriesAxesSetIdx, EXC_CHPROP_ATTAXISINDEX ) && (nSeriesAxesSetIdx == nGroupAxesSetIdx) )
2435 aSeriesVec.push_back( rSeries );
2438 // Are there any series in the current axes set?
2439 if( !aSeriesVec.empty() )
2441 // stacking direction (stacked/percent/deep 3d) from first series
2442 ScfPropertySet aSeriesProp( aSeriesVec.front() );
2443 cssc2::StackingDirection eStacking;
2444 if( !aSeriesProp.GetProperty( eStacking, EXC_CHPROP_STACKINGDIR ) )
2445 eStacking = cssc2::StackingDirection_NO_STACKING;
2447 // stacked or percent chart
2448 if( maTypeInfo.mbSupportsStacking && (eStacking == cssc2::StackingDirection_Y_STACKING) )
2450 // percent overrides simple stacking
2451 maType.SetStacked( bPercent );
2453 // connected data points (only in stacked bar charts)
2454 if (bConnectBars && (maTypeInfo.meTypeCateg == EXC_CHTYPECATEG_BAR))
2456 sal_uInt16 nKey = EXC_CHCHARTLINE_CONNECT;
2457 m_ChartLines.insert(std::make_pair(nKey, std::make_unique<XclExpChLineFormat>(GetChRoot())));
2460 else
2462 // reverse series order for some unstacked 2D chart types
2463 if( maTypeInfo.mbReverseSeries && !Is3dChart() )
2464 ::std::reverse( aSeriesVec.begin(), aSeriesVec.end() );
2467 // deep 3d chart or clustered 3d chart (stacked is not clustered)
2468 if( (eStacking == cssc2::StackingDirection_NO_STACKING) && Is3dWallChart() )
2469 mxChart3d->SetClustered();
2471 // varied point colors
2472 ::set_flag( maData.mnFlags, EXC_CHTYPEGROUP_VARIEDCOLORS, aSeriesProp.GetBoolProperty( EXC_CHPROP_VARYCOLORSBY ) );
2474 // process all series
2475 for( const auto& rxSeries : aSeriesVec )
2477 // create Excel series object, stock charts need special processing
2478 if( maTypeInfo.meTypeId == EXC_CHTYPEID_STOCK )
2479 CreateAllStockSeries( xChartType, rxSeries );
2480 else
2481 CreateDataSeries( xDiagram, rxSeries );
2487 void XclExpChTypeGroup::ConvertCategSequence( Reference< XLabeledDataSequence > const & xCategSeq )
2489 for( size_t nIdx = 0, nSize = maSeries.GetSize(); nIdx < nSize; ++nIdx )
2490 maSeries.GetRecord( nIdx )->ConvertCategSequence( xCategSeq );
2493 void XclExpChTypeGroup::ConvertLegend( const ScfPropertySet& rPropSet )
2495 if( rPropSet.GetBoolProperty( EXC_CHPROP_SHOW ) )
2497 mxLegend.reset( new XclExpChLegend( GetChRoot() ) );
2498 mxLegend->Convert( rPropSet );
2502 void XclExpChTypeGroup::WriteSubRecords( XclExpStream& rStrm )
2504 maType.Save( rStrm );
2505 lclSaveRecord( rStrm, mxChart3d );
2506 lclSaveRecord( rStrm, mxLegend );
2507 lclSaveRecord( rStrm, mxUpBar );
2508 lclSaveRecord( rStrm, mxDownBar );
2509 for (auto const& it : m_ChartLines)
2511 lclSaveRecord( rStrm, it.second.get(), EXC_ID_CHCHARTLINE, it.first );
2515 sal_uInt16 XclExpChTypeGroup::GetFreeFormatIdx() const
2517 return static_cast< sal_uInt16 >( maSeries.GetSize() );
2520 void XclExpChTypeGroup::CreateDataSeries(
2521 Reference< XDiagram > const & xDiagram, Reference< XDataSeries > const & xDataSeries )
2523 // let chart create series object with correct series index
2524 XclExpChSeriesRef xSeries = GetChartData().CreateSeries();
2525 if( xSeries )
2527 if( xSeries->ConvertDataSeries( xDiagram, xDataSeries, maTypeInfo, GetGroupIdx(), GetFreeFormatIdx() ) )
2528 maSeries.AppendRecord( xSeries );
2529 else
2530 GetChartData().RemoveLastSeries();
2534 void XclExpChTypeGroup::CreateAllStockSeries(
2535 Reference< XChartType > const & xChartType, Reference< XDataSeries > const & xDataSeries )
2537 // create existing series objects
2538 bool bHasOpen = CreateStockSeries( xDataSeries, EXC_CHPROP_ROLE_OPENVALUES, false );
2539 bool bHasHigh = CreateStockSeries( xDataSeries, EXC_CHPROP_ROLE_HIGHVALUES, false );
2540 bool bHasLow = CreateStockSeries( xDataSeries, EXC_CHPROP_ROLE_LOWVALUES, false );
2541 bool bHasClose = CreateStockSeries( xDataSeries, EXC_CHPROP_ROLE_CLOSEVALUES, !bHasOpen );
2543 // formatting of special stock chart elements
2544 ScfPropertySet aTypeProp( xChartType );
2545 // hi-lo lines
2546 if( bHasHigh && bHasLow && aTypeProp.GetBoolProperty( EXC_CHPROP_SHOWHIGHLOW ) )
2548 ScfPropertySet aSeriesProp( xDataSeries );
2549 XclExpChLineFormatRef xLineFmt( new XclExpChLineFormat( GetChRoot() ) );
2550 xLineFmt->Convert( GetChRoot(), aSeriesProp, EXC_CHOBJTYPE_HILOLINE );
2551 sal_uInt16 nKey = EXC_CHCHARTLINE_HILO;
2552 m_ChartLines.insert(std::make_pair(nKey, std::make_unique<XclExpChLineFormat>(GetChRoot())));
2554 // dropbars
2555 if( bHasOpen && bHasClose )
2557 // dropbar type is dependent on position in the file - always create both
2558 Reference< XPropertySet > xWhitePropSet, xBlackPropSet;
2559 // white dropbar format
2560 aTypeProp.GetProperty( xWhitePropSet, EXC_CHPROP_WHITEDAY );
2561 ScfPropertySet aWhiteProp( xWhitePropSet );
2562 mxUpBar.reset( new XclExpChDropBar( GetChRoot(), EXC_CHOBJTYPE_WHITEDROPBAR ) );
2563 mxUpBar->Convert( aWhiteProp );
2564 // black dropbar format
2565 aTypeProp.GetProperty( xBlackPropSet, EXC_CHPROP_BLACKDAY );
2566 ScfPropertySet aBlackProp( xBlackPropSet );
2567 mxDownBar.reset( new XclExpChDropBar( GetChRoot(), EXC_CHOBJTYPE_BLACKDROPBAR ) );
2568 mxDownBar->Convert( aBlackProp );
2572 bool XclExpChTypeGroup::CreateStockSeries( Reference< XDataSeries > const & xDataSeries,
2573 const OUString& rValueRole, bool bCloseSymbol )
2575 bool bOk = false;
2576 // let chart create series object with correct series index
2577 XclExpChSeriesRef xSeries = GetChartData().CreateSeries();
2578 if( xSeries )
2580 bOk = xSeries->ConvertStockSeries( xDataSeries,
2581 rValueRole, GetGroupIdx(), GetFreeFormatIdx(), bCloseSymbol );
2582 if( bOk )
2583 maSeries.AppendRecord( xSeries );
2584 else
2585 GetChartData().RemoveLastSeries();
2587 return bOk;
2590 void XclExpChTypeGroup::WriteBody( XclExpStream& rStrm )
2592 rStrm.WriteZeroBytes( 16 );
2593 rStrm << maData.mnFlags << maData.mnGroupIdx;
2596 // Axes =======================================================================
2598 XclExpChLabelRange::XclExpChLabelRange( const XclExpChRoot& rRoot ) :
2599 XclExpRecord( EXC_ID_CHLABELRANGE, 8 ),
2600 XclExpChRoot( rRoot )
2604 void XclExpChLabelRange::Convert( const ScaleData& rScaleData, const ScfPropertySet& rChart1Axis, bool bMirrorOrient )
2606 /* Base time unit (using the property 'ExplicitTimeIncrement' from the old
2607 chart API allows to detect axis type (date axis, if property exists),
2608 and to receive the base time unit currently used in case the base time
2609 unit is set to 'automatic'. */
2610 cssc::TimeIncrement aTimeIncrement;
2611 if( rChart1Axis.GetProperty( aTimeIncrement, EXC_CHPROP_EXPTIMEINCREMENT ) )
2613 // property exists -> this is a date axis currently
2614 ::set_flag( maDateData.mnFlags, EXC_CHDATERANGE_DATEAXIS );
2616 // automatic base time unit, if the UNO Any 'rScaleData.TimeIncrement.TimeResolution' does not contain a valid value...
2617 bool bAutoBase = !rScaleData.TimeIncrement.TimeResolution.has< cssc::TimeIncrement >();
2618 ::set_flag( maDateData.mnFlags, EXC_CHDATERANGE_AUTOBASE, bAutoBase );
2620 // ...but get the current base time unit from the property of the old chart API
2621 sal_Int32 nApiTimeUnit = 0;
2622 bool bValidBaseUnit = aTimeIncrement.TimeResolution >>= nApiTimeUnit;
2623 OSL_ENSURE( bValidBaseUnit, "XclExpChLabelRange::Convert - cannot get base time unit" );
2624 maDateData.mnBaseUnit = bValidBaseUnit ? lclGetTimeUnit( nApiTimeUnit ) : EXC_CHDATERANGE_DAYS;
2626 /* Min/max values depend on base time unit, they specify the number of
2627 days, months, or years starting from null date. */
2628 bool bAutoMin = lclConvertTimeValue( GetRoot(), maDateData.mnMinDate, rScaleData.Minimum, maDateData.mnBaseUnit );
2629 ::set_flag( maDateData.mnFlags, EXC_CHDATERANGE_AUTOMIN, bAutoMin );
2630 bool bAutoMax = lclConvertTimeValue( GetRoot(), maDateData.mnMaxDate, rScaleData.Maximum, maDateData.mnBaseUnit );
2631 ::set_flag( maDateData.mnFlags, EXC_CHDATERANGE_AUTOMAX, bAutoMax );
2634 // automatic axis type detection
2635 ::set_flag( maDateData.mnFlags, EXC_CHDATERANGE_AUTODATE, rScaleData.AutoDateAxis );
2637 // increment
2638 bool bAutoMajor = lclConvertTimeInterval( maDateData.mnMajorStep, maDateData.mnMajorUnit, rScaleData.TimeIncrement.MajorTimeInterval );
2639 ::set_flag( maDateData.mnFlags, EXC_CHDATERANGE_AUTOMAJOR, bAutoMajor );
2640 bool bAutoMinor = lclConvertTimeInterval( maDateData.mnMinorStep, maDateData.mnMinorUnit, rScaleData.TimeIncrement.MinorTimeInterval );
2641 ::set_flag( maDateData.mnFlags, EXC_CHDATERANGE_AUTOMINOR, bAutoMinor );
2643 // origin
2644 double fOrigin = 0.0;
2645 if( !lclIsAutoAnyOrGetValue( fOrigin, rScaleData.Origin ) )
2646 maLabelData.mnCross = limit_cast< sal_uInt16 >( fOrigin, 1, 31999 );
2648 // reverse order
2649 if( (rScaleData.Orientation == cssc2::AxisOrientation_REVERSE) != bMirrorOrient )
2650 ::set_flag( maLabelData.mnFlags, EXC_CHLABELRANGE_REVERSE );
2653 void XclExpChLabelRange::ConvertAxisPosition( const ScfPropertySet& rPropSet )
2655 cssc::ChartAxisPosition eAxisPos = cssc::ChartAxisPosition_VALUE;
2656 rPropSet.GetProperty( eAxisPos, EXC_CHPROP_CROSSOVERPOSITION );
2657 double fCrossingPos = 1.0;
2658 rPropSet.GetProperty( fCrossingPos, EXC_CHPROP_CROSSOVERVALUE );
2660 bool bDateAxis = ::get_flag( maDateData.mnFlags, EXC_CHDATERANGE_DATEAXIS );
2661 switch( eAxisPos )
2663 case cssc::ChartAxisPosition_ZERO:
2664 case cssc::ChartAxisPosition_START:
2665 maLabelData.mnCross = 1;
2666 ::set_flag( maDateData.mnFlags, EXC_CHDATERANGE_AUTOCROSS );
2667 break;
2668 case cssc::ChartAxisPosition_END:
2669 ::set_flag( maLabelData.mnFlags, EXC_CHLABELRANGE_MAXCROSS );
2670 break;
2671 case cssc::ChartAxisPosition_VALUE:
2672 maLabelData.mnCross = limit_cast< sal_uInt16 >( fCrossingPos, 1, 31999 );
2673 ::set_flag( maDateData.mnFlags, EXC_CHDATERANGE_AUTOCROSS, false );
2674 if( bDateAxis )
2675 maDateData.mnCross = lclGetTimeValue( GetRoot(), fCrossingPos, maDateData.mnBaseUnit );
2676 break;
2677 default:
2678 maLabelData.mnCross = 1;
2679 ::set_flag( maDateData.mnFlags, EXC_CHDATERANGE_AUTOCROSS );
2683 void XclExpChLabelRange::Save( XclExpStream& rStrm )
2685 // the CHLABELRANGE record
2686 XclExpRecord::Save( rStrm );
2688 // the CHDATERANGE record with date axis settings (BIFF8 only)
2689 if( GetBiff() == EXC_BIFF8 )
2691 rStrm.StartRecord( EXC_ID_CHDATERANGE, 18 );
2692 rStrm << maDateData.mnMinDate
2693 << maDateData.mnMaxDate
2694 << maDateData.mnMajorStep
2695 << maDateData.mnMajorUnit
2696 << maDateData.mnMinorStep
2697 << maDateData.mnMinorUnit
2698 << maDateData.mnBaseUnit
2699 << maDateData.mnCross
2700 << maDateData.mnFlags;
2701 rStrm.EndRecord();
2705 void XclExpChLabelRange::WriteBody( XclExpStream& rStrm )
2707 rStrm << maLabelData.mnCross << maLabelData.mnLabelFreq << maLabelData.mnTickFreq << maLabelData.mnFlags;
2710 XclExpChValueRange::XclExpChValueRange( const XclExpChRoot& rRoot ) :
2711 XclExpRecord( EXC_ID_CHVALUERANGE, 42 ),
2712 XclExpChRoot( rRoot )
2716 void XclExpChValueRange::Convert( const ScaleData& rScaleData )
2718 // scaling algorithm
2719 bool bLogScale = ScfApiHelper::GetServiceName( rScaleData.Scaling ) == "com.sun.star.chart2.LogarithmicScaling";
2720 ::set_flag( maData.mnFlags, EXC_CHVALUERANGE_LOGSCALE, bLogScale );
2722 // min/max
2723 bool bAutoMin = lclIsAutoAnyOrGetScaledValue( maData.mfMin, rScaleData.Minimum, bLogScale );
2724 ::set_flag( maData.mnFlags, EXC_CHVALUERANGE_AUTOMIN, bAutoMin );
2725 bool bAutoMax = lclIsAutoAnyOrGetScaledValue( maData.mfMax, rScaleData.Maximum, bLogScale );
2726 ::set_flag( maData.mnFlags, EXC_CHVALUERANGE_AUTOMAX, bAutoMax );
2728 // origin
2729 bool bAutoCross = lclIsAutoAnyOrGetScaledValue( maData.mfCross, rScaleData.Origin, bLogScale );
2730 ::set_flag( maData.mnFlags, EXC_CHVALUERANGE_AUTOCROSS, bAutoCross );
2732 // major increment
2733 const IncrementData& rIncrementData = rScaleData.IncrementData;
2734 const bool bAutoMajor = lclIsAutoAnyOrGetValue( maData.mfMajorStep, rIncrementData.Distance ) || (maData.mfMajorStep <= 0.0);
2735 ::set_flag( maData.mnFlags, EXC_CHVALUERANGE_AUTOMAJOR, bAutoMajor );
2736 // minor increment
2737 const Sequence< SubIncrement >& rSubIncrementSeq = rIncrementData.SubIncrements;
2738 sal_Int32 nCount = 0;
2740 // tdf#114168 If IntervalCount is 5, then enable automatic minor calculation.
2741 // During import, if minorUnit is set and majorUnit not, then it is impossible
2742 // to calculate IntervalCount.
2743 const bool bAutoMinor = bLogScale || bAutoMajor || !rSubIncrementSeq.hasElements() ||
2744 lclIsAutoAnyOrGetValue( nCount, rSubIncrementSeq[ 0 ].IntervalCount ) || (nCount < 1) || (nCount == 5);
2746 if( maData.mfMajorStep && !bAutoMinor )
2747 maData.mfMinorStep = maData.mfMajorStep / nCount;
2748 ::set_flag( maData.mnFlags, EXC_CHVALUERANGE_AUTOMINOR, bAutoMinor );
2750 // reverse order
2751 ::set_flag( maData.mnFlags, EXC_CHVALUERANGE_REVERSE, rScaleData.Orientation == cssc2::AxisOrientation_REVERSE );
2754 void XclExpChValueRange::ConvertAxisPosition( const ScfPropertySet& rPropSet )
2756 cssc::ChartAxisPosition eAxisPos = cssc::ChartAxisPosition_VALUE;
2757 double fCrossingPos = 0.0;
2758 if( rPropSet.GetProperty( eAxisPos, EXC_CHPROP_CROSSOVERPOSITION ) && rPropSet.GetProperty( fCrossingPos, EXC_CHPROP_CROSSOVERVALUE ) )
2760 switch( eAxisPos )
2762 case cssc::ChartAxisPosition_ZERO:
2763 case cssc::ChartAxisPosition_START:
2764 ::set_flag( maData.mnFlags, EXC_CHVALUERANGE_AUTOCROSS );
2765 break;
2766 case cssc::ChartAxisPosition_END:
2767 ::set_flag( maData.mnFlags, EXC_CHVALUERANGE_MAXCROSS );
2768 break;
2769 case cssc::ChartAxisPosition_VALUE:
2770 ::set_flag( maData.mnFlags, EXC_CHVALUERANGE_AUTOCROSS, false );
2771 maData.mfCross = ::get_flagvalue< double >( maData.mnFlags, EXC_CHVALUERANGE_LOGSCALE, log( fCrossingPos ) / log( 10.0 ), fCrossingPos );
2772 break;
2773 default:
2774 ::set_flag( maData.mnFlags, EXC_CHVALUERANGE_AUTOCROSS );
2779 void XclExpChValueRange::WriteBody( XclExpStream& rStrm )
2781 rStrm << maData.mfMin
2782 << maData.mfMax
2783 << maData.mfMajorStep
2784 << maData.mfMinorStep
2785 << maData.mfCross
2786 << maData.mnFlags;
2789 namespace {
2791 sal_uInt8 lclGetXclTickPos( sal_Int32 nApiTickmarks )
2793 using namespace cssc2::TickmarkStyle;
2794 sal_uInt8 nXclTickPos = 0;
2795 ::set_flag( nXclTickPos, EXC_CHTICK_INSIDE, ::get_flag( nApiTickmarks, INNER ) );
2796 ::set_flag( nXclTickPos, EXC_CHTICK_OUTSIDE, ::get_flag( nApiTickmarks, OUTER ) );
2797 return nXclTickPos;
2800 } // namespace
2802 XclExpChTick::XclExpChTick( const XclExpChRoot& rRoot ) :
2803 XclExpRecord( EXC_ID_CHTICK, (rRoot.GetBiff() == EXC_BIFF8) ? 30 : 26 ),
2804 XclExpChRoot( rRoot ),
2805 mnTextColorId( XclExpPalette::GetColorIdFromIndex( EXC_COLOR_CHWINDOWTEXT ) )
2809 void XclExpChTick::Convert( const ScfPropertySet& rPropSet, const XclChExtTypeInfo& rTypeInfo, sal_uInt16 nAxisType )
2811 // tick mark style
2812 sal_Int32 nApiTickmarks = 0;
2813 if( rPropSet.GetProperty( nApiTickmarks, EXC_CHPROP_MAJORTICKS ) )
2814 maData.mnMajor = lclGetXclTickPos( nApiTickmarks );
2815 if( rPropSet.GetProperty( nApiTickmarks, EXC_CHPROP_MINORTICKS ) )
2816 maData.mnMinor = lclGetXclTickPos( nApiTickmarks );
2818 // axis labels
2819 if( (rTypeInfo.meTypeCateg == EXC_CHTYPECATEG_RADAR) && (nAxisType == EXC_CHAXIS_X) )
2821 /* Radar charts disable their category labels via chart type, not via
2822 axis, and axis labels are always 'near axis'. */
2823 maData.mnLabelPos = EXC_CHTICK_NEXT;
2825 else if( !rPropSet.GetBoolProperty( EXC_CHPROP_DISPLAYLABELS ) )
2827 // no labels
2828 maData.mnLabelPos = EXC_CHTICK_NOLABEL;
2830 else if( rTypeInfo.mb3dChart && (nAxisType == EXC_CHAXIS_Y) )
2832 // Excel expects 'near axis' at Y axes in 3D charts
2833 maData.mnLabelPos = EXC_CHTICK_NEXT;
2835 else
2837 cssc::ChartAxisLabelPosition eApiLabelPos = cssc::ChartAxisLabelPosition_NEAR_AXIS;
2838 rPropSet.GetProperty( eApiLabelPos, EXC_CHPROP_LABELPOSITION );
2839 switch( eApiLabelPos )
2841 case cssc::ChartAxisLabelPosition_NEAR_AXIS:
2842 case cssc::ChartAxisLabelPosition_NEAR_AXIS_OTHER_SIDE: maData.mnLabelPos = EXC_CHTICK_NEXT; break;
2843 case cssc::ChartAxisLabelPosition_OUTSIDE_START: maData.mnLabelPos = EXC_CHTICK_LOW; break;
2844 case cssc::ChartAxisLabelPosition_OUTSIDE_END: maData.mnLabelPos = EXC_CHTICK_HIGH; break;
2845 default: maData.mnLabelPos = EXC_CHTICK_NEXT;
2850 void XclExpChTick::SetFontColor( const Color& rColor, sal_uInt32 nColorId )
2852 maData.maTextColor = rColor;
2853 ::set_flag( maData.mnFlags, EXC_CHTICK_AUTOCOLOR, rColor == COL_AUTO );
2854 mnTextColorId = nColorId;
2857 void XclExpChTick::SetRotation( sal_uInt16 nRotation )
2859 maData.mnRotation = nRotation;
2860 ::set_flag( maData.mnFlags, EXC_CHTICK_AUTOROT, false );
2861 ::insert_value( maData.mnFlags, XclTools::GetXclOrientFromRot( nRotation ), 2, 3 );
2864 void XclExpChTick::WriteBody( XclExpStream& rStrm )
2866 rStrm << maData.mnMajor
2867 << maData.mnMinor
2868 << maData.mnLabelPos
2869 << maData.mnBackMode;
2870 rStrm.WriteZeroBytes( 16 );
2871 rStrm << maData.maTextColor
2872 << maData.mnFlags;
2873 if( GetBiff() == EXC_BIFF8 )
2874 rStrm << GetPalette().GetColorIndex( mnTextColorId ) << maData.mnRotation;
2877 namespace {
2879 /** Returns an API axis object from the passed coordinate system. */
2880 Reference< XAxis > lclGetApiAxis( Reference< XCoordinateSystem > const & xCoordSystem,
2881 sal_Int32 nApiAxisDim, sal_Int32 nApiAxesSetIdx )
2883 Reference< XAxis > xAxis;
2884 if( (nApiAxisDim >= 0) && xCoordSystem.is() ) try
2886 xAxis = xCoordSystem->getAxisByDimension( nApiAxisDim, nApiAxesSetIdx );
2888 catch( Exception& )
2891 return xAxis;
2894 Reference< cssc::XAxis > lclGetApiChart1Axis( Reference< XChartDocument > const & xChartDoc,
2895 sal_Int32 nApiAxisDim, sal_Int32 nApiAxesSetIdx )
2897 Reference< cssc::XAxis > xChart1Axis;
2900 Reference< cssc::XChartDocument > xChart1Doc( xChartDoc, UNO_QUERY_THROW );
2901 Reference< cssc::XAxisSupplier > xChart1AxisSupp( xChart1Doc->getDiagram(), UNO_QUERY_THROW );
2902 switch( nApiAxesSetIdx )
2904 case EXC_CHART_AXESSET_PRIMARY:
2905 xChart1Axis = xChart1AxisSupp->getAxis( nApiAxisDim );
2906 break;
2907 case EXC_CHART_AXESSET_SECONDARY:
2908 xChart1Axis = xChart1AxisSupp->getSecondaryAxis( nApiAxisDim );
2909 break;
2912 catch( Exception& )
2915 return xChart1Axis;
2918 } // namespace
2920 XclExpChAxis::XclExpChAxis( const XclExpChRoot& rRoot, sal_uInt16 nAxisType ) :
2921 XclExpChGroupBase( rRoot, EXC_CHFRBLOCK_TYPE_AXIS, EXC_ID_CHAXIS, 18 ),
2922 mnNumFmtIdx( EXC_FORMAT_NOTFOUND )
2924 maData.mnType = nAxisType;
2927 void XclExpChAxis::SetFont( XclExpChFontRef xFont, const Color& rColor, sal_uInt32 nColorId )
2929 mxFont = xFont;
2930 if( mxTick )
2931 mxTick->SetFontColor( rColor, nColorId );
2934 void XclExpChAxis::SetRotation( sal_uInt16 nRotation )
2936 if( mxTick )
2937 mxTick->SetRotation( nRotation );
2940 void XclExpChAxis::Convert( Reference< XAxis > const & xAxis, Reference< XAxis > const & xCrossingAxis,
2941 Reference< cssc::XAxis > const & xChart1Axis, const XclChExtTypeInfo& rTypeInfo )
2943 ScfPropertySet aAxisProp( xAxis );
2944 bool bCategoryAxis = ((GetAxisType() == EXC_CHAXIS_X) && rTypeInfo.mbCategoryAxis) || (GetAxisType() == EXC_CHAXIS_Z);
2946 // axis line format -------------------------------------------------------
2948 mxAxisLine.reset( new XclExpChLineFormat( GetChRoot() ) );
2949 mxAxisLine->Convert( GetChRoot(), aAxisProp, EXC_CHOBJTYPE_AXISLINE );
2950 // #i58688# axis enabled
2951 mxAxisLine->SetShowAxis( aAxisProp.GetBoolProperty( EXC_CHPROP_SHOW ) );
2953 // axis scaling and increment ---------------------------------------------
2955 ScfPropertySet aCrossingProp( xCrossingAxis );
2956 if( bCategoryAxis )
2958 mxLabelRange.reset( new XclExpChLabelRange( GetChRoot() ) );
2959 mxLabelRange->SetTicksBetweenCateg( rTypeInfo.mbTicksBetweenCateg );
2960 if( xAxis.is() )
2962 ScfPropertySet aChart1AxisProp( xChart1Axis );
2963 // #i71684# radar charts have reversed rotation direction
2964 mxLabelRange->Convert( xAxis->getScaleData(), aChart1AxisProp, (GetAxisType() == EXC_CHAXIS_X) && (rTypeInfo.meTypeCateg == EXC_CHTYPECATEG_RADAR) );
2966 // get position of crossing axis on this axis from passed axis object
2967 if( aCrossingProp.Is() )
2968 mxLabelRange->ConvertAxisPosition( aCrossingProp );
2970 else
2972 mxValueRange.reset( new XclExpChValueRange( GetChRoot() ) );
2973 if( xAxis.is() )
2974 mxValueRange->Convert( xAxis->getScaleData() );
2975 // get position of crossing axis on this axis from passed axis object
2976 if( aCrossingProp.Is() )
2977 mxValueRange->ConvertAxisPosition( aCrossingProp );
2980 // axis caption text ------------------------------------------------------
2982 // axis ticks properties
2983 mxTick.reset( new XclExpChTick( GetChRoot() ) );
2984 mxTick->Convert( aAxisProp, rTypeInfo, GetAxisType() );
2986 // axis label formatting and rotation
2987 ConvertFontBase( GetChRoot(), aAxisProp );
2988 ConvertRotationBase( aAxisProp, true );
2990 // axis number format
2991 sal_Int32 nApiNumFmt = 0;
2992 if( !bCategoryAxis && aAxisProp.GetProperty( nApiNumFmt, EXC_CHPROP_NUMBERFORMAT ) )
2994 bool bLinkNumberFmtToSource = false;
2995 if ( !aAxisProp.GetProperty( bLinkNumberFmtToSource, EXC_CHPROP_NUMBERFORMAT_LINKSRC ) || !bLinkNumberFmtToSource )
2996 mnNumFmtIdx = GetNumFmtBuffer().Insert( static_cast< sal_uInt32 >( nApiNumFmt ) );
2999 // grid -------------------------------------------------------------------
3001 if( xAxis.is() )
3003 // main grid
3004 ScfPropertySet aGridProp( xAxis->getGridProperties() );
3005 if( aGridProp.GetBoolProperty( EXC_CHPROP_SHOW ) )
3006 mxMajorGrid = lclCreateLineFormat( GetChRoot(), aGridProp, EXC_CHOBJTYPE_GRIDLINE );
3007 // sub grid
3008 Sequence< Reference< XPropertySet > > aSubGridPropSeq = xAxis->getSubGridProperties();
3009 if( aSubGridPropSeq.hasElements() )
3011 ScfPropertySet aSubGridProp( aSubGridPropSeq[ 0 ] );
3012 if( aSubGridProp.GetBoolProperty( EXC_CHPROP_SHOW ) )
3013 mxMinorGrid = lclCreateLineFormat( GetChRoot(), aSubGridProp, EXC_CHOBJTYPE_GRIDLINE );
3018 void XclExpChAxis::ConvertWall( css::uno::Reference< css::chart2::XDiagram > const & xDiagram )
3020 if( xDiagram.is() ) switch( GetAxisType() )
3022 case EXC_CHAXIS_X:
3024 ScfPropertySet aWallProp( xDiagram->getWall() );
3025 mxWallFrame = lclCreateFrame( GetChRoot(), aWallProp, EXC_CHOBJTYPE_WALL3D );
3027 break;
3028 case EXC_CHAXIS_Y:
3030 ScfPropertySet aFloorProp( xDiagram->getFloor() );
3031 mxWallFrame = lclCreateFrame( GetChRoot(), aFloorProp, EXC_CHOBJTYPE_FLOOR3D );
3033 break;
3034 default:
3035 mxWallFrame.reset();
3039 void XclExpChAxis::WriteSubRecords( XclExpStream& rStrm )
3041 lclSaveRecord( rStrm, mxLabelRange );
3042 lclSaveRecord( rStrm, mxValueRange );
3043 if( mnNumFmtIdx != EXC_FORMAT_NOTFOUND )
3044 XclExpUInt16Record( EXC_ID_CHFORMAT, mnNumFmtIdx ).Save( rStrm );
3045 lclSaveRecord( rStrm, mxTick );
3046 lclSaveRecord( rStrm, mxFont );
3047 lclSaveRecord( rStrm, mxAxisLine, EXC_ID_CHAXISLINE, EXC_CHAXISLINE_AXISLINE );
3048 lclSaveRecord( rStrm, mxMajorGrid, EXC_ID_CHAXISLINE, EXC_CHAXISLINE_MAJORGRID );
3049 lclSaveRecord( rStrm, mxMinorGrid, EXC_ID_CHAXISLINE, EXC_CHAXISLINE_MINORGRID );
3050 lclSaveRecord( rStrm, mxWallFrame, EXC_ID_CHAXISLINE, EXC_CHAXISLINE_WALLS );
3053 void XclExpChAxis::WriteBody( XclExpStream& rStrm )
3055 rStrm << maData.mnType;
3056 rStrm.WriteZeroBytes( 16 );
3059 XclExpChAxesSet::XclExpChAxesSet( const XclExpChRoot& rRoot, sal_uInt16 nAxesSetId ) :
3060 XclExpChGroupBase( rRoot, EXC_CHFRBLOCK_TYPE_AXESSET, EXC_ID_CHAXESSET, 18 )
3062 maData.mnAxesSetId = nAxesSetId;
3063 SetFutureRecordContext( 0, nAxesSetId );
3065 /* Need to set a reasonable size for the plot area, otherwise Excel will
3066 move away embedded shapes while auto-sizing the plot area. This is just
3067 a wild guess, but will be fixed with implementing manual positioning of
3068 chart elements. */
3069 maData.maRect.mnX = 262;
3070 maData.maRect.mnY = 626;
3071 maData.maRect.mnWidth = 3187;
3072 maData.maRect.mnHeight = 2633;
3075 sal_uInt16 XclExpChAxesSet::Convert( Reference< XDiagram > const & xDiagram, sal_uInt16 nFirstGroupIdx )
3077 /* First unused chart type group index is passed to be able to continue
3078 counting of chart type groups for secondary axes set. */
3079 sal_uInt16 nGroupIdx = nFirstGroupIdx;
3080 Reference< XCoordinateSystemContainer > xCoordSysCont( xDiagram, UNO_QUERY );
3081 if( xCoordSysCont.is() )
3083 Sequence< Reference< XCoordinateSystem > > aCoordSysSeq = xCoordSysCont->getCoordinateSystems();
3084 if( aCoordSysSeq.hasElements() )
3086 /* Process first coordinate system only. Import filter puts all
3087 chart types into one coordinate system. */
3088 Reference< XCoordinateSystem > xCoordSystem = aCoordSysSeq[ 0 ];
3089 sal_Int32 nApiAxesSetIdx = GetApiAxesSetIndex();
3091 // 3d mode
3092 bool b3dChart = xCoordSystem.is() && (xCoordSystem->getDimension() == 3);
3094 // percent charts
3095 namespace ApiAxisType = cssc2::AxisType;
3096 Reference< XAxis > xApiYAxis = lclGetApiAxis( xCoordSystem, EXC_CHART_AXIS_Y, nApiAxesSetIdx );
3097 bool bPercent = xApiYAxis.is() && (xApiYAxis->getScaleData().AxisType == ApiAxisType::PERCENT);
3099 // connector lines in bar charts
3100 ScfPropertySet aDiaProp( xDiagram );
3101 bool bConnectBars = aDiaProp.GetBoolProperty( EXC_CHPROP_CONNECTBARS );
3103 // swapped axes sets
3104 ScfPropertySet aCoordSysProp( xCoordSystem );
3105 bool bSwappedAxesSet = aCoordSysProp.GetBoolProperty( EXC_CHPROP_SWAPXANDYAXIS );
3107 // X axis for later use
3108 Reference< XAxis > xApiXAxis = lclGetApiAxis( xCoordSystem, EXC_CHART_AXIS_X, nApiAxesSetIdx );
3109 // X axis labels
3110 ScfPropertySet aXAxisProp( xApiXAxis );
3111 bool bHasXLabels = aXAxisProp.GetBoolProperty( EXC_CHPROP_DISPLAYLABELS );
3113 // process chart types
3114 Reference< XChartTypeContainer > xChartTypeCont( xCoordSystem, UNO_QUERY );
3115 if( xChartTypeCont.is() )
3117 const Sequence< Reference< XChartType > > aChartTypeSeq = xChartTypeCont->getChartTypes();
3118 for( const Reference< XChartType >& rChartType : aChartTypeSeq )
3120 XclExpChTypeGroupRef xTypeGroup( new XclExpChTypeGroup( GetChRoot(), nGroupIdx ) );
3121 xTypeGroup->ConvertType( xDiagram, rChartType, nApiAxesSetIdx, b3dChart, bSwappedAxesSet, bHasXLabels );
3122 /* If new chart type group cannot be inserted into a combination
3123 chart with existing type groups, insert all series into last
3124 contained chart type group instead of creating a new group. */
3125 XclExpChTypeGroupRef xLastGroup = GetLastTypeGroup();
3126 if( xLastGroup && !(xTypeGroup->IsCombinable2d() && xLastGroup->IsCombinable2d()) )
3128 xLastGroup->ConvertSeries( xDiagram, rChartType, nApiAxesSetIdx, bPercent, bConnectBars );
3130 else
3132 xTypeGroup->ConvertSeries( xDiagram, rChartType, nApiAxesSetIdx, bPercent, bConnectBars );
3133 if( xTypeGroup->IsValidGroup() )
3135 maTypeGroups.AppendRecord( xTypeGroup );
3136 ++nGroupIdx;
3142 if( XclExpChTypeGroup* pGroup = GetFirstTypeGroup().get() )
3144 const XclChExtTypeInfo& rTypeInfo = pGroup->GetTypeInfo();
3146 // create axes according to chart type (no axes for pie and donut charts)
3147 if( rTypeInfo.meTypeCateg != EXC_CHTYPECATEG_PIE )
3149 ConvertAxis( mxXAxis, EXC_CHAXIS_X, mxXAxisTitle, EXC_CHOBJLINK_XAXIS, xCoordSystem, rTypeInfo, EXC_CHART_AXIS_Y );
3150 ConvertAxis( mxYAxis, EXC_CHAXIS_Y, mxYAxisTitle, EXC_CHOBJLINK_YAXIS, xCoordSystem, rTypeInfo, EXC_CHART_AXIS_X );
3151 if( pGroup->Is3dDeepChart() )
3152 ConvertAxis( mxZAxis, EXC_CHAXIS_Z, mxZAxisTitle, EXC_CHOBJLINK_ZAXIS, xCoordSystem, rTypeInfo, EXC_CHART_AXIS_NONE );
3155 // X axis category ranges
3156 if( rTypeInfo.mbCategoryAxis && xApiXAxis.is() )
3158 const ScaleData aScaleData = xApiXAxis->getScaleData();
3159 for( size_t nIdx = 0, nSize = maTypeGroups.GetSize(); nIdx < nSize; ++nIdx )
3160 maTypeGroups.GetRecord( nIdx )->ConvertCategSequence( aScaleData.Categories );
3163 // legend
3164 if( xDiagram.is() && (GetAxesSetId() == EXC_CHAXESSET_PRIMARY) )
3166 Reference< XLegend > xLegend = xDiagram->getLegend();
3167 if( xLegend.is() )
3169 ScfPropertySet aLegendProp( xLegend );
3170 pGroup->ConvertLegend( aLegendProp );
3177 // wall/floor/diagram frame formatting
3178 if( xDiagram.is() && (GetAxesSetId() == EXC_CHAXESSET_PRIMARY) )
3180 XclExpChTypeGroupRef xTypeGroup = GetFirstTypeGroup();
3181 if( xTypeGroup && xTypeGroup->Is3dWallChart() )
3183 // wall/floor formatting (3D charts)
3184 if( mxXAxis )
3185 mxXAxis->ConvertWall( xDiagram );
3186 if( mxYAxis )
3187 mxYAxis->ConvertWall( xDiagram );
3189 else
3191 // diagram background formatting
3192 ScfPropertySet aWallProp( xDiagram->getWall() );
3193 mxPlotFrame = lclCreateFrame( GetChRoot(), aWallProp, EXC_CHOBJTYPE_PLOTFRAME );
3197 // inner and outer plot area position and size
3200 Reference< cssc::XChartDocument > xChart1Doc( GetChartDocument(), UNO_QUERY_THROW );
3201 Reference< cssc::XDiagramPositioning > xPositioning( xChart1Doc->getDiagram(), UNO_QUERY_THROW );
3202 // set manual flag in chart data
3203 if( !xPositioning->isAutomaticDiagramPositioning() )
3204 GetChartData().SetManualPlotArea();
3205 // the CHAXESSET record contains the inner plot area
3206 maData.maRect = CalcChartRectFromHmm( xPositioning->calculateDiagramPositionExcludingAxes() );
3207 // the embedded CHFRAMEPOS record contains the outer plot area
3208 mxFramePos.reset( new XclExpChFramePos( EXC_CHFRAMEPOS_PARENT ) );
3209 // for pie charts, always use inner plot area size to exclude the data labels as Excel does
3210 const XclExpChTypeGroup* pFirstTypeGroup = GetFirstTypeGroup().get();
3211 bool bPieChart = pFirstTypeGroup && (pFirstTypeGroup->GetTypeInfo().meTypeCateg == EXC_CHTYPECATEG_PIE);
3212 mxFramePos->GetFramePosData().maRect = bPieChart ? maData.maRect :
3213 CalcChartRectFromHmm( xPositioning->calculateDiagramPositionIncludingAxes() );
3215 catch( Exception& )
3219 // return first unused chart type group index for next axes set
3220 return nGroupIdx;
3223 bool XclExpChAxesSet::Is3dChart() const
3225 XclExpChTypeGroupRef xTypeGroup = GetFirstTypeGroup();
3226 return xTypeGroup && xTypeGroup->Is3dChart();
3229 void XclExpChAxesSet::WriteSubRecords( XclExpStream& rStrm )
3231 lclSaveRecord( rStrm, mxFramePos );
3232 lclSaveRecord( rStrm, mxXAxis );
3233 lclSaveRecord( rStrm, mxYAxis );
3234 lclSaveRecord( rStrm, mxZAxis );
3235 lclSaveRecord( rStrm, mxXAxisTitle );
3236 lclSaveRecord( rStrm, mxYAxisTitle );
3237 lclSaveRecord( rStrm, mxZAxisTitle );
3238 if( mxPlotFrame )
3240 XclExpEmptyRecord( EXC_ID_CHPLOTFRAME ).Save( rStrm );
3241 mxPlotFrame->Save( rStrm );
3243 maTypeGroups.Save( rStrm );
3246 XclExpChTypeGroupRef XclExpChAxesSet::GetFirstTypeGroup() const
3248 return maTypeGroups.GetFirstRecord();
3251 XclExpChTypeGroupRef XclExpChAxesSet::GetLastTypeGroup() const
3253 return maTypeGroups.GetLastRecord();
3256 void XclExpChAxesSet::ConvertAxis(
3257 XclExpChAxisRef& rxChAxis, sal_uInt16 nAxisType,
3258 XclExpChTextRef& rxChAxisTitle, sal_uInt16 nTitleTarget,
3259 Reference< XCoordinateSystem > const & xCoordSystem, const XclChExtTypeInfo& rTypeInfo,
3260 sal_Int32 nCrossingAxisDim )
3262 // create and convert axis object
3263 rxChAxis.reset( new XclExpChAxis( GetChRoot(), nAxisType ) );
3264 sal_Int32 nApiAxisDim = rxChAxis->GetApiAxisDimension();
3265 sal_Int32 nApiAxesSetIdx = GetApiAxesSetIndex();
3266 Reference< XAxis > xAxis = lclGetApiAxis( xCoordSystem, nApiAxisDim, nApiAxesSetIdx );
3267 Reference< XAxis > xCrossingAxis = lclGetApiAxis( xCoordSystem, nCrossingAxisDim, nApiAxesSetIdx );
3268 Reference< cssc::XAxis > xChart1Axis = lclGetApiChart1Axis( GetChartDocument(), nApiAxisDim, nApiAxesSetIdx );
3269 rxChAxis->Convert( xAxis, xCrossingAxis, xChart1Axis, rTypeInfo );
3271 // create and convert axis title
3272 Reference< XTitled > xTitled( xAxis, UNO_QUERY );
3273 rxChAxisTitle = lclCreateTitle( GetChRoot(), xTitled, nTitleTarget );
3276 void XclExpChAxesSet::WriteBody( XclExpStream& rStrm )
3278 rStrm << maData.mnAxesSetId << maData.maRect;
3281 // The chart object ===========================================================
3283 static void lcl_getChartSubTitle(const Reference<XChartDocument>& xChartDoc,
3284 OUString& rSubTitle)
3286 Reference< css::chart::XChartDocument > xChartDoc1(xChartDoc, UNO_QUERY);
3287 if (!xChartDoc1.is())
3288 return;
3290 Reference< XPropertySet > xProp(xChartDoc1->getSubTitle(), UNO_QUERY);
3291 if (!xProp.is())
3292 return;
3294 OUString aTitle;
3295 Any any = xProp->getPropertyValue("String");
3296 if (any >>= aTitle)
3297 rSubTitle = aTitle;
3300 XclExpChChart::XclExpChChart( const XclExpRoot& rRoot,
3301 Reference< XChartDocument > const & xChartDoc, const tools::Rectangle& rChartRect ) :
3302 XclExpChGroupBase( XclExpChRoot( rRoot, *this ), EXC_CHFRBLOCK_TYPE_CHART, EXC_ID_CHCHART, 16 )
3304 Size aPtSize = OutputDevice::LogicToLogic( rChartRect.GetSize(), MapMode( MapUnit::Map100thMM ), MapMode( MapUnit::MapPoint ) );
3305 // rectangle is stored in 16.16 fixed-point format
3306 maRect.mnX = maRect.mnY = 0;
3307 maRect.mnWidth = static_cast< sal_Int32 >( aPtSize.Width() << 16 );
3308 maRect.mnHeight = static_cast< sal_Int32 >( aPtSize.Height() << 16 );
3310 // global chart properties (default values)
3311 ::set_flag( maProps.mnFlags, EXC_CHPROPS_SHOWVISIBLEONLY, false );
3312 ::set_flag( maProps.mnFlags, EXC_CHPROPS_MANPLOTAREA );
3313 maProps.mnEmptyMode = EXC_CHPROPS_EMPTY_SKIP;
3315 // always create both axes set objects
3316 mxPrimAxesSet.reset( new XclExpChAxesSet( GetChRoot(), EXC_CHAXESSET_PRIMARY ) );
3317 mxSecnAxesSet.reset( new XclExpChAxesSet( GetChRoot(), EXC_CHAXESSET_SECONDARY ) );
3319 if( xChartDoc.is() )
3321 Reference< XDiagram > xDiagram = xChartDoc->getFirstDiagram();
3323 // global chart properties (only 'include hidden cells' attribute for now)
3324 ScfPropertySet aDiagramProp( xDiagram );
3325 bool bIncludeHidden = aDiagramProp.GetBoolProperty( EXC_CHPROP_INCLUDEHIDDENCELLS );
3326 ::set_flag( maProps.mnFlags, EXC_CHPROPS_SHOWVISIBLEONLY, !bIncludeHidden );
3328 // initialize API conversion (remembers xChartDoc and rChartRect internally)
3329 InitConversion( xChartDoc, rChartRect );
3331 // chart frame
3332 ScfPropertySet aFrameProp( xChartDoc->getPageBackground() );
3333 mxFrame = lclCreateFrame( GetChRoot(), aFrameProp, EXC_CHOBJTYPE_BACKGROUND );
3335 // chart title
3336 Reference< XTitled > xTitled( xChartDoc, UNO_QUERY );
3337 OUString aSubTitle;
3338 lcl_getChartSubTitle(xChartDoc, aSubTitle);
3339 mxTitle = lclCreateTitle( GetChRoot(), xTitled, EXC_CHOBJLINK_TITLE,
3340 !aSubTitle.isEmpty() ? &aSubTitle : nullptr );
3342 // diagrams (axes sets)
3343 sal_uInt16 nFreeGroupIdx = mxPrimAxesSet->Convert( xDiagram, 0 );
3344 if( !mxPrimAxesSet->Is3dChart() )
3345 mxSecnAxesSet->Convert( xDiagram, nFreeGroupIdx );
3347 // treatment of missing values
3348 ScfPropertySet aDiaProp( xDiagram );
3349 sal_Int32 nMissingValues = 0;
3350 if( aDiaProp.GetProperty( nMissingValues, EXC_CHPROP_MISSINGVALUETREATMENT ) )
3352 using namespace cssc::MissingValueTreatment;
3353 switch( nMissingValues )
3355 case LEAVE_GAP: maProps.mnEmptyMode = EXC_CHPROPS_EMPTY_SKIP; break;
3356 case USE_ZERO: maProps.mnEmptyMode = EXC_CHPROPS_EMPTY_ZERO; break;
3357 case CONTINUE: maProps.mnEmptyMode = EXC_CHPROPS_EMPTY_INTERPOLATE; break;
3361 // finish API conversion
3362 FinishConversion();
3366 XclExpChSeriesRef XclExpChChart::CreateSeries()
3368 XclExpChSeriesRef xSeries;
3369 sal_uInt16 nSeriesIdx = static_cast< sal_uInt16 >( maSeries.GetSize() );
3370 if( nSeriesIdx <= EXC_CHSERIES_MAXSERIES )
3372 xSeries.reset( new XclExpChSeries( GetChRoot(), nSeriesIdx ) );
3373 maSeries.AppendRecord( xSeries );
3375 return xSeries;
3378 void XclExpChChart::RemoveLastSeries()
3380 if( !maSeries.IsEmpty() )
3381 maSeries.RemoveRecord( maSeries.GetSize() - 1 );
3384 void XclExpChChart::SetDataLabel( XclExpChTextRef const & xText )
3386 if( xText )
3387 maLabels.AppendRecord( xText );
3390 void XclExpChChart::SetManualPlotArea()
3392 // this flag does not exist in BIFF5
3393 if( GetBiff() == EXC_BIFF8 )
3394 ::set_flag( maProps.mnFlags, EXC_CHPROPS_USEMANPLOTAREA );
3397 void XclExpChChart::WriteSubRecords( XclExpStream& rStrm )
3399 // background format
3400 lclSaveRecord( rStrm, mxFrame );
3402 // data series
3403 maSeries.Save( rStrm );
3405 // CHPROPERTIES record
3406 rStrm.StartRecord( EXC_ID_CHPROPERTIES, 4 );
3407 rStrm << maProps.mnFlags << maProps.mnEmptyMode << sal_uInt8( 0 );
3408 rStrm.EndRecord();
3410 // axes sets (always save primary axes set)
3411 sal_uInt16 nUsedAxesSets = mxSecnAxesSet->IsValidAxesSet() ? 2 : 1;
3412 XclExpUInt16Record( EXC_ID_CHUSEDAXESSETS, nUsedAxesSets ).Save( rStrm );
3413 mxPrimAxesSet->Save( rStrm );
3414 if( mxSecnAxesSet->IsValidAxesSet() )
3415 mxSecnAxesSet->Save( rStrm );
3417 // chart title and data labels
3418 lclSaveRecord( rStrm, mxTitle );
3419 maLabels.Save( rStrm );
3422 void XclExpChChart::WriteBody( XclExpStream& rStrm )
3424 rStrm << maRect;
3427 XclExpChartDrawing::XclExpChartDrawing( const XclExpRoot& rRoot,
3428 const Reference< XModel >& rxModel, const Size& rChartSize ) :
3429 XclExpRoot( rRoot )
3431 if( (rChartSize.Width() > 0) && (rChartSize.Height() > 0) )
3433 ScfPropertySet aPropSet( rxModel );
3434 Reference< XShapes > xShapes;
3435 if( aPropSet.GetProperty( xShapes, EXC_CHPROP_ADDITIONALSHAPES ) && xShapes.is() && (xShapes->getCount() > 0) )
3437 /* Create a new independent object manager with own DFF stream for the
3438 DGCONTAINER, pass global manager as parent for shared usage of
3439 global DFF data (picture container etc.). */
3440 mxObjMgr.reset( new XclExpEmbeddedObjectManager( GetObjectManager(), rChartSize, EXC_CHART_TOTALUNITS, EXC_CHART_TOTALUNITS ) );
3441 // initialize the drawing object list
3442 mxObjMgr->StartSheet();
3443 // process the draw page (convert all shapes)
3444 mxObjRecs = mxObjMgr->ProcessDrawing( xShapes );
3445 // finalize the DFF stream
3446 mxObjMgr->EndDocument();
3451 XclExpChartDrawing::~XclExpChartDrawing()
3455 void XclExpChartDrawing::Save( XclExpStream& rStrm )
3457 if( mxObjRecs )
3458 mxObjRecs->Save( rStrm );
3461 XclExpChart::XclExpChart( const XclExpRoot& rRoot, Reference< XModel > const & xModel, const tools::Rectangle& rChartRect ) :
3462 XclExpSubStream( EXC_BOF_CHART ),
3463 XclExpRoot( rRoot )
3465 AppendNewRecord( new XclExpChartPageSettings( rRoot ) );
3466 AppendNewRecord( new XclExpBoolRecord( EXC_ID_PROTECT, false ) );
3467 AppendNewRecord( new XclExpChartDrawing( rRoot, xModel, rChartRect.GetSize() ) );
3468 AppendNewRecord( new XclExpUInt16Record( EXC_ID_CHUNITS, EXC_CHUNITS_TWIPS ) );
3470 Reference< XChartDocument > xChartDoc( xModel, UNO_QUERY );
3471 AppendNewRecord( new XclExpChChart( rRoot, xChartDoc, rChartRect ) );
3474 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */