1 /************************************************************************* 2 * 3 * OpenOffice.org - a multi-platform office productivity suite 4 * 5 * $RCSfile: sdrattribute.cxx,v $ 6 * 7 * $Revision: 1.5 $ 8 * 9 * last change: $Author: aw $ $Date: 2008-05-27 14:11:19 $ 10 * 11 * The Contents of this file are made available subject to 12 * the terms of GNU Lesser General Public License Version 2.1. 13 * 14 * 15 * GNU Lesser General Public License Version 2.1 16 * ============================================= 17 * Copyright 2005 by Sun Microsystems, Inc. 18 * 901 San Antonio Road, Palo Alto, CA 94303, USA 19 * 20 * This library is free software; you can redistribute it and/or 21 * modify it under the terms of the GNU Lesser General Public 22 * License version 2.1, as published by the Free Software Foundation. 23 * 24 * This library is distributed in the hope that it will be useful, 25 * but WITHOUT ANY WARRANTY; without even the implied warranty of 26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 27 * Lesser General Public License for more details. 28 * 29 * You should have received a copy of the GNU Lesser General Public 30 * License along with this library; if not, write to the Free Software 31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 32 * MA 02111-1307 USA 33 * 34 ************************************************************************/ 35 36 // MARKER(update_precomp.py): autogen include statement, do not remove 37 #include "precompiled_drawinglayer.hxx" 38 39 #include <drawinglayer/attribute/sdrlineattribute.hxx> 40 #include <basegfx/color/bcolor.hxx> 41 42 ////////////////////////////////////////////////////////////////////////////// 43 44 namespace drawinglayer 45 { 46 namespace attribute 47 { 48 class ImpSdrLineAttribute 49 { 50 public: 51 // refcounter 52 sal_uInt32 mnRefCount; 53 54 // line definitions 55 basegfx::B2DLineJoin meJoin; // B2DLINEJOIN_* defines 56 double mfWidth; // 1/100th mm, 0.0==hair 57 double mfTransparence; // [0.0 .. 1.0], 0.0==no transp. 58 basegfx::BColor maColor; // color of line 59 com::sun::star::drawing::LineCap meCap; // BUTT, ROUND, or SQUARE 60 ::std::vector< double > maDotDashArray; // array of double which defines the dot-dash pattern 61 double mfFullDotDashLen; // sum of maDotDashArray (for convenience) 62 63 ImpSdrLineAttribute( 64 basegfx::B2DLineJoin eJoin, 65 double fWidth, 66 double fTransparence, 67 const basegfx::BColor& rColor, 68 com::sun::star::drawing::LineCap eCap, 69 const ::std::vector< double >& rDotDashArray, 70 double fFullDotDashLen) 71 : mnRefCount(0), 72 meJoin(eJoin), 73 mfWidth(fWidth), 74 mfTransparence(fTransparence), 75 maColor(rColor), 76 meCap(eCap), 77 maDotDashArray(rDotDashArray), 78 mfFullDotDashLen(fFullDotDashLen) 79 { 80 } 81 82 ImpSdrLineAttribute(const basegfx::BColor& rColor) 83 : mnRefCount(0), 84 meJoin(basegfx::B2DLINEJOIN_NONE), 85 mfWidth(0.0), 86 mfTransparence(0.0), 87 maColor(rColor), 88 meCap(com::sun::star::drawing::LineCap_BUTT), 89 maDotDashArray(), 90 mfFullDotDashLen(0.0) 91 { 92 } 93 94 // data read access 95 basegfx::B2DLineJoin getJoin() const { return meJoin; } 96 double getWidth() const { return mfWidth; } 97 double getTransparence() const { return mfTransparence; } 98 const basegfx::BColor& getColor() const { return maColor; } 99 com::sun::star::drawing::LineCap getCap() const { return meCap; } 100 const ::std::vector< double >& getDotDashArray() const { return maDotDashArray; } 101 double getFullDotDashLen() const { return mfFullDotDashLen; } 102 103 bool operator==(const ImpSdrLineAttribute& rCandidate) const 104 { 105 return (getJoin() == rCandidate.getJoin() 106 && getWidth() == rCandidate.getWidth() 107 && getTransparence() == rCandidate.getTransparence() 108 && getColor() == rCandidate.getColor() 109 && getCap() == rCandidate.getCap() 110 && getDotDashArray() == rCandidate.getDotDashArray()); 111 } 112 113 static ImpSdrLineAttribute* get_global_default() 114 { 115 static ImpSdrLineAttribute* pDefault = 0; 116 117 if(!pDefault) 118 { 119 pDefault = new ImpSdrLineAttribute( 120 basegfx::B2DLINEJOIN_ROUND, 121 0.0, 122 0.0, 123 basegfx::BColor(), 124 com::sun::star::drawing::LineCap_BUTT, 125 std::vector< double >(), 126 0.0); 127 128 // never delete; start with RefCount 1, not 0 129 pDefault->mnRefCount++; 130 } 131 132 return pDefault; 133 } 134 }; 135 136 SdrLineAttribute::SdrLineAttribute( 137 basegfx::B2DLineJoin eJoin, 138 double fWidth, 139 double fTransparence, 140 const basegfx::BColor& rColor, 141 com::sun::star::drawing::LineCap eCap, 142 const ::std::vector< double >& rDotDashArray, 143 double fFullDotDashLen) 144 : mpSdrLineAttribute( 145 new ImpSdrLineAttribute( 146 eJoin, 147 fWidth, 148 fTransparence, 149 rColor, 150 eCap, 151 rDotDashArray, 152 fFullDotDashLen)) 153 { 154 } 155 156 SdrLineAttribute::SdrLineAttribute( 157 const basegfx::BColor& rColor) 158 : mpSdrLineAttribute( 159 new ImpSdrLineAttribute( 160 rColor)) 161 { 162 } 163 164 SdrLineAttribute::SdrLineAttribute() 165 : mpSdrLineAttribute(ImpSdrLineAttribute::get_global_default()) 166 { 167 mpSdrLineAttribute->mnRefCount++; 168 } 169 170 SdrLineAttribute::SdrLineAttribute(const SdrLineAttribute& rCandidate) 171 : mpSdrLineAttribute(rCandidate.mpSdrLineAttribute) 172 { 173 mpSdrLineAttribute->mnRefCount++; 174 } 175 176 SdrLineAttribute::~SdrLineAttribute() 177 { 178 if(mpSdrLineAttribute->mnRefCount) 179 { 180 mpSdrLineAttribute->mnRefCount--; 181 } 182 else 183 { 184 delete mpSdrLineAttribute; 185 } 186 } 187 188 bool SdrLineAttribute::isDefault() const 189 { 190 return mpSdrLineAttribute == ImpSdrLineAttribute::get_global_default(); 191 } 192 193 SdrLineAttribute& SdrLineAttribute::operator=(const SdrLineAttribute& rCandidate) 194 { 195 if(rCandidate.mpSdrLineAttribute != mpSdrLineAttribute) 196 { 197 if(mpSdrLineAttribute->mnRefCount) 198 { 199 mpSdrLineAttribute->mnRefCount--; 200 } 201 else 202 { 203 delete mpSdrLineAttribute; 204 } 205 206 mpSdrLineAttribute = rCandidate.mpSdrLineAttribute; 207 mpSdrLineAttribute->mnRefCount++; 208 } 209 210 return *this; 211 } 212 213 bool SdrLineAttribute::operator==(const SdrLineAttribute& rCandidate) const 214 { 215 if(rCandidate.mpSdrLineAttribute == mpSdrLineAttribute) 216 { 217 return true; 218 } 219 220 if(rCandidate.isDefault() != isDefault()) 221 { 222 return false; 223 } 224 225 return (*rCandidate.mpSdrLineAttribute == *mpSdrLineAttribute); 226 } 227 228 basegfx::B2DLineJoin SdrLineAttribute::getJoin() const 229 { 230 return mpSdrLineAttribute->getJoin(); 231 } 232 233 double SdrLineAttribute::getWidth() const 234 { 235 return mpSdrLineAttribute->getWidth(); 236 } 237 238 double SdrLineAttribute::getTransparence() const 239 { 240 return mpSdrLineAttribute->getTransparence(); 241 } 242 243 const basegfx::BColor& SdrLineAttribute::getColor() const 244 { 245 return mpSdrLineAttribute->getColor(); 246 } 247 248 const ::std::vector< double >& SdrLineAttribute::getDotDashArray() const 249 { 250 return mpSdrLineAttribute->getDotDashArray(); 251 } 252 253 double SdrLineAttribute::getFullDotDashLen() const 254 { 255 return mpSdrLineAttribute->getFullDotDashLen(); 256 } 257 258 bool SdrLineAttribute::isDashed() const 259 { 260 return (0L != getDotDashArray().size()); 261 } 262 263 com::sun::star::drawing::LineCap SdrLineAttribute::getCap() const 264 { 265 return mpSdrLineAttribute->getCap(); 266 } 267 268 } // end of namespace attribute 269 } // end of namespace drawinglayer 270 271 ////////////////////////////////////////////////////////////////////////////// 272 // eof 273