1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include <svx/sdr/primitive2d/sdrattributecreator.hxx>
30 #include <svl/itemset.hxx>
31 #include <svx/xdef.hxx>
32 #include <basegfx/polygon/b2dpolygon.hxx>
33 #include <svx/xlineit0.hxx>
34 #include <svx/xfillit0.hxx>
35 #include <svx/xlntrit.hxx>
36 #include <svx/xlnwtit.hxx>
37 #include <svx/xlinjoit.hxx>
38 #include <svx/xlnclit.hxx>
39 #include <svx/xlnstwit.hxx>
40 #include <svx/xlnedwit.hxx>
41 #include <svx/xlnstit.hxx>
42 #include <svx/xlnstcit.hxx>
43 #include <svx/xlnedit.hxx>
44 #include <svx/xlnedcit.hxx>
45 #include <svx/xdash.hxx>
46 #include <svx/xlndsit.hxx>
47 #include <svx/xfltrit.hxx>
48 #include <svx/xflftrit.hxx>
49 #include <svx/xflclit.hxx>
50 #include <svx/xgrscit.hxx>
51 #include <svx/xflhtit.hxx>
52 #include <svx/xflbckit.hxx>
53 #include <svx/sdshitm.hxx>
54 #include <svx/sdsxyitm.hxx>
55 #include <svx/sdshcitm.hxx>
56 #include <svx/sdshtitm.hxx>
57 #include <drawinglayer/attribute/sdrfillbitmapattribute.hxx>
58 #include <basegfx/polygon/b2dlinegeometry.hxx>
59 #include <svx/svdotext.hxx>
60 #include <drawinglayer/attribute/fillbitmapattribute.hxx>
61 #include <svx/sdr/attribute/sdrtextattribute.hxx>
62 #include <svx/xbtmpit.hxx>
63 #include <svl/itempool.hxx>
64 #include <vcl/svapp.hxx>
65 #include <basegfx/range/b2drange.hxx>
66 #include <svx/svx3ditems.hxx>
67 #include <com/sun/star/drawing/ProjectionMode.hpp>
68 #include <com/sun/star/drawing/ShadeMode.hpp>
69 #include <drawinglayer/attribute/sdrallattribute3d.hxx>
70 #include <svx/rectenum.hxx>
71 #include <svx/sdtfchim.hxx>
72 #include <svx/svdoutl.hxx>
73 #include <svx/svdmodel.hxx>
74 #include <editeng/editstat.hxx>
75 #include <drawinglayer/attribute/fillhatchattribute.hxx>
76 #include <drawinglayer/attribute/fillgradientattribute.hxx>
77 #include <svx/sdr/attribute/sdrshadowtextattribute.hxx>
78 #include <svx/sdr/attribute/sdrlineshadowtextattribute.hxx>
79 #include <svx/sdr/attribute/sdrformtextattribute.hxx>
80 #include <svx/sdr/attribute/sdrlinefillshadowtextattribute.hxx>
81 #include <drawinglayer/attribute/sdrsceneattribute3d.hxx>
82 #include <drawinglayer/attribute/sdrlightingattribute3d.hxx>
83 #include <drawinglayer/attribute/sdrlightattribute3d.hxx>
84 #include <svx/sdr/attribute/sdrfilltextattribute.hxx>
86 //////////////////////////////////////////////////////////////////////////////
88 namespace drawinglayer
92 attribute::GradientStyle
XGradientStyleToGradientStyle(XGradientStyle eStyle
)
98 return attribute::GRADIENTSTYLE_LINEAR
;
102 return attribute::GRADIENTSTYLE_AXIAL
;
106 return attribute::GRADIENTSTYLE_RADIAL
;
108 case XGRAD_ELLIPTICAL
:
110 return attribute::GRADIENTSTYLE_ELLIPTICAL
;
114 return attribute::GRADIENTSTYLE_SQUARE
;
118 return attribute::GRADIENTSTYLE_RECT
; // XGRAD_RECT
123 attribute::HatchStyle
XHatchStyleToHatchStyle(XHatchStyle eStyle
)
129 return attribute::HATCHSTYLE_SINGLE
;
133 return attribute::HATCHSTYLE_DOUBLE
;
137 return attribute::HATCHSTYLE_TRIPLE
; // XHATCH_TRIPLE
142 basegfx::B2DLineJoin
XLineJointtoB2DLineJoin(XLineJoint eLineJoint
)
146 case XLINEJOINT_MIDDLE
:
148 return basegfx::B2DLINEJOIN_MIDDLE
;
150 case XLINEJOINT_BEVEL
:
152 return basegfx::B2DLINEJOIN_BEVEL
;
154 case XLINEJOINT_MITER
:
156 return basegfx::B2DLINEJOIN_MITER
;
158 case XLINEJOINT_ROUND
:
160 return basegfx::B2DLINEJOIN_ROUND
;
164 return basegfx::B2DLINEJOIN_NONE
; // XLINEJOINT_NONE
169 basegfx::B2DVector
RectPointToB2DVector(RECT_POINT eRectPoint
)
171 basegfx::B2DVector
aRetval(0.0, 0.0);
173 // position changes X
176 case RP_LT
: case RP_LM
: case RP_LB
:
182 case RP_RT
: case RP_RM
: case RP_RB
:
194 // position changes Y
197 case RP_LT
: case RP_MT
: case RP_RT
:
203 case RP_LB
: case RP_MB
: case RP_RB
:
217 } // end of anonymous namespace
218 } // end of namespace drawinglayer
220 //////////////////////////////////////////////////////////////////////////////
222 namespace drawinglayer
224 namespace primitive2d
226 attribute::SdrLineAttribute
createNewSdrLineAttribute(const SfxItemSet
& rSet
)
228 const XLineStyle
eStyle(((XLineStyleItem
&)(rSet
.Get(XATTR_LINESTYLE
))).GetValue());
230 if(XLINE_NONE
!= eStyle
)
232 sal_uInt16
nTransparence(((const XLineTransparenceItem
&)(rSet
.Get(XATTR_LINETRANSPARENCE
))).GetValue());
234 if(nTransparence
> 100)
239 if(100 != nTransparence
)
241 const sal_uInt32
nWidth(((const XLineWidthItem
&)(rSet
.Get(XATTR_LINEWIDTH
))).GetValue());
242 const Color
aColor(((const XLineColorItem
&)(rSet
.Get(XATTR_LINECOLOR
))).GetColorValue());
243 const XLineJoint
eJoint(((const XLineJointItem
&)(rSet
.Get(XATTR_LINEJOINT
))).GetValue());
244 ::std::vector
< double > aDotDashArray
;
245 double fFullDotDashLen(0.0);
247 if(XLINE_DASH
== eStyle
)
249 const XDash
& rDash
= ((const XLineDashItem
&)(rSet
.Get(XATTR_LINEDASH
))).GetDashValue();
251 if(rDash
.GetDots() || rDash
.GetDashes())
253 fFullDotDashLen
= rDash
.CreateDotDashArray(aDotDashArray
, (double)nWidth
);
257 return attribute::SdrLineAttribute(
258 XLineJointtoB2DLineJoin(eJoint
),
260 (double)nTransparence
* 0.01,
267 return attribute::SdrLineAttribute();
270 attribute::SdrLineStartEndAttribute
createNewSdrLineStartEndAttribute(
271 const SfxItemSet
& rSet
,
274 const sal_Int32
nTempStartWidth(((const XLineStartWidthItem
&)(rSet
.Get(XATTR_LINESTARTWIDTH
))).GetValue());
275 const sal_Int32
nTempEndWidth(((const XLineEndWidthItem
&)(rSet
.Get(XATTR_LINEENDWIDTH
))).GetValue());
276 basegfx::B2DPolyPolygon aStartPolyPolygon
;
277 basegfx::B2DPolyPolygon aEndPolyPolygon
;
278 double fStartWidth(0.0);
279 double fEndWidth(0.0);
280 bool bStartActive(false);
281 bool bEndActive(false);
282 bool bStartCentered(true);
283 bool bEndCentered(true);
287 if(nTempStartWidth
< 0L)
289 fStartWidth
= ((double)(-nTempStartWidth
) * fWidth
) * 0.01;
293 fStartWidth
= (double)nTempStartWidth
;
296 if(0.0 != fStartWidth
)
298 aStartPolyPolygon
= basegfx::B2DPolyPolygon(((const XLineStartItem
&)(rSet
.Get(XATTR_LINESTART
))).GetLineStartValue());
300 if(aStartPolyPolygon
.count() && aStartPolyPolygon
.getB2DPolygon(0L).count())
303 bStartCentered
= ((const XLineStartCenterItem
&)(rSet
.Get(XATTR_LINESTARTCENTER
))).GetValue();
310 if(nTempEndWidth
< 0L)
312 fEndWidth
= ((double)(-nTempEndWidth
) * fWidth
) * 0.01;
316 fEndWidth
= (double)nTempEndWidth
;
321 aEndPolyPolygon
= basegfx::B2DPolyPolygon(((const XLineEndItem
&)(rSet
.Get(XATTR_LINEEND
))).GetLineEndValue());
323 if(aEndPolyPolygon
.count() && aEndPolyPolygon
.getB2DPolygon(0L).count())
326 bEndCentered
= ((const XLineEndCenterItem
&)(rSet
.Get(XATTR_LINEENDCENTER
))).GetValue();
331 if(bStartActive
|| bEndActive
)
333 return attribute::SdrLineStartEndAttribute(
334 aStartPolyPolygon
, aEndPolyPolygon
, fStartWidth
, fEndWidth
,
335 bStartActive
, bEndActive
, bStartCentered
, bEndCentered
);
338 return attribute::SdrLineStartEndAttribute();
341 attribute::SdrShadowAttribute
createNewSdrShadowAttribute(const SfxItemSet
& rSet
)
343 const bool bShadow(((SdrShadowItem
&)rSet
.Get(SDRATTR_SHADOW
)).GetValue());
347 sal_uInt16
nTransparence(((SdrShadowTransparenceItem
&)(rSet
.Get(SDRATTR_SHADOWTRANSPARENCE
))).GetValue());
349 if(nTransparence
> 100)
356 sal_uInt16
nFillTransparence(((const XFillTransparenceItem
&)(rSet
.Get(XATTR_FILLTRANSPARENCE
))).GetValue());
358 if(nFillTransparence
> 100)
360 nFillTransparence
= 100;
363 if(nTransparence
== nFillTransparence
)
365 // shadow does not really have an own transparence, but the application
366 // sets the shadow transparence equal to the object transparence for
367 // convenience. This is not useful for primitive creation, so take
368 // this as no shadow transparence
373 if(100 != nTransparence
)
375 const basegfx::B2DVector
aOffset(
376 (double)((SdrShadowXDistItem
&)(rSet
.Get(SDRATTR_SHADOWXDIST
))).GetValue(),
377 (double)((SdrShadowYDistItem
&)(rSet
.Get(SDRATTR_SHADOWYDIST
))).GetValue());
378 const Color
aColor(((SdrShadowColorItem
&)(rSet
.Get(SDRATTR_SHADOWCOLOR
))).GetColorValue());
380 return attribute::SdrShadowAttribute(aOffset
, (double)nTransparence
* 0.01, aColor
.getBColor());
384 return attribute::SdrShadowAttribute();
387 attribute::SdrFillAttribute
createNewSdrFillAttribute(const SfxItemSet
& rSet
)
389 const XFillStyle
eStyle(((XFillStyleItem
&)(rSet
.Get(XATTR_FILLSTYLE
))).GetValue());
391 if(XFILL_NONE
!= eStyle
)
393 sal_uInt16
nTransparence(((const XFillTransparenceItem
&)(rSet
.Get(XATTR_FILLTRANSPARENCE
))).GetValue());
395 if(nTransparence
> 100)
400 if(100 != nTransparence
)
402 const Color
aColor(((const XFillColorItem
&)(rSet
.Get(XATTR_FILLCOLOR
))).GetColorValue());
403 attribute::FillGradientAttribute aGradient
;
404 attribute::FillHatchAttribute aHatch
;
405 attribute::SdrFillBitmapAttribute aBitmap
;
409 case XFILL_NONE
: // for warnings
412 // nothing to do, color is defined
415 case XFILL_GRADIENT
:
417 XGradient
aXGradient(((XFillGradientItem
&)(rSet
.Get(XATTR_FILLGRADIENT
))).GetGradientValue());
419 const Color
aStartColor(aXGradient
.GetStartColor());
420 const sal_uInt16
nStartIntens(aXGradient
.GetStartIntens());
421 basegfx::BColor
aStart(aStartColor
.getBColor());
423 if(nStartIntens
!= 100)
425 const basegfx::BColor aBlack
;
426 aStart
= interpolate(aBlack
, aStart
, (double)nStartIntens
* 0.01);
429 const Color
aEndColor(aXGradient
.GetEndColor());
430 const sal_uInt16
nEndIntens(aXGradient
.GetEndIntens());
431 basegfx::BColor
aEnd(aEndColor
.getBColor());
433 if(nEndIntens
!= 100)
435 const basegfx::BColor aBlack
;
436 aEnd
= interpolate(aBlack
, aEnd
, (double)nEndIntens
* 0.01);
439 aGradient
= attribute::FillGradientAttribute(
440 XGradientStyleToGradientStyle(aXGradient
.GetGradientStyle()),
441 (double)aXGradient
.GetBorder() * 0.01,
442 (double)aXGradient
.GetXOffset() * 0.01,
443 (double)aXGradient
.GetYOffset() * 0.01,
444 (double)aXGradient
.GetAngle() * F_PI1800
,
447 ((const XGradientStepCountItem
&)rSet
.Get(XATTR_GRADIENTSTEPCOUNT
)).GetValue());
453 const XHatch
& rHatch(((XFillHatchItem
&)(rSet
.Get(XATTR_FILLHATCH
))).GetHatchValue());
454 const Color
aColorB(rHatch
.GetColor());
456 aHatch
= attribute::FillHatchAttribute(
457 XHatchStyleToHatchStyle(rHatch
.GetHatchStyle()),
458 (double)rHatch
.GetDistance(),
459 (double)rHatch
.GetAngle() * F_PI1800
,
461 ((const XFillBackgroundItem
&)(rSet
.Get(XATTR_FILLBACKGROUND
))).GetValue());
467 aBitmap
= createNewSdrFillBitmapAttribute(rSet
);
472 return attribute::SdrFillAttribute(
473 (double)nTransparence
* 0.01,
481 return attribute::SdrFillAttribute();
484 // #i101508# Support handing over given text-to-border distances
485 attribute::SdrTextAttribute
createNewSdrTextAttribute(
486 const SfxItemSet
& rSet
,
487 const SdrText
& rText
,
488 const sal_Int32
* pLeft
,
489 const sal_Int32
* pUpper
,
490 const sal_Int32
* pRight
,
491 const sal_Int32
* pLower
)
493 const SdrTextObj
& rTextObj
= rText
.GetObject();
495 if(rText
.GetOutlinerParaObject() && rText
.GetModel())
497 // added TextEdit text suppression
498 bool bInEditMode(false);
500 if(rText
.GetObject().getTextCount() > 1)
502 bInEditMode
= rTextObj
.IsInEditMode() && rText
.GetObject().getActiveText() == &rText
;
506 bInEditMode
= rTextObj
.IsInEditMode();
509 OutlinerParaObject
aOutlinerParaObject(*rText
.GetOutlinerParaObject());
513 OutlinerParaObject
* pTempObj
= rTextObj
.GetEditOutlinerParaObject();
517 aOutlinerParaObject
= *pTempObj
;
523 // GetEditOutlinerParaObject() returning no object does not mean that
524 // text edit mode is not active. Do not reset the flag here
525 // bInEditMode = false;
529 const SdrTextAniKind
eAniKind(rTextObj
.GetTextAniKind());
532 const SdrOutliner
& rDrawTextOutliner
= rText
.GetModel()->GetDrawOutliner(&rTextObj
);
533 const bool bWrongSpell(rDrawTextOutliner
.GetControlWord() & EE_CNTRL_ONLINESPELLING
);
535 return attribute::SdrTextAttribute(
538 ((const XFormTextStyleItem
&)rSet
.Get(XATTR_FORMTXTSTYLE
)).GetValue(),
539 pLeft
? *pLeft
: rTextObj
.GetTextLeftDistance(),
540 pUpper
? *pUpper
: rTextObj
.GetTextUpperDistance(),
541 pRight
? *pRight
: rTextObj
.GetTextRightDistance(),
542 pLower
? *pLower
: rTextObj
.GetTextLowerDistance(),
543 rTextObj
.GetTextHorizontalAdjust(rSet
),
544 rTextObj
.GetTextVerticalAdjust(rSet
),
545 ((const SdrTextContourFrameItem
&)rSet
.Get(SDRATTR_TEXT_CONTOURFRAME
)).GetValue(),
546 rTextObj
.IsFitToSize(),
547 rTextObj
.IsAutoFit(),
548 ((const XFormTextHideFormItem
&)rSet
.Get(XATTR_FORMTXTHIDEFORM
)).GetValue(),
549 SDRTEXTANI_BLINK
== eAniKind
,
550 SDRTEXTANI_SCROLL
== eAniKind
|| SDRTEXTANI_ALTERNATE
== eAniKind
|| SDRTEXTANI_SLIDE
== eAniKind
,
552 ((const SdrTextFixedCellHeightItem
&)rSet
.Get(SDRATTR_TEXT_USEFIXEDCELLHEIGHT
)).GetValue(),
556 return attribute::SdrTextAttribute();
559 attribute::FillGradientAttribute
createNewTransparenceGradientAttribute(const SfxItemSet
& rSet
)
561 const SfxPoolItem
* pGradientItem
;
563 if(SFX_ITEM_SET
== rSet
.GetItemState(XATTR_FILLFLOATTRANSPARENCE
, sal_True
, &pGradientItem
)
564 && ((XFillFloatTransparenceItem
*)pGradientItem
)->IsEnabled())
566 // test if float transparence is completely transparent
567 const XGradient
& rGradient
= ((XFillFloatTransparenceItem
*)pGradientItem
)->GetGradientValue();
568 const sal_uInt8
nStartLuminance(rGradient
.GetStartColor().GetLuminance());
569 const sal_uInt8
nEndLuminance(rGradient
.GetEndColor().GetLuminance());
570 const bool bCompletelyTransparent(0xff == nStartLuminance
&& 0xff == nEndLuminance
);
572 if(!bCompletelyTransparent
)
574 const double fStartLum(nStartLuminance
/ 255.0);
575 const double fEndLum(nEndLuminance
/ 255.0);
577 return attribute::FillGradientAttribute(
578 XGradientStyleToGradientStyle(rGradient
.GetGradientStyle()),
579 (double)rGradient
.GetBorder() * 0.01,
580 (double)rGradient
.GetXOffset() * 0.01,
581 (double)rGradient
.GetYOffset() * 0.01,
582 (double)rGradient
.GetAngle() * F_PI1800
,
583 basegfx::BColor(fStartLum
, fStartLum
, fStartLum
),
584 basegfx::BColor(fEndLum
, fEndLum
, fEndLum
),
589 return attribute::FillGradientAttribute();
592 attribute::SdrFillBitmapAttribute
createNewSdrFillBitmapAttribute(const SfxItemSet
& rSet
)
594 Bitmap
aBitmap((((const XFillBitmapItem
&)(rSet
.Get(XATTR_FILLBITMAP
))).GetBitmapValue()).GetBitmap());
596 // make sure it's not empty, use default instead
597 if(aBitmap
.IsEmpty())
599 aBitmap
= Bitmap(Size(4,4), 8);
602 // if there is no logical size, create a size from pixel size and set MapMode accordingly
603 if(0L == aBitmap
.GetPrefSize().Width() || 0L == aBitmap
.GetPrefSize().Height())
605 aBitmap
.SetPrefSize(aBitmap
.GetSizePixel());
606 aBitmap
.SetPrefMapMode(MAP_PIXEL
);
609 // convert size and MapMode to destination logical size and MapMode. The created
610 // bitmap must have a valid logical size (PrefSize)
611 const MapUnit
aDestinationMapUnit((MapUnit
)rSet
.GetPool()->GetMetric(0));
613 if(aBitmap
.GetPrefMapMode() != aDestinationMapUnit
)
615 // #i100360# for MAP_PIXEL, LogicToLogic will not work properly,
616 // so fallback to Application::GetDefaultDevice()
617 if(MAP_PIXEL
== aBitmap
.GetPrefMapMode().GetMapUnit())
619 aBitmap
.SetPrefSize(Application::GetDefaultDevice()->PixelToLogic(
620 aBitmap
.GetPrefSize(), aDestinationMapUnit
));
624 aBitmap
.SetPrefSize(OutputDevice::LogicToLogic(
625 aBitmap
.GetPrefSize(), aBitmap
.GetPrefMapMode(), aDestinationMapUnit
));
630 const basegfx::B2DVector
aSize(
631 (double)((const SfxMetricItem
&)(rSet
.Get(XATTR_FILLBMP_SIZEX
))).GetValue(),
632 (double)((const SfxMetricItem
&)(rSet
.Get(XATTR_FILLBMP_SIZEY
))).GetValue());
633 const basegfx::B2DVector
aOffset(
634 (double)((const SfxUInt16Item
&) (rSet
.Get(XATTR_FILLBMP_TILEOFFSETX
))).GetValue(),
635 (double)((const SfxUInt16Item
&) (rSet
.Get(XATTR_FILLBMP_TILEOFFSETY
))).GetValue());
636 const basegfx::B2DVector
aOffsetPosition(
637 (double)((const SfxUInt16Item
&) (rSet
.Get(XATTR_FILLBMP_POSOFFSETX
))).GetValue(),
638 (double)((const SfxUInt16Item
&) (rSet
.Get(XATTR_FILLBMP_POSOFFSETY
))).GetValue());
640 return attribute::SdrFillBitmapAttribute(
645 RectPointToB2DVector((RECT_POINT
)((const SfxEnumItem
&)(rSet
.Get(XATTR_FILLBMP_POS
))).GetValue()),
646 ((const SfxBoolItem
&) (rSet
.Get(XATTR_FILLBMP_TILE
))).GetValue(),
647 ((const SfxBoolItem
&) (rSet
.Get(XATTR_FILLBMP_STRETCH
))).GetValue(),
648 ((const SfxBoolItem
&) (rSet
.Get(XATTR_FILLBMP_SIZELOG
))).GetValue());
651 attribute::SdrShadowTextAttribute
createNewSdrShadowTextAttribute(
652 const SfxItemSet
& rSet
,
653 const SdrText
* pText
,
656 attribute::SdrTextAttribute aText
;
658 // #i98072# added option to suppress text
659 // look for text first
660 if(!bSuppressText
&& pText
)
662 aText
= createNewSdrTextAttribute(rSet
, *pText
);
666 const attribute::SdrShadowAttribute
aShadow(createNewSdrShadowAttribute(rSet
));
668 return attribute::SdrShadowTextAttribute(aShadow
, aText
);
671 attribute::SdrLineShadowTextAttribute
createNewSdrLineShadowTextAttribute(
672 const SfxItemSet
& rSet
,
673 const SdrText
* pText
)
675 attribute::SdrLineAttribute aLine
;
676 attribute::SdrLineStartEndAttribute aLineStartEnd
;
677 attribute::SdrTextAttribute aText
;
678 bool bFontworkHideContour(false);
680 // look for text first
683 aText
= createNewSdrTextAttribute(rSet
, *pText
);
685 // when object has text and text is fontwork and hide contour is set for fontwork, force
686 // line and fill style to empty
687 if(!aText
.isDefault()
688 && !aText
.getSdrFormTextAttribute().isDefault()
689 && aText
.isHideContour())
691 bFontworkHideContour
= true;
696 if(!bFontworkHideContour
)
698 aLine
= createNewSdrLineAttribute(rSet
);
700 if(!aLine
.isDefault())
703 aLineStartEnd
= createNewSdrLineStartEndAttribute(rSet
, aLine
.getWidth());
707 if(!aLine
.isDefault() || !aText
.isDefault())
710 const attribute::SdrShadowAttribute
aShadow(createNewSdrShadowAttribute(rSet
));
712 return attribute::SdrLineShadowTextAttribute(aLine
, aLineStartEnd
, aShadow
, aText
);
715 return attribute::SdrLineShadowTextAttribute();
718 attribute::SdrLineFillShadowTextAttribute
createNewSdrLineFillShadowTextAttribute(
719 const SfxItemSet
& rSet
,
720 const SdrText
* pText
)
722 attribute::SdrLineAttribute aLine
;
723 attribute::SdrFillAttribute aFill
;
724 attribute::SdrLineStartEndAttribute aLineStartEnd
;
725 attribute::SdrShadowAttribute aShadow
;
726 attribute::FillGradientAttribute aFillFloatTransGradient
;
727 attribute::SdrTextAttribute aText
;
728 bool bFontworkHideContour(false);
730 // look for text first
733 aText
= createNewSdrTextAttribute(rSet
, *pText
);
735 // when object has text and text is fontwork and hide contour is set for fontwork, force
736 // line and fill style to empty
737 if(!aText
.getSdrFormTextAttribute().isDefault() && aText
.isHideContour())
739 bFontworkHideContour
= true;
743 if(!bFontworkHideContour
)
746 aLine
= createNewSdrLineAttribute(rSet
);
748 if(!aLine
.isDefault())
751 aLineStartEnd
= createNewSdrLineStartEndAttribute(rSet
, aLine
.getWidth());
755 aFill
= createNewSdrFillAttribute(rSet
);
757 if(!aFill
.isDefault())
759 // try fillfloattransparence
760 aFillFloatTransGradient
= createNewTransparenceGradientAttribute(rSet
);
764 if(!aLine
.isDefault() || !aFill
.isDefault() || !aText
.isDefault())
767 aShadow
= createNewSdrShadowAttribute(rSet
);
769 return attribute::SdrLineFillShadowTextAttribute(
770 aLine
, aFill
, aLineStartEnd
, aShadow
, aFillFloatTransGradient
, aText
);
773 return attribute::SdrLineFillShadowTextAttribute();
776 attribute::SdrLineFillShadowAttribute3D
createNewSdrLineFillShadowAttribute(const SfxItemSet
& rSet
, bool bSuppressFill
)
778 attribute::SdrFillAttribute aFill
;
779 attribute::SdrLineStartEndAttribute aLineStartEnd
;
780 attribute::SdrShadowAttribute aShadow
;
781 attribute::FillGradientAttribute aFillFloatTransGradient
;
784 const attribute::SdrLineAttribute
aLine(createNewSdrLineAttribute(rSet
));
786 if(!aLine
.isDefault())
789 aLineStartEnd
= createNewSdrLineStartEndAttribute(rSet
, aLine
.getWidth());
795 aFill
= createNewSdrFillAttribute(rSet
);
797 if(!aFill
.isDefault())
799 // try fillfloattransparence
800 aFillFloatTransGradient
= createNewTransparenceGradientAttribute(rSet
);
804 if(!aLine
.isDefault() || !aFill
.isDefault())
807 aShadow
= createNewSdrShadowAttribute(rSet
);
809 return attribute::SdrLineFillShadowAttribute3D(
810 aLine
, aFill
, aLineStartEnd
, aShadow
, aFillFloatTransGradient
);
813 return attribute::SdrLineFillShadowAttribute3D();
816 attribute::SdrSceneAttribute
createNewSdrSceneAttribute(const SfxItemSet
& rSet
)
819 ::com::sun::star::drawing::ProjectionMode
aProjectionMode(::com::sun::star::drawing::ProjectionMode_PARALLEL
);
820 const sal_uInt16
nProjectionValue(((const Svx3DPerspectiveItem
&)rSet
.Get(SDRATTR_3DSCENE_PERSPECTIVE
)).GetValue());
822 if(1L == nProjectionValue
)
824 aProjectionMode
= ::com::sun::star::drawing::ProjectionMode_PERSPECTIVE
;
828 const double fDistance(((const Svx3DDistanceItem
&)rSet
.Get(SDRATTR_3DSCENE_DISTANCE
)).GetValue());
831 const double fShadowSlant(F_PI180
* ((const Svx3DShadowSlantItem
&)rSet
.Get(SDRATTR_3DSCENE_SHADOW_SLANT
)).GetValue());
834 ::com::sun::star::drawing::ShadeMode
aShadeMode(::com::sun::star::drawing::ShadeMode_FLAT
);
835 const sal_uInt16
nShadeValue(((const Svx3DShadeModeItem
&)rSet
.Get(SDRATTR_3DSCENE_SHADE_MODE
)).GetValue());
837 if(1L == nShadeValue
)
839 aShadeMode
= ::com::sun::star::drawing::ShadeMode_PHONG
;
841 else if(2L == nShadeValue
)
843 aShadeMode
= ::com::sun::star::drawing::ShadeMode_SMOOTH
;
845 else if(3L == nShadeValue
)
847 aShadeMode
= ::com::sun::star::drawing::ShadeMode_DRAFT
;
850 // get two sided lighting
851 const bool bTwoSidedLighting(((const Svx3DTwoSidedLightingItem
&)rSet
.Get(SDRATTR_3DSCENE_TWO_SIDED_LIGHTING
)).GetValue());
853 return attribute::SdrSceneAttribute(fDistance
, fShadowSlant
, aProjectionMode
, aShadeMode
, bTwoSidedLighting
);
856 attribute::SdrLightingAttribute
createNewSdrLightingAttribute(const SfxItemSet
& rSet
)
858 // extract lights from given SfxItemSet (from scene)
859 ::std::vector
< attribute::Sdr3DLightAttribute
> aLightVector
;
861 if(((const Svx3DLightOnOff1Item
&)rSet
.Get(SDRATTR_3DSCENE_LIGHTON_1
)).GetValue())
863 const basegfx::BColor
aColor(((const Svx3DLightcolor1Item
&)rSet
.Get(SDRATTR_3DSCENE_LIGHTCOLOR_1
)).GetValue().getBColor());
864 const basegfx::B3DVector
aDirection(((const Svx3DLightDirection1Item
&)rSet
.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_1
)).GetValue());
865 aLightVector
.push_back(attribute::Sdr3DLightAttribute(aColor
, aDirection
, true));
868 if(((const Svx3DLightOnOff2Item
&)rSet
.Get(SDRATTR_3DSCENE_LIGHTON_2
)).GetValue())
870 const basegfx::BColor
aColor(((const Svx3DLightcolor2Item
&)rSet
.Get(SDRATTR_3DSCENE_LIGHTCOLOR_2
)).GetValue().getBColor());
871 const basegfx::B3DVector
aDirection(((const Svx3DLightDirection2Item
&)rSet
.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_2
)).GetValue());
872 aLightVector
.push_back(attribute::Sdr3DLightAttribute(aColor
, aDirection
, false));
875 if(((const Svx3DLightOnOff3Item
&)rSet
.Get(SDRATTR_3DSCENE_LIGHTON_3
)).GetValue())
877 const basegfx::BColor
aColor(((const Svx3DLightcolor3Item
&)rSet
.Get(SDRATTR_3DSCENE_LIGHTCOLOR_3
)).GetValue().getBColor());
878 const basegfx::B3DVector
aDirection(((const Svx3DLightDirection3Item
&)rSet
.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_3
)).GetValue());
879 aLightVector
.push_back(attribute::Sdr3DLightAttribute(aColor
, aDirection
, false));
882 if(((const Svx3DLightOnOff4Item
&)rSet
.Get(SDRATTR_3DSCENE_LIGHTON_4
)).GetValue())
884 const basegfx::BColor
aColor(((const Svx3DLightcolor4Item
&)rSet
.Get(SDRATTR_3DSCENE_LIGHTCOLOR_4
)).GetValue().getBColor());
885 const basegfx::B3DVector
aDirection(((const Svx3DLightDirection4Item
&)rSet
.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_4
)).GetValue());
886 aLightVector
.push_back(attribute::Sdr3DLightAttribute(aColor
, aDirection
, false));
889 if(((const Svx3DLightOnOff5Item
&)rSet
.Get(SDRATTR_3DSCENE_LIGHTON_5
)).GetValue())
891 const basegfx::BColor
aColor(((const Svx3DLightcolor5Item
&)rSet
.Get(SDRATTR_3DSCENE_LIGHTCOLOR_5
)).GetValue().getBColor());
892 const basegfx::B3DVector
aDirection(((const Svx3DLightDirection5Item
&)rSet
.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_5
)).GetValue());
893 aLightVector
.push_back(attribute::Sdr3DLightAttribute(aColor
, aDirection
, false));
896 if(((const Svx3DLightOnOff6Item
&)rSet
.Get(SDRATTR_3DSCENE_LIGHTON_6
)).GetValue())
898 const basegfx::BColor
aColor(((const Svx3DLightcolor6Item
&)rSet
.Get(SDRATTR_3DSCENE_LIGHTCOLOR_6
)).GetValue().getBColor());
899 const basegfx::B3DVector
aDirection(((const Svx3DLightDirection6Item
&)rSet
.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_6
)).GetValue());
900 aLightVector
.push_back(attribute::Sdr3DLightAttribute(aColor
, aDirection
, false));
903 if(((const Svx3DLightOnOff7Item
&)rSet
.Get(SDRATTR_3DSCENE_LIGHTON_7
)).GetValue())
905 const basegfx::BColor
aColor(((const Svx3DLightcolor7Item
&)rSet
.Get(SDRATTR_3DSCENE_LIGHTCOLOR_7
)).GetValue().getBColor());
906 const basegfx::B3DVector
aDirection(((const Svx3DLightDirection7Item
&)rSet
.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_7
)).GetValue());
907 aLightVector
.push_back(attribute::Sdr3DLightAttribute(aColor
, aDirection
, false));
910 if(((const Svx3DLightOnOff8Item
&)rSet
.Get(SDRATTR_3DSCENE_LIGHTON_8
)).GetValue())
912 const basegfx::BColor
aColor(((const Svx3DLightcolor8Item
&)rSet
.Get(SDRATTR_3DSCENE_LIGHTCOLOR_8
)).GetValue().getBColor());
913 const basegfx::B3DVector
aDirection(((const Svx3DLightDirection8Item
&)rSet
.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_8
)).GetValue());
914 aLightVector
.push_back(attribute::Sdr3DLightAttribute(aColor
, aDirection
, false));
918 const Color
aAmbientValue(((const Svx3DAmbientcolorItem
&)rSet
.Get(SDRATTR_3DSCENE_AMBIENTCOLOR
)).GetValue());
919 const basegfx::BColor
aAmbientLight(aAmbientValue
.getBColor());
921 return attribute::SdrLightingAttribute(aAmbientLight
, aLightVector
);
924 void calculateRelativeCornerRadius(sal_Int32 nRadius
, const basegfx::B2DRange
& rObjectRange
, double& rfCornerRadiusX
, double& rfCornerRadiusY
)
926 rfCornerRadiusX
= rfCornerRadiusY
= (double)nRadius
;
928 if(0.0 != rfCornerRadiusX
)
930 const double fHalfObjectWidth(rObjectRange
.getWidth() * 0.5);
932 if(0.0 != fHalfObjectWidth
)
934 if(rfCornerRadiusX
< 0.0)
936 rfCornerRadiusX
= 0.0;
939 if(rfCornerRadiusX
> fHalfObjectWidth
)
941 rfCornerRadiusX
= fHalfObjectWidth
;
944 rfCornerRadiusX
/= fHalfObjectWidth
;
948 rfCornerRadiusX
= 0.0;
952 if(0.0 != rfCornerRadiusY
)
954 const double fHalfObjectHeight(rObjectRange
.getHeight() * 0.5);
956 if(0.0 != fHalfObjectHeight
)
958 if(rfCornerRadiusY
< 0.0)
960 rfCornerRadiusY
= 0.0;
963 if(rfCornerRadiusY
> fHalfObjectHeight
)
965 rfCornerRadiusY
= fHalfObjectHeight
;
968 rfCornerRadiusY
/= fHalfObjectHeight
;
972 rfCornerRadiusY
= 0.0;
977 // #i101508# Support handing over given text-to-border distances
978 attribute::SdrFillTextAttribute
createNewSdrFillTextAttribute(
979 const SfxItemSet
& rSet
,
980 const SdrText
* pText
,
981 const sal_Int32
* pLeft
,
982 const sal_Int32
* pUpper
,
983 const sal_Int32
* pRight
,
984 const sal_Int32
* pLower
)
986 attribute::SdrFillAttribute aFill
;
987 attribute::FillGradientAttribute aFillFloatTransGradient
;
988 attribute::SdrTextAttribute aText
;
989 bool bFontworkHideContour(false);
991 // look for text first
994 aText
= createNewSdrTextAttribute(rSet
, *pText
, pLeft
, pUpper
, pRight
, pLower
);
996 // when object has text and text is fontwork and hide contour is set for fontwork, force
997 // fill style to empty
998 if(!aText
.getSdrFormTextAttribute().isDefault() && aText
.isHideContour())
1000 bFontworkHideContour
= true;
1004 if(!bFontworkHideContour
)
1007 aFill
= createNewSdrFillAttribute(rSet
);
1009 if(!aFill
.isDefault())
1011 // try fillfloattransparence
1012 aFillFloatTransGradient
= createNewTransparenceGradientAttribute(rSet
);
1016 if(!aFill
.isDefault() || !aText
.isDefault())
1018 return attribute::SdrFillTextAttribute(aFill
, aFillFloatTransGradient
, aText
);
1021 return attribute::SdrFillTextAttribute();
1024 } // end of namespace primitive2d
1025 } // end of namespace drawinglayer
1027 //////////////////////////////////////////////////////////////////////////////
1030 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */