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;
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" };
146 const bool bHasText(rSdrObjCustomShape.
HasText());
148 if ( pRenderedShape || bHasText )
153 if ( pShadowGeometry )
155 if ( pRenderedShape )
157 if (
dynamic_cast<const SdrObjGroup*
>( pRenderedShape.get() ) ==
nullptr )
159 auto pTmp = std::move(pRenderedShape);
165 pShadowGeometry->CloneSdrObject(pShadowGeometry->getSdrModelFromSdrObject()).
get(),
170 pRenderedShape = pShadowGeometry->CloneSdrObject(pShadowGeometry->getSdrModelFromSdrObject());
187 pTextObj->NbcSetOutlinerParaObject( *pParaObj );
200 if(pSdrObjCustomShape)
203 aTextBounds = aCustomShape2d.GetTextRect();
206 pTextObj->SetSnapRect( aTextBounds );
210 if ( rSourceGeo.m_nRotationAngle )
214 rSourceGeo.m_nRotationAngle,
215 rSourceGeo.mfSinRotationAngle,
216 rSourceGeo.mfCosRotationAngle);
220 pTextObj->SetMergedItemSet(aTargetItemSet);
222 if ( pRenderedShape )
224 if (
dynamic_cast<const SdrObjGroup*
>( pRenderedShape.get() ) ==
nullptr )
226 auto pTmp = std::move(pRenderedShape);
233 pRenderedShape = std::move(pTextObj);
237 if ( pRenderedShape )
239 if (
dynamic_cast<const SdrObjGroup*
>( pRenderedShape.get() ) ==
nullptr )
241 auto pTmp = std::move(pRenderedShape);
248 return pRenderedShape;
251Reference< drawing::XShape > SAL_CALL EnhancedCustomShapeEngine::render()
255 if(!pSdrObjCustomShape)
257 return Reference< drawing::XShape >();
262 bool bTextPathOn =
false;
263 const uno::Any* pAny = rGeometryItem.GetPropertyValueByName(
"TextPath",
"TextPath" );
265 *pAny >>= bTextPathOn;
268 Degree100 nRotateAngle = aCustomShape2d.GetRotateAngle();
270 bool bFlipV = aCustomShape2d.IsFlipVert();
271 bool bFlipH = aCustomShape2d.IsFlipHorz();
272 bool bLineGeometryNeededOnly = bTextPathOn;
281 xRenderedShape.get(),
282 *pSdrObjCustomShape));
284 if (xRenderedFontWork)
286 xRenderedShape = std::move(xRenderedFontWork);
290 if (xRenderedShape3d)
292 bFlipV = bFlipH =
false;
293 nRotateAngle = 0_deg100;
294 xRenderedShape = std::move(xRenderedShape3d);
300 if ( rGeoStat.m_nShearAngle )
302 Degree100 nShearAngle = rGeoStat.m_nShearAngle;
303 double nTan = rGeoStat.mfTanShearAngle;
304 if (bFlipV != bFlipH)
306 nShearAngle = -nShearAngle;
310 xRenderedShape->Shear(pSdrObjCustomShape->
GetSnapRect().
Center(), nShearAngle, nTan,
false);
313 xRenderedShape->NbcRotate(pSdrObjCustomShape->
GetSnapRect().
Center(), nRotateAngle);
316 Point aLeft( aRect.Left(), ( aRect.Top() + aRect.Bottom() ) >> 1 );
317 Point aRight( aLeft.X() + 1000, aLeft.Y() );
318 xRenderedShape->NbcMirror( aLeft, aRight );
322 Point aTop( ( aRect.Left() + aRect.Right() ) >> 1, aRect.Top() );
323 Point aBottom( aTop.X(), aTop.Y() + 1000 );
324 xRenderedShape->NbcMirror( aTop, aBottom );
327 xRenderedShape->NbcSetStyleSheet(pSdrObjCustomShape->
GetStyleSheet(),
true);
328 xRenderedShape->RecalcSnapRect();
331 if ( mbForceGroupWithText )
333 xRenderedShape = ImplForceGroupWithText(
335 xRenderedShape.get());
338 Reference< drawing::XShape > xShape;
342 aCustomShape2d.ApplyGluePoints(xRenderedShape.get());
344 xRenderedShape->GetObjInventor(), xRenderedShape.get() );
350awt::Rectangle SAL_CALL EnhancedCustomShapeEngine::getTextBounds()
352 awt::Rectangle aTextRect;
355 uno::Reference< document::XActionLockable > xLockable( mxShape, uno::UNO_QUERY );
357 if(xLockable.is() && !xLockable->isActionLocked())
361 aTextRect.X = aRect.Left();
362 aTextRect.Y = aRect.Top();
363 aTextRect.Width = aRect.GetWidth();
364 aTextRect.Height = aRect.GetHeight();
371drawing::PolyPolygonBezierCoords SAL_CALL EnhancedCustomShapeEngine::getLineGeometry()
373 drawing::PolyPolygonBezierCoords aPolyPolygonBezierCoords;
376 if(pSdrObjCustomShape)
384 bool bFlipV = aCustomShape2d.IsFlipVert();
385 bool bFlipH = aCustomShape2d.IsFlipHorz();
388 if ( rGeoStat.m_nShearAngle )
390 Degree100 nShearAngle = rGeoStat.m_nShearAngle;
391 double nTan = rGeoStat.mfTanShearAngle;
392 if (bFlipV != bFlipH)
394 nShearAngle = -nShearAngle;
397 pObj->Shear( aRect.Center(), nShearAngle, nTan,
false);
399 Degree100 nRotateAngle = aCustomShape2d.GetRotateAngle();
401 pObj->NbcRotate( aRect.Center(), nRotateAngle );
404 Point aTop( ( aRect.Left() + aRect.Right() ) >> 1, aRect.Top() );
405 Point aBottom( aTop.X(), aTop.Y() + 1000 );
406 pObj->NbcMirror( aTop, aBottom );
410 Point aLeft( aRect.Left(), ( aRect.Top() + aRect.Bottom() ) >> 1 );
411 Point aRight( aLeft.X() + 1000, aLeft.Y() );
412 pObj->NbcMirror( aLeft, aRight );
418 while ( aIter.IsMore() )
423 if (
auto pPathObj =
dynamic_cast<const SdrPathObj*
>(pNext) )
425 aPP = pPathObj->GetPathPoly();
440 aPolyPolygonBezierCoords );
444 return aPolyPolygonBezierCoords;
447Sequence< Reference< drawing::XCustomShapeHandle > > SAL_CALL EnhancedCustomShapeEngine::getInteraction()
449 sal_uInt32
i, nHdlCount = 0;
452 if(pSdrObjCustomShape)
455 nHdlCount = aCustomShape2d.GetHdlCount();
458 Sequence< Reference< drawing::XCustomShapeHandle > >
aSeq( nHdlCount );
459 auto aSeqRange = asNonConstRange(aSeq);
461 for ( i = 0;
i < nHdlCount;
i++ )
468extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
470 css::uno::XComponentContext *,
471 css::uno::Sequence<css::uno::Any>
const &)
473 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 rtl::Reference< SdrObject > Create3DObject(const SdrObject *pShape2d, const SdrObjCustomShape &rSdrObjCustomShape)
static rtl::Reference< 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 rtl::Reference< 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 void SAL_CALL acquire() noexcept override final
virtual void SAL_CALL release() noexcept override final
virtual SdrInventor GetObjInventor() const
virtual SdrObjList * GetSubList() const
rtl::Reference< SdrObject > ConvertToPolyObj(bool bBezier, bool bLineToArea) const
SdrModel & getSdrModelFromSdrObject() const
SfxStyleSheet * GetStyleSheet() const
const SfxItemSet & GetMergedItemSet() 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 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)
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
uno::Reference< drawing::XShape > const mxShape
constexpr TypedWhichId< SdrCustomShapeGeometryItem > SDRATTR_CUSTOMSHAPE_GEOMETRY(SDRATTR_CUSTOMSHAPE_FIRST+2)
@ Text
closed free-hand line