1*4bfbcde8SAndrew Rist /**************************************************************
2*4bfbcde8SAndrew Rist  *
3*4bfbcde8SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*4bfbcde8SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*4bfbcde8SAndrew Rist  * distributed with this work for additional information
6*4bfbcde8SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*4bfbcde8SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*4bfbcde8SAndrew Rist  * "License"); you may not use this file except in compliance
9*4bfbcde8SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*4bfbcde8SAndrew Rist  *
11*4bfbcde8SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*4bfbcde8SAndrew Rist  *
13*4bfbcde8SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*4bfbcde8SAndrew Rist  * software distributed under the License is distributed on an
15*4bfbcde8SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*4bfbcde8SAndrew Rist  * KIND, either express or implied.  See the License for the
17*4bfbcde8SAndrew Rist  * specific language governing permissions and limitations
18*4bfbcde8SAndrew Rist  * under the License.
19*4bfbcde8SAndrew Rist  *
20*4bfbcde8SAndrew Rist  *************************************************************/
21cdf0e10cSrcweir 
22cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
23cdf0e10cSrcweir #include "precompiled_drawinglayer.hxx"
24cdf0e10cSrcweir 
25cdf0e10cSrcweir #include <drawinglayer/attribute/sdrlineattribute.hxx>
26cdf0e10cSrcweir #include <basegfx/color/bcolor.hxx>
27cdf0e10cSrcweir 
28cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
29cdf0e10cSrcweir 
30cdf0e10cSrcweir namespace drawinglayer
31cdf0e10cSrcweir {
32cdf0e10cSrcweir 	namespace attribute
33cdf0e10cSrcweir 	{
34cdf0e10cSrcweir 		class ImpSdrLineAttribute
35cdf0e10cSrcweir 		{
36cdf0e10cSrcweir 		public:
37cdf0e10cSrcweir 			// refcounter
38cdf0e10cSrcweir 			sal_uInt32								mnRefCount;
39cdf0e10cSrcweir 
40cdf0e10cSrcweir 			// line definitions
41cdf0e10cSrcweir 			basegfx::B2DLineJoin				    meJoin;				// B2DLINEJOIN_* defines
42cdf0e10cSrcweir 			double									mfWidth;			// 1/100th mm, 0.0==hair
43cdf0e10cSrcweir 			double									mfTransparence;		// [0.0 .. 1.0], 0.0==no transp.
44cdf0e10cSrcweir 			basegfx::BColor							maColor;			// color of line
455aaf853bSArmin Le Grand             com::sun::star::drawing::LineCap        meCap;              // BUTT, ROUND, or SQUARE
46cdf0e10cSrcweir 			::std::vector< double >					maDotDashArray;		// array of double which defines the dot-dash pattern
47cdf0e10cSrcweir 			double									mfFullDotDashLen;	// sum of maDotDashArray (for convenience)
48cdf0e10cSrcweir 
ImpSdrLineAttribute(basegfx::B2DLineJoin eJoin,double fWidth,double fTransparence,const basegfx::BColor & rColor,com::sun::star::drawing::LineCap eCap,const::std::vector<double> & rDotDashArray,double fFullDotDashLen)49cdf0e10cSrcweir             ImpSdrLineAttribute(
50cdf0e10cSrcweir 				basegfx::B2DLineJoin eJoin,
51cdf0e10cSrcweir                 double fWidth,
52cdf0e10cSrcweir                 double fTransparence,
53cdf0e10cSrcweir                 const basegfx::BColor& rColor,
545aaf853bSArmin Le Grand                 com::sun::star::drawing::LineCap eCap,
55cdf0e10cSrcweir 				const ::std::vector< double >& rDotDashArray,
56cdf0e10cSrcweir                 double fFullDotDashLen)
57cdf0e10cSrcweir 			:	mnRefCount(0),
58cdf0e10cSrcweir 		    	meJoin(eJoin),
59cdf0e10cSrcweir 			    mfWidth(fWidth),
60cdf0e10cSrcweir 			    mfTransparence(fTransparence),
61cdf0e10cSrcweir 			    maColor(rColor),
625aaf853bSArmin Le Grand                 meCap(eCap),
63cdf0e10cSrcweir 			    maDotDashArray(rDotDashArray),
64cdf0e10cSrcweir 			    mfFullDotDashLen(fFullDotDashLen)
65cdf0e10cSrcweir 		    {
66cdf0e10cSrcweir 		    }
67cdf0e10cSrcweir 
ImpSdrLineAttribute(const basegfx::BColor & rColor)68cdf0e10cSrcweir             ImpSdrLineAttribute(const basegfx::BColor& rColor)
69cdf0e10cSrcweir 			:	mnRefCount(0),
70cdf0e10cSrcweir 		    	meJoin(basegfx::B2DLINEJOIN_NONE),
71cdf0e10cSrcweir 			    mfWidth(0.0),
72cdf0e10cSrcweir 			    mfTransparence(0.0),
73cdf0e10cSrcweir 			    maColor(rColor),
745aaf853bSArmin Le Grand                 meCap(com::sun::star::drawing::LineCap_BUTT),
75cdf0e10cSrcweir 			    maDotDashArray(),
76cdf0e10cSrcweir 			    mfFullDotDashLen(0.0)
77cdf0e10cSrcweir             {
78cdf0e10cSrcweir             }
79cdf0e10cSrcweir 
80cdf0e10cSrcweir 			// data read access
getJoin() const81cdf0e10cSrcweir 			basegfx::B2DLineJoin getJoin() const { return meJoin; }
getWidth() const82cdf0e10cSrcweir 			double getWidth() const { return mfWidth; }
getTransparence() const83cdf0e10cSrcweir 			double getTransparence() const { return mfTransparence; }
getColor() const84cdf0e10cSrcweir 			const basegfx::BColor& getColor() const { return maColor; }
getCap() const855aaf853bSArmin Le Grand             com::sun::star::drawing::LineCap getCap() const { return meCap; }
getDotDashArray() const86cdf0e10cSrcweir 			const ::std::vector< double >& getDotDashArray() const { return maDotDashArray; }
getFullDotDashLen() const87cdf0e10cSrcweir 			double getFullDotDashLen() const { return mfFullDotDashLen; }
88cdf0e10cSrcweir 
operator ==(const ImpSdrLineAttribute & rCandidate) const89cdf0e10cSrcweir             bool operator==(const ImpSdrLineAttribute& rCandidate) const
90cdf0e10cSrcweir 		    {
91cdf0e10cSrcweir 			    return (getJoin() == rCandidate.getJoin()
92cdf0e10cSrcweir 				    && getWidth() == rCandidate.getWidth()
93cdf0e10cSrcweir 				    && getTransparence() == rCandidate.getTransparence()
94cdf0e10cSrcweir 				    && getColor() == rCandidate.getColor()
955aaf853bSArmin Le Grand                     && getCap() == rCandidate.getCap()
96cdf0e10cSrcweir 				    && getDotDashArray() == rCandidate.getDotDashArray());
97cdf0e10cSrcweir 		    }
98cdf0e10cSrcweir 
get_global_default()99cdf0e10cSrcweir             static ImpSdrLineAttribute* get_global_default()
100cdf0e10cSrcweir             {
101cdf0e10cSrcweir                 static ImpSdrLineAttribute* pDefault = 0;
102cdf0e10cSrcweir 
103cdf0e10cSrcweir                 if(!pDefault)
104cdf0e10cSrcweir                 {
105cdf0e10cSrcweir                     pDefault = new ImpSdrLineAttribute(
106cdf0e10cSrcweir 			            basegfx::B2DLINEJOIN_ROUND,
107cdf0e10cSrcweir                         0.0,
108cdf0e10cSrcweir                         0.0,
109cdf0e10cSrcweir                         basegfx::BColor(),
1105aaf853bSArmin Le Grand                         com::sun::star::drawing::LineCap_BUTT,
111cdf0e10cSrcweir 			            std::vector< double >(),
112cdf0e10cSrcweir                         0.0);
113cdf0e10cSrcweir 
114cdf0e10cSrcweir                     // never delete; start with RefCount 1, not 0
115cdf0e10cSrcweir     			    pDefault->mnRefCount++;
116cdf0e10cSrcweir                 }
117cdf0e10cSrcweir 
118cdf0e10cSrcweir                 return pDefault;
119cdf0e10cSrcweir             }
120cdf0e10cSrcweir 		};
121cdf0e10cSrcweir 
SdrLineAttribute(basegfx::B2DLineJoin eJoin,double fWidth,double fTransparence,const basegfx::BColor & rColor,com::sun::star::drawing::LineCap eCap,const::std::vector<double> & rDotDashArray,double fFullDotDashLen)122cdf0e10cSrcweir         SdrLineAttribute::SdrLineAttribute(
123cdf0e10cSrcweir 			basegfx::B2DLineJoin eJoin,
124cdf0e10cSrcweir             double fWidth,
125cdf0e10cSrcweir             double fTransparence,
126cdf0e10cSrcweir             const basegfx::BColor& rColor,
1275aaf853bSArmin Le Grand             com::sun::star::drawing::LineCap eCap,
128cdf0e10cSrcweir 			const ::std::vector< double >& rDotDashArray,
129cdf0e10cSrcweir             double fFullDotDashLen)
1305aaf853bSArmin Le Grand 		:	mpSdrLineAttribute(
1315aaf853bSArmin Le Grand                 new ImpSdrLineAttribute(
1325aaf853bSArmin Le Grand                     eJoin,
1335aaf853bSArmin Le Grand                     fWidth,
1345aaf853bSArmin Le Grand                     fTransparence,
1355aaf853bSArmin Le Grand                     rColor,
1365aaf853bSArmin Le Grand                     eCap,
1375aaf853bSArmin Le Grand                     rDotDashArray,
1385aaf853bSArmin Le Grand                     fFullDotDashLen))
139cdf0e10cSrcweir 		{
140cdf0e10cSrcweir 		}
141cdf0e10cSrcweir 
SdrLineAttribute(const basegfx::BColor & rColor)142cdf0e10cSrcweir         SdrLineAttribute::SdrLineAttribute(
143cdf0e10cSrcweir             const basegfx::BColor& rColor)
1445aaf853bSArmin Le Grand 		:	mpSdrLineAttribute(
1455aaf853bSArmin Le Grand                 new ImpSdrLineAttribute(
1465aaf853bSArmin Le Grand                     rColor))
147cdf0e10cSrcweir         {
148cdf0e10cSrcweir         }
149cdf0e10cSrcweir 
SdrLineAttribute()150cdf0e10cSrcweir 		SdrLineAttribute::SdrLineAttribute()
151cdf0e10cSrcweir         :	mpSdrLineAttribute(ImpSdrLineAttribute::get_global_default())
152cdf0e10cSrcweir 		{
153cdf0e10cSrcweir 			mpSdrLineAttribute->mnRefCount++;
154cdf0e10cSrcweir 		}
155cdf0e10cSrcweir 
SdrLineAttribute(const SdrLineAttribute & rCandidate)156cdf0e10cSrcweir         SdrLineAttribute::SdrLineAttribute(const SdrLineAttribute& rCandidate)
157cdf0e10cSrcweir 		:	mpSdrLineAttribute(rCandidate.mpSdrLineAttribute)
158cdf0e10cSrcweir 		{
159cdf0e10cSrcweir 			mpSdrLineAttribute->mnRefCount++;
160cdf0e10cSrcweir 		}
161cdf0e10cSrcweir 
~SdrLineAttribute()162cdf0e10cSrcweir 		SdrLineAttribute::~SdrLineAttribute()
163cdf0e10cSrcweir 		{
164cdf0e10cSrcweir 			if(mpSdrLineAttribute->mnRefCount)
165cdf0e10cSrcweir 			{
166cdf0e10cSrcweir 				mpSdrLineAttribute->mnRefCount--;
167cdf0e10cSrcweir 			}
168cdf0e10cSrcweir 			else
169cdf0e10cSrcweir 			{
170cdf0e10cSrcweir 				delete mpSdrLineAttribute;
171cdf0e10cSrcweir 			}
172cdf0e10cSrcweir 		}
173cdf0e10cSrcweir 
isDefault() const174cdf0e10cSrcweir         bool SdrLineAttribute::isDefault() const
175cdf0e10cSrcweir         {
176cdf0e10cSrcweir             return mpSdrLineAttribute == ImpSdrLineAttribute::get_global_default();
177cdf0e10cSrcweir         }
178cdf0e10cSrcweir 
operator =(const SdrLineAttribute & rCandidate)179cdf0e10cSrcweir         SdrLineAttribute& SdrLineAttribute::operator=(const SdrLineAttribute& rCandidate)
180cdf0e10cSrcweir 		{
181cdf0e10cSrcweir 			if(rCandidate.mpSdrLineAttribute != mpSdrLineAttribute)
182cdf0e10cSrcweir 			{
183cdf0e10cSrcweir 				if(mpSdrLineAttribute->mnRefCount)
184cdf0e10cSrcweir 				{
185cdf0e10cSrcweir 					mpSdrLineAttribute->mnRefCount--;
186cdf0e10cSrcweir 				}
187cdf0e10cSrcweir 				else
188cdf0e10cSrcweir 				{
189cdf0e10cSrcweir 					delete mpSdrLineAttribute;
190cdf0e10cSrcweir 				}
191cdf0e10cSrcweir 
192cdf0e10cSrcweir 				mpSdrLineAttribute = rCandidate.mpSdrLineAttribute;
193cdf0e10cSrcweir 				mpSdrLineAttribute->mnRefCount++;
194cdf0e10cSrcweir 			}
195cdf0e10cSrcweir 
196cdf0e10cSrcweir 			return *this;
197cdf0e10cSrcweir 		}
198cdf0e10cSrcweir 
operator ==(const SdrLineAttribute & rCandidate) const199cdf0e10cSrcweir 		bool SdrLineAttribute::operator==(const SdrLineAttribute& rCandidate) const
200cdf0e10cSrcweir 		{
201cdf0e10cSrcweir 			if(rCandidate.mpSdrLineAttribute == mpSdrLineAttribute)
202cdf0e10cSrcweir 			{
203cdf0e10cSrcweir 				return true;
204cdf0e10cSrcweir 			}
205cdf0e10cSrcweir 
206cdf0e10cSrcweir 			if(rCandidate.isDefault() != isDefault())
207cdf0e10cSrcweir 			{
208cdf0e10cSrcweir 				return false;
209cdf0e10cSrcweir 			}
210cdf0e10cSrcweir 
211cdf0e10cSrcweir 			return (*rCandidate.mpSdrLineAttribute == *mpSdrLineAttribute);
212cdf0e10cSrcweir 		}
213cdf0e10cSrcweir 
getJoin() const214cdf0e10cSrcweir 		basegfx::B2DLineJoin SdrLineAttribute::getJoin() const
215cdf0e10cSrcweir         {
216cdf0e10cSrcweir             return mpSdrLineAttribute->getJoin();
217cdf0e10cSrcweir         }
218cdf0e10cSrcweir 
getWidth() const219cdf0e10cSrcweir 		double SdrLineAttribute::getWidth() const
220cdf0e10cSrcweir         {
221cdf0e10cSrcweir             return mpSdrLineAttribute->getWidth();
222cdf0e10cSrcweir         }
223cdf0e10cSrcweir 
getTransparence() const224cdf0e10cSrcweir 		double SdrLineAttribute::getTransparence() const
225cdf0e10cSrcweir         {
226cdf0e10cSrcweir             return mpSdrLineAttribute->getTransparence();
227cdf0e10cSrcweir         }
228cdf0e10cSrcweir 
getColor() const229cdf0e10cSrcweir 		const basegfx::BColor& SdrLineAttribute::getColor() const
230cdf0e10cSrcweir         {
231cdf0e10cSrcweir             return mpSdrLineAttribute->getColor();
232cdf0e10cSrcweir         }
233cdf0e10cSrcweir 
getDotDashArray() const234cdf0e10cSrcweir 		const ::std::vector< double >& SdrLineAttribute::getDotDashArray() const
235cdf0e10cSrcweir         {
236cdf0e10cSrcweir             return mpSdrLineAttribute->getDotDashArray();
237cdf0e10cSrcweir         }
238cdf0e10cSrcweir 
getFullDotDashLen() const239cdf0e10cSrcweir 		double SdrLineAttribute::getFullDotDashLen() const
240cdf0e10cSrcweir         {
241cdf0e10cSrcweir             return mpSdrLineAttribute->getFullDotDashLen();
242cdf0e10cSrcweir         }
243cdf0e10cSrcweir 
isDashed() const244cdf0e10cSrcweir 		bool SdrLineAttribute::isDashed() const
245cdf0e10cSrcweir         {
246cdf0e10cSrcweir             return (0L != getDotDashArray().size());
247cdf0e10cSrcweir         }
248cdf0e10cSrcweir 
getCap() const2495aaf853bSArmin Le Grand         com::sun::star::drawing::LineCap SdrLineAttribute::getCap() const
2505aaf853bSArmin Le Grand         {
2515aaf853bSArmin Le Grand             return mpSdrLineAttribute->getCap();
2525aaf853bSArmin Le Grand         }
2535aaf853bSArmin Le Grand 
254cdf0e10cSrcweir     } // end of namespace attribute
255cdf0e10cSrcweir } // end of namespace drawinglayer
256cdf0e10cSrcweir 
257cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
258cdf0e10cSrcweir // eof
259