update dev300-m58
[ooovba.git] / svx / source / sdr / primitive2d / sdrattributecreator.cxx
blob710df06598ae94d4b6c96ae52465426d4ec53ba8
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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>
80 //////////////////////////////////////////////////////////////////////////////
82 namespace drawinglayer
84 namespace
86 attribute::GradientStyle XGradientStyleToGradientStyle(XGradientStyle eStyle)
88 switch(eStyle)
90 case XGRAD_LINEAR :
92 return attribute::GRADIENTSTYLE_LINEAR;
94 case XGRAD_AXIAL :
96 return attribute::GRADIENTSTYLE_AXIAL;
98 case XGRAD_RADIAL :
100 return attribute::GRADIENTSTYLE_RADIAL;
102 case XGRAD_ELLIPTICAL :
104 return attribute::GRADIENTSTYLE_ELLIPTICAL;
106 case XGRAD_SQUARE :
108 return attribute::GRADIENTSTYLE_SQUARE;
110 default :
112 return attribute::GRADIENTSTYLE_RECT; // XGRAD_RECT
117 attribute::HatchStyle XHatchStyleToHatchStyle(XHatchStyle eStyle)
119 switch(eStyle)
121 case XHATCH_SINGLE :
123 return attribute::HATCHSTYLE_SINGLE;
125 case XHATCH_DOUBLE :
127 return attribute::HATCHSTYLE_DOUBLE;
129 default :
131 return attribute::HATCHSTYLE_TRIPLE; // XHATCH_TRIPLE
136 basegfx::B2DLineJoin XLineJointtoB2DLineJoin(XLineJoint eLineJoint)
138 switch(eLineJoint)
140 case XLINEJOINT_MIDDLE :
142 return basegfx::B2DLINEJOIN_MIDDLE;
144 case XLINEJOINT_BEVEL :
146 return basegfx::B2DLINEJOIN_BEVEL;
148 case XLINEJOINT_MITER :
150 return basegfx::B2DLINEJOIN_MITER;
152 case XLINEJOINT_ROUND :
154 return basegfx::B2DLINEJOIN_ROUND;
156 default :
158 return basegfx::B2DLINEJOIN_NONE; // XLINEJOINT_NONE
163 basegfx::B2DVector RectPointToB2DVector(RECT_POINT eRectPoint)
165 basegfx::B2DVector aRetval(0.0, 0.0);
167 // position changes X
168 switch(eRectPoint)
170 case RP_LT: case RP_LM: case RP_LB:
172 aRetval.setX(-1.0);
173 break;
176 case RP_RT: case RP_RM: case RP_RB:
178 aRetval.setX(1.0);
179 break;
182 default :
184 break;
188 // position changes Y
189 switch(eRectPoint)
191 case RP_LT: case RP_MT: case RP_RT:
193 aRetval.setY(-1.0);
194 break;
197 case RP_LB: case RP_MB: case RP_RB:
199 aRetval.setY(1.0);
200 break;
203 default :
205 break;
209 return aRetval;
211 } // end of anonymous namespace
212 } // end of namespace drawinglayer
214 //////////////////////////////////////////////////////////////////////////////
216 namespace drawinglayer
218 namespace primitive2d
220 attribute::SdrLineAttribute* createNewSdrLineAttribute(const SfxItemSet& rSet)
222 attribute::SdrLineAttribute* pRetval(0L);
223 const XLineStyle eStyle(((XLineStyleItem&)(rSet.Get(XATTR_LINESTYLE))).GetValue());
225 if(XLINE_NONE != eStyle)
227 sal_uInt16 nTransparence(((const XLineTransparenceItem&)(rSet.Get(XATTR_LINETRANSPARENCE))).GetValue());
229 if(nTransparence > 100)
231 nTransparence = 100;
234 if(100 != nTransparence)
236 const sal_uInt32 nWidth(((const XLineWidthItem&)(rSet.Get(XATTR_LINEWIDTH))).GetValue());
237 const Color aColor(((const XLineColorItem&)(rSet.Get(XATTR_LINECOLOR))).GetColorValue());
238 const XLineJoint eJoint(((const XLineJointItem&)(rSet.Get(XATTR_LINEJOINT))).GetValue());
239 ::std::vector< double > aDotDashArray;
240 double fFullDotDashLen(0.0);
242 if(XLINE_DASH == eStyle)
244 const XDash& rDash = ((const XLineDashItem&)(rSet.Get(XATTR_LINEDASH))).GetDashValue();
246 if(rDash.GetDots() || rDash.GetDashes())
248 fFullDotDashLen = rDash.CreateDotDashArray(aDotDashArray, (double)nWidth);
252 pRetval = new attribute::SdrLineAttribute(
253 XLineJointtoB2DLineJoin(eJoint),
254 (double)nWidth,
255 (double)nTransparence * 0.01,
256 aColor.getBColor(),
257 aDotDashArray,
258 fFullDotDashLen);
262 return pRetval;
265 attribute::SdrLineStartEndAttribute* createNewSdrLineStartEndAttribute(const SfxItemSet& rSet, double fWidth)
267 attribute::SdrLineStartEndAttribute* pRetval(0L);
268 const sal_Int32 nTempStartWidth(((const XLineStartWidthItem&)(rSet.Get(XATTR_LINESTARTWIDTH))).GetValue());
269 const sal_Int32 nTempEndWidth(((const XLineEndWidthItem&)(rSet.Get(XATTR_LINEENDWIDTH))).GetValue());
270 basegfx::B2DPolyPolygon aStartPolyPolygon;
271 basegfx::B2DPolyPolygon aEndPolyPolygon;
272 double fStartWidth(0.0);
273 double fEndWidth(0.0);
274 bool bStartActive(false);
275 bool bEndActive(false);
276 bool bStartCentered(true);
277 bool bEndCentered(true);
279 if(nTempStartWidth)
281 if(nTempStartWidth < 0L)
283 fStartWidth = ((double)(-nTempStartWidth) * fWidth) * 0.01;
285 else
287 fStartWidth = (double)nTempStartWidth;
290 if(0.0 != fStartWidth)
292 aStartPolyPolygon = basegfx::B2DPolyPolygon(((const XLineStartItem&)(rSet.Get(XATTR_LINESTART))).GetLineStartValue());
294 if(aStartPolyPolygon.count() && aStartPolyPolygon.getB2DPolygon(0L).count())
296 bStartActive = true;
297 bStartCentered = ((const XLineStartCenterItem&)(rSet.Get(XATTR_LINESTARTCENTER))).GetValue();
302 if(nTempEndWidth)
304 if(nTempEndWidth < 0L)
306 fEndWidth = ((double)(-nTempEndWidth) * fWidth) * 0.01;
308 else
310 fEndWidth = (double)nTempEndWidth;
313 if(0.0 != fEndWidth)
315 aEndPolyPolygon = basegfx::B2DPolyPolygon(((const XLineEndItem&)(rSet.Get(XATTR_LINEEND))).GetLineEndValue());
317 if(aEndPolyPolygon.count() && aEndPolyPolygon.getB2DPolygon(0L).count())
319 bEndActive = true;
320 bEndCentered = ((const XLineEndCenterItem&)(rSet.Get(XATTR_LINEENDCENTER))).GetValue();
325 if(bStartActive || bEndActive)
327 pRetval = new attribute::SdrLineStartEndAttribute(aStartPolyPolygon, aEndPolyPolygon, fStartWidth, fEndWidth, bStartActive, bEndActive, bStartCentered, bEndCentered);
330 return pRetval;
333 attribute::SdrShadowAttribute* createNewSdrShadowAttribute(const SfxItemSet& rSet)
335 attribute::SdrShadowAttribute* pRetval(0L);
336 const bool bShadow(((SdrShadowItem&)rSet.Get(SDRATTR_SHADOW)).GetValue());
338 if(bShadow)
340 sal_uInt16 nTransparence(((SdrShadowTransparenceItem&)(rSet.Get(SDRATTR_SHADOWTRANSPARENCE))).GetValue());
342 if(nTransparence > 100)
344 nTransparence = 100;
347 if(nTransparence)
349 sal_uInt16 nFillTransparence(((const XFillTransparenceItem&)(rSet.Get(XATTR_FILLTRANSPARENCE))).GetValue());
351 if(nFillTransparence > 100)
353 nFillTransparence = 100;
356 if(nTransparence == nFillTransparence)
358 // shadow does not really have an own transparence, but the application
359 // sets the shadow transparence equal to the object transparence for
360 // convenience. This is not useful for primitive creation, so take
361 // this as no shadow transparence
362 nTransparence = 0;
366 if(100 != nTransparence)
368 const basegfx::B2DVector aOffset(
369 (double)((SdrShadowXDistItem&)(rSet.Get(SDRATTR_SHADOWXDIST))).GetValue(),
370 (double)((SdrShadowYDistItem&)(rSet.Get(SDRATTR_SHADOWYDIST))).GetValue());
371 const Color aColor(((SdrShadowColorItem&)(rSet.Get(SDRATTR_SHADOWCOLOR))).GetColorValue());
373 pRetval = new attribute::SdrShadowAttribute(aOffset, (double)nTransparence * 0.01, aColor.getBColor());
377 return pRetval;
380 attribute::SdrFillAttribute* createNewSdrFillAttribute(const SfxItemSet& rSet)
382 attribute::SdrFillAttribute* pRetval(0L);
383 const XFillStyle eStyle(((XFillStyleItem&)(rSet.Get(XATTR_FILLSTYLE))).GetValue());
385 if(XFILL_NONE != eStyle)
387 sal_uInt16 nTransparence(((const XFillTransparenceItem&)(rSet.Get(XATTR_FILLTRANSPARENCE))).GetValue());
389 if(nTransparence > 100)
391 nTransparence = 100;
394 if(100 != nTransparence)
396 const Color aColor(((const XFillColorItem&)(rSet.Get(XATTR_FILLCOLOR))).GetColorValue());
397 attribute::FillGradientAttribute* pGradient(0L);
398 attribute::FillHatchAttribute* pHatch(0L);
399 attribute::SdrFillBitmapAttribute* pBitmap(0L);
401 switch(eStyle)
403 case XFILL_NONE : // for warnings
404 case XFILL_SOLID :
406 // nothing to do, color is defined
407 break;
409 case XFILL_GRADIENT :
411 XGradient aGradient(((XFillGradientItem&)(rSet.Get(XATTR_FILLGRADIENT))).GetGradientValue());
413 const Color aStartColor(aGradient.GetStartColor());
414 const sal_uInt16 nStartIntens(aGradient.GetStartIntens());
415 basegfx::BColor aStart(aStartColor.getBColor());
417 if(nStartIntens != 100)
419 const basegfx::BColor aBlack;
420 aStart = interpolate(aBlack, aStart, (double)nStartIntens * 0.01);
423 const Color aEndColor(aGradient.GetEndColor());
424 const sal_uInt16 nEndIntens(aGradient.GetEndIntens());
425 basegfx::BColor aEnd(aEndColor.getBColor());
427 if(nEndIntens != 100)
429 const basegfx::BColor aBlack;
430 aEnd = interpolate(aBlack, aEnd, (double)nEndIntens * 0.01);
433 pGradient = new attribute::FillGradientAttribute(
434 XGradientStyleToGradientStyle(aGradient.GetGradientStyle()),
435 (double)aGradient.GetBorder() * 0.01,
436 (double)aGradient.GetXOffset() * 0.01,
437 (double)aGradient.GetYOffset() * 0.01,
438 (double)aGradient.GetAngle() * F_PI1800,
439 aStart,
440 aEnd,
441 ((const XGradientStepCountItem&)rSet.Get(XATTR_GRADIENTSTEPCOUNT)).GetValue());
443 break;
445 case XFILL_HATCH :
447 const XHatch& rHatch(((XFillHatchItem&)(rSet.Get(XATTR_FILLHATCH))).GetHatchValue());
448 const Color aColorB(rHatch.GetColor());
450 pHatch = new attribute::FillHatchAttribute(
451 XHatchStyleToHatchStyle(rHatch.GetHatchStyle()),
452 (double)rHatch.GetDistance(),
453 (double)rHatch.GetAngle() * F_PI1800,
454 aColorB.getBColor(),
455 ((const XFillBackgroundItem&)(rSet.Get(XATTR_FILLBACKGROUND))).GetValue());
457 break;
459 case XFILL_BITMAP :
461 pBitmap = createNewSdrFillBitmapAttribute(rSet);
462 break;
466 pRetval = new attribute::SdrFillAttribute(
467 (double)nTransparence * 0.01,
468 aColor.getBColor(),
469 pGradient, pHatch, pBitmap);
473 return pRetval;
476 // #i101508# Support handing over given text-to-border distances
477 attribute::SdrTextAttribute* createNewSdrTextAttribute(
478 const SfxItemSet& rSet,
479 const SdrText& rText,
480 const sal_Int32* pLeft,
481 const sal_Int32* pUpper,
482 const sal_Int32* pRight,
483 const sal_Int32* pLower)
485 attribute::SdrTextAttribute* pRetval(0);
486 const SdrTextObj& rTextObj = rText.GetObject();
488 if(rText.GetOutlinerParaObject() && rText.GetModel())
490 // added TextEdit text suppression
491 bool bInEditMode(false);
493 if(rText.GetObject().getTextCount() > 1)
495 bInEditMode = rTextObj.IsInEditMode() && rText.GetObject().getActiveText() == &rText;
497 else
499 bInEditMode = rTextObj.IsInEditMode();
502 OutlinerParaObject aOutlinerParaObject(*rText.GetOutlinerParaObject());
504 if(bInEditMode)
506 OutlinerParaObject* pTempObj = rTextObj.GetEditOutlinerParaObject();
508 if(pTempObj)
510 aOutlinerParaObject = *pTempObj;
511 delete pTempObj;
513 else
515 // #i100537#
516 // GetEditOutlinerParaObject() returning no object does not mean that
517 // text edit mode is not active. Do not reset the flag here
518 // bInEditMode = false;
522 const SdrFitToSizeType eFit = rTextObj.GetFitToSize();
523 const SdrTextAniKind eAniKind(rTextObj.GetTextAniKind());
525 pRetval = new attribute::SdrTextAttribute(
526 rText,
527 aOutlinerParaObject,
528 ((const XFormTextStyleItem&)rSet.Get(XATTR_FORMTXTSTYLE)).GetValue(),
529 pLeft ? *pLeft : rTextObj.GetTextLeftDistance(),
530 pUpper ? *pUpper : rTextObj.GetTextUpperDistance(),
531 pRight ? *pRight : rTextObj.GetTextRightDistance(),
532 pLower ? *pLower : rTextObj.GetTextLowerDistance(),
533 ((const SdrTextContourFrameItem&)rSet.Get(SDRATTR_TEXT_CONTOURFRAME)).GetValue(),
534 rTextObj.IsFitToSize(),
535 rTextObj.IsAutoFit(),
536 ((const XFormTextHideFormItem&)rSet.Get(XATTR_FORMTXTHIDEFORM)).GetValue(),
537 SDRTEXTANI_BLINK == eAniKind,
538 SDRTEXTANI_SCROLL == eAniKind || SDRTEXTANI_ALTERNATE == eAniKind || SDRTEXTANI_SLIDE == eAniKind,
539 bInEditMode);
542 return pRetval;
545 attribute::FillGradientAttribute* createNewTransparenceGradientAttribute(const SfxItemSet& rSet)
547 attribute::FillGradientAttribute* pRetval = 0L;
548 const SfxPoolItem* pGradientItem;
550 if(SFX_ITEM_SET == rSet.GetItemState(XATTR_FILLFLOATTRANSPARENCE, TRUE, &pGradientItem) && ((XFillFloatTransparenceItem*)pGradientItem)->IsEnabled())
552 // test if float transparence is completely transparent
553 const XGradient& rGradient = ((XFillFloatTransparenceItem*)pGradientItem)->GetGradientValue();
554 const sal_uInt8 nStartLuminance(rGradient.GetStartColor().GetLuminance());
555 const sal_uInt8 nEndLuminance(rGradient.GetEndColor().GetLuminance());
556 const bool bCompletelyTransparent(0xff == nStartLuminance && 0xff == nEndLuminance);
558 if(!bCompletelyTransparent)
560 const double fStartLum(nStartLuminance / 255.0);
561 const double fEndLum(nEndLuminance / 255.0);
563 pRetval = new attribute::FillGradientAttribute(
564 XGradientStyleToGradientStyle(rGradient.GetGradientStyle()),
565 (double)rGradient.GetBorder() * 0.01,
566 (double)rGradient.GetXOffset() * 0.01,
567 (double)rGradient.GetYOffset() * 0.01,
568 (double)rGradient.GetAngle() * F_PI1800,
569 basegfx::BColor(fStartLum, fStartLum, fStartLum),
570 basegfx::BColor(fEndLum, fEndLum, fEndLum),
575 return pRetval;
578 attribute::SdrFillBitmapAttribute* createNewSdrFillBitmapAttribute(const SfxItemSet& rSet)
580 attribute::SdrFillBitmapAttribute* pRetval(0L);
581 Bitmap aBitmap((((const XFillBitmapItem&)(rSet.Get(XATTR_FILLBITMAP))).GetBitmapValue()).GetBitmap());
583 // make sure it's not empty, use default instead
584 if(aBitmap.IsEmpty())
586 aBitmap = Bitmap(Size(4,4), 8);
589 // if there is no logical size, create a size from pixel size and set MapMode accordingly
590 if(0L == aBitmap.GetPrefSize().Width() || 0L == aBitmap.GetPrefSize().Height())
592 aBitmap.SetPrefSize(aBitmap.GetSizePixel());
593 aBitmap.SetPrefMapMode(MAP_PIXEL);
596 // convert size and MapMode to destination logical size and MapMode. The created
597 // bitmap must have a valid logical size (PrefSize)
598 const MapUnit aDestinationMapUnit((MapUnit)rSet.GetPool()->GetMetric(0));
600 if(aBitmap.GetPrefMapMode() != aDestinationMapUnit)
602 // #i100360# for MAP_PIXEL, LogicToLogic will not work properly,
603 // so fallback to Application::GetDefaultDevice()
604 if(MAP_PIXEL == aBitmap.GetPrefMapMode().GetMapUnit())
606 aBitmap.SetPrefSize(Application::GetDefaultDevice()->PixelToLogic(
607 aBitmap.GetPrefSize(), aDestinationMapUnit));
609 else
611 aBitmap.SetPrefSize(OutputDevice::LogicToLogic(
612 aBitmap.GetPrefSize(), aBitmap.GetPrefMapMode(), aDestinationMapUnit));
616 // get size
617 const basegfx::B2DVector aSize(
618 (double)((const SfxMetricItem&)(rSet.Get(XATTR_FILLBMP_SIZEX))).GetValue(),
619 (double)((const SfxMetricItem&)(rSet.Get(XATTR_FILLBMP_SIZEY))).GetValue());
620 const basegfx::B2DVector aOffset(
621 (double)((const SfxUInt16Item&) (rSet.Get(XATTR_FILLBMP_TILEOFFSETX))).GetValue(),
622 (double)((const SfxUInt16Item&) (rSet.Get(XATTR_FILLBMP_TILEOFFSETY))).GetValue());
623 const basegfx::B2DVector aOffsetPosition(
624 (double)((const SfxUInt16Item&) (rSet.Get(XATTR_FILLBMP_POSOFFSETX))).GetValue(),
625 (double)((const SfxUInt16Item&) (rSet.Get(XATTR_FILLBMP_POSOFFSETY))).GetValue());
627 pRetval = new attribute::SdrFillBitmapAttribute(
628 aBitmap,
629 aSize,
630 aOffset,
631 aOffsetPosition,
632 RectPointToB2DVector((RECT_POINT)((const SfxEnumItem&)(rSet.Get(XATTR_FILLBMP_POS))).GetValue()),
633 ((const SfxBoolItem&) (rSet.Get(XATTR_FILLBMP_TILE))).GetValue(),
634 ((const SfxBoolItem&) (rSet.Get(XATTR_FILLBMP_STRETCH))).GetValue(),
635 ((const SfxBoolItem&) (rSet.Get(XATTR_FILLBMP_SIZELOG))).GetValue());
637 return pRetval;
640 attribute::SdrShadowTextAttribute* createNewSdrShadowTextAttribute(const SfxItemSet& rSet, const SdrText& rText, bool bSuppressText)
642 attribute::SdrShadowTextAttribute* pRetval(0L);
643 attribute::SdrShadowAttribute* pShadow(0L);
644 attribute::SdrTextAttribute* pText(0L);
646 // #i98072# added option to suppress text
647 // look for text first
648 if(!bSuppressText)
650 pText = createNewSdrTextAttribute(rSet, rText);
653 // try shadow
654 pShadow = createNewSdrShadowAttribute(rSet);
656 if(pShadow && !pShadow->isVisible())
658 delete pShadow;
659 pShadow = 0L;
662 if(pText || pShadow)
664 pRetval = new attribute::SdrShadowTextAttribute(pShadow, pText);
667 return pRetval;
670 attribute::SdrLineShadowTextAttribute* createNewSdrLineShadowTextAttribute(const SfxItemSet& rSet, const SdrText& rText)
672 attribute::SdrLineShadowTextAttribute* pRetval(0L);
673 attribute::SdrLineAttribute* pLine(0L);
674 attribute::SdrLineStartEndAttribute* pLineStartEnd(0L);
675 attribute::SdrShadowAttribute* pShadow(0L);
676 attribute::SdrTextAttribute* pText(0L);
677 bool bFontworkHideContour(false);
679 // look for text first
680 pText = createNewSdrTextAttribute(rSet, rText);
682 // when object has text and text is fontwork and hide contour is set for fontwork, force
683 // line and fill style to empty
684 if(pText && pText->getSdrFormTextAttribute() && pText->isHideContour())
686 bFontworkHideContour = true;
689 // try line style
690 if(!bFontworkHideContour)
692 pLine = createNewSdrLineAttribute(rSet);
694 if(pLine && !pLine->isVisible())
696 delete pLine;
697 pLine = 0L;
700 if(pLine)
702 // try LineStartEnd
703 pLineStartEnd = createNewSdrLineStartEndAttribute(rSet, pLine->getWidth());
705 if(pLineStartEnd && !pLineStartEnd->isVisible())
707 delete pLineStartEnd;
708 pLineStartEnd = 0L;
713 // try shadow
714 if(pLine || pText)
716 pShadow = createNewSdrShadowAttribute(rSet);
718 if(pShadow && !pShadow->isVisible())
720 delete pShadow;
721 pShadow = 0L;
725 if(pLine || pText)
727 pRetval = new attribute::SdrLineShadowTextAttribute(pLine, pLineStartEnd, pShadow, pText);
730 return pRetval;
733 attribute::SdrLineFillShadowTextAttribute* createNewSdrLineFillShadowTextAttribute(const SfxItemSet& rSet, const SdrText& rText)
735 attribute::SdrLineFillShadowTextAttribute* pRetval(0L);
736 attribute::SdrLineAttribute* pLine(0L);
737 attribute::SdrFillAttribute* pFill(0L);
738 attribute::SdrLineStartEndAttribute* pLineStartEnd(0L);
739 attribute::SdrShadowAttribute* pShadow(0L);
740 attribute::FillGradientAttribute* pFillFloatTransGradient(0L);
741 attribute::SdrTextAttribute* pText(0L);
742 bool bFontworkHideContour(false);
744 // look for text first
745 pText = createNewSdrTextAttribute(rSet, rText);
747 // when object has text and text is fontwork and hide contour is set for fontwork, force
748 // line and fill style to empty
749 if(pText && pText->getSdrFormTextAttribute() && pText->isHideContour())
751 bFontworkHideContour = true;
754 // try line style
755 if(!bFontworkHideContour)
757 pLine = createNewSdrLineAttribute(rSet);
759 if(pLine && !pLine->isVisible())
761 delete pLine;
762 pLine = 0L;
765 if(pLine)
767 // try LineStartEnd
768 pLineStartEnd = createNewSdrLineStartEndAttribute(rSet, pLine->getWidth());
770 if(pLineStartEnd && !pLineStartEnd->isVisible())
772 delete pLineStartEnd;
773 pLineStartEnd = 0L;
778 // try fill style
779 if(!bFontworkHideContour)
781 pFill = createNewSdrFillAttribute(rSet);
783 if(pFill && !pFill->isVisible())
785 delete pFill;
786 pFill = 0L;
789 if(pFill)
791 // try fillfloattransparence
792 pFillFloatTransGradient = createNewTransparenceGradientAttribute(rSet);
796 // try shadow
797 if(pLine || pFill || pText)
799 pShadow = createNewSdrShadowAttribute(rSet);
801 if(pShadow && !pShadow->isVisible())
803 delete pShadow;
804 pShadow = 0L;
808 if(pLine || pFill || pText)
810 pRetval = new attribute::SdrLineFillShadowTextAttribute(pLine, pFill, pLineStartEnd, pShadow, pFillFloatTransGradient, pText);
813 return pRetval;
816 attribute::SdrLineFillShadowAttribute* createNewSdrLineFillShadowAttribute(const SfxItemSet& rSet, bool bSuppressFill)
818 attribute::SdrLineFillShadowAttribute* pRetval(0L);
819 attribute::SdrLineAttribute* pLine(0L);
820 attribute::SdrFillAttribute* pFill(0L);
821 attribute::SdrLineStartEndAttribute* pLineStartEnd(0L);
822 attribute::SdrShadowAttribute* pShadow(0L);
823 attribute::FillGradientAttribute* pFillFloatTransGradient(0L);
825 // try line style
826 pLine = createNewSdrLineAttribute(rSet);
828 if(pLine && !pLine->isVisible())
830 delete pLine;
831 pLine = 0L;
834 if(pLine)
836 // try LineStartEnd
837 pLineStartEnd = createNewSdrLineStartEndAttribute(rSet, pLine->getWidth());
839 if(pLineStartEnd && !pLineStartEnd->isVisible())
841 delete pLineStartEnd;
842 pLineStartEnd = 0L;
846 // try fill style
847 pFill = bSuppressFill ? 0 : createNewSdrFillAttribute(rSet);
849 if(pFill && !pFill->isVisible())
851 delete pFill;
852 pFill = 0L;
855 if(pFill)
857 // try fillfloattransparence
858 pFillFloatTransGradient = createNewTransparenceGradientAttribute(rSet);
861 // try shadow
862 if(pLine || pFill)
864 pShadow = createNewSdrShadowAttribute(rSet);
866 if(pShadow && !pShadow->isVisible())
868 delete pShadow;
869 pShadow = 0L;
873 if(pLine || pFill)
875 pRetval = new attribute::SdrLineFillShadowAttribute(pLine, pFill, pLineStartEnd, pShadow, pFillFloatTransGradient);
878 return pRetval;
881 attribute::SdrSceneAttribute* createNewSdrSceneAttribute(const SfxItemSet& rSet)
883 // get perspective
884 ::com::sun::star::drawing::ProjectionMode aProjectionMode(::com::sun::star::drawing::ProjectionMode_PARALLEL);
885 const sal_uInt16 nProjectionValue(((const Svx3DPerspectiveItem&)rSet.Get(SDRATTR_3DSCENE_PERSPECTIVE)).GetValue());
887 if(1L == nProjectionValue)
889 aProjectionMode = ::com::sun::star::drawing::ProjectionMode_PERSPECTIVE;
892 // get distance
893 const double fDistance(((const Svx3DDistanceItem&)rSet.Get(SDRATTR_3DSCENE_DISTANCE)).GetValue());
895 // get shadow slant
896 const double fShadowSlant(F_PI180 * ((const Svx3DShadowSlantItem&)rSet.Get(SDRATTR_3DSCENE_SHADOW_SLANT)).GetValue());
898 // get shade mode
899 ::com::sun::star::drawing::ShadeMode aShadeMode(::com::sun::star::drawing::ShadeMode_FLAT);
900 const sal_uInt16 nShadeValue(((const Svx3DShadeModeItem&)rSet.Get(SDRATTR_3DSCENE_SHADE_MODE)).GetValue());
902 if(1L == nShadeValue)
904 aShadeMode = ::com::sun::star::drawing::ShadeMode_PHONG;
906 else if(2L == nShadeValue)
908 aShadeMode = ::com::sun::star::drawing::ShadeMode_SMOOTH;
910 else if(3L == nShadeValue)
912 aShadeMode = ::com::sun::star::drawing::ShadeMode_DRAFT;
915 // get two sided lighting
916 const bool bTwoSidedLighting(((const Svx3DTwoSidedLightingItem&)rSet.Get(SDRATTR_3DSCENE_TWO_SIDED_LIGHTING)).GetValue());
918 return new attribute::SdrSceneAttribute(fDistance, fShadowSlant, aProjectionMode, aShadeMode, bTwoSidedLighting);
921 attribute::SdrLightingAttribute* createNewSdrLightingAttribute(const SfxItemSet& rSet)
923 // extract lights from given SfxItemSet (from scene)
924 ::std::vector< attribute::Sdr3DLightAttribute > aLightVector;
926 if(((const Svx3DLightOnOff1Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTON_1)).GetValue())
928 const basegfx::BColor aColor(((const Svx3DLightcolor1Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTCOLOR_1)).GetValue().getBColor());
929 const basegfx::B3DVector aDirection(((const Svx3DLightDirection1Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_1)).GetValue());
930 aLightVector.push_back(attribute::Sdr3DLightAttribute(aColor, aDirection, true));
933 if(((const Svx3DLightOnOff2Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTON_2)).GetValue())
935 const basegfx::BColor aColor(((const Svx3DLightcolor2Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTCOLOR_2)).GetValue().getBColor());
936 const basegfx::B3DVector aDirection(((const Svx3DLightDirection2Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_2)).GetValue());
937 aLightVector.push_back(attribute::Sdr3DLightAttribute(aColor, aDirection, false));
940 if(((const Svx3DLightOnOff3Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTON_3)).GetValue())
942 const basegfx::BColor aColor(((const Svx3DLightcolor3Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTCOLOR_3)).GetValue().getBColor());
943 const basegfx::B3DVector aDirection(((const Svx3DLightDirection3Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_3)).GetValue());
944 aLightVector.push_back(attribute::Sdr3DLightAttribute(aColor, aDirection, false));
947 if(((const Svx3DLightOnOff4Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTON_4)).GetValue())
949 const basegfx::BColor aColor(((const Svx3DLightcolor4Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTCOLOR_4)).GetValue().getBColor());
950 const basegfx::B3DVector aDirection(((const Svx3DLightDirection4Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_4)).GetValue());
951 aLightVector.push_back(attribute::Sdr3DLightAttribute(aColor, aDirection, false));
954 if(((const Svx3DLightOnOff5Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTON_5)).GetValue())
956 const basegfx::BColor aColor(((const Svx3DLightcolor5Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTCOLOR_5)).GetValue().getBColor());
957 const basegfx::B3DVector aDirection(((const Svx3DLightDirection5Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_5)).GetValue());
958 aLightVector.push_back(attribute::Sdr3DLightAttribute(aColor, aDirection, false));
961 if(((const Svx3DLightOnOff6Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTON_6)).GetValue())
963 const basegfx::BColor aColor(((const Svx3DLightcolor6Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTCOLOR_6)).GetValue().getBColor());
964 const basegfx::B3DVector aDirection(((const Svx3DLightDirection6Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_6)).GetValue());
965 aLightVector.push_back(attribute::Sdr3DLightAttribute(aColor, aDirection, false));
968 if(((const Svx3DLightOnOff7Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTON_7)).GetValue())
970 const basegfx::BColor aColor(((const Svx3DLightcolor7Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTCOLOR_7)).GetValue().getBColor());
971 const basegfx::B3DVector aDirection(((const Svx3DLightDirection7Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_7)).GetValue());
972 aLightVector.push_back(attribute::Sdr3DLightAttribute(aColor, aDirection, false));
975 if(((const Svx3DLightOnOff8Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTON_8)).GetValue())
977 const basegfx::BColor aColor(((const Svx3DLightcolor8Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTCOLOR_8)).GetValue().getBColor());
978 const basegfx::B3DVector aDirection(((const Svx3DLightDirection8Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_8)).GetValue());
979 aLightVector.push_back(attribute::Sdr3DLightAttribute(aColor, aDirection, false));
982 // get ambient color
983 const Color aAmbientValue(((const Svx3DAmbientcolorItem&)rSet.Get(SDRATTR_3DSCENE_AMBIENTCOLOR)).GetValue());
984 const basegfx::BColor aAmbientLight(aAmbientValue.getBColor());
986 return new attribute::SdrLightingAttribute(aAmbientLight, aLightVector);
989 void calculateRelativeCornerRadius(sal_Int32 nRadius, const basegfx::B2DRange& rObjectRange, double& rfCornerRadiusX, double& rfCornerRadiusY)
991 rfCornerRadiusX = rfCornerRadiusY = (double)nRadius;
993 if(0.0 != rfCornerRadiusX)
995 const double fHalfObjectWidth(rObjectRange.getWidth() * 0.5);
997 if(0.0 != fHalfObjectWidth)
999 if(rfCornerRadiusX < 0.0)
1001 rfCornerRadiusX = 0.0;
1004 if(rfCornerRadiusX > fHalfObjectWidth)
1006 rfCornerRadiusX = fHalfObjectWidth;
1009 rfCornerRadiusX /= fHalfObjectWidth;
1011 else
1013 rfCornerRadiusX = 0.0;
1017 if(0.0 != rfCornerRadiusY)
1019 const double fHalfObjectHeight(rObjectRange.getHeight() * 0.5);
1021 if(0.0 != fHalfObjectHeight)
1023 if(rfCornerRadiusY < 0.0)
1025 rfCornerRadiusY = 0.0;
1028 if(rfCornerRadiusY > fHalfObjectHeight)
1030 rfCornerRadiusY = fHalfObjectHeight;
1033 rfCornerRadiusY /= fHalfObjectHeight;
1035 else
1037 rfCornerRadiusY = 0.0;
1042 // #i101508# Support handing over given text-to-border distances
1043 attribute::SdrFillTextAttribute* createNewSdrFillTextAttribute(
1044 const SfxItemSet& rSet,
1045 const SdrText* pSdrText,
1046 const sal_Int32* pLeft,
1047 const sal_Int32* pUpper,
1048 const sal_Int32* pRight,
1049 const sal_Int32* pLower)
1051 attribute::SdrFillTextAttribute* pRetval(0L);
1052 attribute::SdrFillAttribute* pFill(0L);
1053 attribute::FillGradientAttribute* pFillFloatTransGradient(0L);
1054 attribute::SdrTextAttribute* pText(0L);
1055 bool bFontworkHideContour(false);
1057 // look for text first
1058 if(pSdrText)
1060 pText = createNewSdrTextAttribute(rSet, *pSdrText, pLeft, pUpper, pRight, pLower);
1063 // when object has text and text is fontwork and hide contour is set for fontwork, force
1064 // fill style to empty
1065 if(pText && pText->getSdrFormTextAttribute() && pText->isHideContour())
1067 bFontworkHideContour = true;
1070 // try fill style
1071 if(!bFontworkHideContour)
1073 pFill = createNewSdrFillAttribute(rSet);
1075 if(pFill && !pFill->isVisible())
1077 delete pFill;
1078 pFill = 0L;
1081 if(pFill)
1083 // try fillfloattransparence
1084 pFillFloatTransGradient = createNewTransparenceGradientAttribute(rSet);
1088 if(pFill || pText)
1090 pRetval = new attribute::SdrFillTextAttribute(pFill, pFillFloatTransGradient, pText);
1093 return pRetval;
1096 } // end of namespace primitive2d
1097 } // end of namespace drawinglayer
1099 //////////////////////////////////////////////////////////////////////////////
1100 // eof