bump product version to 4.1.6.2
[LibreOffice.git] / svx / source / sdr / primitive2d / sdrattributecreator.cxx
bloba6fd57358534e09211081c1c810c2110f89dc31c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <svx/sdr/primitive2d/sdrattributecreator.hxx>
21 #include <svl/itemset.hxx>
22 #include <svx/xdef.hxx>
23 #include <basegfx/polygon/b2dpolygon.hxx>
24 #include <svx/xlineit0.hxx>
25 #include <svx/xfillit0.hxx>
26 #include <svx/xlntrit.hxx>
27 #include <svx/xlnwtit.hxx>
28 #include <svx/xlinjoit.hxx>
29 #include <svx/xlncapit.hxx>
30 #include <svx/xlnclit.hxx>
31 #include <svx/xlnstwit.hxx>
32 #include <svx/xlnedwit.hxx>
33 #include <svx/xlnstit.hxx>
34 #include <svx/xlnstcit.hxx>
35 #include <svx/xlnedit.hxx>
36 #include <svx/xlnedcit.hxx>
37 #include <svx/xdash.hxx>
38 #include <svx/xlndsit.hxx>
39 #include <svx/xfltrit.hxx>
40 #include <svx/xflftrit.hxx>
41 #include <svx/xflclit.hxx>
42 #include <svx/xgrscit.hxx>
43 #include <svx/xflhtit.hxx>
44 #include <svx/xflbckit.hxx>
45 #include <svx/sdshitm.hxx>
46 #include <svx/sdsxyitm.hxx>
47 #include <svx/sdshcitm.hxx>
48 #include <svx/sdshtitm.hxx>
49 #include <drawinglayer/attribute/sdrfillbitmapattribute.hxx>
50 #include <basegfx/polygon/b2dlinegeometry.hxx>
51 #include <svx/svdotext.hxx>
52 #include <drawinglayer/attribute/fillbitmapattribute.hxx>
53 #include <svx/sdr/attribute/sdrtextattribute.hxx>
54 #include <svx/xbtmpit.hxx>
55 #include <svl/itempool.hxx>
56 #include <vcl/svapp.hxx>
57 #include <basegfx/range/b2drange.hxx>
58 #include <svx/svx3ditems.hxx>
59 #include <com/sun/star/drawing/ProjectionMode.hpp>
60 #include <com/sun/star/drawing/ShadeMode.hpp>
61 #include <drawinglayer/attribute/sdrallattribute3d.hxx>
62 #include <svx/rectenum.hxx>
63 #include <svx/sdtfchim.hxx>
64 #include <svx/svdoutl.hxx>
65 #include <svx/svdmodel.hxx>
66 #include <editeng/editstat.hxx>
67 #include <drawinglayer/attribute/fillhatchattribute.hxx>
68 #include <drawinglayer/attribute/fillgradientattribute.hxx>
69 #include <svx/sdr/attribute/sdrshadowtextattribute.hxx>
70 #include <svx/sdr/attribute/sdrlineshadowtextattribute.hxx>
71 #include <svx/sdr/attribute/sdrformtextattribute.hxx>
72 #include <svx/sdr/attribute/sdrlinefillshadowtextattribute.hxx>
73 #include <drawinglayer/attribute/sdrsceneattribute3d.hxx>
74 #include <drawinglayer/attribute/sdrlightingattribute3d.hxx>
75 #include <drawinglayer/attribute/sdrlightattribute3d.hxx>
76 #include <svx/sdr/attribute/sdrfilltextattribute.hxx>
77 #include <com/sun/star/drawing/LineCap.hpp>
79 //////////////////////////////////////////////////////////////////////////////
81 namespace drawinglayer
83 namespace
85 attribute::GradientStyle XGradientStyleToGradientStyle(XGradientStyle eStyle)
87 switch(eStyle)
89 case XGRAD_LINEAR :
91 return attribute::GRADIENTSTYLE_LINEAR;
93 case XGRAD_AXIAL :
95 return attribute::GRADIENTSTYLE_AXIAL;
97 case XGRAD_RADIAL :
99 return attribute::GRADIENTSTYLE_RADIAL;
101 case XGRAD_ELLIPTICAL :
103 return attribute::GRADIENTSTYLE_ELLIPTICAL;
105 case XGRAD_SQUARE :
107 return attribute::GRADIENTSTYLE_SQUARE;
109 default :
111 return attribute::GRADIENTSTYLE_RECT; // XGRAD_RECT
116 attribute::HatchStyle XHatchStyleToHatchStyle(XHatchStyle eStyle)
118 switch(eStyle)
120 case XHATCH_SINGLE :
122 return attribute::HATCHSTYLE_SINGLE;
124 case XHATCH_DOUBLE :
126 return attribute::HATCHSTYLE_DOUBLE;
128 default :
130 return attribute::HATCHSTYLE_TRIPLE; // XHATCH_TRIPLE
135 basegfx::B2DLineJoin LineJointToB2DLineJoin(com::sun::star::drawing::LineJoint eLineJoint)
137 switch(eLineJoint)
139 case com::sun::star::drawing::LineJoint_MIDDLE :
141 return basegfx::B2DLINEJOIN_MIDDLE;
143 case com::sun::star::drawing::LineJoint_BEVEL :
145 return basegfx::B2DLINEJOIN_BEVEL;
147 case com::sun::star::drawing::LineJoint_MITER :
149 return basegfx::B2DLINEJOIN_MITER;
151 case com::sun::star::drawing::LineJoint_ROUND :
153 return basegfx::B2DLINEJOIN_ROUND;
155 default : // com::sun::star::drawing::LineJoint_NONE
157 return basegfx::B2DLINEJOIN_NONE;
162 basegfx::B2DVector RectPointToB2DVector(RECT_POINT eRectPoint)
164 basegfx::B2DVector aRetval(0.0, 0.0);
166 // position changes X
167 switch(eRectPoint)
169 case RP_LT: case RP_LM: case RP_LB:
171 aRetval.setX(-1.0);
172 break;
175 case RP_RT: case RP_RM: case RP_RB:
177 aRetval.setX(1.0);
178 break;
181 default :
183 break;
187 // position changes Y
188 switch(eRectPoint)
190 case RP_LT: case RP_MT: case RP_RT:
192 aRetval.setY(-1.0);
193 break;
196 case RP_LB: case RP_MB: case RP_RB:
198 aRetval.setY(1.0);
199 break;
202 default :
204 break;
208 return aRetval;
210 } // end of anonymous namespace
211 } // end of namespace drawinglayer
213 //////////////////////////////////////////////////////////////////////////////
215 namespace drawinglayer
217 namespace primitive2d
219 attribute::SdrLineAttribute createNewSdrLineAttribute(const SfxItemSet& rSet)
221 const XLineStyle eStyle(((XLineStyleItem&)(rSet.Get(XATTR_LINESTYLE))).GetValue());
223 if(XLINE_NONE != eStyle)
225 sal_uInt16 nTransparence(((const XLineTransparenceItem&)(rSet.Get(XATTR_LINETRANSPARENCE))).GetValue());
227 if(nTransparence > 100)
229 nTransparence = 100;
232 if(100 != nTransparence)
234 const sal_uInt32 nWidth(((const XLineWidthItem&)(rSet.Get(XATTR_LINEWIDTH))).GetValue());
235 const Color aColor(((const XLineColorItem&)(rSet.Get(XATTR_LINECOLOR))).GetColorValue());
236 const com::sun::star::drawing::LineJoint eJoint(((const XLineJointItem&)(rSet.Get(XATTR_LINEJOINT))).GetValue());
237 const com::sun::star::drawing::LineCap eCap(((const XLineCapItem&)(rSet.Get(XATTR_LINECAP))).GetValue());
238 ::std::vector< double > aDotDashArray;
239 double fFullDotDashLen(0.0);
241 if(XLINE_DASH == eStyle)
243 const XDash& rDash = ((const XLineDashItem&)(rSet.Get(XATTR_LINEDASH))).GetDashValue();
245 if(rDash.GetDots() || rDash.GetDashes())
247 fFullDotDashLen = rDash.CreateDotDashArray(aDotDashArray, (double)nWidth);
251 return attribute::SdrLineAttribute(
252 LineJointToB2DLineJoin(eJoint),
253 (double)nWidth,
254 (double)nTransparence * 0.01,
255 aColor.getBColor(),
256 eCap,
257 aDotDashArray,
258 fFullDotDashLen);
262 return attribute::SdrLineAttribute();
265 attribute::SdrLineStartEndAttribute createNewSdrLineStartEndAttribute(
266 const SfxItemSet& rSet,
267 double fWidth)
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);
280 if(nTempStartWidth)
282 if(nTempStartWidth < 0L)
284 fStartWidth = ((double)(-nTempStartWidth) * fWidth) * 0.01;
286 else
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())
297 bStartActive = true;
298 bStartCentered = ((const XLineStartCenterItem&)(rSet.Get(XATTR_LINESTARTCENTER))).GetValue();
303 if(nTempEndWidth)
305 if(nTempEndWidth < 0L)
307 fEndWidth = ((double)(-nTempEndWidth) * fWidth) * 0.01;
309 else
311 fEndWidth = (double)nTempEndWidth;
314 if(0.0 != fEndWidth)
316 aEndPolyPolygon = basegfx::B2DPolyPolygon(((const XLineEndItem&)(rSet.Get(XATTR_LINEEND))).GetLineEndValue());
318 if(aEndPolyPolygon.count() && aEndPolyPolygon.getB2DPolygon(0L).count())
320 bEndActive = true;
321 bEndCentered = ((const XLineEndCenterItem&)(rSet.Get(XATTR_LINEENDCENTER))).GetValue();
326 if(bStartActive || bEndActive)
328 return attribute::SdrLineStartEndAttribute(
329 aStartPolyPolygon, aEndPolyPolygon, fStartWidth, fEndWidth,
330 bStartActive, bEndActive, bStartCentered, bEndCentered);
333 return attribute::SdrLineStartEndAttribute();
336 attribute::SdrShadowAttribute createNewSdrShadowAttribute(const SfxItemSet& rSet)
338 const bool bShadow(((SdrShadowItem&)rSet.Get(SDRATTR_SHADOW)).GetValue());
340 if(bShadow)
342 sal_uInt16 nTransparence(((SdrShadowTransparenceItem&)(rSet.Get(SDRATTR_SHADOWTRANSPARENCE))).GetValue());
344 if(nTransparence > 100)
346 nTransparence = 100;
349 if(nTransparence)
351 sal_uInt16 nFillTransparence(((const XFillTransparenceItem&)(rSet.Get(XATTR_FILLTRANSPARENCE))).GetValue());
353 if(nFillTransparence > 100)
355 nFillTransparence = 100;
358 if(nTransparence == nFillTransparence)
360 // shadow does not really have an own transparence, but the application
361 // sets the shadow transparence equal to the object transparence for
362 // convenience. This is not useful for primitive creation, so take
363 // this as no shadow transparence
364 nTransparence = 0;
368 if(100 != nTransparence)
370 const basegfx::B2DVector aOffset(
371 (double)((SdrShadowXDistItem&)(rSet.Get(SDRATTR_SHADOWXDIST))).GetValue(),
372 (double)((SdrShadowYDistItem&)(rSet.Get(SDRATTR_SHADOWYDIST))).GetValue());
373 const Color aColor(((SdrShadowColorItem&)(rSet.Get(SDRATTR_SHADOWCOLOR))).GetColorValue());
375 return attribute::SdrShadowAttribute(aOffset, (double)nTransparence * 0.01, aColor.getBColor());
379 return attribute::SdrShadowAttribute();
382 attribute::SdrFillAttribute createNewSdrFillAttribute(const SfxItemSet& rSet)
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)
392 nTransparence = 100;
395 if(100 != nTransparence)
397 // need to check XFillFloatTransparence, object fill may still be completely transparent
398 const SfxPoolItem* pGradientItem;
400 if(SFX_ITEM_SET == rSet.GetItemState(XATTR_FILLFLOATTRANSPARENCE, sal_True, &pGradientItem)
401 && ((XFillFloatTransparenceItem*)pGradientItem)->IsEnabled())
403 const XGradient& rGradient = ((XFillFloatTransparenceItem*)pGradientItem)->GetGradientValue();
404 const sal_uInt8 nStartLuminance(rGradient.GetStartColor().GetLuminance());
405 const sal_uInt8 nEndLuminance(rGradient.GetEndColor().GetLuminance());
406 const bool bCompletelyTransparent(0xff == nStartLuminance && 0xff == nEndLuminance);
408 if(bCompletelyTransparent)
410 nTransparence = 100;
415 if(100 != nTransparence)
417 const Color aColor(((const XFillColorItem&)(rSet.Get(XATTR_FILLCOLOR))).GetColorValue());
418 attribute::FillGradientAttribute aGradient;
419 attribute::FillHatchAttribute aHatch;
420 attribute::SdrFillBitmapAttribute aBitmap;
422 switch(eStyle)
424 case XFILL_NONE : // for warnings
425 case XFILL_SOLID :
427 // nothing to do, color is defined
428 break;
430 case XFILL_GRADIENT :
432 XGradient aXGradient(((XFillGradientItem&)(rSet.Get(XATTR_FILLGRADIENT))).GetGradientValue());
434 const Color aStartColor(aXGradient.GetStartColor());
435 const sal_uInt16 nStartIntens(aXGradient.GetStartIntens());
436 basegfx::BColor aStart(aStartColor.getBColor());
438 if(nStartIntens != 100)
440 const basegfx::BColor aBlack;
441 aStart = interpolate(aBlack, aStart, (double)nStartIntens * 0.01);
444 const Color aEndColor(aXGradient.GetEndColor());
445 const sal_uInt16 nEndIntens(aXGradient.GetEndIntens());
446 basegfx::BColor aEnd(aEndColor.getBColor());
448 if(nEndIntens != 100)
450 const basegfx::BColor aBlack;
451 aEnd = interpolate(aBlack, aEnd, (double)nEndIntens * 0.01);
454 aGradient = attribute::FillGradientAttribute(
455 XGradientStyleToGradientStyle(aXGradient.GetGradientStyle()),
456 (double)aXGradient.GetBorder() * 0.01,
457 (double)aXGradient.GetXOffset() * 0.01,
458 (double)aXGradient.GetYOffset() * 0.01,
459 (double)aXGradient.GetAngle() * F_PI1800,
460 aStart,
461 aEnd,
462 ((const XGradientStepCountItem&)rSet.Get(XATTR_GRADIENTSTEPCOUNT)).GetValue());
464 break;
466 case XFILL_HATCH :
468 const XHatch& rHatch(((XFillHatchItem&)(rSet.Get(XATTR_FILLHATCH))).GetHatchValue());
469 const Color aColorB(rHatch.GetColor());
471 aHatch = attribute::FillHatchAttribute(
472 XHatchStyleToHatchStyle(rHatch.GetHatchStyle()),
473 (double)rHatch.GetDistance(),
474 (double)rHatch.GetAngle() * F_PI1800,
475 aColorB.getBColor(),
476 3, // same default as VCL, a minimum of three discrete units (pixels) offset
477 ((const XFillBackgroundItem&)(rSet.Get(XATTR_FILLBACKGROUND))).GetValue());
479 break;
481 case XFILL_BITMAP :
483 aBitmap = createNewSdrFillBitmapAttribute(rSet);
484 break;
488 return attribute::SdrFillAttribute(
489 (double)nTransparence * 0.01,
490 aColor.getBColor(),
491 aGradient,
492 aHatch,
493 aBitmap);
497 return attribute::SdrFillAttribute();
500 // #i101508# Support handing over given text-to-border distances
501 attribute::SdrTextAttribute createNewSdrTextAttribute(
502 const SfxItemSet& rSet,
503 const SdrText& rText,
504 const sal_Int32* pLeft,
505 const sal_Int32* pUpper,
506 const sal_Int32* pRight,
507 const sal_Int32* pLower)
509 const SdrTextObj& rTextObj = rText.GetObject();
511 if(rText.GetOutlinerParaObject() && rText.GetModel())
513 // added TextEdit text suppression
514 bool bInEditMode(false);
516 if(rText.GetObject().getTextCount() > 1)
518 bInEditMode = rTextObj.IsInEditMode() && rText.GetObject().getActiveText() == &rText;
520 else
522 bInEditMode = rTextObj.IsInEditMode();
525 OutlinerParaObject aOutlinerParaObject(*rText.GetOutlinerParaObject());
527 if(bInEditMode)
529 OutlinerParaObject* pTempObj = rTextObj.GetEditOutlinerParaObject();
531 if(pTempObj)
533 aOutlinerParaObject = *pTempObj;
534 delete pTempObj;
536 else
538 // #i100537#
539 // GetEditOutlinerParaObject() returning no object does not mean that
540 // text edit mode is not active. Do not reset the flag here
541 // bInEditMode = false;
545 const SdrTextAniKind eAniKind(rTextObj.GetTextAniKind());
547 // #i107346#
548 const SdrOutliner& rDrawTextOutliner = rText.GetModel()->GetDrawOutliner(&rTextObj);
549 const bool bWrongSpell(rDrawTextOutliner.GetControlWord() & EE_CNTRL_ONLINESPELLING);
551 return attribute::SdrTextAttribute(
552 rText,
553 aOutlinerParaObject,
554 ((const XFormTextStyleItem&)rSet.Get(XATTR_FORMTXTSTYLE)).GetValue(),
555 pLeft ? *pLeft : rTextObj.GetTextLeftDistance(),
556 pUpper ? *pUpper : rTextObj.GetTextUpperDistance(),
557 pRight ? *pRight : rTextObj.GetTextRightDistance(),
558 pLower ? *pLower : rTextObj.GetTextLowerDistance(),
559 rTextObj.GetTextHorizontalAdjust(rSet),
560 rTextObj.GetTextVerticalAdjust(rSet),
561 ((const SdrTextContourFrameItem&)rSet.Get(SDRATTR_TEXT_CONTOURFRAME)).GetValue(),
562 rTextObj.IsFitToSize(),
563 rTextObj.IsAutoFit(),
564 ((const XFormTextHideFormItem&)rSet.Get(XATTR_FORMTXTHIDEFORM)).GetValue(),
565 SDRTEXTANI_BLINK == eAniKind,
566 SDRTEXTANI_SCROLL == eAniKind || SDRTEXTANI_ALTERNATE == eAniKind || SDRTEXTANI_SLIDE == eAniKind,
567 bInEditMode,
568 ((const SdrTextFixedCellHeightItem&)rSet.Get(SDRATTR_TEXT_USEFIXEDCELLHEIGHT)).GetValue(),
569 bWrongSpell);
572 return attribute::SdrTextAttribute();
575 attribute::FillGradientAttribute createNewTransparenceGradientAttribute(const SfxItemSet& rSet)
577 const SfxPoolItem* pGradientItem;
579 if(SFX_ITEM_SET == rSet.GetItemState(XATTR_FILLFLOATTRANSPARENCE, sal_True, &pGradientItem)
580 && ((XFillFloatTransparenceItem*)pGradientItem)->IsEnabled())
582 // test if float transparence is completely transparent
583 const XGradient& rGradient = ((XFillFloatTransparenceItem*)pGradientItem)->GetGradientValue();
584 const sal_uInt8 nStartLuminance(rGradient.GetStartColor().GetLuminance());
585 const sal_uInt8 nEndLuminance(rGradient.GetEndColor().GetLuminance());
586 const bool bCompletelyTransparent(0xff == nStartLuminance && 0xff == nEndLuminance);
587 const bool bNotTransparent(0x00 == nStartLuminance && 0x00 == nEndLuminance);
589 // create nothing when completely transparent: This case is already checked for the
590 // normal fill attributes, XFILL_NONE will be used.
591 // create nothing when not transparent: use normal fill, no need t create a FillGradientAttribute.
592 // Both cases are optimizations, always creating FillGradientAttribute will work, too
593 if(!bNotTransparent && !bCompletelyTransparent)
595 const double fStartLum(nStartLuminance / 255.0);
596 const double fEndLum(nEndLuminance / 255.0);
598 return attribute::FillGradientAttribute(
599 XGradientStyleToGradientStyle(rGradient.GetGradientStyle()),
600 (double)rGradient.GetBorder() * 0.01,
601 (double)rGradient.GetXOffset() * 0.01,
602 (double)rGradient.GetYOffset() * 0.01,
603 (double)rGradient.GetAngle() * F_PI1800,
604 basegfx::BColor(fStartLum, fStartLum, fStartLum),
605 basegfx::BColor(fEndLum, fEndLum, fEndLum),
610 return attribute::FillGradientAttribute();
613 attribute::SdrFillBitmapAttribute createNewSdrFillBitmapAttribute(const SfxItemSet& rSet)
615 BitmapEx aBitmapEx(((const XFillBitmapItem&)(rSet.Get(XATTR_FILLBITMAP))).GetGraphicObject().GetGraphic().GetBitmapEx());
617 // make sure it's not empty, use default instead
618 if(aBitmapEx.IsEmpty())
620 // #i118485# Add PrefMapMode and PrefSize to avoid mini-tiling and
621 // expensive primitive processing in this case. Use 10x10 cm
622 aBitmapEx = Bitmap(Size(4,4), 8);
623 aBitmapEx.SetPrefMapMode(MapMode(MAP_100TH_MM));
624 aBitmapEx.SetPrefSize(Size(10000.0, 10000.0));
627 // if there is no logical size, create a size from pixel size and set MapMode accordingly
628 if(0L == aBitmapEx.GetPrefSize().Width() || 0L == aBitmapEx.GetPrefSize().Height())
630 aBitmapEx.SetPrefSize(aBitmapEx.GetSizePixel());
631 aBitmapEx.SetPrefMapMode(MAP_PIXEL);
634 // convert size and MapMode to destination logical size and MapMode. The created
635 // bitmap must have a valid logical size (PrefSize)
636 const MapUnit aDestinationMapUnit((MapUnit)rSet.GetPool()->GetMetric(0));
638 if(aBitmapEx.GetPrefMapMode() != aDestinationMapUnit)
640 // #i100360# for MAP_PIXEL, LogicToLogic will not work properly,
641 // so fallback to Application::GetDefaultDevice()
642 if(MAP_PIXEL == aBitmapEx.GetPrefMapMode().GetMapUnit())
644 aBitmapEx.SetPrefSize(Application::GetDefaultDevice()->PixelToLogic(
645 aBitmapEx.GetPrefSize(), aDestinationMapUnit));
647 else
649 aBitmapEx.SetPrefSize(OutputDevice::LogicToLogic(
650 aBitmapEx.GetPrefSize(), aBitmapEx.GetPrefMapMode(), aDestinationMapUnit));
654 // get size
655 const basegfx::B2DVector aSize(
656 (double)((const SfxMetricItem&)(rSet.Get(XATTR_FILLBMP_SIZEX))).GetValue(),
657 (double)((const SfxMetricItem&)(rSet.Get(XATTR_FILLBMP_SIZEY))).GetValue());
658 const basegfx::B2DVector aOffset(
659 (double)((const SfxUInt16Item&) (rSet.Get(XATTR_FILLBMP_TILEOFFSETX))).GetValue(),
660 (double)((const SfxUInt16Item&) (rSet.Get(XATTR_FILLBMP_TILEOFFSETY))).GetValue());
661 const basegfx::B2DVector aOffsetPosition(
662 (double)((const SfxUInt16Item&) (rSet.Get(XATTR_FILLBMP_POSOFFSETX))).GetValue(),
663 (double)((const SfxUInt16Item&) (rSet.Get(XATTR_FILLBMP_POSOFFSETY))).GetValue());
665 return attribute::SdrFillBitmapAttribute(
666 aBitmapEx,
667 aSize,
668 aOffset,
669 aOffsetPosition,
670 RectPointToB2DVector((RECT_POINT)((const SfxEnumItem&)(rSet.Get(XATTR_FILLBMP_POS))).GetValue()),
671 ((const SfxBoolItem&) (rSet.Get(XATTR_FILLBMP_TILE))).GetValue(),
672 ((const SfxBoolItem&) (rSet.Get(XATTR_FILLBMP_STRETCH))).GetValue(),
673 ((const SfxBoolItem&) (rSet.Get(XATTR_FILLBMP_SIZELOG))).GetValue());
676 attribute::SdrShadowTextAttribute createNewSdrShadowTextAttribute(
677 const SfxItemSet& rSet,
678 const SdrText* pText,
679 bool bSuppressText)
681 attribute::SdrTextAttribute aText;
683 // #i98072# added option to suppress text
684 // look for text first
685 if(!bSuppressText && pText)
687 aText = createNewSdrTextAttribute(rSet, *pText);
690 // try shadow
691 const attribute::SdrShadowAttribute aShadow(createNewSdrShadowAttribute(rSet));
693 return attribute::SdrShadowTextAttribute(aShadow, aText);
696 attribute::SdrLineShadowTextAttribute createNewSdrLineShadowTextAttribute(
697 const SfxItemSet& rSet,
698 const SdrText* pText)
700 attribute::SdrLineAttribute aLine;
701 attribute::SdrLineStartEndAttribute aLineStartEnd;
702 attribute::SdrTextAttribute aText;
703 bool bFontworkHideContour(false);
705 // look for text first
706 if(pText)
708 aText = createNewSdrTextAttribute(rSet, *pText);
710 // when object has text and text is fontwork and hide contour is set for fontwork, force
711 // line and fill style to empty
712 if(!aText.isDefault()
713 && !aText.getSdrFormTextAttribute().isDefault()
714 && aText.isHideContour())
716 bFontworkHideContour = true;
720 // try line style
721 if(!bFontworkHideContour)
723 aLine = createNewSdrLineAttribute(rSet);
725 if(!aLine.isDefault())
727 // try LineStartEnd
728 aLineStartEnd = createNewSdrLineStartEndAttribute(rSet, aLine.getWidth());
732 if(!aLine.isDefault() || !aText.isDefault())
734 // try shadow
735 const attribute::SdrShadowAttribute aShadow(createNewSdrShadowAttribute(rSet));
737 return attribute::SdrLineShadowTextAttribute(aLine, aLineStartEnd, aShadow, aText);
740 return attribute::SdrLineShadowTextAttribute();
743 attribute::SdrLineFillShadowTextAttribute createNewSdrLineFillShadowTextAttribute(
744 const SfxItemSet& rSet,
745 const SdrText* pText,
746 bool bHasContent)
748 attribute::SdrLineAttribute aLine;
749 attribute::SdrFillAttribute aFill;
750 attribute::SdrLineStartEndAttribute aLineStartEnd;
751 attribute::SdrShadowAttribute aShadow;
752 attribute::FillGradientAttribute aFillFloatTransGradient;
753 attribute::SdrTextAttribute aText;
754 bool bFontworkHideContour(false);
756 // look for text first
757 if(pText)
759 aText = createNewSdrTextAttribute(rSet, *pText);
761 // when object has text and text is fontwork and hide contour is set for fontwork, force
762 // line and fill style to empty
763 if(!aText.getSdrFormTextAttribute().isDefault() && aText.isHideContour())
765 bFontworkHideContour = true;
769 if(!bFontworkHideContour)
771 // try line style
772 aLine = createNewSdrLineAttribute(rSet);
774 if(!aLine.isDefault())
776 // try LineStartEnd
777 aLineStartEnd = createNewSdrLineStartEndAttribute(rSet, aLine.getWidth());
780 // try fill style
781 aFill = createNewSdrFillAttribute(rSet);
783 if(!aFill.isDefault())
785 // try fillfloattransparence
786 aFillFloatTransGradient = createNewTransparenceGradientAttribute(rSet);
790 // bHasContent is used from OLE and graphic objects. Normally a possible shadow
791 // depends on line, fill or text to be set, but for these objects it is possible
792 // to have none of these, but still content which needs to have a shadow (if set),
793 // so shadow needs to be tried
794 if(bHasContent || !aLine.isDefault() || !aFill.isDefault() || !aText.isDefault())
796 // try shadow
797 aShadow = createNewSdrShadowAttribute(rSet);
799 return attribute::SdrLineFillShadowTextAttribute(
800 aLine, aFill, aLineStartEnd, aShadow, aFillFloatTransGradient, aText);
803 return attribute::SdrLineFillShadowTextAttribute();
806 attribute::SdrLineFillShadowAttribute3D createNewSdrLineFillShadowAttribute(const SfxItemSet& rSet, bool bSuppressFill)
808 attribute::SdrFillAttribute aFill;
809 attribute::SdrLineStartEndAttribute aLineStartEnd;
810 attribute::SdrShadowAttribute aShadow;
811 attribute::FillGradientAttribute aFillFloatTransGradient;
813 // try line style
814 const attribute::SdrLineAttribute aLine(createNewSdrLineAttribute(rSet));
816 if(!aLine.isDefault())
818 // try LineStartEnd
819 aLineStartEnd = createNewSdrLineStartEndAttribute(rSet, aLine.getWidth());
822 // try fill style
823 if(!bSuppressFill)
825 aFill = createNewSdrFillAttribute(rSet);
827 if(!aFill.isDefault())
829 // try fillfloattransparence
830 aFillFloatTransGradient = createNewTransparenceGradientAttribute(rSet);
834 if(!aLine.isDefault() || !aFill.isDefault())
836 // try shadow
837 aShadow = createNewSdrShadowAttribute(rSet);
839 return attribute::SdrLineFillShadowAttribute3D(
840 aLine, aFill, aLineStartEnd, aShadow, aFillFloatTransGradient);
843 return attribute::SdrLineFillShadowAttribute3D();
846 attribute::SdrSceneAttribute createNewSdrSceneAttribute(const SfxItemSet& rSet)
848 // get perspective
849 ::com::sun::star::drawing::ProjectionMode aProjectionMode(::com::sun::star::drawing::ProjectionMode_PARALLEL);
850 const sal_uInt16 nProjectionValue(((const Svx3DPerspectiveItem&)rSet.Get(SDRATTR_3DSCENE_PERSPECTIVE)).GetValue());
852 if(1L == nProjectionValue)
854 aProjectionMode = ::com::sun::star::drawing::ProjectionMode_PERSPECTIVE;
857 // get distance
858 const double fDistance(((const Svx3DDistanceItem&)rSet.Get(SDRATTR_3DSCENE_DISTANCE)).GetValue());
860 // get shadow slant
861 const double fShadowSlant(F_PI180 * ((const Svx3DShadowSlantItem&)rSet.Get(SDRATTR_3DSCENE_SHADOW_SLANT)).GetValue());
863 // get shade mode
864 ::com::sun::star::drawing::ShadeMode aShadeMode(::com::sun::star::drawing::ShadeMode_FLAT);
865 const sal_uInt16 nShadeValue(((const Svx3DShadeModeItem&)rSet.Get(SDRATTR_3DSCENE_SHADE_MODE)).GetValue());
867 if(1L == nShadeValue)
869 aShadeMode = ::com::sun::star::drawing::ShadeMode_PHONG;
871 else if(2L == nShadeValue)
873 aShadeMode = ::com::sun::star::drawing::ShadeMode_SMOOTH;
875 else if(3L == nShadeValue)
877 aShadeMode = ::com::sun::star::drawing::ShadeMode_DRAFT;
880 // get two sided lighting
881 const bool bTwoSidedLighting(((const Svx3DTwoSidedLightingItem&)rSet.Get(SDRATTR_3DSCENE_TWO_SIDED_LIGHTING)).GetValue());
883 return attribute::SdrSceneAttribute(fDistance, fShadowSlant, aProjectionMode, aShadeMode, bTwoSidedLighting);
886 attribute::SdrLightingAttribute createNewSdrLightingAttribute(const SfxItemSet& rSet)
888 // extract lights from given SfxItemSet (from scene)
889 ::std::vector< attribute::Sdr3DLightAttribute > aLightVector;
891 if(((const Svx3DLightOnOff1Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTON_1)).GetValue())
893 const basegfx::BColor aColor(((const Svx3DLightcolor1Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTCOLOR_1)).GetValue().getBColor());
894 const basegfx::B3DVector aDirection(((const Svx3DLightDirection1Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_1)).GetValue());
895 aLightVector.push_back(attribute::Sdr3DLightAttribute(aColor, aDirection, true));
898 if(((const Svx3DLightOnOff2Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTON_2)).GetValue())
900 const basegfx::BColor aColor(((const Svx3DLightcolor2Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTCOLOR_2)).GetValue().getBColor());
901 const basegfx::B3DVector aDirection(((const Svx3DLightDirection2Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_2)).GetValue());
902 aLightVector.push_back(attribute::Sdr3DLightAttribute(aColor, aDirection, false));
905 if(((const Svx3DLightOnOff3Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTON_3)).GetValue())
907 const basegfx::BColor aColor(((const Svx3DLightcolor3Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTCOLOR_3)).GetValue().getBColor());
908 const basegfx::B3DVector aDirection(((const Svx3DLightDirection3Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_3)).GetValue());
909 aLightVector.push_back(attribute::Sdr3DLightAttribute(aColor, aDirection, false));
912 if(((const Svx3DLightOnOff4Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTON_4)).GetValue())
914 const basegfx::BColor aColor(((const Svx3DLightcolor4Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTCOLOR_4)).GetValue().getBColor());
915 const basegfx::B3DVector aDirection(((const Svx3DLightDirection4Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_4)).GetValue());
916 aLightVector.push_back(attribute::Sdr3DLightAttribute(aColor, aDirection, false));
919 if(((const Svx3DLightOnOff5Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTON_5)).GetValue())
921 const basegfx::BColor aColor(((const Svx3DLightcolor5Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTCOLOR_5)).GetValue().getBColor());
922 const basegfx::B3DVector aDirection(((const Svx3DLightDirection5Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_5)).GetValue());
923 aLightVector.push_back(attribute::Sdr3DLightAttribute(aColor, aDirection, false));
926 if(((const Svx3DLightOnOff6Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTON_6)).GetValue())
928 const basegfx::BColor aColor(((const Svx3DLightcolor6Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTCOLOR_6)).GetValue().getBColor());
929 const basegfx::B3DVector aDirection(((const Svx3DLightDirection6Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_6)).GetValue());
930 aLightVector.push_back(attribute::Sdr3DLightAttribute(aColor, aDirection, false));
933 if(((const Svx3DLightOnOff7Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTON_7)).GetValue())
935 const basegfx::BColor aColor(((const Svx3DLightcolor7Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTCOLOR_7)).GetValue().getBColor());
936 const basegfx::B3DVector aDirection(((const Svx3DLightDirection7Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_7)).GetValue());
937 aLightVector.push_back(attribute::Sdr3DLightAttribute(aColor, aDirection, false));
940 if(((const Svx3DLightOnOff8Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTON_8)).GetValue())
942 const basegfx::BColor aColor(((const Svx3DLightcolor8Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTCOLOR_8)).GetValue().getBColor());
943 const basegfx::B3DVector aDirection(((const Svx3DLightDirection8Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_8)).GetValue());
944 aLightVector.push_back(attribute::Sdr3DLightAttribute(aColor, aDirection, false));
947 // get ambient color
948 const Color aAmbientValue(((const Svx3DAmbientcolorItem&)rSet.Get(SDRATTR_3DSCENE_AMBIENTCOLOR)).GetValue());
949 const basegfx::BColor aAmbientLight(aAmbientValue.getBColor());
951 return attribute::SdrLightingAttribute(aAmbientLight, aLightVector);
954 void calculateRelativeCornerRadius(sal_Int32 nRadius, const basegfx::B2DRange& rObjectRange, double& rfCornerRadiusX, double& rfCornerRadiusY)
956 rfCornerRadiusX = rfCornerRadiusY = (double)nRadius;
958 if(0.0 != rfCornerRadiusX)
960 const double fHalfObjectWidth(rObjectRange.getWidth() * 0.5);
962 if(0.0 != fHalfObjectWidth)
964 if(rfCornerRadiusX < 0.0)
966 rfCornerRadiusX = 0.0;
969 if(rfCornerRadiusX > fHalfObjectWidth)
971 rfCornerRadiusX = fHalfObjectWidth;
974 rfCornerRadiusX /= fHalfObjectWidth;
976 else
978 rfCornerRadiusX = 0.0;
982 if(0.0 != rfCornerRadiusY)
984 const double fHalfObjectHeight(rObjectRange.getHeight() * 0.5);
986 if(0.0 != fHalfObjectHeight)
988 if(rfCornerRadiusY < 0.0)
990 rfCornerRadiusY = 0.0;
993 if(rfCornerRadiusY > fHalfObjectHeight)
995 rfCornerRadiusY = fHalfObjectHeight;
998 rfCornerRadiusY /= fHalfObjectHeight;
1000 else
1002 rfCornerRadiusY = 0.0;
1007 // #i101508# Support handing over given text-to-border distances
1008 attribute::SdrFillTextAttribute createNewSdrFillTextAttribute(
1009 const SfxItemSet& rSet,
1010 const SdrText* pText,
1011 const sal_Int32* pLeft,
1012 const sal_Int32* pUpper,
1013 const sal_Int32* pRight,
1014 const sal_Int32* pLower)
1016 attribute::SdrFillAttribute aFill;
1017 attribute::FillGradientAttribute aFillFloatTransGradient;
1018 attribute::SdrTextAttribute aText;
1019 bool bFontworkHideContour(false);
1021 // look for text first
1022 if(pText)
1024 aText = createNewSdrTextAttribute(rSet, *pText, pLeft, pUpper, pRight, pLower);
1026 // when object has text and text is fontwork and hide contour is set for fontwork, force
1027 // fill style to empty
1028 if(!aText.getSdrFormTextAttribute().isDefault() && aText.isHideContour())
1030 bFontworkHideContour = true;
1034 if(!bFontworkHideContour)
1036 // try fill style
1037 aFill = createNewSdrFillAttribute(rSet);
1039 if(!aFill.isDefault())
1041 // try fillfloattransparence
1042 aFillFloatTransGradient = createNewTransparenceGradientAttribute(rSet);
1046 if(!aFill.isDefault() || !aText.isDefault())
1048 return attribute::SdrFillTextAttribute(aFill, aFillFloatTransGradient, aText);
1051 return attribute::SdrFillTextAttribute();
1054 } // end of namespace primitive2d
1055 } // end of namespace drawinglayer
1057 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */