1464702f4SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3464702f4SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4464702f4SAndrew Rist * or more contributor license agreements. See the NOTICE file 5464702f4SAndrew Rist * distributed with this work for additional information 6464702f4SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7464702f4SAndrew Rist * to you under the Apache License, Version 2.0 (the 8464702f4SAndrew Rist * "License"); you may not use this file except in compliance 9464702f4SAndrew Rist * with the License. You may obtain a copy of the License at 10464702f4SAndrew Rist * 11464702f4SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12464702f4SAndrew Rist * 13464702f4SAndrew Rist * Unless required by applicable law or agreed to in writing, 14464702f4SAndrew Rist * software distributed under the License is distributed on an 15464702f4SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16464702f4SAndrew Rist * KIND, either express or implied. See the License for the 17464702f4SAndrew Rist * specific language governing permissions and limitations 18464702f4SAndrew Rist * under the License. 19464702f4SAndrew Rist * 20464702f4SAndrew Rist *************************************************************/ 21464702f4SAndrew Rist 22464702f4SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_drawinglayer.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <drawinglayer/attribute/lineattribute.hxx> 28cdf0e10cSrcweir #include <basegfx/color/bcolor.hxx> 29cdf0e10cSrcweir 30cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 31cdf0e10cSrcweir 32cdf0e10cSrcweir namespace drawinglayer 33cdf0e10cSrcweir { 34cdf0e10cSrcweir namespace attribute 35cdf0e10cSrcweir { 36cdf0e10cSrcweir class ImpLineAttribute 37cdf0e10cSrcweir { 38cdf0e10cSrcweir public: 39cdf0e10cSrcweir // refcounter 40cdf0e10cSrcweir sal_uInt32 mnRefCount; 41cdf0e10cSrcweir 42cdf0e10cSrcweir // data definitions 43cdf0e10cSrcweir basegfx::BColor maColor; // color 44cdf0e10cSrcweir double mfWidth; // absolute line width 45cdf0e10cSrcweir basegfx::B2DLineJoin meLineJoin; // type of LineJoin 46*5aaf853bSArmin Le Grand com::sun::star::drawing::LineCap meLineCap; // BUTT, ROUND, or SQUARE 47cdf0e10cSrcweir ImpLineAttribute(const basegfx::BColor & rColor,double fWidth,basegfx::B2DLineJoin aB2DLineJoin,com::sun::star::drawing::LineCap aLineCap)48cdf0e10cSrcweir ImpLineAttribute( 49cdf0e10cSrcweir const basegfx::BColor& rColor, 50cdf0e10cSrcweir double fWidth, 51*5aaf853bSArmin Le Grand basegfx::B2DLineJoin aB2DLineJoin, 52*5aaf853bSArmin Le Grand com::sun::star::drawing::LineCap aLineCap) 53cdf0e10cSrcweir : mnRefCount(0), 54cdf0e10cSrcweir maColor(rColor), 55cdf0e10cSrcweir mfWidth(fWidth), 56*5aaf853bSArmin Le Grand meLineJoin(aB2DLineJoin), 57*5aaf853bSArmin Le Grand meLineCap(aLineCap) 58cdf0e10cSrcweir { 59cdf0e10cSrcweir } 60cdf0e10cSrcweir 61cdf0e10cSrcweir // data read access getColor() const62cdf0e10cSrcweir const basegfx::BColor& getColor() const { return maColor; } getWidth() const63cdf0e10cSrcweir double getWidth() const { return mfWidth; } getLineJoin() const64cdf0e10cSrcweir basegfx::B2DLineJoin getLineJoin() const { return meLineJoin; } getLineCap() const65*5aaf853bSArmin Le Grand com::sun::star::drawing::LineCap getLineCap() const { return meLineCap; } 66cdf0e10cSrcweir operator ==(const ImpLineAttribute & rCandidate) const67cdf0e10cSrcweir bool operator==(const ImpLineAttribute& rCandidate) const 68cdf0e10cSrcweir { 69cdf0e10cSrcweir return (getColor() == rCandidate.getColor() 70cdf0e10cSrcweir && getWidth() == rCandidate.getWidth() 71*5aaf853bSArmin Le Grand && getLineJoin() == rCandidate.getLineJoin() 72*5aaf853bSArmin Le Grand && getLineCap() == rCandidate.getLineCap()); 73cdf0e10cSrcweir } 74cdf0e10cSrcweir get_global_default()75cdf0e10cSrcweir static ImpLineAttribute* get_global_default() 76cdf0e10cSrcweir { 77cdf0e10cSrcweir static ImpLineAttribute* pDefault = 0; 78cdf0e10cSrcweir 79cdf0e10cSrcweir if(!pDefault) 80cdf0e10cSrcweir { 81cdf0e10cSrcweir pDefault = new ImpLineAttribute( 82cdf0e10cSrcweir basegfx::BColor(), 83cdf0e10cSrcweir 0.0, 84*5aaf853bSArmin Le Grand basegfx::B2DLINEJOIN_ROUND, 85*5aaf853bSArmin Le Grand com::sun::star::drawing::LineCap_BUTT); 86cdf0e10cSrcweir 87cdf0e10cSrcweir // never delete; start with RefCount 1, not 0 88cdf0e10cSrcweir pDefault->mnRefCount++; 89cdf0e10cSrcweir } 90cdf0e10cSrcweir 91cdf0e10cSrcweir return pDefault; 92cdf0e10cSrcweir } 93cdf0e10cSrcweir }; 94cdf0e10cSrcweir LineAttribute(const basegfx::BColor & rColor,double fWidth,basegfx::B2DLineJoin aB2DLineJoin,com::sun::star::drawing::LineCap aLineCap)95cdf0e10cSrcweir LineAttribute::LineAttribute( 96cdf0e10cSrcweir const basegfx::BColor& rColor, 97cdf0e10cSrcweir double fWidth, 98*5aaf853bSArmin Le Grand basegfx::B2DLineJoin aB2DLineJoin, 99*5aaf853bSArmin Le Grand com::sun::star::drawing::LineCap aLineCap) 100*5aaf853bSArmin Le Grand : mpLineAttribute( 101*5aaf853bSArmin Le Grand new ImpLineAttribute( 102*5aaf853bSArmin Le Grand rColor, 103*5aaf853bSArmin Le Grand fWidth, 104*5aaf853bSArmin Le Grand aB2DLineJoin, 105*5aaf853bSArmin Le Grand aLineCap)) 106cdf0e10cSrcweir { 107cdf0e10cSrcweir } 108cdf0e10cSrcweir LineAttribute()109cdf0e10cSrcweir LineAttribute::LineAttribute() 110cdf0e10cSrcweir : mpLineAttribute(ImpLineAttribute::get_global_default()) 111cdf0e10cSrcweir { 112cdf0e10cSrcweir mpLineAttribute->mnRefCount++; 113cdf0e10cSrcweir } 114cdf0e10cSrcweir LineAttribute(const LineAttribute & rCandidate)115cdf0e10cSrcweir LineAttribute::LineAttribute(const LineAttribute& rCandidate) 116cdf0e10cSrcweir : mpLineAttribute(rCandidate.mpLineAttribute) 117cdf0e10cSrcweir { 118cdf0e10cSrcweir mpLineAttribute->mnRefCount++; 119cdf0e10cSrcweir } 120cdf0e10cSrcweir ~LineAttribute()121cdf0e10cSrcweir LineAttribute::~LineAttribute() 122cdf0e10cSrcweir { 123cdf0e10cSrcweir if(mpLineAttribute->mnRefCount) 124cdf0e10cSrcweir { 125cdf0e10cSrcweir mpLineAttribute->mnRefCount--; 126cdf0e10cSrcweir } 127cdf0e10cSrcweir else 128cdf0e10cSrcweir { 129cdf0e10cSrcweir delete mpLineAttribute; 130cdf0e10cSrcweir } 131cdf0e10cSrcweir } 132cdf0e10cSrcweir isDefault() const133cdf0e10cSrcweir bool LineAttribute::isDefault() const 134cdf0e10cSrcweir { 135cdf0e10cSrcweir return mpLineAttribute == ImpLineAttribute::get_global_default(); 136cdf0e10cSrcweir } 137cdf0e10cSrcweir operator =(const LineAttribute & rCandidate)138cdf0e10cSrcweir LineAttribute& LineAttribute::operator=(const LineAttribute& rCandidate) 139cdf0e10cSrcweir { 140cdf0e10cSrcweir if(rCandidate.mpLineAttribute != mpLineAttribute) 141cdf0e10cSrcweir { 142cdf0e10cSrcweir if(mpLineAttribute->mnRefCount) 143cdf0e10cSrcweir { 144cdf0e10cSrcweir mpLineAttribute->mnRefCount--; 145cdf0e10cSrcweir } 146cdf0e10cSrcweir else 147cdf0e10cSrcweir { 148cdf0e10cSrcweir delete mpLineAttribute; 149cdf0e10cSrcweir } 150cdf0e10cSrcweir 151cdf0e10cSrcweir mpLineAttribute = rCandidate.mpLineAttribute; 152cdf0e10cSrcweir mpLineAttribute->mnRefCount++; 153cdf0e10cSrcweir } 154cdf0e10cSrcweir 155cdf0e10cSrcweir return *this; 156cdf0e10cSrcweir } 157cdf0e10cSrcweir operator ==(const LineAttribute & rCandidate) const158cdf0e10cSrcweir bool LineAttribute::operator==(const LineAttribute& rCandidate) const 159cdf0e10cSrcweir { 160cdf0e10cSrcweir if(rCandidate.mpLineAttribute == mpLineAttribute) 161cdf0e10cSrcweir { 162cdf0e10cSrcweir return true; 163cdf0e10cSrcweir } 164cdf0e10cSrcweir 165cdf0e10cSrcweir if(rCandidate.isDefault() != isDefault()) 166cdf0e10cSrcweir { 167cdf0e10cSrcweir return false; 168cdf0e10cSrcweir } 169cdf0e10cSrcweir 170cdf0e10cSrcweir return (*rCandidate.mpLineAttribute == *mpLineAttribute); 171cdf0e10cSrcweir } 172cdf0e10cSrcweir getColor() const173cdf0e10cSrcweir const basegfx::BColor& LineAttribute::getColor() const 174cdf0e10cSrcweir { 175cdf0e10cSrcweir return mpLineAttribute->getColor(); 176cdf0e10cSrcweir } 177cdf0e10cSrcweir getWidth() const178cdf0e10cSrcweir double LineAttribute::getWidth() const 179cdf0e10cSrcweir { 180cdf0e10cSrcweir return mpLineAttribute->getWidth(); 181cdf0e10cSrcweir } 182cdf0e10cSrcweir getLineJoin() const183cdf0e10cSrcweir basegfx::B2DLineJoin LineAttribute::getLineJoin() const 184cdf0e10cSrcweir { 185cdf0e10cSrcweir return mpLineAttribute->getLineJoin(); 186cdf0e10cSrcweir } 187cdf0e10cSrcweir getLineCap() const188*5aaf853bSArmin Le Grand com::sun::star::drawing::LineCap LineAttribute::getLineCap() const 189*5aaf853bSArmin Le Grand { 190*5aaf853bSArmin Le Grand return mpLineAttribute->getLineCap(); 191*5aaf853bSArmin Le Grand } 192*5aaf853bSArmin Le Grand 193cdf0e10cSrcweir } // end of namespace attribute 194cdf0e10cSrcweir } // end of namespace drawinglayer 195cdf0e10cSrcweir 196cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 197cdf0e10cSrcweir // eof 198