1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #include "precompiled_svx.hxx"
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>
85 
86 //////////////////////////////////////////////////////////////////////////////
87 
88 namespace drawinglayer
89 {
90 	namespace
91 	{
92 		attribute::GradientStyle XGradientStyleToGradientStyle(XGradientStyle eStyle)
93 		{
94 			switch(eStyle)
95 			{
96 				case XGRAD_LINEAR :
97 				{
98 					return attribute::GRADIENTSTYLE_LINEAR;
99 				}
100 				case XGRAD_AXIAL :
101 				{
102 					return attribute::GRADIENTSTYLE_AXIAL;
103 				}
104 				case XGRAD_RADIAL :
105 				{
106 					return attribute::GRADIENTSTYLE_RADIAL;
107 				}
108 				case XGRAD_ELLIPTICAL :
109 				{
110 					return attribute::GRADIENTSTYLE_ELLIPTICAL;
111 				}
112 				case XGRAD_SQUARE :
113 				{
114 					return attribute::GRADIENTSTYLE_SQUARE;
115 				}
116 				default :
117 				{
118 					return attribute::GRADIENTSTYLE_RECT; // XGRAD_RECT
119 				}
120 			}
121 		}
122 
123 		attribute::HatchStyle XHatchStyleToHatchStyle(XHatchStyle eStyle)
124 		{
125 			switch(eStyle)
126 			{
127 				case XHATCH_SINGLE :
128 				{
129 					return attribute::HATCHSTYLE_SINGLE;
130 				}
131 				case XHATCH_DOUBLE :
132 				{
133 					return attribute::HATCHSTYLE_DOUBLE;
134 				}
135 				default :
136 				{
137 					return attribute::HATCHSTYLE_TRIPLE; // XHATCH_TRIPLE
138 				}
139 			}
140 		}
141 
142 		basegfx::B2DLineJoin XLineJointtoB2DLineJoin(XLineJoint eLineJoint)
143 		{
144 			switch(eLineJoint)
145 			{
146 				case XLINEJOINT_MIDDLE :
147 				{
148 					return basegfx::B2DLINEJOIN_MIDDLE;
149 				}
150 				case XLINEJOINT_BEVEL :
151 				{
152 					return basegfx::B2DLINEJOIN_BEVEL;
153 				}
154 				case XLINEJOINT_MITER :
155 				{
156 					return basegfx::B2DLINEJOIN_MITER;
157 				}
158 				case XLINEJOINT_ROUND :
159 				{
160 					return basegfx::B2DLINEJOIN_ROUND;
161 				}
162 				default :
163 				{
164 					return basegfx::B2DLINEJOIN_NONE; // XLINEJOINT_NONE
165 				}
166 			}
167 		}
168 
169 		basegfx::B2DVector RectPointToB2DVector(RECT_POINT eRectPoint)
170 		{
171 			basegfx::B2DVector aRetval(0.0, 0.0);
172 
173 			// position changes X
174 			switch(eRectPoint)
175 			{
176 				case RP_LT: case RP_LM: case RP_LB:
177 				{
178 					aRetval.setX(-1.0);
179 					break;
180 				}
181 
182 				case RP_RT: case RP_RM: case RP_RB:
183 				{
184 					aRetval.setX(1.0);
185 					break;
186 				}
187 
188 				default :
189 				{
190 					break;
191 				}
192 			}
193 
194 			// position changes Y
195 			switch(eRectPoint)
196 			{
197 				case RP_LT: case RP_MT: case RP_RT:
198 				{
199 					aRetval.setY(-1.0);
200 					break;
201 				}
202 
203 				case RP_LB: case RP_MB: case RP_RB:
204 				{
205 					aRetval.setY(1.0);
206 					break;
207 				}
208 
209 				default :
210 				{
211 					break;
212 				}
213 			}
214 
215 			return aRetval;
216 		}
217 	} // end of anonymous namespace
218 } // end of namespace drawinglayer
219 
220 //////////////////////////////////////////////////////////////////////////////
221 
222 namespace drawinglayer
223 {
224 	namespace primitive2d
225 	{
226 		attribute::SdrLineAttribute createNewSdrLineAttribute(const SfxItemSet& rSet)
227 		{
228 			const XLineStyle eStyle(((XLineStyleItem&)(rSet.Get(XATTR_LINESTYLE))).GetValue());
229 
230 			if(XLINE_NONE != eStyle)
231 			{
232 				sal_uInt16 nTransparence(((const XLineTransparenceItem&)(rSet.Get(XATTR_LINETRANSPARENCE))).GetValue());
233 
234 				if(nTransparence > 100)
235 				{
236 					nTransparence = 100;
237 				}
238 
239 				if(100 != nTransparence)
240 				{
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);
246 
247 					if(XLINE_DASH == eStyle)
248 					{
249 						const XDash& rDash = ((const XLineDashItem&)(rSet.Get(XATTR_LINEDASH))).GetDashValue();
250 
251 						if(rDash.GetDots() || rDash.GetDashes())
252 						{
253 							fFullDotDashLen = rDash.CreateDotDashArray(aDotDashArray, (double)nWidth);
254 						}
255 					}
256 
257 					return attribute::SdrLineAttribute(
258 						XLineJointtoB2DLineJoin(eJoint),
259 						(double)nWidth,
260 						(double)nTransparence * 0.01,
261 						aColor.getBColor(),
262 						aDotDashArray,
263 						fFullDotDashLen);
264 				}
265 			}
266 
267 			return attribute::SdrLineAttribute();
268 		}
269 
270 		attribute::SdrLineStartEndAttribute createNewSdrLineStartEndAttribute(
271 			const SfxItemSet& rSet,
272 			double fWidth)
273 		{
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);
284 
285 			if(nTempStartWidth)
286 			{
287 				if(nTempStartWidth < 0L)
288 				{
289 					fStartWidth = ((double)(-nTempStartWidth) * fWidth) * 0.01;
290 				}
291 				else
292 				{
293 					fStartWidth = (double)nTempStartWidth;
294 				}
295 
296 				if(0.0 != fStartWidth)
297 				{
298 					aStartPolyPolygon = basegfx::B2DPolyPolygon(((const XLineStartItem&)(rSet.Get(XATTR_LINESTART))).GetLineStartValue());
299 
300 					if(aStartPolyPolygon.count() && aStartPolyPolygon.getB2DPolygon(0L).count())
301 					{
302 						bStartActive = true;
303 						bStartCentered = ((const XLineStartCenterItem&)(rSet.Get(XATTR_LINESTARTCENTER))).GetValue();
304 					}
305 				}
306 			}
307 
308 			if(nTempEndWidth)
309 			{
310 				if(nTempEndWidth < 0L)
311 				{
312 					fEndWidth = ((double)(-nTempEndWidth) * fWidth) * 0.01;
313 				}
314 				else
315 				{
316 					fEndWidth = (double)nTempEndWidth;
317 				}
318 
319 				if(0.0 != fEndWidth)
320 				{
321 					aEndPolyPolygon = basegfx::B2DPolyPolygon(((const XLineEndItem&)(rSet.Get(XATTR_LINEEND))).GetLineEndValue());
322 
323 					if(aEndPolyPolygon.count() && aEndPolyPolygon.getB2DPolygon(0L).count())
324 					{
325 						bEndActive = true;
326 						bEndCentered = ((const XLineEndCenterItem&)(rSet.Get(XATTR_LINEENDCENTER))).GetValue();
327 					}
328 				}
329 			}
330 
331 			if(bStartActive || bEndActive)
332 			{
333 				return attribute::SdrLineStartEndAttribute(
334 					aStartPolyPolygon, aEndPolyPolygon, fStartWidth, fEndWidth,
335 					bStartActive, bEndActive, bStartCentered, bEndCentered);
336 			}
337 
338 			return attribute::SdrLineStartEndAttribute();
339 		}
340 
341 		attribute::SdrShadowAttribute createNewSdrShadowAttribute(const SfxItemSet& rSet)
342 		{
343 			const bool bShadow(((SdrShadowItem&)rSet.Get(SDRATTR_SHADOW)).GetValue());
344 
345 			if(bShadow)
346 			{
347 				sal_uInt16 nTransparence(((SdrShadowTransparenceItem&)(rSet.Get(SDRATTR_SHADOWTRANSPARENCE))).GetValue());
348 
349 				if(nTransparence > 100)
350 				{
351 					nTransparence = 100;
352 				}
353 
354 				if(nTransparence)
355 				{
356 					sal_uInt16 nFillTransparence(((const XFillTransparenceItem&)(rSet.Get(XATTR_FILLTRANSPARENCE))).GetValue());
357 
358 					if(nFillTransparence > 100)
359 					{
360 						nFillTransparence = 100;
361 					}
362 
363 					if(nTransparence == nFillTransparence)
364 					{
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
369 						nTransparence = 0;
370 					}
371 				}
372 
373 				if(100 != nTransparence)
374 				{
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());
379 
380 					return attribute::SdrShadowAttribute(aOffset, (double)nTransparence * 0.01, aColor.getBColor());
381 				}
382 			}
383 
384 			return attribute::SdrShadowAttribute();
385 		}
386 
387 		attribute::SdrFillAttribute createNewSdrFillAttribute(const SfxItemSet& rSet)
388 		{
389 			const XFillStyle eStyle(((XFillStyleItem&)(rSet.Get(XATTR_FILLSTYLE))).GetValue());
390 
391 			if(XFILL_NONE != eStyle)
392 			{
393 				sal_uInt16 nTransparence(((const XFillTransparenceItem&)(rSet.Get(XATTR_FILLTRANSPARENCE))).GetValue());
394 
395 				if(nTransparence > 100)
396 				{
397 					nTransparence = 100;
398 				}
399 
400 				if(100 != nTransparence)
401 				{
402 					const Color aColor(((const XFillColorItem&)(rSet.Get(XATTR_FILLCOLOR))).GetColorValue());
403 					attribute::FillGradientAttribute aGradient;
404 					attribute::FillHatchAttribute aHatch;
405 					attribute::SdrFillBitmapAttribute aBitmap;
406 
407 					switch(eStyle)
408 					{
409 						case XFILL_NONE : // for warnings
410 						case XFILL_SOLID :
411 						{
412 							// nothing to do, color is defined
413 							break;
414 						}
415 						case XFILL_GRADIENT :
416 						{
417 							XGradient aXGradient(((XFillGradientItem&)(rSet.Get(XATTR_FILLGRADIENT))).GetGradientValue());
418 
419 							const Color aStartColor(aXGradient.GetStartColor());
420 							const sal_uInt16 nStartIntens(aXGradient.GetStartIntens());
421 							basegfx::BColor aStart(aStartColor.getBColor());
422 
423 							if(nStartIntens != 100)
424 							{
425 								const basegfx::BColor aBlack;
426 								aStart = interpolate(aBlack, aStart, (double)nStartIntens * 0.01);
427 							}
428 
429 							const Color aEndColor(aXGradient.GetEndColor());
430 							const sal_uInt16 nEndIntens(aXGradient.GetEndIntens());
431 							basegfx::BColor aEnd(aEndColor.getBColor());
432 
433 							if(nEndIntens != 100)
434 							{
435 								const basegfx::BColor aBlack;
436 								aEnd = interpolate(aBlack, aEnd, (double)nEndIntens * 0.01);
437 							}
438 
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,
445 								aStart,
446 								aEnd,
447 								((const XGradientStepCountItem&)rSet.Get(XATTR_GRADIENTSTEPCOUNT)).GetValue());
448 
449 							break;
450 						}
451 						case XFILL_HATCH :
452 						{
453 							const XHatch& rHatch(((XFillHatchItem&)(rSet.Get(XATTR_FILLHATCH))).GetHatchValue());
454 							const Color aColorB(rHatch.GetColor());
455 
456 							aHatch = attribute::FillHatchAttribute(
457 								XHatchStyleToHatchStyle(rHatch.GetHatchStyle()),
458 								(double)rHatch.GetDistance(),
459 								(double)rHatch.GetAngle() * F_PI1800,
460 								aColorB.getBColor(),
461 								((const XFillBackgroundItem&)(rSet.Get(XATTR_FILLBACKGROUND))).GetValue());
462 
463 							break;
464 						}
465 						case XFILL_BITMAP :
466 						{
467 							aBitmap = createNewSdrFillBitmapAttribute(rSet);
468 							break;
469 						}
470 					}
471 
472 					return attribute::SdrFillAttribute(
473 						(double)nTransparence * 0.01,
474 						aColor.getBColor(),
475 						aGradient,
476 						aHatch,
477 						aBitmap);
478 				}
479 			}
480 
481 			return attribute::SdrFillAttribute();
482 		}
483 
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)
492 		{
493 			const SdrTextObj& rTextObj = rText.GetObject();
494 
495 			if(rText.GetOutlinerParaObject() && rText.GetModel())
496 			{
497 				// added TextEdit text suppression
498 				bool bInEditMode(false);
499 
500 				if(rText.GetObject().getTextCount() > 1)
501 				{
502 					bInEditMode = rTextObj.IsInEditMode() && rText.GetObject().getActiveText() == &rText;
503 				}
504 				else
505 				{
506 					bInEditMode = rTextObj.IsInEditMode();
507 				}
508 
509                 OutlinerParaObject aOutlinerParaObject(*rText.GetOutlinerParaObject());
510 
511                 if(bInEditMode)
512                 {
513                     OutlinerParaObject* pTempObj = rTextObj.GetEditOutlinerParaObject();
514 
515                     if(pTempObj)
516                     {
517                         aOutlinerParaObject = *pTempObj;
518                         delete pTempObj;
519                     }
520                     else
521                     {
522                         // #i100537#
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;
526                     }
527                 }
528 
529 			    const SdrFitToSizeType eFit(rTextObj.GetFitToSize());
530 			    const SdrTextAniKind eAniKind(rTextObj.GetTextAniKind());
531 
532 				// #i107346#
533 				const SdrOutliner& rDrawTextOutliner = rText.GetModel()->GetDrawOutliner(&rTextObj);
534 				const bool bWrongSpell(rDrawTextOutliner.GetControlWord() & EE_CNTRL_ONLINESPELLING);
535 
536 			    return attribute::SdrTextAttribute(
537 				    rText,
538                     aOutlinerParaObject,
539 				    ((const XFormTextStyleItem&)rSet.Get(XATTR_FORMTXTSTYLE)).GetValue(),
540 					pLeft ? *pLeft : rTextObj.GetTextLeftDistance(),
541 					pUpper ? *pUpper : rTextObj.GetTextUpperDistance(),
542 					pRight ? *pRight : rTextObj.GetTextRightDistance(),
543 					pLower ? *pLower : rTextObj.GetTextLowerDistance(),
544                     rTextObj.GetTextHorizontalAdjust(rSet),
545                     rTextObj.GetTextVerticalAdjust(rSet),
546 				    ((const SdrTextContourFrameItem&)rSet.Get(SDRATTR_TEXT_CONTOURFRAME)).GetValue(),
547 				    (SDRTEXTFIT_PROPORTIONAL == eFit || SDRTEXTFIT_ALLLINES == eFit),
548 				    ((const XFormTextHideFormItem&)rSet.Get(XATTR_FORMTXTHIDEFORM)).GetValue(),
549 				    SDRTEXTANI_BLINK == eAniKind,
550 				    SDRTEXTANI_SCROLL == eAniKind || SDRTEXTANI_ALTERNATE == eAniKind || SDRTEXTANI_SLIDE == eAniKind,
551                     bInEditMode,
552                     ((const SdrTextFixedCellHeightItem&)rSet.Get(SDRATTR_TEXT_USEFIXEDCELLHEIGHT)).GetValue(),
553 					bWrongSpell);
554 			}
555 
556 			return attribute::SdrTextAttribute();
557 		}
558 
559 		attribute::FillGradientAttribute createNewTransparenceGradientAttribute(const SfxItemSet& rSet)
560 		{
561 			const SfxPoolItem* pGradientItem;
562 
563 			if(SFX_ITEM_SET == rSet.GetItemState(XATTR_FILLFLOATTRANSPARENCE, sal_True, &pGradientItem)
564 				&& ((XFillFloatTransparenceItem*)pGradientItem)->IsEnabled())
565 			{
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);
571 
572 				if(!bCompletelyTransparent)
573 				{
574 					const double fStartLum(nStartLuminance / 255.0);
575 					const double fEndLum(nEndLuminance / 255.0);
576 
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),
585 						0);
586 				}
587 			}
588 
589 			return attribute::FillGradientAttribute();
590 		}
591 
592 		attribute::SdrFillBitmapAttribute createNewSdrFillBitmapAttribute(const SfxItemSet& rSet)
593 		{
594 			Bitmap aBitmap((((const XFillBitmapItem&)(rSet.Get(XATTR_FILLBITMAP))).GetBitmapValue()).GetBitmap());
595 
596 			// make sure it's not empty, use default instead
597 			if(aBitmap.IsEmpty())
598 			{
599                 // #i118485# Add PrefMapMode and PrefSize to avoid mini-tiling and
600                 // expensive primitive processing in this case. Use 10x10 cm
601 				aBitmap = Bitmap(Size(4,4), 8);
602                 aBitmap.SetPrefMapMode(MapMode(MAP_100TH_MM));
603                 aBitmap.SetPrefSize(Size(10000.0, 10000.0));
604 			}
605 
606 			// if there is no logical size, create a size from pixel size and set MapMode accordingly
607 			if(0L == aBitmap.GetPrefSize().Width() || 0L == aBitmap.GetPrefSize().Height())
608 			{
609 				aBitmap.SetPrefSize(aBitmap.GetSizePixel());
610 				aBitmap.SetPrefMapMode(MAP_PIXEL);
611 			}
612 
613 			// convert size and MapMode to destination logical size and MapMode. The created
614 			// bitmap must have a valid logical size (PrefSize)
615 			const MapUnit aDestinationMapUnit((MapUnit)rSet.GetPool()->GetMetric(0));
616 
617 			if(aBitmap.GetPrefMapMode() != aDestinationMapUnit)
618 			{
619 				// #i100360# for MAP_PIXEL, LogicToLogic will not work properly,
620                 // so fallback to Application::GetDefaultDevice()
621     			if(MAP_PIXEL == aBitmap.GetPrefMapMode().GetMapUnit())
622                 {
623     				aBitmap.SetPrefSize(Application::GetDefaultDevice()->PixelToLogic(
624 	    				aBitmap.GetPrefSize(), aDestinationMapUnit));
625                 }
626                 else
627                 {
628                     aBitmap.SetPrefSize(OutputDevice::LogicToLogic(
629 	    				aBitmap.GetPrefSize(), aBitmap.GetPrefMapMode(), aDestinationMapUnit));
630                 }
631 			}
632 
633 			// get size
634 			const basegfx::B2DVector aSize(
635 				(double)((const SfxMetricItem&)(rSet.Get(XATTR_FILLBMP_SIZEX))).GetValue(),
636 				(double)((const SfxMetricItem&)(rSet.Get(XATTR_FILLBMP_SIZEY))).GetValue());
637 			const basegfx::B2DVector aOffset(
638 				(double)((const SfxUInt16Item&) (rSet.Get(XATTR_FILLBMP_TILEOFFSETX))).GetValue(),
639 				(double)((const SfxUInt16Item&) (rSet.Get(XATTR_FILLBMP_TILEOFFSETY))).GetValue());
640 			const basegfx::B2DVector aOffsetPosition(
641 				(double)((const SfxUInt16Item&) (rSet.Get(XATTR_FILLBMP_POSOFFSETX))).GetValue(),
642 				(double)((const SfxUInt16Item&) (rSet.Get(XATTR_FILLBMP_POSOFFSETY))).GetValue());
643 
644 			return attribute::SdrFillBitmapAttribute(
645 				aBitmap,
646 				aSize,
647 				aOffset,
648 				aOffsetPosition,
649 				RectPointToB2DVector((RECT_POINT)((const SfxEnumItem&)(rSet.Get(XATTR_FILLBMP_POS))).GetValue()),
650 				((const SfxBoolItem&) (rSet.Get(XATTR_FILLBMP_TILE))).GetValue(),
651 				((const SfxBoolItem&) (rSet.Get(XATTR_FILLBMP_STRETCH))).GetValue(),
652 				((const SfxBoolItem&) (rSet.Get(XATTR_FILLBMP_SIZELOG))).GetValue());
653 		}
654 
655 		attribute::SdrShadowTextAttribute createNewSdrShadowTextAttribute(
656             const SfxItemSet& rSet,
657             const SdrText* pText,
658             bool bSuppressText)
659 		{
660 			attribute::SdrTextAttribute aText;
661 
662 			// #i98072# added option to suppress text
663             // look for text first
664             if(!bSuppressText && pText)
665             {
666     			aText = createNewSdrTextAttribute(rSet, *pText);
667             }
668 
669 			// try shadow
670 			const attribute::SdrShadowAttribute aShadow(createNewSdrShadowAttribute(rSet));
671 
672 			return attribute::SdrShadowTextAttribute(aShadow, aText);
673 		}
674 
675 		attribute::SdrLineShadowTextAttribute createNewSdrLineShadowTextAttribute(
676             const SfxItemSet& rSet,
677             const SdrText* pText)
678 		{
679 			attribute::SdrLineAttribute aLine;
680 			attribute::SdrLineStartEndAttribute aLineStartEnd;
681 			attribute::SdrTextAttribute aText;
682 			bool bFontworkHideContour(false);
683 
684 			// look for text first
685             if(pText)
686             {
687     			aText = createNewSdrTextAttribute(rSet, *pText);
688 
689 			    // when object has text and text is fontwork and hide contour is set for fontwork, force
690 			    // line and fill style to empty
691 			    if(!aText.isDefault()
692                     && !aText.getSdrFormTextAttribute().isDefault()
693                     && aText.isHideContour())
694 			    {
695 				    bFontworkHideContour = true;
696 			    }
697 			}
698 
699 			// try line style
700 			if(!bFontworkHideContour)
701 			{
702 				aLine = createNewSdrLineAttribute(rSet);
703 
704 				if(!aLine.isDefault())
705 				{
706 					// try LineStartEnd
707 					aLineStartEnd = createNewSdrLineStartEndAttribute(rSet, aLine.getWidth());
708 				}
709 			}
710 
711 			if(!aLine.isDefault() || !aText.isDefault())
712 			{
713 				// try shadow
714 				const attribute::SdrShadowAttribute aShadow(createNewSdrShadowAttribute(rSet));
715 
716 				return attribute::SdrLineShadowTextAttribute(aLine, aLineStartEnd, aShadow, aText);
717 			}
718 
719 			return attribute::SdrLineShadowTextAttribute();
720 		}
721 
722 		attribute::SdrLineFillShadowTextAttribute createNewSdrLineFillShadowTextAttribute(
723             const SfxItemSet& rSet,
724             const SdrText* pText)
725 		{
726 			attribute::SdrLineAttribute aLine;
727 			attribute::SdrFillAttribute aFill;
728 			attribute::SdrLineStartEndAttribute aLineStartEnd;
729 			attribute::SdrShadowAttribute aShadow;
730 			attribute::FillGradientAttribute aFillFloatTransGradient;
731 			attribute::SdrTextAttribute aText;
732 			bool bFontworkHideContour(false);
733 
734 			// look for text first
735             if(pText)
736             {
737     			aText = createNewSdrTextAttribute(rSet, *pText);
738 
739 			    // when object has text and text is fontwork and hide contour is set for fontwork, force
740 			    // line and fill style to empty
741 			    if(!aText.getSdrFormTextAttribute().isDefault() && aText.isHideContour())
742 			    {
743 				    bFontworkHideContour = true;
744 			    }
745             }
746 
747 			if(!bFontworkHideContour)
748 			{
749 				// try line style
750 				aLine = createNewSdrLineAttribute(rSet);
751 
752 				if(!aLine.isDefault())
753 				{
754 					// try LineStartEnd
755 					aLineStartEnd = createNewSdrLineStartEndAttribute(rSet, aLine.getWidth());
756 				}
757 
758 				// try fill style
759 				aFill = createNewSdrFillAttribute(rSet);
760 
761 				if(!aFill.isDefault())
762 				{
763 					// try fillfloattransparence
764 					aFillFloatTransGradient = createNewTransparenceGradientAttribute(rSet);
765 				}
766 			}
767 
768 			if(!aLine.isDefault() || !aFill.isDefault() || !aText.isDefault())
769 			{
770 				// try shadow
771 				aShadow = createNewSdrShadowAttribute(rSet);
772 
773 				return attribute::SdrLineFillShadowTextAttribute(
774 					aLine, aFill, aLineStartEnd, aShadow, aFillFloatTransGradient, aText);
775 			}
776 
777 			return attribute::SdrLineFillShadowTextAttribute();
778 		}
779 
780 		attribute::SdrLineFillShadowAttribute3D createNewSdrLineFillShadowAttribute(const SfxItemSet& rSet, bool bSuppressFill)
781 		{
782 			attribute::SdrFillAttribute aFill;
783 			attribute::SdrLineStartEndAttribute aLineStartEnd;
784 			attribute::SdrShadowAttribute aShadow;
785 			attribute::FillGradientAttribute aFillFloatTransGradient;
786 
787 			// try line style
788 			const attribute::SdrLineAttribute aLine(createNewSdrLineAttribute(rSet));
789 
790 			if(!aLine.isDefault())
791 			{
792 				// try LineStartEnd
793 				aLineStartEnd = createNewSdrLineStartEndAttribute(rSet, aLine.getWidth());
794 			}
795 
796 			// try fill style
797 			if(!bSuppressFill)
798 			{
799 				aFill = createNewSdrFillAttribute(rSet);
800 
801 				if(!aFill.isDefault())
802 				{
803 					// try fillfloattransparence
804 					aFillFloatTransGradient = createNewTransparenceGradientAttribute(rSet);
805 				}
806 			}
807 
808 			if(!aLine.isDefault() || !aFill.isDefault())
809 			{
810 				// try shadow
811 				aShadow = createNewSdrShadowAttribute(rSet);
812 
813 				return attribute::SdrLineFillShadowAttribute3D(
814 					aLine, aFill, aLineStartEnd, aShadow, aFillFloatTransGradient);
815 			}
816 
817 			return attribute::SdrLineFillShadowAttribute3D();
818 		}
819 
820 		attribute::SdrSceneAttribute createNewSdrSceneAttribute(const SfxItemSet& rSet)
821 		{
822 			// get perspective
823 			::com::sun::star::drawing::ProjectionMode aProjectionMode(::com::sun::star::drawing::ProjectionMode_PARALLEL);
824 			const sal_uInt16 nProjectionValue(((const Svx3DPerspectiveItem&)rSet.Get(SDRATTR_3DSCENE_PERSPECTIVE)).GetValue());
825 
826 			if(1L == nProjectionValue)
827 			{
828 				aProjectionMode = ::com::sun::star::drawing::ProjectionMode_PERSPECTIVE;
829 			}
830 
831 			// get distance
832 			const double fDistance(((const Svx3DDistanceItem&)rSet.Get(SDRATTR_3DSCENE_DISTANCE)).GetValue());
833 
834 			// get shadow slant
835 			const double fShadowSlant(F_PI180 * ((const Svx3DShadowSlantItem&)rSet.Get(SDRATTR_3DSCENE_SHADOW_SLANT)).GetValue());
836 
837 			// get shade mode
838 			::com::sun::star::drawing::ShadeMode aShadeMode(::com::sun::star::drawing::ShadeMode_FLAT);
839 			const sal_uInt16 nShadeValue(((const Svx3DShadeModeItem&)rSet.Get(SDRATTR_3DSCENE_SHADE_MODE)).GetValue());
840 
841 			if(1L == nShadeValue)
842 			{
843 				aShadeMode = ::com::sun::star::drawing::ShadeMode_PHONG;
844 			}
845 			else if(2L == nShadeValue)
846 			{
847 				aShadeMode = ::com::sun::star::drawing::ShadeMode_SMOOTH;
848 			}
849 			else if(3L == nShadeValue)
850 			{
851 				aShadeMode = ::com::sun::star::drawing::ShadeMode_DRAFT;
852 			}
853 
854 			// get two sided lighting
855 			const bool bTwoSidedLighting(((const Svx3DTwoSidedLightingItem&)rSet.Get(SDRATTR_3DSCENE_TWO_SIDED_LIGHTING)).GetValue());
856 
857 			return attribute::SdrSceneAttribute(fDistance, fShadowSlant, aProjectionMode, aShadeMode, bTwoSidedLighting);
858 		}
859 
860 		attribute::SdrLightingAttribute createNewSdrLightingAttribute(const SfxItemSet& rSet)
861 		{
862 			// extract lights from given SfxItemSet (from scene)
863 			::std::vector< attribute::Sdr3DLightAttribute > aLightVector;
864 
865             if(((const Svx3DLightOnOff1Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTON_1)).GetValue())
866             {
867 				const basegfx::BColor aColor(((const Svx3DLightcolor1Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTCOLOR_1)).GetValue().getBColor());
868 				const basegfx::B3DVector aDirection(((const Svx3DLightDirection1Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_1)).GetValue());
869 				aLightVector.push_back(attribute::Sdr3DLightAttribute(aColor, aDirection, true));
870             }
871 
872             if(((const Svx3DLightOnOff2Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTON_2)).GetValue())
873             {
874 				const basegfx::BColor aColor(((const Svx3DLightcolor2Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTCOLOR_2)).GetValue().getBColor());
875 				const basegfx::B3DVector aDirection(((const Svx3DLightDirection2Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_2)).GetValue());
876 				aLightVector.push_back(attribute::Sdr3DLightAttribute(aColor, aDirection, false));
877             }
878 
879             if(((const Svx3DLightOnOff3Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTON_3)).GetValue())
880             {
881 				const basegfx::BColor aColor(((const Svx3DLightcolor3Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTCOLOR_3)).GetValue().getBColor());
882 				const basegfx::B3DVector aDirection(((const Svx3DLightDirection3Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_3)).GetValue());
883 				aLightVector.push_back(attribute::Sdr3DLightAttribute(aColor, aDirection, false));
884             }
885 
886             if(((const Svx3DLightOnOff4Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTON_4)).GetValue())
887             {
888 				const basegfx::BColor aColor(((const Svx3DLightcolor4Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTCOLOR_4)).GetValue().getBColor());
889 				const basegfx::B3DVector aDirection(((const Svx3DLightDirection4Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_4)).GetValue());
890 				aLightVector.push_back(attribute::Sdr3DLightAttribute(aColor, aDirection, false));
891             }
892 
893             if(((const Svx3DLightOnOff5Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTON_5)).GetValue())
894             {
895 				const basegfx::BColor aColor(((const Svx3DLightcolor5Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTCOLOR_5)).GetValue().getBColor());
896 				const basegfx::B3DVector aDirection(((const Svx3DLightDirection5Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_5)).GetValue());
897 				aLightVector.push_back(attribute::Sdr3DLightAttribute(aColor, aDirection, false));
898             }
899 
900             if(((const Svx3DLightOnOff6Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTON_6)).GetValue())
901             {
902 				const basegfx::BColor aColor(((const Svx3DLightcolor6Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTCOLOR_6)).GetValue().getBColor());
903 				const basegfx::B3DVector aDirection(((const Svx3DLightDirection6Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_6)).GetValue());
904 				aLightVector.push_back(attribute::Sdr3DLightAttribute(aColor, aDirection, false));
905             }
906 
907             if(((const Svx3DLightOnOff7Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTON_7)).GetValue())
908             {
909 				const basegfx::BColor aColor(((const Svx3DLightcolor7Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTCOLOR_7)).GetValue().getBColor());
910 				const basegfx::B3DVector aDirection(((const Svx3DLightDirection7Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_7)).GetValue());
911 				aLightVector.push_back(attribute::Sdr3DLightAttribute(aColor, aDirection, false));
912             }
913 
914             if(((const Svx3DLightOnOff8Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTON_8)).GetValue())
915             {
916 				const basegfx::BColor aColor(((const Svx3DLightcolor8Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTCOLOR_8)).GetValue().getBColor());
917 				const basegfx::B3DVector aDirection(((const Svx3DLightDirection8Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_8)).GetValue());
918 				aLightVector.push_back(attribute::Sdr3DLightAttribute(aColor, aDirection, false));
919             }
920 
921             // get ambient color
922 			const Color aAmbientValue(((const Svx3DAmbientcolorItem&)rSet.Get(SDRATTR_3DSCENE_AMBIENTCOLOR)).GetValue());
923 			const basegfx::BColor aAmbientLight(aAmbientValue.getBColor());
924 
925             return attribute::SdrLightingAttribute(aAmbientLight, aLightVector);
926 		}
927 
928 		void calculateRelativeCornerRadius(sal_Int32 nRadius, const basegfx::B2DRange& rObjectRange, double& rfCornerRadiusX, double& rfCornerRadiusY)
929 		{
930 			rfCornerRadiusX = rfCornerRadiusY = (double)nRadius;
931 
932 			if(0.0 != rfCornerRadiusX)
933 			{
934 				const double fHalfObjectWidth(rObjectRange.getWidth() * 0.5);
935 
936 				if(0.0 != fHalfObjectWidth)
937 				{
938 					if(rfCornerRadiusX < 0.0)
939 					{
940 						rfCornerRadiusX = 0.0;
941 					}
942 
943 					if(rfCornerRadiusX > fHalfObjectWidth)
944 					{
945 						rfCornerRadiusX = fHalfObjectWidth;
946 					}
947 
948 					rfCornerRadiusX /= fHalfObjectWidth;
949 				}
950 				else
951 				{
952 					rfCornerRadiusX = 0.0;
953 				}
954 			}
955 
956 			if(0.0 != rfCornerRadiusY)
957 			{
958 				const double fHalfObjectHeight(rObjectRange.getHeight() * 0.5);
959 
960 				if(0.0 != fHalfObjectHeight)
961 				{
962 					if(rfCornerRadiusY < 0.0)
963 					{
964 						rfCornerRadiusY = 0.0;
965 					}
966 
967 					if(rfCornerRadiusY > fHalfObjectHeight)
968 					{
969 						rfCornerRadiusY = fHalfObjectHeight;
970 					}
971 
972 					rfCornerRadiusY /= fHalfObjectHeight;
973 				}
974 				else
975 				{
976 					rfCornerRadiusY = 0.0;
977 				}
978 			}
979 		}
980 
981 		// #i101508# Support handing over given text-to-border distances
982 		attribute::SdrFillTextAttribute createNewSdrFillTextAttribute(
983 			const SfxItemSet& rSet,
984 			const SdrText* pText,
985 			const sal_Int32* pLeft,
986 			const sal_Int32* pUpper,
987 			const sal_Int32* pRight,
988 			const sal_Int32* pLower)
989 		{
990 			attribute::SdrFillAttribute aFill;
991 			attribute::FillGradientAttribute aFillFloatTransGradient;
992 			attribute::SdrTextAttribute aText;
993 			bool bFontworkHideContour(false);
994 
995 			// look for text first
996             if(pText)
997             {
998     			aText = createNewSdrTextAttribute(rSet, *pText, pLeft, pUpper, pRight, pLower);
999 
1000 			    // when object has text and text is fontwork and hide contour is set for fontwork, force
1001 			    // fill style to empty
1002 			    if(!aText.getSdrFormTextAttribute().isDefault() && aText.isHideContour())
1003 			    {
1004 				    bFontworkHideContour = true;
1005 			    }
1006             }
1007 
1008 			if(!bFontworkHideContour)
1009 			{
1010 				// try fill style
1011 				aFill = createNewSdrFillAttribute(rSet);
1012 
1013 				if(!aFill.isDefault())
1014 				{
1015 					// try fillfloattransparence
1016 					aFillFloatTransGradient = createNewTransparenceGradientAttribute(rSet);
1017 				}
1018 			}
1019 
1020 			if(!aFill.isDefault() || !aText.isDefault())
1021 			{
1022 				return attribute::SdrFillTextAttribute(aFill, aFillFloatTransGradient, aText);
1023 			}
1024 
1025 			return attribute::SdrFillTextAttribute();
1026 		}
1027 
1028 	} // end of namespace primitive2d
1029 } // end of namespace drawinglayer
1030 
1031 //////////////////////////////////////////////////////////////////////////////
1032 // eof
1033