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 26 #include <svx/sdr/attribute/sdrformtextattribute.hxx> 27 #include <basegfx/vector/b2enums.hxx> 28 #include <svl/itemset.hxx> 29 #include <svx/xftdiit.hxx> 30 #include <svx/xftstit.hxx> 31 #include <svx/xftshxy.hxx> 32 #include <svx/xftshtit.hxx> 33 #include <svx/xtextit0.hxx> 34 #include <svx/xftadit.hxx> 35 #include <svx/xftshit.hxx> 36 #include <svx/xftshcit.hxx> 37 #include <svx/xftmrit.hxx> 38 #include <svx/xftouit.hxx> 39 #include <svx/sdshtitm.hxx> 40 #include <svx/xlntrit.hxx> 41 #include <svx/sdshcitm.hxx> 42 #include <svx/xlnclit.hxx> 43 #include <svx/xlnwtit.hxx> 44 #include <svx/xlinjoit.hxx> 45 #include <svx/xlncapit.hxx> 46 #include <svx/xlineit0.hxx> 47 #include <svx/xdash.hxx> 48 #include <svx/xlndsit.hxx> 49 #include <drawinglayer/attribute/lineattribute.hxx> 50 #include <drawinglayer/attribute/strokeattribute.hxx> 51 #include <svx/sdr/attribute/sdrformtextoutlineattribute.hxx> 52 #include <com/sun/star/drawing/LineCap.hpp> 53 54 ////////////////////////////////////////////////////////////////////////////// 55 // helper to get line, stroke and transparence attributes from SfxItemSet 56 57 namespace 58 { impGetB2DLineJoin(com::sun::star::drawing::LineJoint eLineJoint)59 basegfx::B2DLineJoin impGetB2DLineJoin(com::sun::star::drawing::LineJoint eLineJoint) 60 { 61 switch(eLineJoint) 62 { 63 case com::sun::star::drawing::LineJoint_MIDDLE : 64 { 65 return basegfx::B2DLINEJOIN_MIDDLE; 66 } 67 case com::sun::star::drawing::LineJoint_BEVEL : 68 { 69 return basegfx::B2DLINEJOIN_BEVEL; 70 } 71 case com::sun::star::drawing::LineJoint_MITER : 72 { 73 return basegfx::B2DLINEJOIN_MITER; 74 } 75 case com::sun::star::drawing::LineJoint_ROUND : 76 { 77 return basegfx::B2DLINEJOIN_ROUND; 78 } 79 default : // com::sun::star::drawing::LineJoint_NONE 80 { 81 return basegfx::B2DLINEJOIN_NONE; // XLINEJOINT_NONE 82 } 83 } 84 } 85 impGetStrokeTransparence(bool bShadow,const SfxItemSet & rSet)86 sal_uInt8 impGetStrokeTransparence(bool bShadow, const SfxItemSet& rSet) 87 { 88 sal_uInt8 nRetval; 89 90 if(bShadow) 91 { 92 nRetval = (sal_uInt8)((((SdrShadowTransparenceItem&)(rSet.Get(SDRATTR_SHADOWTRANSPARENCE))).GetValue() * 255) / 100); 93 } 94 else 95 { 96 nRetval = (sal_uInt8)((((XLineTransparenceItem&)(rSet.Get(XATTR_LINETRANSPARENCE))).GetValue() * 255) / 100); 97 } 98 99 return nRetval; 100 } 101 impGetLineAttribute(bool bShadow,const SfxItemSet & rSet)102 drawinglayer::attribute::LineAttribute impGetLineAttribute(bool bShadow, const SfxItemSet& rSet) 103 { 104 basegfx::BColor aColorAttribute; 105 106 if(bShadow) 107 { 108 const Color aShadowColor(((SdrShadowColorItem&)(rSet.Get(SDRATTR_SHADOWCOLOR))).GetColorValue()); 109 aColorAttribute = aShadowColor.getBColor(); 110 } 111 else 112 { 113 const Color aLineColor(((XLineColorItem&)(rSet.Get(XATTR_LINECOLOR))).GetColorValue()); 114 aColorAttribute = aLineColor.getBColor(); 115 } 116 117 const sal_uInt32 nLineWidth = ((const XLineWidthItem&)(rSet.Get(XATTR_LINEWIDTH))).GetValue(); 118 const com::sun::star::drawing::LineJoint eLineJoint = ((const XLineJointItem&)(rSet.Get(XATTR_LINEJOINT))).GetValue(); 119 const com::sun::star::drawing::LineCap eLineCap = ((const XLineCapItem&)(rSet.Get(XATTR_LINECAP))).GetValue(); 120 121 return drawinglayer::attribute::LineAttribute( 122 aColorAttribute, 123 (double)nLineWidth, 124 impGetB2DLineJoin(eLineJoint), 125 eLineCap); 126 } 127 impGetStrokeAttribute(const SfxItemSet & rSet)128 drawinglayer::attribute::StrokeAttribute impGetStrokeAttribute(const SfxItemSet& rSet) 129 { 130 const XLineStyle eLineStyle = ((XLineStyleItem&)(rSet.Get(XATTR_LINESTYLE))).GetValue(); 131 double fFullDotDashLen(0.0); 132 ::std::vector< double > aDotDashArray; 133 134 if(XLINE_DASH == eLineStyle) 135 { 136 const XDash& rDash = ((const XLineDashItem&)(rSet.Get(XATTR_LINEDASH))).GetDashValue(); 137 138 if(rDash.GetDots() || rDash.GetDashes()) 139 { 140 const sal_uInt32 nLineWidth = ((const XLineWidthItem&)(rSet.Get(XATTR_LINEWIDTH))).GetValue(); 141 fFullDotDashLen = rDash.CreateDotDashArray(aDotDashArray, (double)nLineWidth); 142 } 143 } 144 145 return drawinglayer::attribute::StrokeAttribute(aDotDashArray, fFullDotDashLen); 146 } 147 } // end of anonymous namespace 148 149 ////////////////////////////////////////////////////////////////////////////// 150 151 namespace drawinglayer 152 { 153 namespace attribute 154 { 155 class ImpSdrFormTextAttribute 156 { 157 public: 158 // refcounter 159 sal_uInt32 mnRefCount; 160 161 // FormText (FontWork) Attributes 162 sal_Int32 mnFormTextDistance; // distance from line in upright direction 163 sal_Int32 mnFormTextStart; // shift from polygon start 164 sal_Int32 mnFormTextShdwXVal; // shadow distance or 10th degrees 165 sal_Int32 mnFormTextShdwYVal; // shadow distance or scaling 166 sal_uInt16 mnFormTextShdwTransp; // shadow transparence 167 XFormTextStyle meFormTextStyle; // on/off and char orientation 168 XFormTextAdjust meFormTextAdjust; // adjustment (left/right/center) and scale 169 XFormTextShadow meFormTextShadow; // shadow mode 170 Color maFormTextShdwColor; // shadow color 171 172 // outline attributes; used when getFormTextOutline() is true and (for 173 // shadow) when getFormTextShadow() != XFTSHADOW_NONE 174 SdrFormTextOutlineAttribute maOutline; 175 SdrFormTextOutlineAttribute maShadowOutline; 176 177 // bitfield 178 unsigned mbFormTextMirror : 1; // change orientation 179 unsigned mbFormTextOutline : 1; // show contour of objects 180 ImpSdrFormTextAttribute(const SfxItemSet & rSet)181 ImpSdrFormTextAttribute(const SfxItemSet& rSet) 182 : mnRefCount(0), 183 mnFormTextDistance(((const XFormTextDistanceItem&)rSet.Get(XATTR_FORMTXTDISTANCE)).GetValue()), 184 mnFormTextStart(((const XFormTextStartItem&)rSet.Get(XATTR_FORMTXTSTART)).GetValue()), 185 mnFormTextShdwXVal(((const XFormTextShadowXValItem&)rSet.Get(XATTR_FORMTXTSHDWXVAL)).GetValue()), 186 mnFormTextShdwYVal(((const XFormTextShadowYValItem&)rSet.Get(XATTR_FORMTXTSHDWYVAL)).GetValue()), 187 mnFormTextShdwTransp(((const XFormTextShadowTranspItem&)rSet.Get(XATTR_FORMTXTSHDWTRANSP)).GetValue()), 188 meFormTextStyle(((const XFormTextStyleItem&)rSet.Get(XATTR_FORMTXTSTYLE)).GetValue()), 189 meFormTextAdjust(((const XFormTextAdjustItem&)rSet.Get(XATTR_FORMTXTADJUST)).GetValue()), 190 meFormTextShadow(((const XFormTextShadowItem&)rSet.Get(XATTR_FORMTXTSHADOW)).GetValue()), 191 maFormTextShdwColor(((const XFormTextShadowColorItem&)rSet.Get(XATTR_FORMTXTSHDWCOLOR)).GetColorValue()), 192 maOutline(), 193 maShadowOutline(), 194 mbFormTextMirror(((const XFormTextMirrorItem&)rSet.Get(XATTR_FORMTXTMIRROR)).GetValue()), 195 mbFormTextOutline(((const XFormTextOutlineItem&)rSet.Get(XATTR_FORMTXTOUTLINE)).GetValue()) 196 { 197 if(getFormTextOutline()) 198 { 199 const StrokeAttribute aStrokeAttribute(impGetStrokeAttribute(rSet)); 200 201 // also need to prepare attributes for outlines 202 { 203 const LineAttribute aLineAttribute(impGetLineAttribute(false, rSet)); 204 const sal_uInt8 nTransparence(impGetStrokeTransparence(false, rSet)); 205 206 maOutline = SdrFormTextOutlineAttribute( 207 aLineAttribute, aStrokeAttribute, nTransparence); 208 } 209 210 if(XFTSHADOW_NONE != getFormTextShadow()) 211 { 212 // also need to prepare attributes for shadow outlines 213 const LineAttribute aLineAttribute(impGetLineAttribute(true, rSet)); 214 const sal_uInt8 nTransparence(impGetStrokeTransparence(true, rSet)); 215 216 maShadowOutline = SdrFormTextOutlineAttribute( 217 aLineAttribute, aStrokeAttribute, nTransparence); 218 } 219 } 220 } 221 ImpSdrFormTextAttribute()222 ImpSdrFormTextAttribute() 223 : mnRefCount(0), 224 mnFormTextDistance(0), 225 mnFormTextStart(0), 226 mnFormTextShdwXVal(0), 227 mnFormTextShdwYVal(0), 228 mnFormTextShdwTransp(0), 229 meFormTextStyle(XFT_NONE), 230 meFormTextAdjust(XFT_CENTER), 231 meFormTextShadow(XFTSHADOW_NONE), 232 maFormTextShdwColor(), 233 maOutline(), 234 maShadowOutline(), 235 mbFormTextMirror(false), 236 mbFormTextOutline(false) 237 { 238 } 239 240 // data read access getFormTextDistance() const241 sal_Int32 getFormTextDistance() const { return mnFormTextDistance; } getFormTextStart() const242 sal_Int32 getFormTextStart() const { return mnFormTextStart; } getFormTextShdwXVal() const243 sal_Int32 getFormTextShdwXVal() const { return mnFormTextShdwXVal; } getFormTextShdwYVal() const244 sal_Int32 getFormTextShdwYVal() const { return mnFormTextShdwYVal; } getFormTextShdwTransp() const245 sal_uInt16 getFormTextShdwTransp() const { return mnFormTextShdwTransp; } getFormTextStyle() const246 XFormTextStyle getFormTextStyle() const { return meFormTextStyle; } getFormTextAdjust() const247 XFormTextAdjust getFormTextAdjust() const { return meFormTextAdjust; } getFormTextShadow() const248 XFormTextShadow getFormTextShadow() const { return meFormTextShadow; } getFormTextShdwColor() const249 Color getFormTextShdwColor() const { return maFormTextShdwColor; } getOutline() const250 const SdrFormTextOutlineAttribute& getOutline() const { return maOutline; } getShadowOutline() const251 const SdrFormTextOutlineAttribute& getShadowOutline() const { return maShadowOutline; } getFormTextMirror() const252 bool getFormTextMirror() const { return mbFormTextMirror; } getFormTextOutline() const253 bool getFormTextOutline() const { return mbFormTextOutline; } 254 255 // compare operator operator ==(const ImpSdrFormTextAttribute & rCandidate) const256 bool operator==(const ImpSdrFormTextAttribute& rCandidate) const 257 { 258 return (getFormTextDistance() == rCandidate.getFormTextDistance() 259 && getFormTextStart() == rCandidate.getFormTextStart() 260 && getFormTextShdwXVal() == rCandidate.getFormTextShdwXVal() 261 && getFormTextShdwYVal() == rCandidate.getFormTextShdwYVal() 262 && getFormTextShdwTransp() == rCandidate.getFormTextShdwTransp() 263 && getFormTextStyle() == rCandidate.getFormTextStyle() 264 && getFormTextAdjust() == rCandidate.getFormTextAdjust() 265 && getFormTextShadow() == rCandidate.getFormTextShadow() 266 && getFormTextShdwColor() == rCandidate.getFormTextShdwColor() 267 && getOutline() == rCandidate.getOutline() 268 && getShadowOutline() == rCandidate.getShadowOutline() 269 && getFormTextMirror() == rCandidate.getFormTextMirror() 270 && getFormTextOutline() == rCandidate.getFormTextOutline()); 271 } 272 get_global_default()273 static ImpSdrFormTextAttribute* get_global_default() 274 { 275 static ImpSdrFormTextAttribute* pDefault = 0; 276 277 if(!pDefault) 278 { 279 pDefault = new ImpSdrFormTextAttribute(); 280 281 // never delete; start with RefCount 1, not 0 282 pDefault->mnRefCount++; 283 } 284 285 return pDefault; 286 } 287 }; 288 SdrFormTextAttribute(const SfxItemSet & rSet)289 SdrFormTextAttribute::SdrFormTextAttribute(const SfxItemSet& rSet) 290 : mpSdrFormTextAttribute(new ImpSdrFormTextAttribute(rSet)) 291 { 292 } 293 SdrFormTextAttribute()294 SdrFormTextAttribute::SdrFormTextAttribute() 295 : mpSdrFormTextAttribute(ImpSdrFormTextAttribute::get_global_default()) 296 { 297 mpSdrFormTextAttribute->mnRefCount++; 298 } 299 SdrFormTextAttribute(const SdrFormTextAttribute & rCandidate)300 SdrFormTextAttribute::SdrFormTextAttribute(const SdrFormTextAttribute& rCandidate) 301 : mpSdrFormTextAttribute(rCandidate.mpSdrFormTextAttribute) 302 { 303 mpSdrFormTextAttribute->mnRefCount++; 304 } 305 ~SdrFormTextAttribute()306 SdrFormTextAttribute::~SdrFormTextAttribute() 307 { 308 if(mpSdrFormTextAttribute->mnRefCount) 309 { 310 mpSdrFormTextAttribute->mnRefCount--; 311 } 312 else 313 { 314 delete mpSdrFormTextAttribute; 315 } 316 } 317 isDefault() const318 bool SdrFormTextAttribute::isDefault() const 319 { 320 return mpSdrFormTextAttribute == ImpSdrFormTextAttribute::get_global_default(); 321 } 322 operator =(const SdrFormTextAttribute & rCandidate)323 SdrFormTextAttribute& SdrFormTextAttribute::operator=(const SdrFormTextAttribute& rCandidate) 324 { 325 if(rCandidate.mpSdrFormTextAttribute != mpSdrFormTextAttribute) 326 { 327 if(mpSdrFormTextAttribute->mnRefCount) 328 { 329 mpSdrFormTextAttribute->mnRefCount--; 330 } 331 else 332 { 333 delete mpSdrFormTextAttribute; 334 } 335 336 mpSdrFormTextAttribute = rCandidate.mpSdrFormTextAttribute; 337 mpSdrFormTextAttribute->mnRefCount++; 338 } 339 340 return *this; 341 } 342 operator ==(const SdrFormTextAttribute & rCandidate) const343 bool SdrFormTextAttribute::operator==(const SdrFormTextAttribute& rCandidate) const 344 { 345 if(rCandidate.mpSdrFormTextAttribute == mpSdrFormTextAttribute) 346 { 347 return true; 348 } 349 350 if(rCandidate.isDefault() != isDefault()) 351 { 352 return false; 353 } 354 355 return (*rCandidate.mpSdrFormTextAttribute == *mpSdrFormTextAttribute); 356 } 357 getFormTextDistance() const358 sal_Int32 SdrFormTextAttribute::getFormTextDistance() const 359 { 360 return mpSdrFormTextAttribute->getFormTextDistance(); 361 } 362 getFormTextStart() const363 sal_Int32 SdrFormTextAttribute::getFormTextStart() const 364 { 365 return mpSdrFormTextAttribute->getFormTextStart(); 366 } 367 getFormTextShdwXVal() const368 sal_Int32 SdrFormTextAttribute::getFormTextShdwXVal() const 369 { 370 return mpSdrFormTextAttribute->getFormTextShdwXVal(); 371 } 372 getFormTextShdwYVal() const373 sal_Int32 SdrFormTextAttribute::getFormTextShdwYVal() const 374 { 375 return mpSdrFormTextAttribute->getFormTextShdwYVal(); 376 } 377 getFormTextShdwTransp() const378 sal_uInt16 SdrFormTextAttribute::getFormTextShdwTransp() const 379 { 380 return mpSdrFormTextAttribute->getFormTextShdwTransp(); 381 } 382 getFormTextStyle() const383 XFormTextStyle SdrFormTextAttribute::getFormTextStyle() const 384 { 385 return mpSdrFormTextAttribute->getFormTextStyle(); 386 } 387 getFormTextAdjust() const388 XFormTextAdjust SdrFormTextAttribute::getFormTextAdjust() const 389 { 390 return mpSdrFormTextAttribute->getFormTextAdjust(); 391 } 392 getFormTextShadow() const393 XFormTextShadow SdrFormTextAttribute::getFormTextShadow() const 394 { 395 return mpSdrFormTextAttribute->getFormTextShadow(); 396 } 397 getFormTextShdwColor() const398 Color SdrFormTextAttribute::getFormTextShdwColor() const 399 { 400 return mpSdrFormTextAttribute->getFormTextShdwColor(); 401 } 402 getOutline() const403 const SdrFormTextOutlineAttribute& SdrFormTextAttribute::getOutline() const 404 { 405 return mpSdrFormTextAttribute->getOutline(); 406 } 407 getShadowOutline() const408 const SdrFormTextOutlineAttribute& SdrFormTextAttribute::getShadowOutline() const 409 { 410 return mpSdrFormTextAttribute->getShadowOutline(); 411 } 412 getFormTextMirror() const413 bool SdrFormTextAttribute::getFormTextMirror() const 414 { 415 return mpSdrFormTextAttribute->getFormTextMirror(); 416 } 417 getFormTextOutline() const418 bool SdrFormTextAttribute::getFormTextOutline() const 419 { 420 return mpSdrFormTextAttribute->getFormTextOutline(); 421 } 422 } // end of namespace attribute 423 } // end of namespace drawinglayer 424 425 ////////////////////////////////////////////////////////////////////////////// 426 // eof 427