1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #include "precompiled_svx.hxx" 25 #include <svx/sdr/primitive2d/sdrattributecreator.hxx> 26 #include <svl/itemset.hxx> 27 #include <svx/xdef.hxx> 28 #include <basegfx/polygon/b2dpolygon.hxx> 29 #include <svx/xlineit0.hxx> 30 #include <svx/xfillit0.hxx> 31 #include <svx/xlntrit.hxx> 32 #include <svx/xlnwtit.hxx> 33 #include <svx/xlinjoit.hxx> 34 #include <svx/xlncapit.hxx> 35 #include <svx/xlnclit.hxx> 36 #include <svx/xlnstwit.hxx> 37 #include <svx/xlnedwit.hxx> 38 #include <svx/xlnstit.hxx> 39 #include <svx/xlnstcit.hxx> 40 #include <svx/xlnedit.hxx> 41 #include <svx/xlnedcit.hxx> 42 #include <svx/xdash.hxx> 43 #include <svx/xlndsit.hxx> 44 #include <svx/xfltrit.hxx> 45 #include <svx/xflftrit.hxx> 46 #include <svx/xflclit.hxx> 47 #include <svx/xgrscit.hxx> 48 #include <svx/xflhtit.hxx> 49 #include <svx/xflbckit.hxx> 50 #include <svx/sdshitm.hxx> 51 #include <svx/sdsxyitm.hxx> 52 #include <svx/sdshcitm.hxx> 53 #include <svx/sdshtitm.hxx> 54 #include <drawinglayer/attribute/sdrfillgraphicattribute.hxx> 55 #include <basegfx/polygon/b2dlinegeometry.hxx> 56 #include <svx/svdotext.hxx> 57 #include <drawinglayer/attribute/fillgraphicattribute.hxx> 58 #include <svx/sdr/attribute/sdrtextattribute.hxx> 59 #include <svx/xbtmpit.hxx> 60 #include <svl/itempool.hxx> 61 #include <vcl/svapp.hxx> 62 #include <basegfx/range/b2drange.hxx> 63 #include <svx/svx3ditems.hxx> 64 #include <com/sun/star/drawing/ProjectionMode.hpp> 65 #include <com/sun/star/drawing/ShadeMode.hpp> 66 #include <drawinglayer/attribute/sdrallattribute3d.hxx> 67 #include <svx/rectenum.hxx> 68 #include <svx/sdtfchim.hxx> 69 #include <svx/svdoutl.hxx> 70 #include <svx/svdmodel.hxx> 71 #include <editeng/editstat.hxx> 72 #include <drawinglayer/attribute/fillhatchattribute.hxx> 73 #include <drawinglayer/attribute/fillgradientattribute.hxx> 74 #include <svx/sdr/attribute/sdrshadowtextattribute.hxx> 75 #include <svx/sdr/attribute/sdrlineshadowtextattribute.hxx> 76 #include <svx/sdr/attribute/sdrformtextattribute.hxx> 77 #include <svx/sdr/attribute/sdrlinefillshadowtextattribute.hxx> 78 #include <drawinglayer/attribute/sdrsceneattribute3d.hxx> 79 #include <drawinglayer/attribute/sdrlightingattribute3d.hxx> 80 #include <drawinglayer/attribute/sdrlightattribute3d.hxx> 81 #include <svx/sdr/attribute/sdrfilltextattribute.hxx> 82 #include <com/sun/star/drawing/LineCap.hpp> 83 84 ////////////////////////////////////////////////////////////////////////////// 85 86 namespace drawinglayer 87 { 88 namespace 89 { XGradientStyleToGradientStyle(XGradientStyle eStyle)90 attribute::GradientStyle XGradientStyleToGradientStyle(XGradientStyle eStyle) 91 { 92 switch(eStyle) 93 { 94 case XGRAD_LINEAR : 95 { 96 return attribute::GRADIENTSTYLE_LINEAR; 97 } 98 case XGRAD_AXIAL : 99 { 100 return attribute::GRADIENTSTYLE_AXIAL; 101 } 102 case XGRAD_RADIAL : 103 { 104 return attribute::GRADIENTSTYLE_RADIAL; 105 } 106 case XGRAD_ELLIPTICAL : 107 { 108 return attribute::GRADIENTSTYLE_ELLIPTICAL; 109 } 110 case XGRAD_SQUARE : 111 { 112 return attribute::GRADIENTSTYLE_SQUARE; 113 } 114 default : 115 { 116 return attribute::GRADIENTSTYLE_RECT; // XGRAD_RECT 117 } 118 } 119 } 120 XHatchStyleToHatchStyle(XHatchStyle eStyle)121 attribute::HatchStyle XHatchStyleToHatchStyle(XHatchStyle eStyle) 122 { 123 switch(eStyle) 124 { 125 case XHATCH_SINGLE : 126 { 127 return attribute::HATCHSTYLE_SINGLE; 128 } 129 case XHATCH_DOUBLE : 130 { 131 return attribute::HATCHSTYLE_DOUBLE; 132 } 133 default : 134 { 135 return attribute::HATCHSTYLE_TRIPLE; // XHATCH_TRIPLE 136 } 137 } 138 } 139 LineJointToB2DLineJoin(com::sun::star::drawing::LineJoint eLineJoint)140 basegfx::B2DLineJoin LineJointToB2DLineJoin(com::sun::star::drawing::LineJoint eLineJoint) 141 { 142 switch(eLineJoint) 143 { 144 case com::sun::star::drawing::LineJoint_MIDDLE : 145 { 146 return basegfx::B2DLINEJOIN_MIDDLE; 147 } 148 case com::sun::star::drawing::LineJoint_BEVEL : 149 { 150 return basegfx::B2DLINEJOIN_BEVEL; 151 } 152 case com::sun::star::drawing::LineJoint_MITER : 153 { 154 return basegfx::B2DLINEJOIN_MITER; 155 } 156 case com::sun::star::drawing::LineJoint_ROUND : 157 { 158 return basegfx::B2DLINEJOIN_ROUND; 159 } 160 default : // com::sun::star::drawing::LineJoint_NONE 161 { 162 return basegfx::B2DLINEJOIN_NONE; 163 } 164 } 165 } 166 RectPointToB2DVector(RECT_POINT eRectPoint)167 basegfx::B2DVector RectPointToB2DVector(RECT_POINT eRectPoint) 168 { 169 basegfx::B2DVector aRetval(0.0, 0.0); 170 171 // position changes X 172 switch(eRectPoint) 173 { 174 case RP_LT: case RP_LM: case RP_LB: 175 { 176 aRetval.setX(-1.0); 177 break; 178 } 179 180 case RP_RT: case RP_RM: case RP_RB: 181 { 182 aRetval.setX(1.0); 183 break; 184 } 185 186 default : 187 { 188 break; 189 } 190 } 191 192 // position changes Y 193 switch(eRectPoint) 194 { 195 case RP_LT: case RP_MT: case RP_RT: 196 { 197 aRetval.setY(-1.0); 198 break; 199 } 200 201 case RP_LB: case RP_MB: case RP_RB: 202 { 203 aRetval.setY(1.0); 204 break; 205 } 206 207 default : 208 { 209 break; 210 } 211 } 212 213 return aRetval; 214 } 215 } // end of anonymous namespace 216 } // end of namespace drawinglayer 217 218 ////////////////////////////////////////////////////////////////////////////// 219 220 namespace drawinglayer 221 { 222 namespace primitive2d 223 { createNewSdrLineAttribute(const SfxItemSet & rSet)224 attribute::SdrLineAttribute createNewSdrLineAttribute(const SfxItemSet& rSet) 225 { 226 const XLineStyle eStyle(((XLineStyleItem&)(rSet.Get(XATTR_LINESTYLE))).GetValue()); 227 228 if(XLINE_NONE != eStyle) 229 { 230 sal_uInt16 nTransparence(((const XLineTransparenceItem&)(rSet.Get(XATTR_LINETRANSPARENCE))).GetValue()); 231 232 if(nTransparence > 100) 233 { 234 nTransparence = 100; 235 } 236 237 if(100 != nTransparence) 238 { 239 const sal_uInt32 nWidth(((const XLineWidthItem&)(rSet.Get(XATTR_LINEWIDTH))).GetValue()); 240 const Color aColor(((const XLineColorItem&)(rSet.Get(XATTR_LINECOLOR))).GetColorValue()); 241 const com::sun::star::drawing::LineJoint eJoint(((const XLineJointItem&)(rSet.Get(XATTR_LINEJOINT))).GetValue()); 242 const com::sun::star::drawing::LineCap eCap(((const XLineCapItem&)(rSet.Get(XATTR_LINECAP))).GetValue()); 243 ::std::vector< double > aDotDashArray; 244 double fFullDotDashLen(0.0); 245 246 if(XLINE_DASH == eStyle) 247 { 248 const XDash& rDash = ((const XLineDashItem&)(rSet.Get(XATTR_LINEDASH))).GetDashValue(); 249 250 if(rDash.GetDots() || rDash.GetDashes()) 251 { 252 fFullDotDashLen = rDash.CreateDotDashArray(aDotDashArray, (double)nWidth); 253 } 254 } 255 256 return attribute::SdrLineAttribute( 257 LineJointToB2DLineJoin(eJoint), 258 (double)nWidth, 259 (double)nTransparence * 0.01, 260 aColor.getBColor(), 261 eCap, 262 aDotDashArray, 263 fFullDotDashLen); 264 } 265 } 266 267 return attribute::SdrLineAttribute(); 268 } 269 createNewSdrLineStartEndAttribute(const SfxItemSet & rSet,double fWidth)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 createNewSdrShadowAttribute(const SfxItemSet & rSet)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 createNewSdrFillAttribute(const SfxItemSet & rSet)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 // need to check XFillFloatTransparence, object fill may still be completely transparent 403 const SfxPoolItem* pGradientItem; 404 405 if(SFX_ITEM_SET == rSet.GetItemState(XATTR_FILLFLOATTRANSPARENCE, sal_True, &pGradientItem) 406 && ((XFillFloatTransparenceItem*)pGradientItem)->IsEnabled()) 407 { 408 const XGradient& rGradient = ((XFillFloatTransparenceItem*)pGradientItem)->GetGradientValue(); 409 const sal_uInt8 nStartLuminance(rGradient.GetStartColor().GetLuminance()); 410 const sal_uInt8 nEndLuminance(rGradient.GetEndColor().GetLuminance()); 411 const bool bCompletelyTransparent(0xff == nStartLuminance && 0xff == nEndLuminance); 412 413 if(bCompletelyTransparent) 414 { 415 nTransparence = 100; 416 } 417 } 418 } 419 420 if(100 != nTransparence) 421 { 422 const Color aColor(((const XFillColorItem&)(rSet.Get(XATTR_FILLCOLOR))).GetColorValue()); 423 attribute::FillGradientAttribute aGradient; 424 attribute::FillHatchAttribute aHatch; 425 attribute::SdrFillGraphicAttribute aFillGraphic; 426 427 switch(eStyle) 428 { 429 case XFILL_NONE : // for warnings 430 case XFILL_SOLID : 431 { 432 // nothing to do, color is defined 433 break; 434 } 435 case XFILL_GRADIENT : 436 { 437 XGradient aXGradient(((XFillGradientItem&)(rSet.Get(XATTR_FILLGRADIENT))).GetGradientValue()); 438 439 const Color aStartColor(aXGradient.GetStartColor()); 440 const sal_uInt16 nStartIntens(aXGradient.GetStartIntens()); 441 basegfx::BColor aStart(aStartColor.getBColor()); 442 443 if(nStartIntens != 100) 444 { 445 const basegfx::BColor aBlack; 446 aStart = interpolate(aBlack, aStart, (double)nStartIntens * 0.01); 447 } 448 449 const Color aEndColor(aXGradient.GetEndColor()); 450 const sal_uInt16 nEndIntens(aXGradient.GetEndIntens()); 451 basegfx::BColor aEnd(aEndColor.getBColor()); 452 453 if(nEndIntens != 100) 454 { 455 const basegfx::BColor aBlack; 456 aEnd = interpolate(aBlack, aEnd, (double)nEndIntens * 0.01); 457 } 458 459 aGradient = attribute::FillGradientAttribute( 460 XGradientStyleToGradientStyle(aXGradient.GetGradientStyle()), 461 (double)aXGradient.GetBorder() * 0.01, 462 (double)aXGradient.GetXOffset() * 0.01, 463 (double)aXGradient.GetYOffset() * 0.01, 464 (double)aXGradient.GetAngle() * F_PI1800, 465 aStart, 466 aEnd, 467 ((const XGradientStepCountItem&)rSet.Get(XATTR_GRADIENTSTEPCOUNT)).GetValue()); 468 469 break; 470 } 471 case XFILL_HATCH : 472 { 473 const XHatch& rHatch(((XFillHatchItem&)(rSet.Get(XATTR_FILLHATCH))).GetHatchValue()); 474 const Color aColorB(rHatch.GetColor()); 475 476 aHatch = attribute::FillHatchAttribute( 477 XHatchStyleToHatchStyle(rHatch.GetHatchStyle()), 478 (double)rHatch.GetDistance(), 479 (double)rHatch.GetAngle() * F_PI1800, 480 aColorB.getBColor(), 481 3, // same default as VCL, a minimum of three discrete units (pixels) offset 482 ((const XFillBackgroundItem&)(rSet.Get(XATTR_FILLBACKGROUND))).GetValue()); 483 484 break; 485 } 486 case XFILL_BITMAP : 487 { 488 aFillGraphic = createNewSdrFillGraphicAttribute(rSet); 489 break; 490 } 491 } 492 493 return attribute::SdrFillAttribute( 494 (double)nTransparence * 0.01, 495 aColor.getBColor(), 496 aGradient, 497 aHatch, 498 aFillGraphic); 499 } 500 } 501 502 return attribute::SdrFillAttribute(); 503 } 504 505 // #i101508# Support handing over given text-to-border distances createNewSdrTextAttribute(const SfxItemSet & rSet,const SdrText & rText,const sal_Int32 * pLeft,const sal_Int32 * pUpper,const sal_Int32 * pRight,const sal_Int32 * pLower)506 attribute::SdrTextAttribute createNewSdrTextAttribute( 507 const SfxItemSet& rSet, 508 const SdrText& rText, 509 const sal_Int32* pLeft, 510 const sal_Int32* pUpper, 511 const sal_Int32* pRight, 512 const sal_Int32* pLower) 513 { 514 const SdrTextObj& rTextObj = rText.GetObject(); 515 516 if(rText.GetOutlinerParaObject() && rText.GetModel()) 517 { 518 // added TextEdit text suppression 519 bool bInEditMode(false); 520 521 if(rText.GetObject().getTextCount() > 1) 522 { 523 bInEditMode = rTextObj.IsInEditMode() && rText.GetObject().getActiveText() == &rText; 524 } 525 else 526 { 527 bInEditMode = rTextObj.IsInEditMode(); 528 } 529 530 OutlinerParaObject aOutlinerParaObject(*rText.GetOutlinerParaObject()); 531 532 if(bInEditMode) 533 { 534 OutlinerParaObject* pTempObj = rTextObj.GetEditOutlinerParaObject(); 535 536 if(pTempObj) 537 { 538 aOutlinerParaObject = *pTempObj; 539 delete pTempObj; 540 } 541 else 542 { 543 // #i100537# 544 // GetEditOutlinerParaObject() returning no object does not mean that 545 // text edit mode is not active. Do not reset the flag here 546 // bInEditMode = false; 547 } 548 } 549 550 const SdrFitToSizeType eFit(rTextObj.GetFitToSize()); 551 const SdrTextAniKind eAniKind(rTextObj.GetTextAniKind()); 552 553 // #i107346# 554 const SdrOutliner& rDrawTextOutliner = rText.GetModel()->GetDrawOutliner(&rTextObj); 555 const bool bWrongSpell(rDrawTextOutliner.GetControlWord() & EE_CNTRL_ONLINESPELLING); 556 557 return attribute::SdrTextAttribute( 558 rText, 559 aOutlinerParaObject, 560 ((const XFormTextStyleItem&)rSet.Get(XATTR_FORMTXTSTYLE)).GetValue(), 561 pLeft ? *pLeft : rTextObj.GetTextLeftDistance(), 562 pUpper ? *pUpper : rTextObj.GetTextUpperDistance(), 563 pRight ? *pRight : rTextObj.GetTextRightDistance(), 564 pLower ? *pLower : rTextObj.GetTextLowerDistance(), 565 rTextObj.GetTextHorizontalAdjust(rSet), 566 rTextObj.GetTextVerticalAdjust(rSet), 567 ((const SdrTextContourFrameItem&)rSet.Get(SDRATTR_TEXT_CONTOURFRAME)).GetValue(), 568 (SDRTEXTFIT_PROPORTIONAL == eFit || SDRTEXTFIT_ALLLINES == eFit), 569 ((const XFormTextHideFormItem&)rSet.Get(XATTR_FORMTXTHIDEFORM)).GetValue(), 570 SDRTEXTANI_BLINK == eAniKind, 571 SDRTEXTANI_SCROLL == eAniKind || SDRTEXTANI_ALTERNATE == eAniKind || SDRTEXTANI_SLIDE == eAniKind, 572 bInEditMode, 573 ((const SdrTextFixedCellHeightItem&)rSet.Get(SDRATTR_TEXT_USEFIXEDCELLHEIGHT)).GetValue(), 574 bWrongSpell); 575 } 576 577 return attribute::SdrTextAttribute(); 578 } 579 createNewTransparenceGradientAttribute(const SfxItemSet & rSet)580 attribute::FillGradientAttribute createNewTransparenceGradientAttribute(const SfxItemSet& rSet) 581 { 582 const SfxPoolItem* pGradientItem; 583 584 if(SFX_ITEM_SET == rSet.GetItemState(XATTR_FILLFLOATTRANSPARENCE, sal_True, &pGradientItem) 585 && ((XFillFloatTransparenceItem*)pGradientItem)->IsEnabled()) 586 { 587 // test if float transparence is completely transparent 588 const XGradient& rGradient = ((XFillFloatTransparenceItem*)pGradientItem)->GetGradientValue(); 589 const sal_uInt8 nStartLuminance(rGradient.GetStartColor().GetLuminance()); 590 const sal_uInt8 nEndLuminance(rGradient.GetEndColor().GetLuminance()); 591 const bool bCompletelyTransparent(0xff == nStartLuminance && 0xff == nEndLuminance); 592 const bool bNotTransparent(0x00 == nStartLuminance && 0x00 == nEndLuminance); 593 594 // create nothing when completely transparent: This case is already checked for the 595 // normal fill attributes, XFILL_NONE will be used. 596 // create nothing when not transparent: use normal fill, no need t create a FillGradientAttribute. 597 // Both cases are optimizations, always creating FillGradientAttribute will work, too 598 if(!bNotTransparent && !bCompletelyTransparent) 599 { 600 const double fStartLum(nStartLuminance / 255.0); 601 const double fEndLum(nEndLuminance / 255.0); 602 603 return attribute::FillGradientAttribute( 604 XGradientStyleToGradientStyle(rGradient.GetGradientStyle()), 605 (double)rGradient.GetBorder() * 0.01, 606 (double)rGradient.GetXOffset() * 0.01, 607 (double)rGradient.GetYOffset() * 0.01, 608 (double)rGradient.GetAngle() * F_PI1800, 609 basegfx::BColor(fStartLum, fStartLum, fStartLum), 610 basegfx::BColor(fEndLum, fEndLum, fEndLum), 611 0); 612 } 613 } 614 615 return attribute::FillGradientAttribute(); 616 } 617 createNewSdrFillGraphicAttribute(const SfxItemSet & rSet)618 attribute::SdrFillGraphicAttribute createNewSdrFillGraphicAttribute(const SfxItemSet& rSet) 619 { 620 Graphic aGraphic(((const XFillBitmapItem&)(rSet.Get(XATTR_FILLBITMAP))).GetGraphicObject().GetGraphic()); 621 622 if(!(GRAPHIC_BITMAP == aGraphic.GetType() || GRAPHIC_GDIMETAFILE == aGraphic.GetType())) 623 { 624 // no content if not bitmap or metafile 625 OSL_ENSURE(false, "No fill graphic in SfxItemSet (!)"); 626 return attribute::SdrFillGraphicAttribute(); 627 } 628 629 Size aPrefSize(aGraphic.GetPrefSize()); 630 631 if(!aPrefSize.Width() || !aPrefSize.Height()) 632 { 633 // if there is no logical size, create a size from pixel size and set MapMode accordingly 634 if(GRAPHIC_BITMAP == aGraphic.GetType()) 635 { 636 aGraphic.SetPrefSize(aGraphic.GetBitmapEx().GetSizePixel()); 637 aGraphic.SetPrefMapMode(MAP_PIXEL); 638 } 639 } 640 641 if(!aPrefSize.Width() || !aPrefSize.Height()) 642 { 643 // no content if no size 644 OSL_ENSURE(false, "Graphic has no size in SfxItemSet (!)"); 645 return attribute::SdrFillGraphicAttribute(); 646 } 647 648 // convert size and MapMode to destination logical size and MapMode 649 const MapUnit aDestinationMapUnit((MapUnit)rSet.GetPool()->GetMetric(0)); 650 basegfx::B2DVector aGraphicLogicSize(aGraphic.GetPrefSize().Width(), aGraphic.GetPrefSize().Height()); 651 652 if(aGraphic.GetPrefMapMode() != aDestinationMapUnit) 653 { 654 // #i100360# for MAP_PIXEL, LogicToLogic will not work properly, 655 // so fallback to Application::GetDefaultDevice() 656 Size aNewSize(0, 0); 657 658 if(MAP_PIXEL == aGraphic.GetPrefMapMode().GetMapUnit()) 659 { 660 aNewSize = Application::GetDefaultDevice()->PixelToLogic( 661 aGraphic.GetPrefSize(), 662 aDestinationMapUnit); 663 } 664 else 665 { 666 aNewSize = OutputDevice::LogicToLogic( 667 aGraphic.GetPrefSize(), 668 aGraphic.GetPrefMapMode(), 669 aDestinationMapUnit); 670 } 671 672 // #124002# do not set new size using SetPrefSize at the graphic, this will lead to problems. 673 // Instead, adapt the GraphicLogicSize which will be used for further decompositions 674 aGraphicLogicSize = basegfx::B2DVector(aNewSize.Width(), aNewSize.Height()); 675 } 676 677 // get size 678 const basegfx::B2DVector aSize( 679 (double)((const SfxMetricItem&)(rSet.Get(XATTR_FILLBMP_SIZEX))).GetValue(), 680 (double)((const SfxMetricItem&)(rSet.Get(XATTR_FILLBMP_SIZEY))).GetValue()); 681 const basegfx::B2DVector aOffset( 682 (double)((const SfxUInt16Item&) (rSet.Get(XATTR_FILLBMP_TILEOFFSETX))).GetValue(), 683 (double)((const SfxUInt16Item&) (rSet.Get(XATTR_FILLBMP_TILEOFFSETY))).GetValue()); 684 const basegfx::B2DVector aOffsetPosition( 685 (double)((const SfxUInt16Item&) (rSet.Get(XATTR_FILLBMP_POSOFFSETX))).GetValue(), 686 (double)((const SfxUInt16Item&) (rSet.Get(XATTR_FILLBMP_POSOFFSETY))).GetValue()); 687 688 return attribute::SdrFillGraphicAttribute( 689 aGraphic, 690 aGraphicLogicSize, 691 aSize, 692 aOffset, 693 aOffsetPosition, 694 RectPointToB2DVector((RECT_POINT)((const SfxEnumItem&)(rSet.Get(XATTR_FILLBMP_POS))).GetValue()), 695 ((const SfxBoolItem&) (rSet.Get(XATTR_FILLBMP_TILE))).GetValue(), 696 ((const SfxBoolItem&) (rSet.Get(XATTR_FILLBMP_STRETCH))).GetValue(), 697 ((const SfxBoolItem&) (rSet.Get(XATTR_FILLBMP_SIZELOG))).GetValue()); 698 } 699 createNewSdrShadowTextAttribute(const SfxItemSet & rSet,const SdrText * pText,bool bSuppressText)700 attribute::SdrShadowTextAttribute createNewSdrShadowTextAttribute( 701 const SfxItemSet& rSet, 702 const SdrText* pText, 703 bool bSuppressText) 704 { 705 attribute::SdrTextAttribute aText; 706 707 // #i98072# added option to suppress text 708 // look for text first 709 if(!bSuppressText && pText) 710 { 711 aText = createNewSdrTextAttribute(rSet, *pText); 712 } 713 714 // try shadow 715 const attribute::SdrShadowAttribute aShadow(createNewSdrShadowAttribute(rSet)); 716 717 return attribute::SdrShadowTextAttribute(aShadow, aText); 718 } 719 createNewSdrLineShadowTextAttribute(const SfxItemSet & rSet,const SdrText * pText)720 attribute::SdrLineShadowTextAttribute createNewSdrLineShadowTextAttribute( 721 const SfxItemSet& rSet, 722 const SdrText* pText) 723 { 724 attribute::SdrLineAttribute aLine; 725 attribute::SdrLineStartEndAttribute aLineStartEnd; 726 attribute::SdrTextAttribute aText; 727 bool bFontworkHideContour(false); 728 729 // look for text first 730 if(pText) 731 { 732 aText = createNewSdrTextAttribute(rSet, *pText); 733 734 // when object has text and text is fontwork and hide contour is set for fontwork, force 735 // line and fill style to empty 736 if(!aText.isDefault() 737 && !aText.getSdrFormTextAttribute().isDefault() 738 && aText.isHideContour()) 739 { 740 bFontworkHideContour = true; 741 } 742 } 743 744 // try line style 745 if(!bFontworkHideContour) 746 { 747 aLine = createNewSdrLineAttribute(rSet); 748 749 if(!aLine.isDefault()) 750 { 751 // try LineStartEnd 752 aLineStartEnd = createNewSdrLineStartEndAttribute(rSet, aLine.getWidth()); 753 } 754 } 755 756 if(!aLine.isDefault() || !aText.isDefault()) 757 { 758 // try shadow 759 const attribute::SdrShadowAttribute aShadow(createNewSdrShadowAttribute(rSet)); 760 761 return attribute::SdrLineShadowTextAttribute(aLine, aLineStartEnd, aShadow, aText); 762 } 763 764 return attribute::SdrLineShadowTextAttribute(); 765 } 766 createNewSdrLineFillShadowTextAttribute(const SfxItemSet & rSet,const SdrText * pText,bool bHasContent)767 attribute::SdrLineFillShadowTextAttribute createNewSdrLineFillShadowTextAttribute( 768 const SfxItemSet& rSet, 769 const SdrText* pText, 770 bool bHasContent) 771 { 772 attribute::SdrLineAttribute aLine; 773 attribute::SdrFillAttribute aFill; 774 attribute::SdrLineStartEndAttribute aLineStartEnd; 775 attribute::SdrShadowAttribute aShadow; 776 attribute::FillGradientAttribute aFillFloatTransGradient; 777 attribute::SdrTextAttribute aText; 778 bool bFontworkHideContour(false); 779 780 // look for text first 781 if(pText) 782 { 783 aText = createNewSdrTextAttribute(rSet, *pText); 784 785 // when object has text and text is fontwork and hide contour is set for fontwork, force 786 // line and fill style to empty 787 if(!aText.getSdrFormTextAttribute().isDefault() && aText.isHideContour()) 788 { 789 bFontworkHideContour = true; 790 } 791 } 792 793 if(!bFontworkHideContour) 794 { 795 // try line style 796 aLine = createNewSdrLineAttribute(rSet); 797 798 if(!aLine.isDefault()) 799 { 800 // try LineStartEnd 801 aLineStartEnd = createNewSdrLineStartEndAttribute(rSet, aLine.getWidth()); 802 } 803 804 // try fill style 805 aFill = createNewSdrFillAttribute(rSet); 806 807 if(!aFill.isDefault()) 808 { 809 // try fillfloattransparence 810 aFillFloatTransGradient = createNewTransparenceGradientAttribute(rSet); 811 } 812 } 813 814 // bHasContent is used from OLE and graphic objects. Normally a possible shadow 815 // depends on line, fill or text to be set, but for these objects it is possible 816 // to have none of these, but still content which needs to have a shadow (if set), 817 // so shadow needs to be tried 818 if(bHasContent || !aLine.isDefault() || !aFill.isDefault() || !aText.isDefault()) 819 { 820 // try shadow 821 aShadow = createNewSdrShadowAttribute(rSet); 822 823 return attribute::SdrLineFillShadowTextAttribute( 824 aLine, aFill, aLineStartEnd, aShadow, aFillFloatTransGradient, aText); 825 } 826 827 return attribute::SdrLineFillShadowTextAttribute(); 828 } 829 createNewSdrLineFillShadowAttribute(const SfxItemSet & rSet,bool bSuppressFill)830 attribute::SdrLineFillShadowAttribute3D createNewSdrLineFillShadowAttribute(const SfxItemSet& rSet, bool bSuppressFill) 831 { 832 attribute::SdrFillAttribute aFill; 833 attribute::SdrLineStartEndAttribute aLineStartEnd; 834 attribute::SdrShadowAttribute aShadow; 835 attribute::FillGradientAttribute aFillFloatTransGradient; 836 837 // try line style 838 const attribute::SdrLineAttribute aLine(createNewSdrLineAttribute(rSet)); 839 840 if(!aLine.isDefault()) 841 { 842 // try LineStartEnd 843 aLineStartEnd = createNewSdrLineStartEndAttribute(rSet, aLine.getWidth()); 844 } 845 846 // try fill style 847 if(!bSuppressFill) 848 { 849 aFill = createNewSdrFillAttribute(rSet); 850 851 if(!aFill.isDefault()) 852 { 853 // try fillfloattransparence 854 aFillFloatTransGradient = createNewTransparenceGradientAttribute(rSet); 855 } 856 } 857 858 if(!aLine.isDefault() || !aFill.isDefault()) 859 { 860 // try shadow 861 aShadow = createNewSdrShadowAttribute(rSet); 862 863 return attribute::SdrLineFillShadowAttribute3D( 864 aLine, aFill, aLineStartEnd, aShadow, aFillFloatTransGradient); 865 } 866 867 return attribute::SdrLineFillShadowAttribute3D(); 868 } 869 createNewSdrSceneAttribute(const SfxItemSet & rSet)870 attribute::SdrSceneAttribute createNewSdrSceneAttribute(const SfxItemSet& rSet) 871 { 872 // get perspective 873 ::com::sun::star::drawing::ProjectionMode aProjectionMode(::com::sun::star::drawing::ProjectionMode_PARALLEL); 874 const sal_uInt16 nProjectionValue(((const Svx3DPerspectiveItem&)rSet.Get(SDRATTR_3DSCENE_PERSPECTIVE)).GetValue()); 875 876 if(1L == nProjectionValue) 877 { 878 aProjectionMode = ::com::sun::star::drawing::ProjectionMode_PERSPECTIVE; 879 } 880 881 // get distance 882 const double fDistance(((const Svx3DDistanceItem&)rSet.Get(SDRATTR_3DSCENE_DISTANCE)).GetValue()); 883 884 // get shadow slant 885 const double fShadowSlant(F_PI180 * ((const Svx3DShadowSlantItem&)rSet.Get(SDRATTR_3DSCENE_SHADOW_SLANT)).GetValue()); 886 887 // get shade mode 888 ::com::sun::star::drawing::ShadeMode aShadeMode(::com::sun::star::drawing::ShadeMode_FLAT); 889 const sal_uInt16 nShadeValue(((const Svx3DShadeModeItem&)rSet.Get(SDRATTR_3DSCENE_SHADE_MODE)).GetValue()); 890 891 if(1L == nShadeValue) 892 { 893 aShadeMode = ::com::sun::star::drawing::ShadeMode_PHONG; 894 } 895 else if(2L == nShadeValue) 896 { 897 aShadeMode = ::com::sun::star::drawing::ShadeMode_SMOOTH; 898 } 899 else if(3L == nShadeValue) 900 { 901 aShadeMode = ::com::sun::star::drawing::ShadeMode_DRAFT; 902 } 903 904 // get two sided lighting 905 const bool bTwoSidedLighting(((const Svx3DTwoSidedLightingItem&)rSet.Get(SDRATTR_3DSCENE_TWO_SIDED_LIGHTING)).GetValue()); 906 907 return attribute::SdrSceneAttribute(fDistance, fShadowSlant, aProjectionMode, aShadeMode, bTwoSidedLighting); 908 } 909 createNewSdrLightingAttribute(const SfxItemSet & rSet)910 attribute::SdrLightingAttribute createNewSdrLightingAttribute(const SfxItemSet& rSet) 911 { 912 // extract lights from given SfxItemSet (from scene) 913 ::std::vector< attribute::Sdr3DLightAttribute > aLightVector; 914 915 if(((const Svx3DLightOnOff1Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTON_1)).GetValue()) 916 { 917 const basegfx::BColor aColor(((const Svx3DLightcolor1Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTCOLOR_1)).GetValue().getBColor()); 918 const basegfx::B3DVector aDirection(((const Svx3DLightDirection1Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_1)).GetValue()); 919 aLightVector.push_back(attribute::Sdr3DLightAttribute(aColor, aDirection, true)); 920 } 921 922 if(((const Svx3DLightOnOff2Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTON_2)).GetValue()) 923 { 924 const basegfx::BColor aColor(((const Svx3DLightcolor2Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTCOLOR_2)).GetValue().getBColor()); 925 const basegfx::B3DVector aDirection(((const Svx3DLightDirection2Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_2)).GetValue()); 926 aLightVector.push_back(attribute::Sdr3DLightAttribute(aColor, aDirection, false)); 927 } 928 929 if(((const Svx3DLightOnOff3Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTON_3)).GetValue()) 930 { 931 const basegfx::BColor aColor(((const Svx3DLightcolor3Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTCOLOR_3)).GetValue().getBColor()); 932 const basegfx::B3DVector aDirection(((const Svx3DLightDirection3Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_3)).GetValue()); 933 aLightVector.push_back(attribute::Sdr3DLightAttribute(aColor, aDirection, false)); 934 } 935 936 if(((const Svx3DLightOnOff4Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTON_4)).GetValue()) 937 { 938 const basegfx::BColor aColor(((const Svx3DLightcolor4Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTCOLOR_4)).GetValue().getBColor()); 939 const basegfx::B3DVector aDirection(((const Svx3DLightDirection4Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_4)).GetValue()); 940 aLightVector.push_back(attribute::Sdr3DLightAttribute(aColor, aDirection, false)); 941 } 942 943 if(((const Svx3DLightOnOff5Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTON_5)).GetValue()) 944 { 945 const basegfx::BColor aColor(((const Svx3DLightcolor5Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTCOLOR_5)).GetValue().getBColor()); 946 const basegfx::B3DVector aDirection(((const Svx3DLightDirection5Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_5)).GetValue()); 947 aLightVector.push_back(attribute::Sdr3DLightAttribute(aColor, aDirection, false)); 948 } 949 950 if(((const Svx3DLightOnOff6Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTON_6)).GetValue()) 951 { 952 const basegfx::BColor aColor(((const Svx3DLightcolor6Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTCOLOR_6)).GetValue().getBColor()); 953 const basegfx::B3DVector aDirection(((const Svx3DLightDirection6Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_6)).GetValue()); 954 aLightVector.push_back(attribute::Sdr3DLightAttribute(aColor, aDirection, false)); 955 } 956 957 if(((const Svx3DLightOnOff7Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTON_7)).GetValue()) 958 { 959 const basegfx::BColor aColor(((const Svx3DLightcolor7Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTCOLOR_7)).GetValue().getBColor()); 960 const basegfx::B3DVector aDirection(((const Svx3DLightDirection7Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_7)).GetValue()); 961 aLightVector.push_back(attribute::Sdr3DLightAttribute(aColor, aDirection, false)); 962 } 963 964 if(((const Svx3DLightOnOff8Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTON_8)).GetValue()) 965 { 966 const basegfx::BColor aColor(((const Svx3DLightcolor8Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTCOLOR_8)).GetValue().getBColor()); 967 const basegfx::B3DVector aDirection(((const Svx3DLightDirection8Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_8)).GetValue()); 968 aLightVector.push_back(attribute::Sdr3DLightAttribute(aColor, aDirection, false)); 969 } 970 971 // get ambient color 972 const Color aAmbientValue(((const Svx3DAmbientcolorItem&)rSet.Get(SDRATTR_3DSCENE_AMBIENTCOLOR)).GetValue()); 973 const basegfx::BColor aAmbientLight(aAmbientValue.getBColor()); 974 975 return attribute::SdrLightingAttribute(aAmbientLight, aLightVector); 976 } 977 calculateRelativeCornerRadius(sal_Int32 nRadius,const basegfx::B2DRange & rObjectRange,double & rfCornerRadiusX,double & rfCornerRadiusY)978 void calculateRelativeCornerRadius(sal_Int32 nRadius, const basegfx::B2DRange& rObjectRange, double& rfCornerRadiusX, double& rfCornerRadiusY) 979 { 980 rfCornerRadiusX = rfCornerRadiusY = (double)nRadius; 981 982 if(0.0 != rfCornerRadiusX) 983 { 984 const double fHalfObjectWidth(rObjectRange.getWidth() * 0.5); 985 986 if(0.0 != fHalfObjectWidth) 987 { 988 if(rfCornerRadiusX < 0.0) 989 { 990 rfCornerRadiusX = 0.0; 991 } 992 993 if(rfCornerRadiusX > fHalfObjectWidth) 994 { 995 rfCornerRadiusX = fHalfObjectWidth; 996 } 997 998 rfCornerRadiusX /= fHalfObjectWidth; 999 } 1000 else 1001 { 1002 rfCornerRadiusX = 0.0; 1003 } 1004 } 1005 1006 if(0.0 != rfCornerRadiusY) 1007 { 1008 const double fHalfObjectHeight(rObjectRange.getHeight() * 0.5); 1009 1010 if(0.0 != fHalfObjectHeight) 1011 { 1012 if(rfCornerRadiusY < 0.0) 1013 { 1014 rfCornerRadiusY = 0.0; 1015 } 1016 1017 if(rfCornerRadiusY > fHalfObjectHeight) 1018 { 1019 rfCornerRadiusY = fHalfObjectHeight; 1020 } 1021 1022 rfCornerRadiusY /= fHalfObjectHeight; 1023 } 1024 else 1025 { 1026 rfCornerRadiusY = 0.0; 1027 } 1028 } 1029 } 1030 1031 // #i101508# Support handing over given text-to-border distances createNewSdrFillTextAttribute(const SfxItemSet & rSet,const SdrText * pText,const sal_Int32 * pLeft,const sal_Int32 * pUpper,const sal_Int32 * pRight,const sal_Int32 * pLower)1032 attribute::SdrFillTextAttribute createNewSdrFillTextAttribute( 1033 const SfxItemSet& rSet, 1034 const SdrText* pText, 1035 const sal_Int32* pLeft, 1036 const sal_Int32* pUpper, 1037 const sal_Int32* pRight, 1038 const sal_Int32* pLower) 1039 { 1040 attribute::SdrFillAttribute aFill; 1041 attribute::FillGradientAttribute aFillFloatTransGradient; 1042 attribute::SdrTextAttribute aText; 1043 bool bFontworkHideContour(false); 1044 1045 // look for text first 1046 if(pText) 1047 { 1048 aText = createNewSdrTextAttribute(rSet, *pText, pLeft, pUpper, pRight, pLower); 1049 1050 // when object has text and text is fontwork and hide contour is set for fontwork, force 1051 // fill style to empty 1052 if(!aText.getSdrFormTextAttribute().isDefault() && aText.isHideContour()) 1053 { 1054 bFontworkHideContour = true; 1055 } 1056 } 1057 1058 if(!bFontworkHideContour) 1059 { 1060 // try fill style 1061 aFill = createNewSdrFillAttribute(rSet); 1062 1063 if(!aFill.isDefault()) 1064 { 1065 // try fillfloattransparence 1066 aFillFloatTransGradient = createNewTransparenceGradientAttribute(rSet); 1067 } 1068 } 1069 1070 if(!aFill.isDefault() || !aText.isDefault()) 1071 { 1072 return attribute::SdrFillTextAttribute(aFill, aFillFloatTransGradient, aText); 1073 } 1074 1075 return attribute::SdrFillTextAttribute(); 1076 } 1077 1078 } // end of namespace primitive2d 1079 } // end of namespace drawinglayer 1080 1081 ////////////////////////////////////////////////////////////////////////////// 1082 // eof 1083