42 #include <com/sun/star/drawing/Position3D.hpp>
43 #include <com/sun/star/drawing/Direction3D.hpp>
44 #include <com/sun/star/drawing/ShadeMode.hpp>
46 #include <com/sun/star/drawing/EnhancedCustomShapeParameterPair.hpp>
63 css::drawing::EnhancedCustomShapeParameterPair aOriginParaPair;
65 if ( ! ( pAny && ( *pAny >>= aOriginParaPair ) && ( aOriginParaPair.First.Value >>= rOriginX ) && ( aOriginParaPair.Second.Value >>= rOriginY ) ) )
74 css::drawing::EnhancedCustomShapeParameterPair aRotateAngleParaPair;
76 if ( ! ( pAny && ( *pAny >>= aRotateAngleParaPair ) && ( aRotateAngleParaPair.First.Value >>= rAngleX ) && ( aRotateAngleParaPair.Second.Value >>= rAngleY ) ) )
87 css::drawing::EnhancedCustomShapeParameterPair aSkewParaPair;
89 if ( ! ( pAny && ( *pAny >>= aSkewParaPair ) && ( aSkewParaPair.First.Value >>= rSkewAmount ) && ( aSkewParaPair.Second.Value >>= rSkewAngle ) ) )
97 void GetExtrusionDepth(
const SdrCustomShapeGeometryItem& rItem,
const double* pMap,
double& rBackwardDepth,
double& rForwardDepth )
99 css::drawing::EnhancedCustomShapeParameterPair aDepthParaPair;
100 double fDepth = 0, fFraction = 0;
102 if ( pAny && ( *pAny >>= aDepthParaPair ) && ( aDepthParaPair.First.Value >>= fDepth ) && ( aDepthParaPair.Second.Value >>= fFraction ) )
104 rForwardDepth = fDepth * fFraction;
105 rBackwardDepth = fDepth - rForwardDepth;
109 rBackwardDepth = 1270;
115 rBackwardDepth *= fMap;
116 rForwardDepth *= fMap;
122 double fRetValue = fDefault;
131 drawing::ShadeMode eRet( eDefault );
140 bool bRetValue = bDefault;
148 const drawing::Position3D& rDefault,
const double* pMap )
150 drawing::Position3D aRetValue( rDefault );
156 aRetValue.PositionX *= *pMap;
157 aRetValue.PositionY *= *pMap;
158 aRetValue.PositionZ *= *pMap;
163 drawing::Direction3D GetDirection3D(
const SdrCustomShapeGeometryItem& rItem,
const OUString& rPropertyName,
const drawing::Direction3D& rDefault )
165 drawing::Direction3D aRetValue( rDefault );
177 : aCenter(rSdrObjCustomShape.GetSnapRect().
Center())
178 , eProjectionMode(
drawing::ProjectionMode_PARALLEL )
185 const Any* pAny = rGeometryItem.GetPropertyValueByName(
"Extrusion",
"ProjectionMode" );
197 drawing::Position3D aViewPointDefault( 3472, -3472, 25000 );
198 drawing::Position3D aViewPoint( GetPosition3D( rGeometryItem,
"ViewPoint", aViewPointDefault, pMap ) );
210 for ( j = 0; j < rPoly3D.
count(); j++ )
213 double fDepth(-( aPoint.getZ() * fSkew ) / 100.0);
215 aPoint.getX() + (fDepth * cos( fSkewAngle )),
216 aPoint.getY() - (fDepth * sin( fSkewAngle )),
226 if ( eProjectionMode == drawing::ProjectionMode_PARALLEL )
228 aPoint2D.setX( static_cast<sal_Int32>(rPoint3D.getX()) );
229 aPoint2D.setY( static_cast<sal_Int32>(rPoint3D.getY()) );
233 double fX = rPoint3D.getX() - fOriginX;
234 double fY = rPoint3D.getY() - fOriginY;
235 double f = ( - fViewPoint.getZ() ) / ( rPoint3D.getZ() - fViewPoint.getZ() );
236 aPoint2D.setX( static_cast<sal_Int32>(( fX - fViewPoint.getX() ) * f + fViewPoint.getX() + fOriginX ) );
237 aPoint2D.setY( static_cast<sal_Int32>(( fY - fViewPoint.getY() ) * f + fViewPoint.getY() + fOriginY ) );
239 aPoint2D.Move( aCenter.X(), aCenter.Y() );
245 return eProjectionMode == css::drawing::ProjectionMode_PARALLEL;
254 double fMap(1.0), *pMap =
nullptr;
257 if ( aFraction.GetNumerator() != 1 || aFraction.GetDenominator() != 1 )
259 fMap *= double(aFraction);
271 if ( GetBool( rGeometryItem,
"Extrusion",
false ) )
273 bool bIsMirroredX(rSdrObjCustomShape.
IsMirroredX());
274 bool bIsMirroredY(rSdrObjCustomShape.
IsMirroredY());
277 if ( nObjectRotation )
279 double a = (36000 - nObjectRotation.get()) *
F_PI18000;
280 tools::Long dx = aSnapRect.Right() - aSnapRect.Left();
281 tools::Long dy = aSnapRect.Bottom()- aSnapRect.Top();
282 Point aP( aSnapRect.TopLeft() );
284 aSnapRect.SetLeft( aP.X() );
285 aSnapRect.SetTop( aP.Y() );
286 aSnapRect.SetRight( aSnapRect.Left() + dx );
287 aSnapRect.SetBottom( aSnapRect.Top() + dy );
289 Point aCenter( aSnapRect.Center() );
303 std::vector< E3dCompoundObject* > aPlaceholderObjectList;
305 double fExtrusionBackward, fExtrusionForward;
306 GetExtrusionDepth( rGeometryItem, pMap, fExtrusionBackward, fExtrusionForward );
307 double fDepth = fExtrusionBackward - fExtrusionForward;
311 drawing::ProjectionMode eProjectionMode( drawing::ProjectionMode_PARALLEL );
312 const Any* pAny = rGeometryItem.GetPropertyValueByName(
"Extrusion",
"ProjectionMode" );
314 *pAny >>= eProjectionMode;
317 E3dDefaultAttributes a3DDefaultAttr;
318 a3DDefaultAttr.SetDefaultLatheCharacterMode(
true );
319 a3DDefaultAttr.SetDefaultExtrudeCharacterMode(
true );
323 bool bSceneHasObjects (
false );
324 bool bUseTwoFillStyles(
false );
326 drawing::ShadeMode eShadeMode( GetShadeMode( rGeometryItem, drawing::ShadeMode_FLAT ) );
327 bool bUseExtrusionColor = GetBool( rGeometryItem,
"Color",
false );
332 aSet.Put( Svx3DTextureModeItem( 1 ) );
333 aSet.Put( Svx3DNormalsKindItem( 1 ) );
335 if ( eShadeMode == drawing::ShadeMode_DRAFT )
344 if ( eFillStyle == drawing::FillStyle_NONE )
346 else if ( ( eFillStyle == drawing::FillStyle_BITMAP ) || ( eFillStyle == drawing::FillStyle_GRADIENT ) || bUseExtrusionColor )
347 bUseTwoFillStyles =
true;
355 if(bUseTwoFillStyles || (bIsMirroredX && !bIsMirroredY) || (!bIsMirroredX && bIsMirroredY))
364 const bool bMultipleSubObjects(aIter.
Count() > 1);
373 drawing::FillStyle aLocalFillStyle(eFillStyle);
375 if (
auto pPathObj = dynamic_cast<const SdrPathObj*>(pNext) )
378 bool bNeedToConvertToContour(
false);
384 if(!bMultipleSubObjects)
388 if(drawing::FillStyle_NONE == eStyle)
395 if(!bNeedToConvertToContour && !aLine.
isDefault())
403 bNeedToConvertToContour =
true;
409 if(bNeedToConvertToContour)
421 if(eShadeMode == drawing::ShadeMode_DRAFT)
426 aLocalFillStyle = drawing::FillStyle_NONE;
436 aLocalFillStyle = drawing::FillStyle_SOLID;
451 aPolyPoly = pPathObj->GetPathPoly();
462 if( aPolyPoly.
count() )
471 aBoundRect2d.
Union( aBoundRect );
478 bUseTwoFillStyles ? 0 : fDepth );
483 if ( bIsPlaceholderObject )
484 aPlaceholderObjectList.push_back( p3DObj );
485 else if ( bUseTwoFillStyles )
511 if ( aSnapRect != aBoundRect && aSnapRect.
GetWidth() > 0 && aSnapRect.GetHeight() > 0)
516 double fXScale =
static_cast<double>(aBoundRect.
GetWidth()) / static_cast<double>(aSnapRect.GetWidth());
517 double fYScale =
static_cast<double>(aBoundRect.
GetHeight()) / static_cast<double>(aSnapRect.GetHeight());
519 Point aPt( static_cast<sal_Int32>( static_cast<double>( aBoundRect.
Left() - aSnapRect.Left() )* static_cast<double>(aBmpSize.Width()) / static_cast<double>(aSnapRect.GetWidth()) ),
520 static_cast<sal_Int32
>(
static_cast<double>( aBoundRect.
Top() - aSnapRect.Top() ) * static_cast<double>(aBmpSize.Height()) / static_cast<double>(aSnapRect.GetHeight()) ) );
521 Size aSize( static_cast<sal_Int32>( aBmpSize.Width() * fXScale ),
522 static_cast<sal_Int32>( aBmpSize.Height() * fYScale ) );
524 aFillBmp.
Crop( aCropRect );
529 p3DObj =
new E3dExtrudeObj(
536 if ( bUseExtrusionColor )
544 p3DObj =
new E3dExtrudeObj(
554 aFrontTransform.
translate( 0.0, 0.0, fDepth );
557 if ( ( aLocalFillStyle == drawing::FillStyle_BITMAP ) && !aFillBmp.
IsEmpty() )
562 else if ( aLocalFillStyle == drawing::FillStyle_NONE )
571 bSceneHasObjects =
true;
575 if ( bSceneHasObjects )
599 double fOriginX, fOriginY;
600 GetOrigin( rGeometryItem, fOriginX, fOriginY );
601 fOriginX = fOriginX * aSnapRect.GetWidth();
602 fOriginY = fOriginY * aSnapRect.GetHeight();
607 double fXRotate, fYRotate;
608 GetRotateAngle( rGeometryItem, fXRotate, fYRotate );
610 if ( fZRotate != 0.0 )
611 aNewTransform.rotate( 0.0, 0.0, fZRotate );
613 aNewTransform.scale( -1.0, 1, 1 );
615 aNewTransform.scale( 1, -1.0, 1 );
616 if( fYRotate != 0.0 )
617 aNewTransform.rotate( 0.0, -fYRotate, 0.0 );
618 if( fXRotate != 0.0 )
619 aNewTransform.rotate( -fXRotate, 0.0, 0.0 );
622 double fSkew, fAlpha;
623 GetSkew( rGeometryItem, fSkew, fAlpha );
626 double fInvTanBeta( fSkew / 100.0 );
629 aNewTransform.shearXY(
630 fInvTanBeta * cos(fAlpha),
631 fInvTanBeta * sin(fAlpha));
641 aNewTransform.translate( -fOriginX, fOriginY, 0.0 );
643 drawing::Position3D aViewPointDefault( 3472, -3472, 25000 );
644 drawing::Position3D aViewPoint( GetPosition3D( rGeometryItem,
"ViewPoint", aViewPointDefault, pMap ) );
645 double fViewPointX = aViewPoint.PositionX;
646 double fViewPointY = aViewPoint.PositionY;
647 double fViewPointZ = aViewPoint.PositionZ;
659 double fAmbientIntensity = GetDouble( rGeometryItem,
"Brightness", 22178.0 / 655.36 ) / 100.0;
661 drawing::Direction3D aFirstLightDirectionDefault( 50000, 0, 10000 );
662 drawing::Direction3D aFirstLightDirection( GetDirection3D( rGeometryItem,
"FirstLightDirection", aFirstLightDirectionDefault ) );
663 if ( aFirstLightDirection.DirectionZ == 0.0 )
664 aFirstLightDirection.DirectionZ = 1.0;
666 double fLightIntensity = GetDouble( rGeometryItem,
"FirstLightLevel", 43712.0 / 655.36 ) / 100.0;
668 GetBool( rGeometryItem,
"FirstLightHarsh",
false );
670 drawing::Direction3D aSecondLightDirectionDefault( -50000, 0, 10000 );
671 drawing::Direction3D aSecondLightDirection( GetDirection3D( rGeometryItem,
"SecondLightDirection", aSecondLightDirectionDefault ) );
672 if ( aSecondLightDirection.DirectionZ == 0.0 )
673 aSecondLightDirection.DirectionZ = -1;
675 double fLight2Intensity = GetDouble( rGeometryItem,
"SecondLightLevel", 43712.0 / 655.36 ) / 100.0;
677 GetBool( rGeometryItem,
"SecondLightHarsh",
false );
678 GetBool( rGeometryItem,
"LightFace",
false );
680 sal_uInt16 nAmbientColor =
static_cast<sal_uInt16
>( fAmbientIntensity * 255.0 );
681 if ( nAmbientColor > 255 )
683 Color aGlobalAmbientColor( static_cast<sal_uInt8>(nAmbientColor), static_cast<sal_uInt8>(nAmbientColor), static_cast<sal_uInt8>(nAmbientColor) );
687 basegfx::B3DVector aSpotLight1( aFirstLightDirection.DirectionX, - ( aFirstLightDirection.DirectionY ), -( aFirstLightDirection.DirectionZ ) );
690 Color aAmbientSpot1Color( nSpotLight1, nSpotLight1, nSpotLight1 );
695 basegfx::B3DVector aSpotLight2( aSecondLightDirection.DirectionX, -aSecondLightDirection.DirectionY, -aSecondLightDirection.DirectionZ );
698 Color aAmbientSpot2Color( nSpotLight2, nSpotLight2, nSpotLight2 );
705 Color aAmbientSpot3Color( nSpotLight3, nSpotLight3, nSpotLight3 );
709 double fSpecular = GetDouble( rGeometryItem,
"Specularity", 0 ) / 100;
710 bool bMetal = GetBool( rGeometryItem,
"Metal",
false );
712 Color aSpecularCol( 225,225,225 );
715 aSpecularCol =
Color( 200, 200, 200 );
718 sal_Int32 nIntensity =
static_cast<sal_Int32
>(fSpecular) * 100;
719 if ( nIntensity > 100 )
721 else if ( nIntensity < 0 )
723 nIntensity = 100 - nIntensity;
761 double fExtrusionBackward, fExtrusionForward;
762 GetExtrusionDepth( rGeometryItem, pMap, fExtrusionBackward, fExtrusionForward );
769 for ( i = 0; i < 4; i++ )
771 aBoundVolume.
append(
basegfx::B3DPoint(aPolygon[ static_cast<sal_uInt16>(i) ].
X() - aCenter.X(), aPolygon[
static_cast<sal_uInt16
>(i) ].
Y() - aCenter.Y(), fExtrusionForward));
774 for ( i = 0; i < 4; i++ )
776 aBoundVolume.
append(
basegfx::B3DPoint(aPolygon[ static_cast<sal_uInt16>(i) ].
X() - aCenter.X(), aPolygon[
static_cast<sal_uInt16
>(i) ].
Y() - aCenter.Y(), fExtrusionBackward));
779 drawing::Direction3D aRotationCenterDefault( 0, 0, 0 );
780 drawing::Direction3D aRotationCenter( GetDirection3D( rGeometryItem,
"RotationCenter", aRotationCenterDefault ) );
782 double fXRotate, fYRotate;
783 GetRotateAngle( rGeometryItem, fXRotate, fYRotate );
788 aMatrix.
translate(-aRotationCenter.DirectionX, -aRotationCenter.DirectionY, -aRotationCenter.DirectionZ);
789 if ( fZRotate != 0.0 )
790 aMatrix.
rotate( 0.0, 0.0, fZRotate );
792 aMatrix.
scale( -1.0, 1, 1 );
794 aMatrix.
scale( 1, -1.0, 1 );
795 if( fYRotate != 0.0 )
796 aMatrix.
rotate( 0.0, fYRotate, 0.0 );
797 if( fXRotate != 0.0 )
798 aMatrix.
rotate( -fXRotate, 0.0, 0.0 );
799 aMatrix.
translate(aRotationCenter.DirectionX, aRotationCenter.DirectionY, aRotationCenter.DirectionZ);
810 for ( i = 0; i < 8; i++ )
811 aTransformed[ static_cast<sal_uInt16>(i) ] = aTransformation2D.
Transform2D( aBoundVolume.
getB3DPoint( i ) );
void SetAutoAdjustProjection(bool bAdjust)
virtual SdrObject * RemoveObject(size_t nObjNum) override
SfxBoolItem makeSvx3DLightOnOff2Item(bool bVal)
SfxBoolItem makeSvx3DDoubleSidedItem(bool bVal)
void SetViewWindow(double fX, double fY, double fW, double fH)
const Fraction & GetScaleFraction() const
constexpr TypedWhichId< XFillStyleItem > XATTR_FILLSTYLE(XATTR_FILL_FIRST)
static tools::Rectangle CalculateNewSnapRect(const SdrObjCustomShape &rSdrObjCustomShape, const tools::Rectangle &rSnapRect, const tools::Rectangle &rBoundRect, const double *pMap)
constexpr TypedWhichId< XLineStyleItem > XATTR_LINESTYLE(XATTR_LINE_FIRST)
SvxColorItem makeSvx3DLightcolor2Item(const Color &rCol)
const basegfx::B3DHomMatrix & GetTransform() const
static void Free(SdrObject *&_rpObject)
virtual sdr::properties::BaseProperties & GetProperties() const
virtual const tools::Rectangle & GetSnapRect() const override
SfxUInt16Item makeSvx3DMaterialSpecularIntensityItem(sal_uInt16 nVal)
void scale(double fX, double fY, double fZ)
constexpr TypedWhichId< XLineTransparenceItem > XATTR_LINETRANSPARENCE(XATTR_LINE_FIRST+10)
SfxUInt16Item makeSvx3DPercentDiagonalItem(sal_uInt16 nVal)
MapUnit GetScaleUnit() const
virtual void NbcSetTransform(const basegfx::B3DHomMatrix &rMatrix) override
SfxBoolItem makeSvx3DLightOnOff1Item(bool bVal)
void SetCamera(const Camera3D &rNewCamera)
attribute::SdrLineAttribute createNewSdrLineAttribute(const SfxItemSet &rSet)
void SetMergedItemSet(const SfxItemSet &rSet, bool bClearAllItems=false)
void append(const B3DPoint &rPoint, sal_uInt32 nCount=1)
double getStartWidth() const
B2IRange fround(const B2DRange &rRange)
const Color & GetColorValue() const
SvxColorItem makeSvx3DMaterialSpecularItem(const Color &rCol)
constexpr auto convert(N n, sal_Int64 mul, sal_Int64 div)
virtual void NbcSetTransform(const basegfx::B3DHomMatrix &rMatrix)
const GraphicObject & GetGraphicObject() const
constexpr TypedWhichId< SvxWritingModeItem > SDRATTR_TEXTDIRECTION(SDRATTR_NOTPERSIST_FIRST+34)
B3DPoint const & getB3DPoint(sal_uInt32 nIndex) const
virtual void SetObjectItem(const SfxPoolItem &rItem)=0
#define DBG_ASSERT(sCon, aError)
constexpr TypedWhichId< SdrCustomShapeGeometryItem > SDRATTR_CUSTOMSHAPE_GEOMETRY(SDRATTR_CUSTOMSHAPE_FIRST+2)
constexpr TypedWhichId< XSecondaryFillColorItem > XATTR_SECONDARYFILLCOLOR(XATTR_FILL_FIRST+12)
constexpr TypedWhichId< XFillBitmapItem > XATTR_FILLBITMAP(XATTR_FILL_FIRST+4)
void SetFocalLength(double fLen)
SdrModel & getSdrModelFromSdrObject() const
constexpr double deg2rad(double v)
virtual void SetLogicRect(const tools::Rectangle &rRect)
const basegfx::B3DRange & GetBoundVolume() const
void SetMergedItem(const SfxPoolItem &rItem)
BitmapEx GetBitmapEx(const GraphicConversionParameters &rParameters=GraphicConversionParameters()) const
const SfxPoolItem & GetMergedItem(const sal_uInt16 nWhich) const
attribute::SdrLineStartEndAttribute createNewSdrLineStartEndAttribute(const SfxItemSet &rSet, double fWidth)
virtual void SetRectsDirty(bool bNotMyself=false, bool bRecursive=true) override
B2DRange getRange(const B2DPolygon &rCandidate)
SvxColorItem makeSvx3DLightcolor1Item(const Color &rCol)
virtual SdrLayerID GetLayer() const
void SetPosAndLookAt(const basegfx::B3DPoint &rNewPos, const basegfx::B3DPoint &rNewLookAt)
void translate(double fX, double fY, double fZ)
virtual Degree100 GetRotateAngle() const override
SvxColorItem makeSvx3DAmbientcolorItem(const Color &rCol)
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
void RotatePoint(Point &rPnt, const Point &rRef, double sn, double cs)
SdrObjectUniquePtr ConvertToPolyObj(bool bBezier, bool bLineToArea) const
static SdrObject * Create3DObject(const SdrObject *pShape2d, const SdrObjCustomShape &rSdrObjCustomShape)
B2DPolygon adaptiveSubdivideByAngle(const B2DPolygon &rCandidate, double fAngleBound)
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
const Graphic & GetGraphic() const
virtual void InsertObject(SdrObject *pObj, size_t nPos=SAL_MAX_SIZE) override
SvxB3DVectorItem makeSvx3DLightDirection2Item(const basegfx::B3DVector &rVec)
double GetObjectRotation() const
SdrObject * ConvertToContourObj(SdrObject *pRet, bool bForceLineDash=false) const
SvxB3DVectorItem makeSvx3DLightDirection1Item(const basegfx::B3DVector &rVec)
void SetProjection(ProjectionType ePrj)
const SfxItemSet & GetMergedItemSet() const
SvxB3DVectorItem makeSvx3DLightDirection3Item(const basegfx::B3DVector &rVec)
SfxBoolItem makeSvx3DLightOnOff3Item(bool bVal)
constexpr TypedWhichId< XFillBmpTileItem > XATTR_FILLBMP_TILE(XATTR_FILL_FIRST+7)
bool isStartActive() const
std::unique_ptr< SdrObject, SdrObjectFreeOp > SdrObjectUniquePtr
const basegfx::B2DPolyPolygon & GetPathPoly() const
css::uno::Any * GetPropertyValueByName(const OUString &rPropName)
SfxBoolItem makeSvx3DTwoSidedLightingItem(bool bVal)
SvxColorItem makeSvx3DLightcolor3Item(const Color &rCol)
void rotate(double fAngleX, double fAngleY, double fAngleZ)
void(* f)(TrueTypeTable *)
double getEndWidth() const
bool areControlPointsUsed() const
const Size & GetSizePixel() const
void transform(const B3DHomMatrix &rMatrix)
constexpr TypedWhichId< XLineColorItem > XATTR_LINECOLOR(XATTR_LINE_FIRST+3)
bool Crop(const tools::Rectangle &rRectPixel)
const Camera3D & GetCamera() const
virtual void NbcSetSnapRect(const tools::Rectangle &rRect) override
double getFullDotDashLen() const
virtual const tools::Rectangle & GetLogicRect() const override
virtual void NbcSetLayer(SdrLayerID nLayer)