1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: sdrattributecreator.cxx,v $
11 * $Revision: 1.2.18.1 $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 #include "precompiled_svx.hxx"
33 #include <svx/sdr/primitive2d/sdrattributecreator.hxx>
34 #include <svtools/itemset.hxx>
35 #include <svx/xdef.hxx>
36 #include <basegfx/polygon/b2dpolygon.hxx>
37 #include <svx/xlineit0.hxx>
38 #include <svx/xfillit0.hxx>
39 #include <svx/xlntrit.hxx>
40 #include <svx/xlnwtit.hxx>
41 #include <xlinjoit.hxx>
42 #include <svx/xlnclit.hxx>
43 #include <svx/xlnstwit.hxx>
44 #include <svx/xlnedwit.hxx>
45 #include <svx/xlnstit.hxx>
46 #include <svx/xlnstcit.hxx>
47 #include <svx/xlnedit.hxx>
48 #include <svx/xlnedcit.hxx>
49 #include <svx/xdash.hxx>
50 #include <svx/xlndsit.hxx>
51 #include <svx/xfltrit.hxx>
52 #include <svx/xflftrit.hxx>
53 #include <svx/xflclit.hxx>
54 #include <svx/xgrscit.hxx>
55 #include <svx/xflhtit.hxx>
56 #include <svx/xflbckit.hxx>
57 #include <svx/sdshitm.hxx>
58 #include <svx/sdsxyitm.hxx>
59 #include <svx/sdshcitm.hxx>
60 #include <svx/sdshtitm.hxx>
61 #include <drawinglayer/attribute/fillattribute.hxx>
62 #include <drawinglayer/attribute/sdrfillbitmapattribute.hxx>
63 #include <basegfx/polygon/b2dlinegeometry.hxx>
64 #include <drawinglayer/attribute/sdrattribute.hxx>
65 #include <svx/svdotext.hxx>
66 #include <drawinglayer/attribute/fillbitmapattribute.hxx>
67 #include <svx/sdr/attribute/sdrtextattribute.hxx>
68 #include <svx/sdr/attribute/sdrallattribute.hxx>
69 #include <svx/xbtmpit.hxx>
70 #include <svtools/itempool.hxx>
71 #include <vcl/svapp.hxx>
72 #include <basegfx/range/b2drange.hxx>
73 #include <svx/svx3ditems.hxx>
74 #include <com/sun/star/drawing/ProjectionMode.hpp>
75 #include <com/sun/star/drawing/ShadeMode.hpp>
76 #include <drawinglayer/attribute/sdrattribute3d.hxx>
77 #include <drawinglayer/attribute/sdrallattribute3d.hxx>
78 #include <svx/rectenum.hxx>
79 #include <svx/sdtfchim.hxx>
81 //////////////////////////////////////////////////////////////////////////////
83 namespace drawinglayer
87 attribute::GradientStyle
XGradientStyleToGradientStyle(XGradientStyle eStyle
)
93 return attribute::GRADIENTSTYLE_LINEAR
;
97 return attribute::GRADIENTSTYLE_AXIAL
;
101 return attribute::GRADIENTSTYLE_RADIAL
;
103 case XGRAD_ELLIPTICAL
:
105 return attribute::GRADIENTSTYLE_ELLIPTICAL
;
109 return attribute::GRADIENTSTYLE_SQUARE
;
113 return attribute::GRADIENTSTYLE_RECT
; // XGRAD_RECT
118 attribute::HatchStyle
XHatchStyleToHatchStyle(XHatchStyle eStyle
)
124 return attribute::HATCHSTYLE_SINGLE
;
128 return attribute::HATCHSTYLE_DOUBLE
;
132 return attribute::HATCHSTYLE_TRIPLE
; // XHATCH_TRIPLE
137 basegfx::B2DLineJoin
XLineJointtoB2DLineJoin(XLineJoint eLineJoint
)
141 case XLINEJOINT_MIDDLE
:
143 return basegfx::B2DLINEJOIN_MIDDLE
;
145 case XLINEJOINT_BEVEL
:
147 return basegfx::B2DLINEJOIN_BEVEL
;
149 case XLINEJOINT_MITER
:
151 return basegfx::B2DLINEJOIN_MITER
;
153 case XLINEJOINT_ROUND
:
155 return basegfx::B2DLINEJOIN_ROUND
;
159 return basegfx::B2DLINEJOIN_NONE
; // XLINEJOINT_NONE
164 basegfx::B2DVector
RectPointToB2DVector(RECT_POINT eRectPoint
)
166 basegfx::B2DVector
aRetval(0.0, 0.0);
168 // position changes X
171 case RP_LT
: case RP_LM
: case RP_LB
:
177 case RP_RT
: case RP_RM
: case RP_RB
:
189 // position changes Y
192 case RP_LT
: case RP_MT
: case RP_RT
:
198 case RP_LB
: case RP_MB
: case RP_RB
:
212 } // end of anonymous namespace
213 } // end of namespace drawinglayer
215 //////////////////////////////////////////////////////////////////////////////
217 namespace drawinglayer
219 namespace primitive2d
221 attribute::SdrLineAttribute
* createNewSdrLineAttribute(const SfxItemSet
& rSet
)
223 attribute::SdrLineAttribute
* pRetval(0L);
224 const XLineStyle
eStyle(((XLineStyleItem
&)(rSet
.Get(XATTR_LINESTYLE
))).GetValue());
226 if(XLINE_NONE
!= eStyle
)
228 sal_uInt16
nTransparence(((const XLineTransparenceItem
&)(rSet
.Get(XATTR_LINETRANSPARENCE
))).GetValue());
230 if(nTransparence
> 100)
235 if(100 != nTransparence
)
237 const sal_uInt32
nWidth(((const XLineWidthItem
&)(rSet
.Get(XATTR_LINEWIDTH
))).GetValue());
238 const Color
aColor(((const XLineColorItem
&)(rSet
.Get(XATTR_LINECOLOR
))).GetColorValue());
239 const XLineJoint
eJoint(((const XLineJointItem
&)(rSet
.Get(XATTR_LINEJOINT
))).GetValue());
240 ::std::vector
< double > aDotDashArray
;
241 double fFullDotDashLen(0.0);
243 if(XLINE_DASH
== eStyle
)
245 const XDash
& rDash
= ((const XLineDashItem
&)(rSet
.Get(XATTR_LINEDASH
))).GetDashValue();
247 if(rDash
.GetDots() || rDash
.GetDashes())
249 fFullDotDashLen
= rDash
.CreateDotDashArray(aDotDashArray
, (double)nWidth
);
253 pRetval
= new attribute::SdrLineAttribute(
254 XLineJointtoB2DLineJoin(eJoint
),
256 (double)nTransparence
* 0.01,
266 attribute::SdrLineStartEndAttribute
* createNewSdrLineStartEndAttribute(const SfxItemSet
& rSet
, double fWidth
)
268 attribute::SdrLineStartEndAttribute
* pRetval(0L);
269 const sal_Int32
nTempStartWidth(((const XLineStartWidthItem
&)(rSet
.Get(XATTR_LINESTARTWIDTH
))).GetValue());
270 const sal_Int32
nTempEndWidth(((const XLineEndWidthItem
&)(rSet
.Get(XATTR_LINEENDWIDTH
))).GetValue());
271 basegfx::B2DPolyPolygon aStartPolyPolygon
;
272 basegfx::B2DPolyPolygon aEndPolyPolygon
;
273 double fStartWidth(0.0);
274 double fEndWidth(0.0);
275 bool bStartActive(false);
276 bool bEndActive(false);
277 bool bStartCentered(true);
278 bool bEndCentered(true);
282 if(nTempStartWidth
< 0L)
284 fStartWidth
= ((double)(-nTempStartWidth
) * fWidth
) * 0.01;
288 fStartWidth
= (double)nTempStartWidth
;
291 if(0.0 != fStartWidth
)
293 aStartPolyPolygon
= basegfx::B2DPolyPolygon(((const XLineStartItem
&)(rSet
.Get(XATTR_LINESTART
))).GetLineStartValue());
295 if(aStartPolyPolygon
.count() && aStartPolyPolygon
.getB2DPolygon(0L).count())
298 bStartCentered
= ((const XLineStartCenterItem
&)(rSet
.Get(XATTR_LINESTARTCENTER
))).GetValue();
305 if(nTempEndWidth
< 0L)
307 fEndWidth
= ((double)(-nTempEndWidth
) * fWidth
) * 0.01;
311 fEndWidth
= (double)nTempEndWidth
;
316 aEndPolyPolygon
= basegfx::B2DPolyPolygon(((const XLineEndItem
&)(rSet
.Get(XATTR_LINEEND
))).GetLineEndValue());
318 if(aEndPolyPolygon
.count() && aEndPolyPolygon
.getB2DPolygon(0L).count())
321 bEndCentered
= ((const XLineEndCenterItem
&)(rSet
.Get(XATTR_LINEENDCENTER
))).GetValue();
326 if(bStartActive
|| bEndActive
)
328 pRetval
= new attribute::SdrLineStartEndAttribute(aStartPolyPolygon
, aEndPolyPolygon
, fStartWidth
, fEndWidth
, bStartActive
, bEndActive
, bStartCentered
, bEndCentered
);
334 attribute::SdrShadowAttribute
* createNewSdrShadowAttribute(const SfxItemSet
& rSet
)
336 attribute::SdrShadowAttribute
* pRetval(0L);
337 const bool bShadow(((SdrShadowItem
&)rSet
.Get(SDRATTR_SHADOW
)).GetValue());
341 sal_uInt16
nTransparence(((SdrShadowTransparenceItem
&)(rSet
.Get(SDRATTR_SHADOWTRANSPARENCE
))).GetValue());
343 if(nTransparence
> 100)
350 sal_uInt16
nFillTransparence(((const XFillTransparenceItem
&)(rSet
.Get(XATTR_FILLTRANSPARENCE
))).GetValue());
352 if(nFillTransparence
> 100)
354 nFillTransparence
= 100;
357 if(nTransparence
== nFillTransparence
)
359 // shadow does not really have an own transparence, but the application
360 // sets the shadow transparence equal to the object transparence for
361 // convenience. This is not useful for primitive creation, so take
362 // this as no shadow transparence
367 if(100 != nTransparence
)
369 const basegfx::B2DVector
aOffset(
370 (double)((SdrShadowXDistItem
&)(rSet
.Get(SDRATTR_SHADOWXDIST
))).GetValue(),
371 (double)((SdrShadowYDistItem
&)(rSet
.Get(SDRATTR_SHADOWYDIST
))).GetValue());
372 const Color
aColor(((SdrShadowColorItem
&)(rSet
.Get(SDRATTR_SHADOWCOLOR
))).GetColorValue());
374 pRetval
= new attribute::SdrShadowAttribute(aOffset
, (double)nTransparence
* 0.01, aColor
.getBColor());
381 attribute::SdrFillAttribute
* createNewSdrFillAttribute(const SfxItemSet
& rSet
)
383 attribute::SdrFillAttribute
* pRetval(0L);
384 const XFillStyle
eStyle(((XFillStyleItem
&)(rSet
.Get(XATTR_FILLSTYLE
))).GetValue());
386 if(XFILL_NONE
!= eStyle
)
388 sal_uInt16
nTransparence(((const XFillTransparenceItem
&)(rSet
.Get(XATTR_FILLTRANSPARENCE
))).GetValue());
390 if(nTransparence
> 100)
395 if(100 != nTransparence
)
397 const Color
aColor(((const XFillColorItem
&)(rSet
.Get(XATTR_FILLCOLOR
))).GetColorValue());
398 attribute::FillGradientAttribute
* pGradient(0L);
399 attribute::FillHatchAttribute
* pHatch(0L);
400 attribute::SdrFillBitmapAttribute
* pBitmap(0L);
404 case XFILL_NONE
: // for warnings
407 // nothing to do, color is defined
410 case XFILL_GRADIENT
:
412 XGradient
aGradient(((XFillGradientItem
&)(rSet
.Get(XATTR_FILLGRADIENT
))).GetGradientValue());
414 const Color
aStartColor(aGradient
.GetStartColor());
415 const sal_uInt16
nStartIntens(aGradient
.GetStartIntens());
416 basegfx::BColor
aStart(aStartColor
.getBColor());
418 if(nStartIntens
!= 100)
420 const basegfx::BColor aBlack
;
421 aStart
= interpolate(aBlack
, aStart
, (double)nStartIntens
* 0.01);
424 const Color
aEndColor(aGradient
.GetEndColor());
425 const sal_uInt16
nEndIntens(aGradient
.GetEndIntens());
426 basegfx::BColor
aEnd(aEndColor
.getBColor());
428 if(nEndIntens
!= 100)
430 const basegfx::BColor aBlack
;
431 aEnd
= interpolate(aBlack
, aEnd
, (double)nEndIntens
* 0.01);
434 pGradient
= new attribute::FillGradientAttribute(
435 XGradientStyleToGradientStyle(aGradient
.GetGradientStyle()),
436 (double)aGradient
.GetBorder() * 0.01,
437 (double)aGradient
.GetXOffset() * 0.01,
438 (double)aGradient
.GetYOffset() * 0.01,
439 (double)aGradient
.GetAngle() * F_PI1800
,
442 ((const XGradientStepCountItem
&)rSet
.Get(XATTR_GRADIENTSTEPCOUNT
)).GetValue());
448 const XHatch
& rHatch(((XFillHatchItem
&)(rSet
.Get(XATTR_FILLHATCH
))).GetHatchValue());
449 const Color
aColorB(rHatch
.GetColor());
451 pHatch
= new attribute::FillHatchAttribute(
452 XHatchStyleToHatchStyle(rHatch
.GetHatchStyle()),
453 (double)rHatch
.GetDistance(),
454 (double)rHatch
.GetAngle() * F_PI1800
,
456 ((const XFillBackgroundItem
&)(rSet
.Get(XATTR_FILLBACKGROUND
))).GetValue());
462 pBitmap
= createNewSdrFillBitmapAttribute(rSet
);
467 pRetval
= new attribute::SdrFillAttribute(
468 (double)nTransparence
* 0.01,
470 pGradient
, pHatch
, pBitmap
);
477 // #i101508# Support handing over given text-to-border distances
478 attribute::SdrTextAttribute
* createNewSdrTextAttribute(
479 const SfxItemSet
& rSet
,
480 const SdrText
& rText
,
481 const sal_Int32
* pLeft
,
482 const sal_Int32
* pUpper
,
483 const sal_Int32
* pRight
,
484 const sal_Int32
* pLower
)
486 attribute::SdrTextAttribute
* pRetval(0);
487 const SdrTextObj
& rTextObj
= rText
.GetObject();
489 if(rText
.GetOutlinerParaObject() && rText
.GetModel())
491 // added TextEdit text suppression
492 bool bInEditMode(false);
494 if(rText
.GetObject().getTextCount() > 1)
496 bInEditMode
= rTextObj
.IsInEditMode() && rText
.GetObject().getActiveText() == &rText
;
500 bInEditMode
= rTextObj
.IsInEditMode();
503 OutlinerParaObject
aOutlinerParaObject(*rText
.GetOutlinerParaObject());
507 OutlinerParaObject
* pTempObj
= rTextObj
.GetEditOutlinerParaObject();
511 aOutlinerParaObject
= *pTempObj
;
517 // GetEditOutlinerParaObject() returning no object does not mean that
518 // text edit mode is not active. Do not reset the flag here
519 // bInEditMode = false;
523 const SdrFitToSizeType
eFit(rTextObj
.GetFitToSize());
524 const SdrTextAniKind
eAniKind(rTextObj
.GetTextAniKind());
526 pRetval
= new attribute::SdrTextAttribute(
529 ((const XFormTextStyleItem
&)rSet
.Get(XATTR_FORMTXTSTYLE
)).GetValue(),
530 pLeft
? *pLeft
: rTextObj
.GetTextLeftDistance(),
531 pUpper
? *pUpper
: rTextObj
.GetTextUpperDistance(),
532 pRight
? *pRight
: rTextObj
.GetTextRightDistance(),
533 pLower
? *pLower
: rTextObj
.GetTextLowerDistance(),
534 rTextObj
.GetTextHorizontalAdjust(rSet
),
535 rTextObj
.GetTextVerticalAdjust(rSet
),
536 ((const SdrTextContourFrameItem
&)rSet
.Get(SDRATTR_TEXT_CONTOURFRAME
)).GetValue(),
537 rTextObj
.IsFitToSize(),
538 rTextObj
.IsAutoFit(),
539 ((const XFormTextHideFormItem
&)rSet
.Get(XATTR_FORMTXTHIDEFORM
)).GetValue(),
540 SDRTEXTANI_BLINK
== eAniKind
,
541 SDRTEXTANI_SCROLL
== eAniKind
|| SDRTEXTANI_ALTERNATE
== eAniKind
|| SDRTEXTANI_SLIDE
== eAniKind
,
543 ((const SdrTextFixedCellHeightItem
&)rSet
.Get(SDRATTR_TEXT_USEFIXEDCELLHEIGHT
)).GetValue());
549 attribute::FillGradientAttribute
* createNewTransparenceGradientAttribute(const SfxItemSet
& rSet
)
551 attribute::FillGradientAttribute
* pRetval
= 0L;
552 const SfxPoolItem
* pGradientItem
;
554 if(SFX_ITEM_SET
== rSet
.GetItemState(XATTR_FILLFLOATTRANSPARENCE
, TRUE
, &pGradientItem
) && ((XFillFloatTransparenceItem
*)pGradientItem
)->IsEnabled())
556 // test if float transparence is completely transparent
557 const XGradient
& rGradient
= ((XFillFloatTransparenceItem
*)pGradientItem
)->GetGradientValue();
558 const sal_uInt8
nStartLuminance(rGradient
.GetStartColor().GetLuminance());
559 const sal_uInt8
nEndLuminance(rGradient
.GetEndColor().GetLuminance());
560 const bool bCompletelyTransparent(0xff == nStartLuminance
&& 0xff == nEndLuminance
);
562 if(!bCompletelyTransparent
)
564 const double fStartLum(nStartLuminance
/ 255.0);
565 const double fEndLum(nEndLuminance
/ 255.0);
567 pRetval
= new attribute::FillGradientAttribute(
568 XGradientStyleToGradientStyle(rGradient
.GetGradientStyle()),
569 (double)rGradient
.GetBorder() * 0.01,
570 (double)rGradient
.GetXOffset() * 0.01,
571 (double)rGradient
.GetYOffset() * 0.01,
572 (double)rGradient
.GetAngle() * F_PI1800
,
573 basegfx::BColor(fStartLum
, fStartLum
, fStartLum
),
574 basegfx::BColor(fEndLum
, fEndLum
, fEndLum
),
582 attribute::SdrFillBitmapAttribute
* createNewSdrFillBitmapAttribute(const SfxItemSet
& rSet
)
584 attribute::SdrFillBitmapAttribute
* pRetval(0L);
585 Bitmap
aBitmap((((const XFillBitmapItem
&)(rSet
.Get(XATTR_FILLBITMAP
))).GetBitmapValue()).GetBitmap());
587 // make sure it's not empty, use default instead
588 if(aBitmap
.IsEmpty())
590 aBitmap
= Bitmap(Size(4,4), 8);
593 // if there is no logical size, create a size from pixel size and set MapMode accordingly
594 if(0L == aBitmap
.GetPrefSize().Width() || 0L == aBitmap
.GetPrefSize().Height())
596 aBitmap
.SetPrefSize(aBitmap
.GetSizePixel());
597 aBitmap
.SetPrefMapMode(MAP_PIXEL
);
600 // convert size and MapMode to destination logical size and MapMode. The created
601 // bitmap must have a valid logical size (PrefSize)
602 const MapUnit
aDestinationMapUnit((MapUnit
)rSet
.GetPool()->GetMetric(0));
604 if(aBitmap
.GetPrefMapMode() != aDestinationMapUnit
)
606 // #i100360# for MAP_PIXEL, LogicToLogic will not work properly,
607 // so fallback to Application::GetDefaultDevice()
608 if(MAP_PIXEL
== aBitmap
.GetPrefMapMode().GetMapUnit())
610 aBitmap
.SetPrefSize(Application::GetDefaultDevice()->PixelToLogic(
611 aBitmap
.GetPrefSize(), aDestinationMapUnit
));
615 aBitmap
.SetPrefSize(OutputDevice::LogicToLogic(
616 aBitmap
.GetPrefSize(), aBitmap
.GetPrefMapMode(), aDestinationMapUnit
));
621 const basegfx::B2DVector
aSize(
622 (double)((const SfxMetricItem
&)(rSet
.Get(XATTR_FILLBMP_SIZEX
))).GetValue(),
623 (double)((const SfxMetricItem
&)(rSet
.Get(XATTR_FILLBMP_SIZEY
))).GetValue());
624 const basegfx::B2DVector
aOffset(
625 (double)((const SfxUInt16Item
&) (rSet
.Get(XATTR_FILLBMP_TILEOFFSETX
))).GetValue(),
626 (double)((const SfxUInt16Item
&) (rSet
.Get(XATTR_FILLBMP_TILEOFFSETY
))).GetValue());
627 const basegfx::B2DVector
aOffsetPosition(
628 (double)((const SfxUInt16Item
&) (rSet
.Get(XATTR_FILLBMP_POSOFFSETX
))).GetValue(),
629 (double)((const SfxUInt16Item
&) (rSet
.Get(XATTR_FILLBMP_POSOFFSETY
))).GetValue());
631 pRetval
= new attribute::SdrFillBitmapAttribute(
636 RectPointToB2DVector((RECT_POINT
)((const SfxEnumItem
&)(rSet
.Get(XATTR_FILLBMP_POS
))).GetValue()),
637 ((const SfxBoolItem
&) (rSet
.Get(XATTR_FILLBMP_TILE
))).GetValue(),
638 ((const SfxBoolItem
&) (rSet
.Get(XATTR_FILLBMP_STRETCH
))).GetValue(),
639 ((const SfxBoolItem
&) (rSet
.Get(XATTR_FILLBMP_SIZELOG
))).GetValue());
644 attribute::SdrShadowTextAttribute
* createNewSdrShadowTextAttribute(const SfxItemSet
& rSet
, const SdrText
& rText
, bool bSuppressText
)
646 attribute::SdrShadowTextAttribute
* pRetval(0L);
647 attribute::SdrShadowAttribute
* pShadow(0L);
648 attribute::SdrTextAttribute
* pText(0L);
650 // #i98072# added option to suppress text
651 // look for text first
654 pText
= createNewSdrTextAttribute(rSet
, rText
);
658 pShadow
= createNewSdrShadowAttribute(rSet
);
660 if(pShadow
&& !pShadow
->isVisible())
668 pRetval
= new attribute::SdrShadowTextAttribute(pShadow
, pText
);
674 attribute::SdrLineShadowTextAttribute
* createNewSdrLineShadowTextAttribute(const SfxItemSet
& rSet
, const SdrText
& rText
)
676 attribute::SdrLineShadowTextAttribute
* pRetval(0L);
677 attribute::SdrLineAttribute
* pLine(0L);
678 attribute::SdrLineStartEndAttribute
* pLineStartEnd(0L);
679 attribute::SdrShadowAttribute
* pShadow(0L);
680 attribute::SdrTextAttribute
* pText(0L);
681 bool bFontworkHideContour(false);
683 // look for text first
684 pText
= createNewSdrTextAttribute(rSet
, rText
);
686 // when object has text and text is fontwork and hide contour is set for fontwork, force
687 // line and fill style to empty
688 if(pText
&& pText
->getSdrFormTextAttribute() && pText
->isHideContour())
690 bFontworkHideContour
= true;
694 if(!bFontworkHideContour
)
696 pLine
= createNewSdrLineAttribute(rSet
);
698 if(pLine
&& !pLine
->isVisible())
707 pLineStartEnd
= createNewSdrLineStartEndAttribute(rSet
, pLine
->getWidth());
709 if(pLineStartEnd
&& !pLineStartEnd
->isVisible())
711 delete pLineStartEnd
;
720 pShadow
= createNewSdrShadowAttribute(rSet
);
722 if(pShadow
&& !pShadow
->isVisible())
731 pRetval
= new attribute::SdrLineShadowTextAttribute(pLine
, pLineStartEnd
, pShadow
, pText
);
737 attribute::SdrLineFillShadowTextAttribute
* createNewSdrLineFillShadowTextAttribute(const SfxItemSet
& rSet
, const SdrText
& rText
)
739 attribute::SdrLineFillShadowTextAttribute
* pRetval(0L);
740 attribute::SdrLineAttribute
* pLine(0L);
741 attribute::SdrFillAttribute
* pFill(0L);
742 attribute::SdrLineStartEndAttribute
* pLineStartEnd(0L);
743 attribute::SdrShadowAttribute
* pShadow(0L);
744 attribute::FillGradientAttribute
* pFillFloatTransGradient(0L);
745 attribute::SdrTextAttribute
* pText(0L);
746 bool bFontworkHideContour(false);
748 // look for text first
749 pText
= createNewSdrTextAttribute(rSet
, rText
);
751 // when object has text and text is fontwork and hide contour is set for fontwork, force
752 // line and fill style to empty
753 if(pText
&& pText
->getSdrFormTextAttribute() && pText
->isHideContour())
755 bFontworkHideContour
= true;
759 if(!bFontworkHideContour
)
761 pLine
= createNewSdrLineAttribute(rSet
);
763 if(pLine
&& !pLine
->isVisible())
772 pLineStartEnd
= createNewSdrLineStartEndAttribute(rSet
, pLine
->getWidth());
774 if(pLineStartEnd
&& !pLineStartEnd
->isVisible())
776 delete pLineStartEnd
;
783 if(!bFontworkHideContour
)
785 pFill
= createNewSdrFillAttribute(rSet
);
787 if(pFill
&& !pFill
->isVisible())
795 // try fillfloattransparence
796 pFillFloatTransGradient
= createNewTransparenceGradientAttribute(rSet
);
801 if(pLine
|| pFill
|| pText
)
803 pShadow
= createNewSdrShadowAttribute(rSet
);
805 if(pShadow
&& !pShadow
->isVisible())
812 if(pLine
|| pFill
|| pText
)
814 pRetval
= new attribute::SdrLineFillShadowTextAttribute(pLine
, pFill
, pLineStartEnd
, pShadow
, pFillFloatTransGradient
, pText
);
820 attribute::SdrLineFillShadowAttribute
* createNewSdrLineFillShadowAttribute(const SfxItemSet
& rSet
, bool bSuppressFill
)
822 attribute::SdrLineFillShadowAttribute
* pRetval(0L);
823 attribute::SdrLineAttribute
* pLine(0L);
824 attribute::SdrFillAttribute
* pFill(0L);
825 attribute::SdrLineStartEndAttribute
* pLineStartEnd(0L);
826 attribute::SdrShadowAttribute
* pShadow(0L);
827 attribute::FillGradientAttribute
* pFillFloatTransGradient(0L);
830 pLine
= createNewSdrLineAttribute(rSet
);
832 if(pLine
&& !pLine
->isVisible())
841 pLineStartEnd
= createNewSdrLineStartEndAttribute(rSet
, pLine
->getWidth());
843 if(pLineStartEnd
&& !pLineStartEnd
->isVisible())
845 delete pLineStartEnd
;
851 pFill
= bSuppressFill
? 0 : createNewSdrFillAttribute(rSet
);
853 if(pFill
&& !pFill
->isVisible())
861 // try fillfloattransparence
862 pFillFloatTransGradient
= createNewTransparenceGradientAttribute(rSet
);
868 pShadow
= createNewSdrShadowAttribute(rSet
);
870 if(pShadow
&& !pShadow
->isVisible())
879 pRetval
= new attribute::SdrLineFillShadowAttribute(pLine
, pFill
, pLineStartEnd
, pShadow
, pFillFloatTransGradient
);
885 attribute::SdrSceneAttribute
* createNewSdrSceneAttribute(const SfxItemSet
& rSet
)
888 ::com::sun::star::drawing::ProjectionMode
aProjectionMode(::com::sun::star::drawing::ProjectionMode_PARALLEL
);
889 const sal_uInt16
nProjectionValue(((const Svx3DPerspectiveItem
&)rSet
.Get(SDRATTR_3DSCENE_PERSPECTIVE
)).GetValue());
891 if(1L == nProjectionValue
)
893 aProjectionMode
= ::com::sun::star::drawing::ProjectionMode_PERSPECTIVE
;
897 const double fDistance(((const Svx3DDistanceItem
&)rSet
.Get(SDRATTR_3DSCENE_DISTANCE
)).GetValue());
900 const double fShadowSlant(F_PI180
* ((const Svx3DShadowSlantItem
&)rSet
.Get(SDRATTR_3DSCENE_SHADOW_SLANT
)).GetValue());
903 ::com::sun::star::drawing::ShadeMode
aShadeMode(::com::sun::star::drawing::ShadeMode_FLAT
);
904 const sal_uInt16
nShadeValue(((const Svx3DShadeModeItem
&)rSet
.Get(SDRATTR_3DSCENE_SHADE_MODE
)).GetValue());
906 if(1L == nShadeValue
)
908 aShadeMode
= ::com::sun::star::drawing::ShadeMode_PHONG
;
910 else if(2L == nShadeValue
)
912 aShadeMode
= ::com::sun::star::drawing::ShadeMode_SMOOTH
;
914 else if(3L == nShadeValue
)
916 aShadeMode
= ::com::sun::star::drawing::ShadeMode_DRAFT
;
919 // get two sided lighting
920 const bool bTwoSidedLighting(((const Svx3DTwoSidedLightingItem
&)rSet
.Get(SDRATTR_3DSCENE_TWO_SIDED_LIGHTING
)).GetValue());
922 return new attribute::SdrSceneAttribute(fDistance
, fShadowSlant
, aProjectionMode
, aShadeMode
, bTwoSidedLighting
);
925 attribute::SdrLightingAttribute
* createNewSdrLightingAttribute(const SfxItemSet
& rSet
)
927 // extract lights from given SfxItemSet (from scene)
928 ::std::vector
< attribute::Sdr3DLightAttribute
> aLightVector
;
930 if(((const Svx3DLightOnOff1Item
&)rSet
.Get(SDRATTR_3DSCENE_LIGHTON_1
)).GetValue())
932 const basegfx::BColor
aColor(((const Svx3DLightcolor1Item
&)rSet
.Get(SDRATTR_3DSCENE_LIGHTCOLOR_1
)).GetValue().getBColor());
933 const basegfx::B3DVector
aDirection(((const Svx3DLightDirection1Item
&)rSet
.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_1
)).GetValue());
934 aLightVector
.push_back(attribute::Sdr3DLightAttribute(aColor
, aDirection
, true));
937 if(((const Svx3DLightOnOff2Item
&)rSet
.Get(SDRATTR_3DSCENE_LIGHTON_2
)).GetValue())
939 const basegfx::BColor
aColor(((const Svx3DLightcolor2Item
&)rSet
.Get(SDRATTR_3DSCENE_LIGHTCOLOR_2
)).GetValue().getBColor());
940 const basegfx::B3DVector
aDirection(((const Svx3DLightDirection2Item
&)rSet
.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_2
)).GetValue());
941 aLightVector
.push_back(attribute::Sdr3DLightAttribute(aColor
, aDirection
, false));
944 if(((const Svx3DLightOnOff3Item
&)rSet
.Get(SDRATTR_3DSCENE_LIGHTON_3
)).GetValue())
946 const basegfx::BColor
aColor(((const Svx3DLightcolor3Item
&)rSet
.Get(SDRATTR_3DSCENE_LIGHTCOLOR_3
)).GetValue().getBColor());
947 const basegfx::B3DVector
aDirection(((const Svx3DLightDirection3Item
&)rSet
.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_3
)).GetValue());
948 aLightVector
.push_back(attribute::Sdr3DLightAttribute(aColor
, aDirection
, false));
951 if(((const Svx3DLightOnOff4Item
&)rSet
.Get(SDRATTR_3DSCENE_LIGHTON_4
)).GetValue())
953 const basegfx::BColor
aColor(((const Svx3DLightcolor4Item
&)rSet
.Get(SDRATTR_3DSCENE_LIGHTCOLOR_4
)).GetValue().getBColor());
954 const basegfx::B3DVector
aDirection(((const Svx3DLightDirection4Item
&)rSet
.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_4
)).GetValue());
955 aLightVector
.push_back(attribute::Sdr3DLightAttribute(aColor
, aDirection
, false));
958 if(((const Svx3DLightOnOff5Item
&)rSet
.Get(SDRATTR_3DSCENE_LIGHTON_5
)).GetValue())
960 const basegfx::BColor
aColor(((const Svx3DLightcolor5Item
&)rSet
.Get(SDRATTR_3DSCENE_LIGHTCOLOR_5
)).GetValue().getBColor());
961 const basegfx::B3DVector
aDirection(((const Svx3DLightDirection5Item
&)rSet
.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_5
)).GetValue());
962 aLightVector
.push_back(attribute::Sdr3DLightAttribute(aColor
, aDirection
, false));
965 if(((const Svx3DLightOnOff6Item
&)rSet
.Get(SDRATTR_3DSCENE_LIGHTON_6
)).GetValue())
967 const basegfx::BColor
aColor(((const Svx3DLightcolor6Item
&)rSet
.Get(SDRATTR_3DSCENE_LIGHTCOLOR_6
)).GetValue().getBColor());
968 const basegfx::B3DVector
aDirection(((const Svx3DLightDirection6Item
&)rSet
.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_6
)).GetValue());
969 aLightVector
.push_back(attribute::Sdr3DLightAttribute(aColor
, aDirection
, false));
972 if(((const Svx3DLightOnOff7Item
&)rSet
.Get(SDRATTR_3DSCENE_LIGHTON_7
)).GetValue())
974 const basegfx::BColor
aColor(((const Svx3DLightcolor7Item
&)rSet
.Get(SDRATTR_3DSCENE_LIGHTCOLOR_7
)).GetValue().getBColor());
975 const basegfx::B3DVector
aDirection(((const Svx3DLightDirection7Item
&)rSet
.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_7
)).GetValue());
976 aLightVector
.push_back(attribute::Sdr3DLightAttribute(aColor
, aDirection
, false));
979 if(((const Svx3DLightOnOff8Item
&)rSet
.Get(SDRATTR_3DSCENE_LIGHTON_8
)).GetValue())
981 const basegfx::BColor
aColor(((const Svx3DLightcolor8Item
&)rSet
.Get(SDRATTR_3DSCENE_LIGHTCOLOR_8
)).GetValue().getBColor());
982 const basegfx::B3DVector
aDirection(((const Svx3DLightDirection8Item
&)rSet
.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_8
)).GetValue());
983 aLightVector
.push_back(attribute::Sdr3DLightAttribute(aColor
, aDirection
, false));
987 const Color
aAmbientValue(((const Svx3DAmbientcolorItem
&)rSet
.Get(SDRATTR_3DSCENE_AMBIENTCOLOR
)).GetValue());
988 const basegfx::BColor
aAmbientLight(aAmbientValue
.getBColor());
990 return new attribute::SdrLightingAttribute(aAmbientLight
, aLightVector
);
993 void calculateRelativeCornerRadius(sal_Int32 nRadius
, const basegfx::B2DRange
& rObjectRange
, double& rfCornerRadiusX
, double& rfCornerRadiusY
)
995 rfCornerRadiusX
= rfCornerRadiusY
= (double)nRadius
;
997 if(0.0 != rfCornerRadiusX
)
999 const double fHalfObjectWidth(rObjectRange
.getWidth() * 0.5);
1001 if(0.0 != fHalfObjectWidth
)
1003 if(rfCornerRadiusX
< 0.0)
1005 rfCornerRadiusX
= 0.0;
1008 if(rfCornerRadiusX
> fHalfObjectWidth
)
1010 rfCornerRadiusX
= fHalfObjectWidth
;
1013 rfCornerRadiusX
/= fHalfObjectWidth
;
1017 rfCornerRadiusX
= 0.0;
1021 if(0.0 != rfCornerRadiusY
)
1023 const double fHalfObjectHeight(rObjectRange
.getHeight() * 0.5);
1025 if(0.0 != fHalfObjectHeight
)
1027 if(rfCornerRadiusY
< 0.0)
1029 rfCornerRadiusY
= 0.0;
1032 if(rfCornerRadiusY
> fHalfObjectHeight
)
1034 rfCornerRadiusY
= fHalfObjectHeight
;
1037 rfCornerRadiusY
/= fHalfObjectHeight
;
1041 rfCornerRadiusY
= 0.0;
1046 // #i101508# Support handing over given text-to-border distances
1047 attribute::SdrFillTextAttribute
* createNewSdrFillTextAttribute(
1048 const SfxItemSet
& rSet
,
1049 const SdrText
* pSdrText
,
1050 const sal_Int32
* pLeft
,
1051 const sal_Int32
* pUpper
,
1052 const sal_Int32
* pRight
,
1053 const sal_Int32
* pLower
)
1055 attribute::SdrFillTextAttribute
* pRetval(0L);
1056 attribute::SdrFillAttribute
* pFill(0L);
1057 attribute::FillGradientAttribute
* pFillFloatTransGradient(0L);
1058 attribute::SdrTextAttribute
* pText(0L);
1059 bool bFontworkHideContour(false);
1061 // look for text first
1064 pText
= createNewSdrTextAttribute(rSet
, *pSdrText
, pLeft
, pUpper
, pRight
, pLower
);
1067 // when object has text and text is fontwork and hide contour is set for fontwork, force
1068 // fill style to empty
1069 if(pText
&& pText
->getSdrFormTextAttribute() && pText
->isHideContour())
1071 bFontworkHideContour
= true;
1075 if(!bFontworkHideContour
)
1077 pFill
= createNewSdrFillAttribute(rSet
);
1079 if(pFill
&& !pFill
->isVisible())
1087 // try fillfloattransparence
1088 pFillFloatTransGradient
= createNewTransparenceGradientAttribute(rSet
);
1094 pRetval
= new attribute::SdrFillTextAttribute(pFill
, pFillFloatTransGradient
, pText
);
1100 } // end of namespace primitive2d
1101 } // end of namespace drawinglayer
1103 //////////////////////////////////////////////////////////////////////////////