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 { 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 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 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 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 { 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 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::SdrFillGraphicAttribute aFillGraphic; 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 3, // same default as VCL, a minimum of three discrete units (pixels) offset 462 ((const XFillBackgroundItem&)(rSet.Get(XATTR_FILLBACKGROUND))).GetValue()); 463 464 break; 465 } 466 case XFILL_BITMAP : 467 { 468 aFillGraphic = createNewSdrFillGraphicAttribute(rSet); 469 break; 470 } 471 } 472 473 return attribute::SdrFillAttribute( 474 (double)nTransparence * 0.01, 475 aColor.getBColor(), 476 aGradient, 477 aHatch, 478 aFillGraphic); 479 } 480 } 481 482 return attribute::SdrFillAttribute(); 483 } 484 485 // #i101508# Support handing over given text-to-border distances 486 attribute::SdrTextAttribute createNewSdrTextAttribute( 487 const SfxItemSet& rSet, 488 const SdrText& rText, 489 const sal_Int32* pLeft, 490 const sal_Int32* pUpper, 491 const sal_Int32* pRight, 492 const sal_Int32* pLower) 493 { 494 const SdrTextObj& rTextObj = rText.GetObject(); 495 496 if(rText.GetOutlinerParaObject() && rText.GetModel()) 497 { 498 // added TextEdit text suppression 499 bool bInEditMode(false); 500 501 if(rText.GetObject().getTextCount() > 1) 502 { 503 bInEditMode = rTextObj.IsInEditMode() && rText.GetObject().getActiveText() == &rText; 504 } 505 else 506 { 507 bInEditMode = rTextObj.IsInEditMode(); 508 } 509 510 OutlinerParaObject aOutlinerParaObject(*rText.GetOutlinerParaObject()); 511 512 if(bInEditMode) 513 { 514 OutlinerParaObject* pTempObj = rTextObj.GetEditOutlinerParaObject(); 515 516 if(pTempObj) 517 { 518 aOutlinerParaObject = *pTempObj; 519 delete pTempObj; 520 } 521 else 522 { 523 // #i100537# 524 // GetEditOutlinerParaObject() returning no object does not mean that 525 // text edit mode is not active. Do not reset the flag here 526 // bInEditMode = false; 527 } 528 } 529 530 const SdrFitToSizeType eFit(rTextObj.GetFitToSize()); 531 const SdrTextAniKind eAniKind(rTextObj.GetTextAniKind()); 532 533 // #i107346# 534 const SdrOutliner& rDrawTextOutliner = rText.GetModel()->GetDrawOutliner(&rTextObj); 535 const bool bWrongSpell(rDrawTextOutliner.GetControlWord() & EE_CNTRL_ONLINESPELLING); 536 537 return attribute::SdrTextAttribute( 538 rText, 539 aOutlinerParaObject, 540 ((const XFormTextStyleItem&)rSet.Get(XATTR_FORMTXTSTYLE)).GetValue(), 541 pLeft ? *pLeft : rTextObj.GetTextLeftDistance(), 542 pUpper ? *pUpper : rTextObj.GetTextUpperDistance(), 543 pRight ? *pRight : rTextObj.GetTextRightDistance(), 544 pLower ? *pLower : rTextObj.GetTextLowerDistance(), 545 rTextObj.GetTextHorizontalAdjust(rSet), 546 rTextObj.GetTextVerticalAdjust(rSet), 547 ((const SdrTextContourFrameItem&)rSet.Get(SDRATTR_TEXT_CONTOURFRAME)).GetValue(), 548 (SDRTEXTFIT_PROPORTIONAL == eFit || SDRTEXTFIT_ALLLINES == eFit), 549 ((const XFormTextHideFormItem&)rSet.Get(XATTR_FORMTXTHIDEFORM)).GetValue(), 550 SDRTEXTANI_BLINK == eAniKind, 551 SDRTEXTANI_SCROLL == eAniKind || SDRTEXTANI_ALTERNATE == eAniKind || SDRTEXTANI_SLIDE == eAniKind, 552 bInEditMode, 553 ((const SdrTextFixedCellHeightItem&)rSet.Get(SDRATTR_TEXT_USEFIXEDCELLHEIGHT)).GetValue(), 554 bWrongSpell); 555 } 556 557 return attribute::SdrTextAttribute(); 558 } 559 560 attribute::FillGradientAttribute createNewTransparenceGradientAttribute(const SfxItemSet& rSet) 561 { 562 const SfxPoolItem* pGradientItem; 563 564 if(SFX_ITEM_SET == rSet.GetItemState(XATTR_FILLFLOATTRANSPARENCE, sal_True, &pGradientItem) 565 && ((XFillFloatTransparenceItem*)pGradientItem)->IsEnabled()) 566 { 567 // test if float transparence is completely transparent 568 const XGradient& rGradient = ((XFillFloatTransparenceItem*)pGradientItem)->GetGradientValue(); 569 const sal_uInt8 nStartLuminance(rGradient.GetStartColor().GetLuminance()); 570 const sal_uInt8 nEndLuminance(rGradient.GetEndColor().GetLuminance()); 571 const bool bCompletelyTransparent(0xff == nStartLuminance && 0xff == nEndLuminance); 572 573 if(!bCompletelyTransparent) 574 { 575 const double fStartLum(nStartLuminance / 255.0); 576 const double fEndLum(nEndLuminance / 255.0); 577 578 return attribute::FillGradientAttribute( 579 XGradientStyleToGradientStyle(rGradient.GetGradientStyle()), 580 (double)rGradient.GetBorder() * 0.01, 581 (double)rGradient.GetXOffset() * 0.01, 582 (double)rGradient.GetYOffset() * 0.01, 583 (double)rGradient.GetAngle() * F_PI1800, 584 basegfx::BColor(fStartLum, fStartLum, fStartLum), 585 basegfx::BColor(fEndLum, fEndLum, fEndLum), 586 0); 587 } 588 } 589 590 return attribute::FillGradientAttribute(); 591 } 592 593 attribute::SdrFillGraphicAttribute createNewSdrFillGraphicAttribute(const SfxItemSet& rSet) 594 { 595 Graphic aGraphic(((const XFillBitmapItem&)(rSet.Get(XATTR_FILLBITMAP))).GetGraphicObject().GetGraphic()); 596 597 if(!(GRAPHIC_BITMAP == aGraphic.GetType() || GRAPHIC_GDIMETAFILE == aGraphic.GetType())) 598 { 599 // no content if not bitmap or metafile 600 OSL_ENSURE(false, "No fill graphic in SfxItemSet (!)"); 601 return attribute::SdrFillGraphicAttribute(); 602 } 603 604 Size aPrefSize(aGraphic.GetPrefSize()); 605 606 if(!aPrefSize.Width() || !aPrefSize.Height()) 607 { 608 // if there is no logical size, create a size from pixel size and set MapMode accordingly 609 if(GRAPHIC_BITMAP == aGraphic.GetType()) 610 { 611 aGraphic.SetPrefSize(aGraphic.GetBitmapEx().GetSizePixel()); 612 aGraphic.SetPrefMapMode(MAP_PIXEL); 613 } 614 } 615 616 if(!aPrefSize.Width() || !aPrefSize.Height()) 617 { 618 // no content if no size 619 OSL_ENSURE(false, "Graphic has no size in SfxItemSet (!)"); 620 return attribute::SdrFillGraphicAttribute(); 621 } 622 623 // convert size and MapMode to destination logical size and MapMode 624 const MapUnit aDestinationMapUnit((MapUnit)rSet.GetPool()->GetMetric(0)); 625 626 if(aGraphic.GetPrefMapMode() != aDestinationMapUnit) 627 { 628 // #i100360# for MAP_PIXEL, LogicToLogic will not work properly, 629 // so fallback to Application::GetDefaultDevice() 630 if(MAP_PIXEL == aGraphic.GetPrefMapMode().GetMapUnit()) 631 { 632 aGraphic.SetPrefSize( 633 Application::GetDefaultDevice()->PixelToLogic( 634 aGraphic.GetPrefSize(), 635 aDestinationMapUnit)); 636 } 637 else 638 { 639 aGraphic.SetPrefSize( 640 OutputDevice::LogicToLogic( 641 aGraphic.GetPrefSize(), 642 aGraphic.GetPrefMapMode(), 643 aDestinationMapUnit)); 644 } 645 } 646 647 // get size 648 const basegfx::B2DVector aSize( 649 (double)((const SfxMetricItem&)(rSet.Get(XATTR_FILLBMP_SIZEX))).GetValue(), 650 (double)((const SfxMetricItem&)(rSet.Get(XATTR_FILLBMP_SIZEY))).GetValue()); 651 const basegfx::B2DVector aOffset( 652 (double)((const SfxUInt16Item&) (rSet.Get(XATTR_FILLBMP_TILEOFFSETX))).GetValue(), 653 (double)((const SfxUInt16Item&) (rSet.Get(XATTR_FILLBMP_TILEOFFSETY))).GetValue()); 654 const basegfx::B2DVector aOffsetPosition( 655 (double)((const SfxUInt16Item&) (rSet.Get(XATTR_FILLBMP_POSOFFSETX))).GetValue(), 656 (double)((const SfxUInt16Item&) (rSet.Get(XATTR_FILLBMP_POSOFFSETY))).GetValue()); 657 658 return attribute::SdrFillGraphicAttribute( 659 aGraphic, 660 aSize, 661 aOffset, 662 aOffsetPosition, 663 RectPointToB2DVector((RECT_POINT)((const SfxEnumItem&)(rSet.Get(XATTR_FILLBMP_POS))).GetValue()), 664 ((const SfxBoolItem&) (rSet.Get(XATTR_FILLBMP_TILE))).GetValue(), 665 ((const SfxBoolItem&) (rSet.Get(XATTR_FILLBMP_STRETCH))).GetValue(), 666 ((const SfxBoolItem&) (rSet.Get(XATTR_FILLBMP_SIZELOG))).GetValue()); 667 } 668 669 attribute::SdrShadowTextAttribute createNewSdrShadowTextAttribute( 670 const SfxItemSet& rSet, 671 const SdrText* pText, 672 bool bSuppressText) 673 { 674 attribute::SdrTextAttribute aText; 675 676 // #i98072# added option to suppress text 677 // look for text first 678 if(!bSuppressText && pText) 679 { 680 aText = createNewSdrTextAttribute(rSet, *pText); 681 } 682 683 // try shadow 684 const attribute::SdrShadowAttribute aShadow(createNewSdrShadowAttribute(rSet)); 685 686 return attribute::SdrShadowTextAttribute(aShadow, aText); 687 } 688 689 attribute::SdrLineShadowTextAttribute createNewSdrLineShadowTextAttribute( 690 const SfxItemSet& rSet, 691 const SdrText* pText) 692 { 693 attribute::SdrLineAttribute aLine; 694 attribute::SdrLineStartEndAttribute aLineStartEnd; 695 attribute::SdrTextAttribute aText; 696 bool bFontworkHideContour(false); 697 698 // look for text first 699 if(pText) 700 { 701 aText = createNewSdrTextAttribute(rSet, *pText); 702 703 // when object has text and text is fontwork and hide contour is set for fontwork, force 704 // line and fill style to empty 705 if(!aText.isDefault() 706 && !aText.getSdrFormTextAttribute().isDefault() 707 && aText.isHideContour()) 708 { 709 bFontworkHideContour = true; 710 } 711 } 712 713 // try line style 714 if(!bFontworkHideContour) 715 { 716 aLine = createNewSdrLineAttribute(rSet); 717 718 if(!aLine.isDefault()) 719 { 720 // try LineStartEnd 721 aLineStartEnd = createNewSdrLineStartEndAttribute(rSet, aLine.getWidth()); 722 } 723 } 724 725 if(!aLine.isDefault() || !aText.isDefault()) 726 { 727 // try shadow 728 const attribute::SdrShadowAttribute aShadow(createNewSdrShadowAttribute(rSet)); 729 730 return attribute::SdrLineShadowTextAttribute(aLine, aLineStartEnd, aShadow, aText); 731 } 732 733 return attribute::SdrLineShadowTextAttribute(); 734 } 735 736 attribute::SdrLineFillShadowTextAttribute createNewSdrLineFillShadowTextAttribute( 737 const SfxItemSet& rSet, 738 const SdrText* pText, 739 bool bHasContent) 740 { 741 attribute::SdrLineAttribute aLine; 742 attribute::SdrFillAttribute aFill; 743 attribute::SdrLineStartEndAttribute aLineStartEnd; 744 attribute::SdrShadowAttribute aShadow; 745 attribute::FillGradientAttribute aFillFloatTransGradient; 746 attribute::SdrTextAttribute aText; 747 bool bFontworkHideContour(false); 748 749 // look for text first 750 if(pText) 751 { 752 aText = createNewSdrTextAttribute(rSet, *pText); 753 754 // when object has text and text is fontwork and hide contour is set for fontwork, force 755 // line and fill style to empty 756 if(!aText.getSdrFormTextAttribute().isDefault() && aText.isHideContour()) 757 { 758 bFontworkHideContour = true; 759 } 760 } 761 762 if(!bFontworkHideContour) 763 { 764 // try line style 765 aLine = createNewSdrLineAttribute(rSet); 766 767 if(!aLine.isDefault()) 768 { 769 // try LineStartEnd 770 aLineStartEnd = createNewSdrLineStartEndAttribute(rSet, aLine.getWidth()); 771 } 772 773 // try fill style 774 aFill = createNewSdrFillAttribute(rSet); 775 776 if(!aFill.isDefault()) 777 { 778 // try fillfloattransparence 779 aFillFloatTransGradient = createNewTransparenceGradientAttribute(rSet); 780 } 781 } 782 783 // bHasContent is used from OLE and graphic objects. Normally a possible shadow 784 // depends on line, fill or text to be set, but for these objects it is possible 785 // to have none of these, but still content which needs to have a shadow (if set), 786 // so shadow needs to be tried 787 if(bHasContent || !aLine.isDefault() || !aFill.isDefault() || !aText.isDefault()) 788 { 789 // try shadow 790 aShadow = createNewSdrShadowAttribute(rSet); 791 792 return attribute::SdrLineFillShadowTextAttribute( 793 aLine, aFill, aLineStartEnd, aShadow, aFillFloatTransGradient, aText); 794 } 795 796 return attribute::SdrLineFillShadowTextAttribute(); 797 } 798 799 attribute::SdrLineFillShadowAttribute3D createNewSdrLineFillShadowAttribute(const SfxItemSet& rSet, bool bSuppressFill) 800 { 801 attribute::SdrFillAttribute aFill; 802 attribute::SdrLineStartEndAttribute aLineStartEnd; 803 attribute::SdrShadowAttribute aShadow; 804 attribute::FillGradientAttribute aFillFloatTransGradient; 805 806 // try line style 807 const attribute::SdrLineAttribute aLine(createNewSdrLineAttribute(rSet)); 808 809 if(!aLine.isDefault()) 810 { 811 // try LineStartEnd 812 aLineStartEnd = createNewSdrLineStartEndAttribute(rSet, aLine.getWidth()); 813 } 814 815 // try fill style 816 if(!bSuppressFill) 817 { 818 aFill = createNewSdrFillAttribute(rSet); 819 820 if(!aFill.isDefault()) 821 { 822 // try fillfloattransparence 823 aFillFloatTransGradient = createNewTransparenceGradientAttribute(rSet); 824 } 825 } 826 827 if(!aLine.isDefault() || !aFill.isDefault()) 828 { 829 // try shadow 830 aShadow = createNewSdrShadowAttribute(rSet); 831 832 return attribute::SdrLineFillShadowAttribute3D( 833 aLine, aFill, aLineStartEnd, aShadow, aFillFloatTransGradient); 834 } 835 836 return attribute::SdrLineFillShadowAttribute3D(); 837 } 838 839 attribute::SdrSceneAttribute createNewSdrSceneAttribute(const SfxItemSet& rSet) 840 { 841 // get perspective 842 ::com::sun::star::drawing::ProjectionMode aProjectionMode(::com::sun::star::drawing::ProjectionMode_PARALLEL); 843 const sal_uInt16 nProjectionValue(((const Svx3DPerspectiveItem&)rSet.Get(SDRATTR_3DSCENE_PERSPECTIVE)).GetValue()); 844 845 if(1L == nProjectionValue) 846 { 847 aProjectionMode = ::com::sun::star::drawing::ProjectionMode_PERSPECTIVE; 848 } 849 850 // get distance 851 const double fDistance(((const Svx3DDistanceItem&)rSet.Get(SDRATTR_3DSCENE_DISTANCE)).GetValue()); 852 853 // get shadow slant 854 const double fShadowSlant(F_PI180 * ((const Svx3DShadowSlantItem&)rSet.Get(SDRATTR_3DSCENE_SHADOW_SLANT)).GetValue()); 855 856 // get shade mode 857 ::com::sun::star::drawing::ShadeMode aShadeMode(::com::sun::star::drawing::ShadeMode_FLAT); 858 const sal_uInt16 nShadeValue(((const Svx3DShadeModeItem&)rSet.Get(SDRATTR_3DSCENE_SHADE_MODE)).GetValue()); 859 860 if(1L == nShadeValue) 861 { 862 aShadeMode = ::com::sun::star::drawing::ShadeMode_PHONG; 863 } 864 else if(2L == nShadeValue) 865 { 866 aShadeMode = ::com::sun::star::drawing::ShadeMode_SMOOTH; 867 } 868 else if(3L == nShadeValue) 869 { 870 aShadeMode = ::com::sun::star::drawing::ShadeMode_DRAFT; 871 } 872 873 // get two sided lighting 874 const bool bTwoSidedLighting(((const Svx3DTwoSidedLightingItem&)rSet.Get(SDRATTR_3DSCENE_TWO_SIDED_LIGHTING)).GetValue()); 875 876 return attribute::SdrSceneAttribute(fDistance, fShadowSlant, aProjectionMode, aShadeMode, bTwoSidedLighting); 877 } 878 879 attribute::SdrLightingAttribute createNewSdrLightingAttribute(const SfxItemSet& rSet) 880 { 881 // extract lights from given SfxItemSet (from scene) 882 ::std::vector< attribute::Sdr3DLightAttribute > aLightVector; 883 884 if(((const Svx3DLightOnOff1Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTON_1)).GetValue()) 885 { 886 const basegfx::BColor aColor(((const Svx3DLightcolor1Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTCOLOR_1)).GetValue().getBColor()); 887 const basegfx::B3DVector aDirection(((const Svx3DLightDirection1Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_1)).GetValue()); 888 aLightVector.push_back(attribute::Sdr3DLightAttribute(aColor, aDirection, true)); 889 } 890 891 if(((const Svx3DLightOnOff2Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTON_2)).GetValue()) 892 { 893 const basegfx::BColor aColor(((const Svx3DLightcolor2Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTCOLOR_2)).GetValue().getBColor()); 894 const basegfx::B3DVector aDirection(((const Svx3DLightDirection2Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_2)).GetValue()); 895 aLightVector.push_back(attribute::Sdr3DLightAttribute(aColor, aDirection, false)); 896 } 897 898 if(((const Svx3DLightOnOff3Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTON_3)).GetValue()) 899 { 900 const basegfx::BColor aColor(((const Svx3DLightcolor3Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTCOLOR_3)).GetValue().getBColor()); 901 const basegfx::B3DVector aDirection(((const Svx3DLightDirection3Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_3)).GetValue()); 902 aLightVector.push_back(attribute::Sdr3DLightAttribute(aColor, aDirection, false)); 903 } 904 905 if(((const Svx3DLightOnOff4Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTON_4)).GetValue()) 906 { 907 const basegfx::BColor aColor(((const Svx3DLightcolor4Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTCOLOR_4)).GetValue().getBColor()); 908 const basegfx::B3DVector aDirection(((const Svx3DLightDirection4Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_4)).GetValue()); 909 aLightVector.push_back(attribute::Sdr3DLightAttribute(aColor, aDirection, false)); 910 } 911 912 if(((const Svx3DLightOnOff5Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTON_5)).GetValue()) 913 { 914 const basegfx::BColor aColor(((const Svx3DLightcolor5Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTCOLOR_5)).GetValue().getBColor()); 915 const basegfx::B3DVector aDirection(((const Svx3DLightDirection5Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_5)).GetValue()); 916 aLightVector.push_back(attribute::Sdr3DLightAttribute(aColor, aDirection, false)); 917 } 918 919 if(((const Svx3DLightOnOff6Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTON_6)).GetValue()) 920 { 921 const basegfx::BColor aColor(((const Svx3DLightcolor6Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTCOLOR_6)).GetValue().getBColor()); 922 const basegfx::B3DVector aDirection(((const Svx3DLightDirection6Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_6)).GetValue()); 923 aLightVector.push_back(attribute::Sdr3DLightAttribute(aColor, aDirection, false)); 924 } 925 926 if(((const Svx3DLightOnOff7Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTON_7)).GetValue()) 927 { 928 const basegfx::BColor aColor(((const Svx3DLightcolor7Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTCOLOR_7)).GetValue().getBColor()); 929 const basegfx::B3DVector aDirection(((const Svx3DLightDirection7Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_7)).GetValue()); 930 aLightVector.push_back(attribute::Sdr3DLightAttribute(aColor, aDirection, false)); 931 } 932 933 if(((const Svx3DLightOnOff8Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTON_8)).GetValue()) 934 { 935 const basegfx::BColor aColor(((const Svx3DLightcolor8Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTCOLOR_8)).GetValue().getBColor()); 936 const basegfx::B3DVector aDirection(((const Svx3DLightDirection8Item&)rSet.Get(SDRATTR_3DSCENE_LIGHTDIRECTION_8)).GetValue()); 937 aLightVector.push_back(attribute::Sdr3DLightAttribute(aColor, aDirection, false)); 938 } 939 940 // get ambient color 941 const Color aAmbientValue(((const Svx3DAmbientcolorItem&)rSet.Get(SDRATTR_3DSCENE_AMBIENTCOLOR)).GetValue()); 942 const basegfx::BColor aAmbientLight(aAmbientValue.getBColor()); 943 944 return attribute::SdrLightingAttribute(aAmbientLight, aLightVector); 945 } 946 947 void calculateRelativeCornerRadius(sal_Int32 nRadius, const basegfx::B2DRange& rObjectRange, double& rfCornerRadiusX, double& rfCornerRadiusY) 948 { 949 rfCornerRadiusX = rfCornerRadiusY = (double)nRadius; 950 951 if(0.0 != rfCornerRadiusX) 952 { 953 const double fHalfObjectWidth(rObjectRange.getWidth() * 0.5); 954 955 if(0.0 != fHalfObjectWidth) 956 { 957 if(rfCornerRadiusX < 0.0) 958 { 959 rfCornerRadiusX = 0.0; 960 } 961 962 if(rfCornerRadiusX > fHalfObjectWidth) 963 { 964 rfCornerRadiusX = fHalfObjectWidth; 965 } 966 967 rfCornerRadiusX /= fHalfObjectWidth; 968 } 969 else 970 { 971 rfCornerRadiusX = 0.0; 972 } 973 } 974 975 if(0.0 != rfCornerRadiusY) 976 { 977 const double fHalfObjectHeight(rObjectRange.getHeight() * 0.5); 978 979 if(0.0 != fHalfObjectHeight) 980 { 981 if(rfCornerRadiusY < 0.0) 982 { 983 rfCornerRadiusY = 0.0; 984 } 985 986 if(rfCornerRadiusY > fHalfObjectHeight) 987 { 988 rfCornerRadiusY = fHalfObjectHeight; 989 } 990 991 rfCornerRadiusY /= fHalfObjectHeight; 992 } 993 else 994 { 995 rfCornerRadiusY = 0.0; 996 } 997 } 998 } 999 1000 // #i101508# Support handing over given text-to-border distances 1001 attribute::SdrFillTextAttribute createNewSdrFillTextAttribute( 1002 const SfxItemSet& rSet, 1003 const SdrText* pText, 1004 const sal_Int32* pLeft, 1005 const sal_Int32* pUpper, 1006 const sal_Int32* pRight, 1007 const sal_Int32* pLower) 1008 { 1009 attribute::SdrFillAttribute aFill; 1010 attribute::FillGradientAttribute aFillFloatTransGradient; 1011 attribute::SdrTextAttribute aText; 1012 bool bFontworkHideContour(false); 1013 1014 // look for text first 1015 if(pText) 1016 { 1017 aText = createNewSdrTextAttribute(rSet, *pText, pLeft, pUpper, pRight, pLower); 1018 1019 // when object has text and text is fontwork and hide contour is set for fontwork, force 1020 // fill style to empty 1021 if(!aText.getSdrFormTextAttribute().isDefault() && aText.isHideContour()) 1022 { 1023 bFontworkHideContour = true; 1024 } 1025 } 1026 1027 if(!bFontworkHideContour) 1028 { 1029 // try fill style 1030 aFill = createNewSdrFillAttribute(rSet); 1031 1032 if(!aFill.isDefault()) 1033 { 1034 // try fillfloattransparence 1035 aFillFloatTransGradient = createNewTransparenceGradientAttribute(rSet); 1036 } 1037 } 1038 1039 if(!aFill.isDefault() || !aText.isDefault()) 1040 { 1041 return attribute::SdrFillTextAttribute(aFill, aFillFloatTransGradient, aText); 1042 } 1043 1044 return attribute::SdrFillTextAttribute(); 1045 } 1046 1047 } // end of namespace primitive2d 1048 } // end of namespace drawinglayer 1049 1050 ////////////////////////////////////////////////////////////////////////////// 1051 // eof 1052