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/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
46cdf0e10cSrcweir 
47cdf0e10cSrcweir 			ImpLineAttribute(
48cdf0e10cSrcweir                 const basegfx::BColor& rColor,
49cdf0e10cSrcweir 				double fWidth,
50cdf0e10cSrcweir 				basegfx::B2DLineJoin aB2DLineJoin)
51cdf0e10cSrcweir 			:	mnRefCount(0),
52cdf0e10cSrcweir                 maColor(rColor),
53cdf0e10cSrcweir                 mfWidth(fWidth),
54cdf0e10cSrcweir                 meLineJoin(aB2DLineJoin)
55cdf0e10cSrcweir 			{
56cdf0e10cSrcweir 			}
57cdf0e10cSrcweir 
58cdf0e10cSrcweir 			// data read access
59cdf0e10cSrcweir 			const basegfx::BColor& getColor() const { return maColor; }
60cdf0e10cSrcweir 			double getWidth() const { return mfWidth; }
61cdf0e10cSrcweir 			basegfx::B2DLineJoin getLineJoin() const { return meLineJoin; }
62cdf0e10cSrcweir 
63cdf0e10cSrcweir 			bool operator==(const ImpLineAttribute& rCandidate) const
64cdf0e10cSrcweir 			{
65cdf0e10cSrcweir 				return (getColor() == rCandidate.getColor()
66cdf0e10cSrcweir 					&& getWidth() == rCandidate.getWidth()
67cdf0e10cSrcweir 					&& getLineJoin() == rCandidate.getLineJoin());
68cdf0e10cSrcweir 			}
69cdf0e10cSrcweir 
70cdf0e10cSrcweir             static ImpLineAttribute* get_global_default()
71cdf0e10cSrcweir             {
72cdf0e10cSrcweir                 static ImpLineAttribute* pDefault = 0;
73cdf0e10cSrcweir 
74cdf0e10cSrcweir                 if(!pDefault)
75cdf0e10cSrcweir                 {
76cdf0e10cSrcweir                     pDefault = new ImpLineAttribute(
77cdf0e10cSrcweir                         basegfx::BColor(),
78cdf0e10cSrcweir                         0.0,
79cdf0e10cSrcweir                         basegfx::B2DLINEJOIN_ROUND);
80cdf0e10cSrcweir 
81cdf0e10cSrcweir                     // never delete; start with RefCount 1, not 0
82cdf0e10cSrcweir     			    pDefault->mnRefCount++;
83cdf0e10cSrcweir                 }
84cdf0e10cSrcweir 
85cdf0e10cSrcweir                 return pDefault;
86cdf0e10cSrcweir             }
87cdf0e10cSrcweir 		};
88cdf0e10cSrcweir 
89cdf0e10cSrcweir         LineAttribute::LineAttribute(
90cdf0e10cSrcweir             const basegfx::BColor& rColor,
91cdf0e10cSrcweir 			double fWidth,
92cdf0e10cSrcweir 			basegfx::B2DLineJoin aB2DLineJoin)
93cdf0e10cSrcweir 		:	mpLineAttribute(new ImpLineAttribute(
94cdf0e10cSrcweir                 rColor, fWidth, aB2DLineJoin))
95cdf0e10cSrcweir 		{
96cdf0e10cSrcweir 		}
97cdf0e10cSrcweir 
98cdf0e10cSrcweir 		LineAttribute::LineAttribute()
99cdf0e10cSrcweir         :	mpLineAttribute(ImpLineAttribute::get_global_default())
100cdf0e10cSrcweir 		{
101cdf0e10cSrcweir 			mpLineAttribute->mnRefCount++;
102cdf0e10cSrcweir 		}
103cdf0e10cSrcweir 
104cdf0e10cSrcweir         LineAttribute::LineAttribute(const LineAttribute& rCandidate)
105cdf0e10cSrcweir 		:	mpLineAttribute(rCandidate.mpLineAttribute)
106cdf0e10cSrcweir 		{
107cdf0e10cSrcweir 			mpLineAttribute->mnRefCount++;
108cdf0e10cSrcweir 		}
109cdf0e10cSrcweir 
110cdf0e10cSrcweir 		LineAttribute::~LineAttribute()
111cdf0e10cSrcweir 		{
112cdf0e10cSrcweir 			if(mpLineAttribute->mnRefCount)
113cdf0e10cSrcweir 			{
114cdf0e10cSrcweir 				mpLineAttribute->mnRefCount--;
115cdf0e10cSrcweir 			}
116cdf0e10cSrcweir 			else
117cdf0e10cSrcweir 			{
118cdf0e10cSrcweir 				delete mpLineAttribute;
119cdf0e10cSrcweir 			}
120cdf0e10cSrcweir 		}
121cdf0e10cSrcweir 
122cdf0e10cSrcweir         bool LineAttribute::isDefault() const
123cdf0e10cSrcweir         {
124cdf0e10cSrcweir             return mpLineAttribute == ImpLineAttribute::get_global_default();
125cdf0e10cSrcweir         }
126cdf0e10cSrcweir 
127cdf0e10cSrcweir         LineAttribute& LineAttribute::operator=(const LineAttribute& rCandidate)
128cdf0e10cSrcweir 		{
129cdf0e10cSrcweir 			if(rCandidate.mpLineAttribute != mpLineAttribute)
130cdf0e10cSrcweir 			{
131cdf0e10cSrcweir 				if(mpLineAttribute->mnRefCount)
132cdf0e10cSrcweir 				{
133cdf0e10cSrcweir 					mpLineAttribute->mnRefCount--;
134cdf0e10cSrcweir 				}
135cdf0e10cSrcweir 				else
136cdf0e10cSrcweir 				{
137cdf0e10cSrcweir 					delete mpLineAttribute;
138cdf0e10cSrcweir 				}
139cdf0e10cSrcweir 
140cdf0e10cSrcweir 				mpLineAttribute = rCandidate.mpLineAttribute;
141cdf0e10cSrcweir 				mpLineAttribute->mnRefCount++;
142cdf0e10cSrcweir 			}
143cdf0e10cSrcweir 
144cdf0e10cSrcweir 			return *this;
145cdf0e10cSrcweir 		}
146cdf0e10cSrcweir 
147cdf0e10cSrcweir 		bool LineAttribute::operator==(const LineAttribute& rCandidate) const
148cdf0e10cSrcweir 		{
149cdf0e10cSrcweir 			if(rCandidate.mpLineAttribute == mpLineAttribute)
150cdf0e10cSrcweir 			{
151cdf0e10cSrcweir 				return true;
152cdf0e10cSrcweir 			}
153cdf0e10cSrcweir 
154cdf0e10cSrcweir 			if(rCandidate.isDefault() != isDefault())
155cdf0e10cSrcweir 			{
156cdf0e10cSrcweir 				return false;
157cdf0e10cSrcweir 			}
158cdf0e10cSrcweir 
159cdf0e10cSrcweir 			return (*rCandidate.mpLineAttribute == *mpLineAttribute);
160cdf0e10cSrcweir 		}
161cdf0e10cSrcweir 
162cdf0e10cSrcweir 		const basegfx::BColor& LineAttribute::getColor() const
163cdf0e10cSrcweir 		{
164cdf0e10cSrcweir 			return mpLineAttribute->getColor();
165cdf0e10cSrcweir 		}
166cdf0e10cSrcweir 
167cdf0e10cSrcweir 		double LineAttribute::getWidth() const
168cdf0e10cSrcweir         {
169cdf0e10cSrcweir             return mpLineAttribute->getWidth();
170cdf0e10cSrcweir         }
171cdf0e10cSrcweir 
172cdf0e10cSrcweir         basegfx::B2DLineJoin LineAttribute::getLineJoin() const
173cdf0e10cSrcweir         {
174cdf0e10cSrcweir             return mpLineAttribute->getLineJoin();
175cdf0e10cSrcweir         }
176cdf0e10cSrcweir 
177cdf0e10cSrcweir     } // end of namespace attribute
178cdf0e10cSrcweir } // end of namespace drawinglayer
179cdf0e10cSrcweir 
180cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
181cdf0e10cSrcweir // eof
182