22#include <com/sun/star/chart/XAxisXSupplier.hpp>
23#include <com/sun/star/chart/XAxisYSupplier.hpp>
24#include <com/sun/star/chart/XAxisZSupplier.hpp>
25#include <com/sun/star/chart/XChartDocument.hpp>
26#include <com/sun/star/chart/XSecondAxisTitleSupplier.hpp>
27#include <com/sun/star/chart2/XChartDocument.hpp>
28#include <com/sun/star/chart2/RelativePosition.hpp>
29#include <com/sun/star/chart2/RelativeSize.hpp>
30#include <com/sun/star/chart2/XTitle.hpp>
31#include <com/sun/star/lang/XMultiServiceFactory.hpp>
32#include <com/sun/star/uno/XComponentContext.hpp>
33#include <osl/diagnose.h>
38#include <oox/token/properties.hxx>
39#include <oox/token/tokens.hxx>
44namespace cssc = ::com::sun::star::chart;
52using ::oox::core::XmlFilterBase;
56struct TitleKey :
public ::std::pair< ObjectType, ::std::pair< sal_Int32, sal_Int32 > >
58 explicit TitleKey(
ObjectType eObjType, sal_Int32 nMainIdx = -1, sal_Int32 nSubIdx = -1 )
59 {
first = eObjType; second.first = nMainIdx; second.second = nSubIdx; }
67 typedef Reference< XShape > (*GetShapeFunc)(
const Reference< cssc::XChartDocument >& );
73 explicit TitleLayoutInfo() :
mpGetShape( nullptr ) {}
76 ConverterRoot
const & rRoot,
77 const Reference< cssc::XChartDocument >& rxChart1Doc );
80void TitleLayoutInfo::convertTitlePos( ConverterRoot
const & rRoot,
const Reference< cssc::XChartDocument >& rxChart1Doc )
88 Reference< XShape > xTitleShape =
mpGetShape( rxChart1Doc );
91 SAL_WARN(
"oox",
"failed to get a TitleShape");
96 PropertySet aTitleProp(
mxTitle );
97 aTitleProp.getProperty( fAngle, PROP_TextRotation );
100 LayoutConverter aLayoutConv( rRoot, rLayout );
101 aLayoutConv.convertFromModel( xTitleShape, fAngle );
114#define OOX_FRAGMENT_GETTITLESHAPE( shape_supplier, supplier_func, property_name ) \
115 PropertySet aPropSet( shape_supplier ); \
116 if( shape_supplier.is() && aPropSet.getBoolProperty( PROP_##property_name ) ) \
117 return shape_supplier->supplier_func(); \
118 return Reference< XShape >(); \
122#define OOX_DEFINEFUNC_GETAXISTITLESHAPE( func_name, interface_type, supplier_func, property_name ) \
123Reference< XShape > func_name( const Reference< cssc::XChartDocument >& rxChart1Doc ) \
125 Reference< cssc::interface_type > xAxisSupp( rxChart1Doc->getDiagram(), UNO_QUERY ); \
126 OOX_FRAGMENT_GETTITLESHAPE( xAxisSupp, supplier_func, property_name ) \
130Reference< XShape > lclGetMainTitleShape(
const Reference< cssc::XChartDocument >& rxChart1Doc )
141#undef OOX_DEFINEFUNC_GETAXISTITLESHAPE
142#undef OOX_IMPLEMENT_GETTITLESHAPE
149 std::map< TitleKey, TitleLayoutInfo >
161 const awt::Size& rChartSize );
170 const awt::Size& rChartSize ) :
171 maFormatter( rFilter, rxChartDoc, rChartModel ),
173 mrConverter( rChartConverter ),
177 OSL_ENSURE(
mxDoc.is(),
"ConverterData::ConverterData - missing chart document" );
181 mxDoc->lockControllers();
201 mxDoc->unlockControllers();
213 const awt::Size& rChartSize ) :
229 xInt = xMSF->createInstance( rServiceName );
234 OSL_ENSURE( xInt.is(),
"ConverterRoot::createInstance - cannot create instance" );
240 return mxData->mrFilter.getComponentContext();
250 return mxData->mrConverter;
265 return mxData->maFormatter;
271 OSL_ENSURE( rxTitle.is(),
"ConverterRoot::registerTitleLayout - missing title object" );
272 TitleLayoutInfo& rTitleInfo =
mxData->maTitles[ TitleKey( eObjType, nMainIdx, nSubIdx ) ];
273 OSL_ENSURE( rTitleInfo.mpGetShape,
"ConverterRoot::registerTitleLayout - invalid title key" );
274 rTitleInfo.mxTitle = rxTitle;
275 rTitleInfo.mxLayout = rxLayout;
283 for (
auto & title :
mxData->maTitles)
284 title.second.convertTitlePos( *
this, xChart1Doc );
294sal_Int32 lclCalcPosition( sal_Int32 nChartSize,
double fPos, sal_Int32 nPosMode )
299 return getLimitedValue< sal_Int32, double >( nChartSize * fPos + 0.5, 0, nChartSize );
301 OSL_FAIL(
"lclCalcPosition - relative positioning not supported" );
305 OSL_FAIL(
"lclCalcPosition - unknown positioning mode" );
310sal_Int32 lclCalcSize( sal_Int32 nPos, sal_Int32 nChartSize,
double fSize, sal_Int32 nSizeMode )
312 sal_Int32
nValue = getLimitedValue< sal_Int32, double >( nChartSize * fSize + 0.5, 0, nChartSize );
321 OSL_FAIL(
"lclCalcSize - unknown size mode" );
326double lclCalcRelSize(
double fPos,
double fSize, sal_Int32 nSizeMode )
336 OSL_ENSURE(
false,
"lclCalcRelSize - unknown size mode" );
339 return getLimitedValue< double, double >( fSize, 0.0, 1.0 - fPos );
358 if( aChartSize.Width <= 0 || aChartSize.Height <= 0 )
364 if( (orRect.X >= 0) && (orRect.Y >= 0) )
368 return (orRect.Width > 0) && (orRect.Height > 0);
380 RelativePosition aPos(
381 getLimitedValue< double, double >(
mrModel.
mfX, 0.0, 1.0 ),
382 getLimitedValue< double, double >(
mrModel.
mfY, 0.0, 1.0 ),
383 Alignment_TOP_LEFT );
384 rPropSet.
setProperty( PROP_RelativePosition, aPos );
389 if( (aSize.Primary > 0.0) && (aSize.Secondary > 0.0) )
404 if( aChartSize.Width <= 0 || aChartSize.Height <= 0 )
408 awt::Point aShapePos(
411 if( (aShapePos.X < 0) || (aShapePos.Y < 0) )
414 bool bPropSet =
false;
416 awt::Size aShapeSize = rxShape->getSize();
418 if( aShapeSize.Height > 0 || aShapeSize.Width > 0 )
422 if( fRotationAngle > 180.0 )
423 aShapePos.X +=
static_cast<sal_Int32
>(fSin * aShapeSize.Height + 0.5);
425 else if( fRotationAngle > 0.0 )
426 aShapePos.Y +=
static_cast<sal_Int32
>(fSin * aShapeSize.Width + 0.5);
428 else if( fRotationAngle == 90.0 || fRotationAngle == 270.0 )
431 RelativePosition aPos(
432 getLimitedValue< double, double >(
mrModel.
mfX, 0.0, 1.0),
433 getLimitedValue< double, double >(
mrModel.
mfY, 0.0, 1.0),
434 fRotationAngle == 90.0 ? Alignment_TOP_RIGHT : Alignment_BOTTOM_LEFT );
436 if( aShapeProp.setProperty(PROP_RelativePosition, aPos) )
441 rxShape->setPosition( aShapePos );
geometry::RealSize2D maSize
A wrapper for a UNO property set.
bool setProperty(sal_Int32 nPropId, const Type &rValue)
Puts the passed value into the property set.
Base class of all converter classes.
::oox::core::XmlFilterBase & getFilter() const
Returns the filter object of the imported/exported document.
css::uno::Reference< css::chart2::XChartDocument > const & getChartDocument() const
Returns the API chart document model.
ChartConverter & getChartConverter() const
Returns the chart converter.
const css::awt::Size & getChartSize() const
Returns the position and size of the chart shape in 1/100 mm.
void convertTitlePositions()
Converts the positions of the main title and all axis titles.
void registerTitleLayout(const css::uno::Reference< css::chart2::XTitle > &rxTitle, const ModelRef< LayoutModel > &rxLayout, ObjectType eObjType, sal_Int32 nMainIdx, sal_Int32 nSubIdx)
Registers a title object and its layout data, needed for conversion of the title position using the o...
ObjectFormatter & getFormatter() const
Returns the object formatter.
static css::awt::Size getDefaultPageSize()
Returns the default position and size of the chart shape in 1/100 mm.
std::shared_ptr< ConverterData > mxData
css::uno::Reference< css::uno::XInterface > createInstance(const OUString &rServiceName) const
Creates an instance for the passed service name, using the process service factory.
ConverterRoot(::oox::core::XmlFilterBase &rFilter, ChartConverter &rChartConverter, const ChartSpaceModel &rChartModel, const css::uno::Reference< css::chart2::XChartDocument > &rxChartDoc, const css::awt::Size &rChartSize)
css::uno::Reference< css::uno::XComponentContext > const & getComponentContext() const
LayoutConverter(const ConverterRoot &rParent, LayoutModel &rModel)
bool calcAbsRectangle(css::awt::Rectangle &orRect) const
Tries to calculate the absolute position and size from the contained OOXML layout model.
bool convertFromModel(PropertySet &rPropSet)
Tries to set the position and size from the contained OOXML layout model.
virtual ~LayoutConverter() override
ModelType & getOrCreate()
GetShapeFunc mpGetShape
The layout model, if existing.
Reference< XTitle > mxTitle
#define OOX_DEFINEFUNC_GETAXISTITLESHAPE(func_name, interface_type, supplier_func, property_name)
Implements a function returning the drawing shape of an axis title, if existing, using the specified ...
#define OOX_FRAGMENT_GETTITLESHAPE(shape_supplier, supplier_func, property_name)
A code fragment that returns a shape object from the passed shape supplier using the specified interf...
ModelRef< LayoutModel > mxLayout
The API title object.
#define SAL_WARN(area, stream)
constexpr double deg2rad(double v)
std::u16string_view getTitle(std::u16string_view aPath)
constexpr OUStringLiteral first
std::shared_ptr< T > make_shared(Args &&... args)
const sal_Int32 API_Y_AXIS
const sal_Int32 API_PRIM_AXESSET
const sal_Int32 API_X_AXIS
ObjectType
Enumerates different object types for specific automatic formatting behaviour.
@ OBJECTTYPE_AXISTITLE
Axis line, labels, tick marks.
@ OBJECTTYPE_CHARTTITLE
Chart background.
const sal_Int32 API_SECN_AXESSET
const sal_Int32 API_Z_AXIS
const PowerPointImport & mrFilter
ConverterData(XmlFilterBase &rFilter, ChartConverter &rChartConverter, const ChartSpaceModel &rChartModel, const Reference< XChartDocument > &rxChartDoc, const awt::Size &rChartSize)
std::map< TitleKey, TitleLayoutInfo > maTitles
Reference< XChartDocument > mxDoc
ObjectFormatter maFormatter
ChartConverter & mrConverter
sal_Int32 mnXMode
Height of this object.
double mfW
Top position of this object.
sal_Int32 mnYMode
Mode for left position.
double mfY
Left position of this object.
sal_Int32 mnHMode
Mode for width.
sal_Int32 mnWMode
Mode for top position.
bool mbAutoLayout
Layout target for plot area.
double mfH
Width of this object.