/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
/** A helper structure to store all data related to title objects. Needed for the conversion of manual title positions that needs the old Chart1 API.
*/ struct TitleLayoutInfo
{ typedef Reference< XShape > (*GetShapeFunc)( const Reference< cssc::XChartDocument >& );
Reference< XTitle > mxTitle; /// The API title object.
ModelRef< LayoutModel > mxLayout; /// The layout model, if existing.
GetShapeFunc mpGetShape; /// Helper function to receive the title shape.
try
{ // try to get the title shape
Reference< XShape > xTitleShape = mpGetShape( rxChart1Doc ); if (!xTitleShape)
{
SAL_WARN("oox", "failed to get a TitleShape"); return;
} // get title rotation angle, needed for correction of position of top-left edge double fAngle = 0.0;
PropertySet aTitleProp( mxTitle );
aTitleProp.getProperty( fAngle, PROP_TextRotation ); // convert the position
LayoutModel& rLayout = mxLayout.getOrCreate();
LayoutConverter aLayoutConv( rRoot, rLayout );
aLayoutConv.convertFromModel( xTitleShape, fAngle );
} catch( Exception& )
{
}
}
/* The following local functions implement getting the XShape interface of all supported title objects (chart and axes). This needs some effort due to the
design of the old Chart1 API used to access these objects. */
/** A code fragment that returns a shape object from the passed shape supplier
using the specified interface function. Checks a boolean property first. */ #define OOX_FRAGMENT_GETTITLESHAPE( shape_supplier, supplier_func, property_name ) \
PropertySet aPropSet( shape_supplier ); \ if( shape_supplier.is() && aPropSet.getBoolProperty( PROP_##property_name ) ) \ return shape_supplier->supplier_func(); \ return Reference< XShape >(); \
/** Implements a function returning the drawing shape of an axis title, if
existing, using the specified API interface and its function. */ #define OOX_DEFINEFUNC_GETAXISTITLESHAPE( func_name, interface_type, supplier_func, property_name ) \
Reference< XShape > func_name( const Reference< cssc::XChartDocument >& rxChart1Doc ) \
{ \
Reference< cssc::interface_type > xAxisSupp( rxChart1Doc->getDiagram(), UNO_QUERY ); \
OOX_FRAGMENT_GETTITLESHAPE( xAxisSupp, supplier_func, property_name ) \
}
/** Returns the drawing shape of the main title, if existing. */
Reference< XShape > lclGetMainTitleShape( const Reference< cssc::XChartDocument >& rxChart1Doc )
{
OOX_FRAGMENT_GETTITLESHAPE( rxChart1Doc, getTitle, HasMainTitle )
}
/** Returns a position value in the chart area in 1/100 mm. */
sal_Int32 lclCalcPosition( sal_Int32 nChartSize, double fPos, sal_Int32 nPosMode )
{ switch( nPosMode )
{ case XML_edge: // absolute start position as factor of chart size return getLimitedValue< sal_Int32, double >( nChartSize * fPos + 0.5, 0, nChartSize ); case XML_factor: // position relative to object default position
OSL_FAIL( "lclCalcPosition - relative positioning not supported" ); return -1;
};
/** Returns a size value in the chart area in 1/100 mm. */
sal_Int32 lclCalcSize( sal_Int32 nPos, sal_Int32 nChartSize, double fSize, sal_Int32 nSizeMode )
{
sal_Int32 nValue = getLimitedValue< sal_Int32, double >( nChartSize * fSize + 0.5, 0, nChartSize ); switch( nSizeMode )
{ case XML_factor: // passed value is width/height return nValue; case XML_edge: // passed value is right/bottom position return nValue - nPos + 1;
};
bool bPropSet = false; // the call to XShape.getSize() may recalc the chart view
awt::Size aShapeSize = rxShape->getSize(); // rotated shapes need special handling... if( aShapeSize.Height > 0 || aShapeSize.Width > 0 )
{ double fSin = fabs(sin(basegfx::deg2rad(fRotationAngle))); // add part of height to X direction, if title is rotated down if( fRotationAngle > 180.0 )
aShapePos.X += static_cast<sal_Int32>(fSin * aShapeSize.Height + 0.5); // add part of width to Y direction, if title is rotated up elseif( fRotationAngle > 0.0 )
aShapePos.Y += static_cast<sal_Int32>(fSin * aShapeSize.Width + 0.5);
} elseif( fRotationAngle == 90.0 || fRotationAngle == 270.0 )
{
PropertySet aShapeProp( rxShape );
RelativePosition aPos(
getLimitedValue< double, double >(mrModel.mfX, 0.0, 1.0),
getLimitedValue< double, double >(mrModel.mfY, 0.0, 1.0),
fRotationAngle == 90.0 ? Alignment_TOP_RIGHT : Alignment_BOTTOM_LEFT ); // set the resulting position at the shape if( aShapeProp.setProperty(PROP_RelativePosition, aPos) )
bPropSet = true;
} // set the resulting position at the shape if( !bPropSet )
rxShape->setPosition( aShapePos );
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.