20#include <com/sun/star/uno/Reference.h>
21#include <com/sun/star/uno/XComponentContext.hpp>
22#include <com/sun/star/awt/Rectangle.hpp>
23#include <com/sun/star/beans/PropertyValue.hpp>
24#include <com/sun/star/drawing/PolyPolygonBezierCoords.hpp>
25#include <com/sun/star/lang/XInitialization.hpp>
26#include <com/sun/star/lang/XServiceInfo.hpp>
27#include <com/sun/star/drawing/XCustomShapeEngine.hpp>
45#include <com/sun/star/document/XActionLockable.hpp>
50using namespace css::uno;
57class EnhancedCustomShapeEngine :
public cppu::WeakImplHelper
59 css::lang::XInitialization,
60 css::lang::XServiceInfo,
61 css::drawing::XCustomShapeEngine
64 css::uno::Reference< css::drawing::XShape >
mxShape;
65 bool mbForceGroupWithText;
67 std::unique_ptr<SdrObject, SdrObjectFreeOp> ImplForceGroupWithText(
69 std::unique_ptr<SdrObject, SdrObjectFreeOp> pRenderedShape);
72 EnhancedCustomShapeEngine();
75 virtual void SAL_CALL acquire() noexcept override;
76 virtual
void SAL_CALL release() noexcept override;
79 virtual
void SAL_CALL initialize( const css::
uno::Sequence< css::
uno::Any >& aArguments ) override;
82 virtual OUString SAL_CALL getImplementationName() override;
83 virtual
sal_Bool SAL_CALL supportsService( const OUString& rServiceName ) override;
84 virtual css::
uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
87 virtual css::
uno::Reference< css::
drawing::XShape > SAL_CALL render() override;
88 virtual css::awt::Rectangle SAL_CALL getTextBounds() override;
89 virtual css::
drawing::PolyPolygonBezierCoords SAL_CALL getLineGeometry() override;
90 virtual css::
uno::Sequence< css::
uno::Reference< css::
drawing::XCustomShapeHandle > > SAL_CALL getInteraction() override;
93EnhancedCustomShapeEngine::EnhancedCustomShapeEngine() :
94 mbForceGroupWithText ( false )
99void SAL_CALL EnhancedCustomShapeEngine::acquire() noexcept
101 OWeakObject::acquire();
103void SAL_CALL EnhancedCustomShapeEngine::release() noexcept
105 OWeakObject::release();
109void SAL_CALL EnhancedCustomShapeEngine::initialize(
const Sequence< Any >& aArguments )
111 Sequence< beans::PropertyValue > aParameter;
112 for (
const auto& rArgument : aArguments )
114 if ( rArgument >>= aParameter )
117 for (
const beans::PropertyValue& rProp : std::as_const(aParameter) )
119 if ( rProp.Name ==
"CustomShape" )
121 else if ( rProp.Name ==
"ForceGroupWithText" )
122 rProp.Value >>= mbForceGroupWithText;
127OUString SAL_CALL EnhancedCustomShapeEngine::getImplementationName()
129 return "com.sun.star.drawing.EnhancedCustomShapeEngine";
131sal_Bool SAL_CALL EnhancedCustomShapeEngine::supportsService(
const OUString& rServiceName )
135Sequence< OUString > SAL_CALL EnhancedCustomShapeEngine::getSupportedServiceNames()
137 return {
"com.sun.star.drawing.CustomShapeEngine" };
141std::unique_ptr<SdrObject, SdrObjectFreeOp> EnhancedCustomShapeEngine::ImplForceGroupWithText(
143 std::unique_ptr<SdrObject, SdrObjectFreeOp> pRenderedShape)
145 const bool bHasText(rSdrObjCustomShape.
HasText());
147 if ( pRenderedShape || bHasText )
152 if ( pShadowGeometry )
154 if ( pRenderedShape )
156 if (
dynamic_cast<const SdrObjGroup*
>( pRenderedShape.get() ) ==
nullptr )
158 auto pTmp = std::move(pRenderedShape);
164 pShadowGeometry->CloneSdrObject(pShadowGeometry->getSdrModelFromSdrObject()),
169 pRenderedShape.reset( pShadowGeometry->CloneSdrObject(pShadowGeometry->getSdrModelFromSdrObject()) );
186 pTextObj->NbcSetOutlinerParaObject( *pParaObj );
199 if(pSdrObjCustomShape)
202 aTextBounds = aCustomShape2d.GetTextRect();
205 pTextObj->SetSnapRect( aTextBounds );
209 if ( rSourceGeo.nRotationAngle )
213 rSourceGeo.nRotationAngle,
214 rSourceGeo.mfSinRotationAngle,
215 rSourceGeo.mfCosRotationAngle);
219 pTextObj->SetMergedItemSet(aTargetItemSet);
221 if ( pRenderedShape )
223 if (
dynamic_cast<const SdrObjGroup*
>( pRenderedShape.get() ) ==
nullptr )
225 auto pTmp = std::move(pRenderedShape);
232 pRenderedShape = std::move(pTextObj);
236 if ( pRenderedShape )
238 if (
dynamic_cast<const SdrObjGroup*
>( pRenderedShape.get() ) ==
nullptr )
240 auto pTmp = std::move(pRenderedShape);
247 return pRenderedShape;
250void SetTemporary( uno::Reference< drawing::XShape >
const & xShape )
254 SvxShape* pShape = comphelper::getFromUnoTunnel<SvxShape>( xShape );
260Reference< drawing::XShape > SAL_CALL EnhancedCustomShapeEngine::render()
264 if(!pSdrObjCustomShape)
266 return Reference< drawing::XShape >();
271 bool bTextPathOn =
false;
272 const uno::Any* pAny = rGeometryItem.GetPropertyValueByName(
"TextPath",
"TextPath" );
274 *pAny >>= bTextPathOn;
277 Degree100 nRotateAngle = aCustomShape2d.GetRotateAngle();
279 bool bFlipV = aCustomShape2d.IsFlipVert();
280 bool bFlipH = aCustomShape2d.IsFlipHorz();
281 bool bLineGeometryNeededOnly = bTextPathOn;
283 std::unique_ptr<SdrObject, SdrObjectFreeOp> xRenderedShape(aCustomShape2d.CreateObject(bLineGeometryNeededOnly));
288 std::unique_ptr<SdrObject, SdrObjectFreeOp> xRenderedFontWork(
290 xRenderedShape.get(),
291 *pSdrObjCustomShape));
293 if (xRenderedFontWork)
295 xRenderedShape = std::move(xRenderedFontWork);
299 if (xRenderedShape3d)
301 bFlipV = bFlipH =
false;
302 nRotateAngle = 0_deg100;
303 xRenderedShape = std::move(xRenderedShape3d);
309 if ( rGeoStat.nShearAngle )
311 Degree100 nShearAngle = rGeoStat.nShearAngle;
312 double nTan = rGeoStat.mfTanShearAngle;
313 if (bFlipV != bFlipH)
315 nShearAngle = -nShearAngle;
319 xRenderedShape->Shear(pSdrObjCustomShape->
GetSnapRect().
Center(), nShearAngle, nTan,
false);
322 xRenderedShape->NbcRotate(pSdrObjCustomShape->
GetSnapRect().
Center(), nRotateAngle);
325 Point aLeft( aRect.Left(), ( aRect.Top() + aRect.Bottom() ) >> 1 );
326 Point aRight( aLeft.X() + 1000, aLeft.Y() );
327 xRenderedShape->NbcMirror( aLeft, aRight );
331 Point aTop( ( aRect.Left() + aRect.Right() ) >> 1, aRect.Top() );
332 Point aBottom( aTop.X(), aTop.Y() + 1000 );
333 xRenderedShape->NbcMirror( aTop, aBottom );
336 xRenderedShape->NbcSetStyleSheet(pSdrObjCustomShape->
GetStyleSheet(),
true);
337 xRenderedShape->RecalcSnapRect();
340 if ( mbForceGroupWithText )
342 xRenderedShape = ImplForceGroupWithText(
344 std::move(xRenderedShape));
347 Reference< drawing::XShape > xShape;
351 aCustomShape2d.ApplyGluePoints(xRenderedShape.get());
352 SdrObject* pRenderedShape = xRenderedShape.release();
357 SetTemporary( xShape );
362awt::Rectangle SAL_CALL EnhancedCustomShapeEngine::getTextBounds()
364 awt::Rectangle aTextRect;
367 uno::Reference< document::XActionLockable > xLockable( mxShape, uno::UNO_QUERY );
369 if(xLockable.is() && !xLockable->isActionLocked())
373 aTextRect.X = aRect.Left();
374 aTextRect.Y = aRect.Top();
375 aTextRect.Width = aRect.GetWidth();
376 aTextRect.Height = aRect.GetHeight();
383drawing::PolyPolygonBezierCoords SAL_CALL EnhancedCustomShapeEngine::getLineGeometry()
385 drawing::PolyPolygonBezierCoords aPolyPolygonBezierCoords;
388 if(pSdrObjCustomShape)
396 bool bFlipV = aCustomShape2d.IsFlipVert();
397 bool bFlipH = aCustomShape2d.IsFlipHorz();
400 if ( rGeoStat.nShearAngle )
402 Degree100 nShearAngle = rGeoStat.nShearAngle;
403 double nTan = rGeoStat.mfTanShearAngle;
404 if (bFlipV != bFlipH)
406 nShearAngle = -nShearAngle;
409 pObj->Shear( aRect.Center(), nShearAngle, nTan,
false);
411 Degree100 nRotateAngle = aCustomShape2d.GetRotateAngle();
413 pObj->NbcRotate( aRect.Center(), nRotateAngle );
416 Point aTop( ( aRect.Left() + aRect.Right() ) >> 1, aRect.Top() );
417 Point aBottom( aTop.X(), aTop.Y() + 1000 );
418 pObj->NbcMirror( aTop, aBottom );
422 Point aLeft( aRect.Left(), ( aRect.Top() + aRect.Bottom() ) >> 1 );
423 Point aRight( aLeft.X() + 1000, aLeft.Y() );
424 pObj->NbcMirror( aLeft, aRight );
430 while ( aIter.IsMore() )
435 if (
auto pPathObj =
dynamic_cast<const SdrPathObj*
>(pNext) )
437 aPP = pPathObj->GetPathPoly();
452 aPolyPolygonBezierCoords );
456 return aPolyPolygonBezierCoords;
459Sequence< Reference< drawing::XCustomShapeHandle > > SAL_CALL EnhancedCustomShapeEngine::getInteraction()
461 sal_uInt32
i, nHdlCount = 0;
464 if(pSdrObjCustomShape)
467 nHdlCount = aCustomShape2d.GetHdlCount();
470 Sequence< Reference< drawing::XCustomShapeHandle > >
aSeq( nHdlCount );
471 auto aSeqRange = asNonConstRange(aSeq);
473 for ( i = 0;
i < nHdlCount;
i++ )
480extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
482 css::uno::XComponentContext *,
483 css::uno::Sequence<css::uno::Any>
const &)
485 return cppu::acquire(
new EnhancedCustomShapeEngine);
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_drawing_EnhancedCustomShapeEngine_get_implementation(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)
static SdrObject * Create3DObject(const SdrObject *pShape2d, const SdrObjCustomShape &rSdrObjCustomShape)
static SdrObject * CreateFontWork(const SdrObject *pShape2d, const SdrObjCustomShape &rSdrObjCustomShape)
The transformation of a rectangle into a polygon, by using angle parameters from GeoStat.
virtual const tools::Rectangle & GetSnapRect() const override
const SdrObject * GetSdrObjectShadowFromCustomShape() const
static SdrObject * MakeNewObject(SdrModel &rSdrModel, SdrInventor nInventor, SdrObjKind nObjIdentifier, const tools::Rectangle *pSnapRect=nullptr)
virtual void NbcInsertObject(SdrObject *pObj, size_t nPos=SAL_MAX_SIZE)
static SdrObject * getSdrObjectFromXShape(const css::uno::Reference< css::uno::XInterface > &xInt)
const SfxPoolItem & GetMergedItem(const sal_uInt16 nWhich) const
virtual SdrInventor GetObjInventor() const
virtual SdrObjList * GetSubList() const
SdrModel & getSdrModelFromSdrObject() const
SfxStyleSheet * GetStyleSheet() const
virtual SdrObjKind GetObjIdentifier() const
const SfxItemSet & GetMergedItemSet() const
SdrObjectUniquePtr ConvertToPolyObj(bool bBezier, bool bLineToArea) const
const basegfx::B2DPolyPolygon & GetPathPoly() const
virtual OutlinerParaObject * GetOutlinerParaObject() const override
virtual bool HasText() const override
const GeoStat & GetGeoStat() const
static rtl::Reference< SvxShape > CreateShapeByTypeAndInventor(SdrObjKind nType, SdrInventor nInventor, SdrObject *pObj, SvxDrawPage *pPage=nullptr, OUString const &referer=OUString())
void TakeSdrObjectOwnership()
takes the ownership of the SdrObject.
void append(const B2DPolygon &rPolygon, sal_uInt32 nCount=1)
Sequence< sal_Int8 > aSeq
void B2DPolyPolygonToUnoPolyPolygonBezierCoords(const B2DPolyPolygon &rPolyPolygon, css::drawing::PolyPolygonBezierCoords &rPolyPolygonBezierCoordsRetval)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
uno::Reference< drawing::XShape > const mxShape
constexpr TypedWhichId< SdrCustomShapeGeometryItem > SDRATTR_CUSTOMSHAPE_GEOMETRY(SDRATTR_CUSTOMSHAPE_FIRST+2)
std::unique_ptr< SdrObject, SdrObjectFreeOp > SdrObjectUniquePtr
@ Text
periodic cubic Spline (ni)