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/sdrformtextoutlineattribute.hxx> 27 #include <drawinglayer/attribute/lineattribute.hxx> 28 #include <drawinglayer/attribute/strokeattribute.hxx> 29 30 ////////////////////////////////////////////////////////////////////////////// 31 32 namespace drawinglayer 33 { 34 namespace attribute 35 { 36 class ImpSdrFormTextOutlineAttribute 37 { 38 public: 39 // refcounter 40 sal_uInt32 mnRefCount; 41 42 // one set of attributes for FormText (FontWork) outline visualisation 43 LineAttribute maLineAttribute; 44 StrokeAttribute maStrokeAttribute; 45 sal_uInt8 mnTransparence; 46 ImpSdrFormTextOutlineAttribute(const LineAttribute & rLineAttribute,const StrokeAttribute & rStrokeAttribute,sal_uInt8 nTransparence)47 ImpSdrFormTextOutlineAttribute( 48 const LineAttribute& rLineAttribute, 49 const StrokeAttribute& rStrokeAttribute, 50 sal_uInt8 nTransparence) 51 : mnRefCount(0), 52 maLineAttribute(rLineAttribute), 53 maStrokeAttribute(rStrokeAttribute), 54 mnTransparence(nTransparence) 55 { 56 } 57 58 // data read access getLineAttribute() const59 const LineAttribute& getLineAttribute() const { return maLineAttribute; } getStrokeAttribute() const60 const StrokeAttribute& getStrokeAttribute() const { return maStrokeAttribute; } getTransparence() const61 sal_uInt8 getTransparence() const { return mnTransparence; } 62 63 // compare operator operator ==(const ImpSdrFormTextOutlineAttribute & rCandidate) const64 bool operator==(const ImpSdrFormTextOutlineAttribute& rCandidate) const 65 { 66 return (getLineAttribute() == rCandidate.getLineAttribute() 67 && getStrokeAttribute() == rCandidate.getStrokeAttribute() 68 && getTransparence() == rCandidate.getTransparence()); 69 } 70 get_global_default()71 static ImpSdrFormTextOutlineAttribute* get_global_default() 72 { 73 static ImpSdrFormTextOutlineAttribute* pDefault = 0; 74 75 if(!pDefault) 76 { 77 pDefault = new ImpSdrFormTextOutlineAttribute( 78 LineAttribute(), 79 StrokeAttribute(), 80 0); 81 82 // never delete; start with RefCount 1, not 0 83 pDefault->mnRefCount++; 84 } 85 86 return pDefault; 87 } 88 }; 89 SdrFormTextOutlineAttribute(const LineAttribute & rLineAttribute,const StrokeAttribute & rStrokeAttribute,sal_uInt8 nTransparence)90 SdrFormTextOutlineAttribute::SdrFormTextOutlineAttribute( 91 const LineAttribute& rLineAttribute, 92 const StrokeAttribute& rStrokeAttribute, 93 sal_uInt8 nTransparence) 94 : mpSdrFormTextOutlineAttribute(new ImpSdrFormTextOutlineAttribute( 95 rLineAttribute, rStrokeAttribute, nTransparence)) 96 { 97 } 98 SdrFormTextOutlineAttribute()99 SdrFormTextOutlineAttribute::SdrFormTextOutlineAttribute() 100 : mpSdrFormTextOutlineAttribute(ImpSdrFormTextOutlineAttribute::get_global_default()) 101 { 102 mpSdrFormTextOutlineAttribute->mnRefCount++; 103 } 104 SdrFormTextOutlineAttribute(const SdrFormTextOutlineAttribute & rCandidate)105 SdrFormTextOutlineAttribute::SdrFormTextOutlineAttribute(const SdrFormTextOutlineAttribute& rCandidate) 106 : mpSdrFormTextOutlineAttribute(rCandidate.mpSdrFormTextOutlineAttribute) 107 { 108 mpSdrFormTextOutlineAttribute->mnRefCount++; 109 } 110 ~SdrFormTextOutlineAttribute()111 SdrFormTextOutlineAttribute::~SdrFormTextOutlineAttribute() 112 { 113 if(mpSdrFormTextOutlineAttribute->mnRefCount) 114 { 115 mpSdrFormTextOutlineAttribute->mnRefCount--; 116 } 117 else 118 { 119 delete mpSdrFormTextOutlineAttribute; 120 } 121 } 122 isDefault() const123 bool SdrFormTextOutlineAttribute::isDefault() const 124 { 125 return mpSdrFormTextOutlineAttribute == ImpSdrFormTextOutlineAttribute::get_global_default(); 126 } 127 operator =(const SdrFormTextOutlineAttribute & rCandidate)128 SdrFormTextOutlineAttribute& SdrFormTextOutlineAttribute::operator=(const SdrFormTextOutlineAttribute& rCandidate) 129 { 130 if(rCandidate.mpSdrFormTextOutlineAttribute != mpSdrFormTextOutlineAttribute) 131 { 132 if(mpSdrFormTextOutlineAttribute->mnRefCount) 133 { 134 mpSdrFormTextOutlineAttribute->mnRefCount--; 135 } 136 else 137 { 138 delete mpSdrFormTextOutlineAttribute; 139 } 140 141 mpSdrFormTextOutlineAttribute = rCandidate.mpSdrFormTextOutlineAttribute; 142 mpSdrFormTextOutlineAttribute->mnRefCount++; 143 } 144 145 return *this; 146 } 147 operator ==(const SdrFormTextOutlineAttribute & rCandidate) const148 bool SdrFormTextOutlineAttribute::operator==(const SdrFormTextOutlineAttribute& rCandidate) const 149 { 150 if(rCandidate.mpSdrFormTextOutlineAttribute == mpSdrFormTextOutlineAttribute) 151 { 152 return true; 153 } 154 155 if(rCandidate.isDefault() != isDefault()) 156 { 157 return false; 158 } 159 160 return (*rCandidate.mpSdrFormTextOutlineAttribute == *mpSdrFormTextOutlineAttribute); 161 } 162 getLineAttribute() const163 const LineAttribute& SdrFormTextOutlineAttribute::getLineAttribute() const 164 { 165 return mpSdrFormTextOutlineAttribute->getLineAttribute(); 166 } 167 getStrokeAttribute() const168 const StrokeAttribute& SdrFormTextOutlineAttribute::getStrokeAttribute() const 169 { 170 return mpSdrFormTextOutlineAttribute->getStrokeAttribute(); 171 } 172 getTransparence() const173 sal_uInt8 SdrFormTextOutlineAttribute::getTransparence() const 174 { 175 return mpSdrFormTextOutlineAttribute->getTransparence(); 176 } 177 } // end of namespace attribute 178 } // end of namespace drawinglayer 179 180 ////////////////////////////////////////////////////////////////////////////// 181 // eof 182