22#include <osl/diagnose.h>
25#include <com/sun/star/awt/Rectangle.hpp>
32#include <oox/token/namespaces.hxx>
33#include <oox/token/tokens.hxx>
50 OSL_ENSURE( !
mbRelSize,
"ShapeAnchor::importExt - unexpected 'cdr:ext' element" );
58 switch( nParentContext )
60 case CDR_TOKEN(
from ):
64 OSL_ENSURE(
mbRelSize,
"ShapeAnchor::setPos - unexpected 'cdr:to' element" );
68 OSL_FAIL(
"ShapeAnchor::setPos - unexpected parent element" );
70 if( pAnchorPos )
switch( nElement )
74 default: OSL_FAIL(
"ShapeAnchor::setPos - unexpected element" );
82 OSL_ENSURE(
maFrom.
isValid(),
"ShapeAnchor::calcAnchorRectEmu - invalid from position" );
87 aAnchorRect.
X =
static_cast< sal_Int64
>(
maFrom.
mfX * rChartRect.
Width + 0.5 );
88 aAnchorRect.
Y =
static_cast< sal_Int64
>(
maFrom.
mfY * rChartRect.
Height + 0.5 );
93 aAnchorRect.
Width =
static_cast< sal_Int64
>(
maTo.
mfX * rChartRect.
Width + 0.5 ) - aAnchorRect.
X;
94 if( aAnchorRect.
Width < 0 )
96 aAnchorRect.
X += aAnchorRect.
Width;
97 aAnchorRect.
Width *= -1;
99 aAnchorRect.
Height =
static_cast< sal_Int64
>(
maTo.
mfY * rChartRect.
Height + 0.5 ) - aAnchorRect.
Y;
100 if( aAnchorRect.
Height < 0 )
102 aAnchorRect.
Y += aAnchorRect.
Height;
117 const awt::Size& rChartSize,
const awt::Point& rShapesOffset,
bool bOleSupport ) :
120 mbOleSupport( bOleSupport )
134 switch( getCurrentElement() )
137 if( nElement == C_TOKEN( userShapes ) )
return this;
140 case C_TOKEN( userShapes ):
143 case CDR_TOKEN( absSizeAnchor ):
144 mxAnchor = std::make_shared<ShapeAnchor>(
false );
146 case CDR_TOKEN( relSizeAnchor ):
147 mxAnchor = std::make_shared<ShapeAnchor>(
true );
152 case CDR_TOKEN( absSizeAnchor ):
153 case CDR_TOKEN( relSizeAnchor ):
156 case CDR_TOKEN( sp ):
157 mxShape = std::make_shared<Shape>(
"com.sun.star.drawing.CustomShape" );
159 case CDR_TOKEN( cxnSp ):
160 mxShape = std::make_shared<Shape>(
"com.sun.star.drawing.ConnectorShape" );
162 mxShape->getConnectorShapeProperties());
163 case CDR_TOKEN( pic ):
164 mxShape = std::make_shared<Shape>(
"com.sun.star.drawing.GraphicObjectShape" );
166 case CDR_TOKEN( graphicFrame ):
169 mxShape = std::make_shared<Shape>(
"com.sun.star.drawing.GraphicObjectShape" );
171 case CDR_TOKEN( grpSp ):
172 mxShape = std::make_shared<Shape>(
"com.sun.star.drawing.GroupShape" );
175 case CDR_TOKEN(
from ):
176 case CDR_TOKEN(
to ):
179 case CDR_TOKEN( ext ):
185 case CDR_TOKEN(
from ):
186 case CDR_TOKEN(
to ):
200 if( isCurrentElement( CDR_TOKEN(
x ), CDR_TOKEN(
y ) ) &&
mxAnchor )
201 mxAnchor->setPos( getCurrentElement(), getParentElement(), rChars );
206 if( !isCurrentElement( CDR_TOKEN( absSizeAnchor ), CDR_TOKEN( relSizeAnchor ) ) )
212 if( (aShapeRectEmu.
X >= 0) && (aShapeRectEmu.
Y >= 0) && (aShapeRectEmu.
Width >= 0) && (aShapeRectEmu.
Height >= 0) )
214 const sal_Int32 aRotation =
mxShape->getRotation();
217 sal_Int64 nHalfWidth = aShapeRectEmu.
Width / 2;
218 sal_Int64 nHalfHeight = aShapeRectEmu.
Height / 2;
219 aShapeRectEmu.
X = aShapeRectEmu.
X + nHalfWidth - nHalfHeight;
220 aShapeRectEmu.
Y = aShapeRectEmu.
Y + nHalfHeight - nHalfWidth;
221 std::swap(aShapeRectEmu.
Width, aShapeRectEmu.
Height);
224 awt::Rectangle aShapeRectEmu32(
225 getLimitedValue< sal_Int32, sal_Int64 >( aShapeRectEmu.
X, 0,
SAL_MAX_INT32 ),
226 getLimitedValue< sal_Int32, sal_Int64 >( aShapeRectEmu.
Y, 0,
SAL_MAX_INT32 ),
231 mxShape->setPosition(awt::Point(aShapeRectEmu32.X, aShapeRectEmu32.Y));
232 mxShape->setSize(awt::Size(aShapeRectEmu32.Width, aShapeRectEmu32.Height));
Provides access to attribute values of an element.
std::optional< sal_Int64 > getHyper(sal_Int32 nAttrToken) const
Returns the 64-bit signed integer value of the specified attribute (decimal).
std::shared_ptr< ShapeAnchor > mxAnchor
Current top-level shape.
::oox::drawingml::ShapePtr mxShape
Drawing page of this sheet.
css::uno::Reference< css::drawing::XShapes > mxDrawPage
virtual void onCharacters(const OUString &rChars) override
virtual ~ChartDrawingFragment() override
virtual ::oox::core::ContextHandlerRef onCreateContext(sal_Int32 nElement, const AttributeList &rAttribs) override
virtual void onEndElement() override
bool mbOleSupport
Position and size of the chart object for embedded shapes (in EMUs).
ChartDrawingFragment(::oox::core::XmlFilterBase &rFilter, const OUString &rFragmentPath, const css::uno::Reference< css::drawing::XShapes > &rxDrawPage, const css::awt::Size &rChartSize, const css::awt::Point &rShapesOffset, bool bOleSupport)
EmuRectangle maChartRectEmu
Current anchor of top-level shape.
EmuRectangle calcAnchorRectEmu(const EmuRectangle &rChartRect) const
Calculates the resulting shape anchor in EMUs.
ShapeAnchor(bool bRelSize)
void importExt(const AttributeList &rAttribs)
Imports the absolute anchor size from the cdr:ext element.
AnchorSizeModel maSize
Bottom-right position relative to chart object.
bool mbRelSize
Shape size, if anchor has absolute size.
AnchorPosModel maTo
Top-left position relative to chart object.
void setPos(sal_Int32 nElement, sal_Int32 nParentContext, std::u16string_view rValue)
Sets the relative anchor position from the cdr:from or cdr:to element.
double toDouble(std::u16string_view str)
const sal_Int32 XML_ROOT_CONTEXT
std::shared_ptr< Shape > ShapePtr
const sal_Int32 PER_DEGREE
sal_Int64 convertHmmToEmu(sal_Int32 nValue)
Converts the passed 32-bit integer value from 1/100 mm to EMUs.
uno::Reference< drawing::XDrawPage > mxDrawPage
A structure for a rectangle with 64-bit integer components.
void setSize(const EmuSize &rSize)
Relative shape position in a chart object.
double mfY
X coordinate relative to chart object (0.0 to 1.0).