1*464702f4SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*464702f4SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*464702f4SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*464702f4SAndrew Rist * distributed with this work for additional information 6*464702f4SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*464702f4SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*464702f4SAndrew Rist * "License"); you may not use this file except in compliance 9*464702f4SAndrew Rist * with the License. You may obtain a copy of the License at 10*464702f4SAndrew Rist * 11*464702f4SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*464702f4SAndrew Rist * 13*464702f4SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*464702f4SAndrew Rist * software distributed under the License is distributed on an 15*464702f4SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*464702f4SAndrew Rist * KIND, either express or implied. See the License for the 17*464702f4SAndrew Rist * specific language governing permissions and limitations 18*464702f4SAndrew Rist * under the License. 19*464702f4SAndrew Rist * 20*464702f4SAndrew Rist *************************************************************/ 21*464702f4SAndrew Rist 22*464702f4SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_drawinglayer.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <drawinglayer/attribute/strokeattribute.hxx> 28cdf0e10cSrcweir #include <numeric> 29cdf0e10cSrcweir 30cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 31cdf0e10cSrcweir 32cdf0e10cSrcweir namespace drawinglayer 33cdf0e10cSrcweir { 34cdf0e10cSrcweir namespace attribute 35cdf0e10cSrcweir { 36cdf0e10cSrcweir class ImpStrokeAttribute 37cdf0e10cSrcweir { 38cdf0e10cSrcweir public: 39cdf0e10cSrcweir // refcounter 40cdf0e10cSrcweir sal_uInt32 mnRefCount; 41cdf0e10cSrcweir 42cdf0e10cSrcweir // data definitions 43cdf0e10cSrcweir ::std::vector< double > maDotDashArray; // array of double which defines the dot-dash pattern 44cdf0e10cSrcweir double mfFullDotDashLen; // sum of maDotDashArray (for convenience) 45cdf0e10cSrcweir ImpStrokeAttribute(const::std::vector<double> & rDotDashArray,double fFullDotDashLen)46cdf0e10cSrcweir ImpStrokeAttribute( 47cdf0e10cSrcweir const ::std::vector< double >& rDotDashArray, 48cdf0e10cSrcweir double fFullDotDashLen) 49cdf0e10cSrcweir : mnRefCount(0), 50cdf0e10cSrcweir maDotDashArray(rDotDashArray), 51cdf0e10cSrcweir mfFullDotDashLen(fFullDotDashLen) 52cdf0e10cSrcweir { 53cdf0e10cSrcweir } 54cdf0e10cSrcweir 55cdf0e10cSrcweir // data read access getDotDashArray() const56cdf0e10cSrcweir const ::std::vector< double >& getDotDashArray() const { return maDotDashArray; } getFullDotDashLen() const57cdf0e10cSrcweir double getFullDotDashLen() const 58cdf0e10cSrcweir { 59cdf0e10cSrcweir if(0.0 == mfFullDotDashLen && maDotDashArray.size()) 60cdf0e10cSrcweir { 61cdf0e10cSrcweir // calculate length on demand 62cdf0e10cSrcweir const double fAccumulated(::std::accumulate(maDotDashArray.begin(), maDotDashArray.end(), 0.0)); 63cdf0e10cSrcweir const_cast< ImpStrokeAttribute* >(this)->mfFullDotDashLen = fAccumulated; 64cdf0e10cSrcweir } 65cdf0e10cSrcweir 66cdf0e10cSrcweir return mfFullDotDashLen; 67cdf0e10cSrcweir } 68cdf0e10cSrcweir operator ==(const ImpStrokeAttribute & rCandidate) const69cdf0e10cSrcweir bool operator==(const ImpStrokeAttribute& rCandidate) const 70cdf0e10cSrcweir { 71cdf0e10cSrcweir return (getDotDashArray() == rCandidate.getDotDashArray() 72cdf0e10cSrcweir && getFullDotDashLen() == rCandidate.getFullDotDashLen()); 73cdf0e10cSrcweir } 74cdf0e10cSrcweir get_global_default()75cdf0e10cSrcweir static ImpStrokeAttribute* get_global_default() 76cdf0e10cSrcweir { 77cdf0e10cSrcweir static ImpStrokeAttribute* pDefault = 0; 78cdf0e10cSrcweir 79cdf0e10cSrcweir if(!pDefault) 80cdf0e10cSrcweir { 81cdf0e10cSrcweir pDefault = new ImpStrokeAttribute( 82cdf0e10cSrcweir std::vector< double >(), 83cdf0e10cSrcweir 0.0); 84cdf0e10cSrcweir 85cdf0e10cSrcweir // never delete; start with RefCount 1, not 0 86cdf0e10cSrcweir pDefault->mnRefCount++; 87cdf0e10cSrcweir } 88cdf0e10cSrcweir 89cdf0e10cSrcweir return pDefault; 90cdf0e10cSrcweir } 91cdf0e10cSrcweir }; 92cdf0e10cSrcweir StrokeAttribute(const::std::vector<double> & rDotDashArray,double fFullDotDashLen)93cdf0e10cSrcweir StrokeAttribute::StrokeAttribute( 94cdf0e10cSrcweir const ::std::vector< double >& rDotDashArray, 95cdf0e10cSrcweir double fFullDotDashLen) 96cdf0e10cSrcweir : mpStrokeAttribute(new ImpStrokeAttribute( 97cdf0e10cSrcweir rDotDashArray, fFullDotDashLen)) 98cdf0e10cSrcweir { 99cdf0e10cSrcweir } 100cdf0e10cSrcweir StrokeAttribute()101cdf0e10cSrcweir StrokeAttribute::StrokeAttribute() 102cdf0e10cSrcweir : mpStrokeAttribute(ImpStrokeAttribute::get_global_default()) 103cdf0e10cSrcweir { 104cdf0e10cSrcweir mpStrokeAttribute->mnRefCount++; 105cdf0e10cSrcweir } 106cdf0e10cSrcweir StrokeAttribute(const StrokeAttribute & rCandidate)107cdf0e10cSrcweir StrokeAttribute::StrokeAttribute(const StrokeAttribute& rCandidate) 108cdf0e10cSrcweir : mpStrokeAttribute(rCandidate.mpStrokeAttribute) 109cdf0e10cSrcweir { 110cdf0e10cSrcweir mpStrokeAttribute->mnRefCount++; 111cdf0e10cSrcweir } 112cdf0e10cSrcweir ~StrokeAttribute()113cdf0e10cSrcweir StrokeAttribute::~StrokeAttribute() 114cdf0e10cSrcweir { 115cdf0e10cSrcweir if(mpStrokeAttribute->mnRefCount) 116cdf0e10cSrcweir { 117cdf0e10cSrcweir mpStrokeAttribute->mnRefCount--; 118cdf0e10cSrcweir } 119cdf0e10cSrcweir else 120cdf0e10cSrcweir { 121cdf0e10cSrcweir delete mpStrokeAttribute; 122cdf0e10cSrcweir } 123cdf0e10cSrcweir } 124cdf0e10cSrcweir isDefault() const125cdf0e10cSrcweir bool StrokeAttribute::isDefault() const 126cdf0e10cSrcweir { 127cdf0e10cSrcweir return mpStrokeAttribute == ImpStrokeAttribute::get_global_default(); 128cdf0e10cSrcweir } 129cdf0e10cSrcweir operator =(const StrokeAttribute & rCandidate)130cdf0e10cSrcweir StrokeAttribute& StrokeAttribute::operator=(const StrokeAttribute& rCandidate) 131cdf0e10cSrcweir { 132cdf0e10cSrcweir if(rCandidate.mpStrokeAttribute != mpStrokeAttribute) 133cdf0e10cSrcweir { 134cdf0e10cSrcweir if(mpStrokeAttribute->mnRefCount) 135cdf0e10cSrcweir { 136cdf0e10cSrcweir mpStrokeAttribute->mnRefCount--; 137cdf0e10cSrcweir } 138cdf0e10cSrcweir else 139cdf0e10cSrcweir { 140cdf0e10cSrcweir delete mpStrokeAttribute; 141cdf0e10cSrcweir } 142cdf0e10cSrcweir 143cdf0e10cSrcweir mpStrokeAttribute = rCandidate.mpStrokeAttribute; 144cdf0e10cSrcweir mpStrokeAttribute->mnRefCount++; 145cdf0e10cSrcweir } 146cdf0e10cSrcweir 147cdf0e10cSrcweir return *this; 148cdf0e10cSrcweir } 149cdf0e10cSrcweir operator ==(const StrokeAttribute & rCandidate) const150cdf0e10cSrcweir bool StrokeAttribute::operator==(const StrokeAttribute& rCandidate) const 151cdf0e10cSrcweir { 152cdf0e10cSrcweir if(rCandidate.mpStrokeAttribute == mpStrokeAttribute) 153cdf0e10cSrcweir { 154cdf0e10cSrcweir return true; 155cdf0e10cSrcweir } 156cdf0e10cSrcweir 157cdf0e10cSrcweir if(rCandidate.isDefault() != isDefault()) 158cdf0e10cSrcweir { 159cdf0e10cSrcweir return false; 160cdf0e10cSrcweir } 161cdf0e10cSrcweir 162cdf0e10cSrcweir return (*rCandidate.mpStrokeAttribute == *mpStrokeAttribute); 163cdf0e10cSrcweir } 164cdf0e10cSrcweir getDotDashArray() const165cdf0e10cSrcweir const ::std::vector< double >& StrokeAttribute::getDotDashArray() const 166cdf0e10cSrcweir { 167cdf0e10cSrcweir return mpStrokeAttribute->getDotDashArray(); 168cdf0e10cSrcweir } 169cdf0e10cSrcweir getFullDotDashLen() const170cdf0e10cSrcweir double StrokeAttribute::getFullDotDashLen() const 171cdf0e10cSrcweir { 172cdf0e10cSrcweir return mpStrokeAttribute->getFullDotDashLen(); 173cdf0e10cSrcweir } 174cdf0e10cSrcweir } // end of namespace attribute 175cdf0e10cSrcweir } // end of namespace drawinglayer 176cdf0e10cSrcweir 177cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 178cdf0e10cSrcweir // eof 179