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 // MARKER(update_precomp.py): autogen include statement, do not remove
23 #include "precompiled_drawinglayer.hxx"
24 
25 #include <drawinglayer/attribute/fillhatchattribute.hxx>
26 #include <basegfx/color/bcolor.hxx>
27 
28 //////////////////////////////////////////////////////////////////////////////
29 
30 namespace drawinglayer
31 {
32 	namespace attribute
33 	{
34 		class ImpFillHatchAttribute
35 		{
36 		public:
37 			// refcounter
38 			sal_uInt32								mnRefCount;
39 
40             // data definitions
41 			HatchStyle								meStyle;
42 			double									mfDistance;
43 			double									mfAngle;
44 			basegfx::BColor							maColor;
45             sal_uInt32                              mnMinimalDiscreteDistance;
46 
47 			// bitfield
48 			unsigned								mbFillBackground : 1;
49 
ImpFillHatchAttribute(HatchStyle eStyle,double fDistance,double fAngle,const basegfx::BColor & rColor,sal_uInt32 nMinimalDiscreteDistance,bool bFillBackground)50 			ImpFillHatchAttribute(
51                 HatchStyle eStyle,
52                 double fDistance,
53                 double fAngle,
54                 const basegfx::BColor& rColor,
55                 sal_uInt32 nMinimalDiscreteDistance,
56                 bool bFillBackground)
57 			:	mnRefCount(0),
58 			    meStyle(eStyle),
59 		    	mfDistance(fDistance),
60 			    mfAngle(fAngle),
61 			    maColor(rColor),
62                 mnMinimalDiscreteDistance(nMinimalDiscreteDistance),
63 			    mbFillBackground(bFillBackground)
64             {
65             }
66 
67 			// data read access
getStyle() const68 			HatchStyle getStyle() const { return meStyle; }
getDistance() const69 			double getDistance() const { return mfDistance; }
getAngle() const70 			double getAngle() const { return mfAngle; }
getColor() const71 			const basegfx::BColor& getColor() const { return maColor; }
getMinimalDiscreteDistance() const72             sal_uInt32 getMinimalDiscreteDistance() const { return mnMinimalDiscreteDistance; }
isFillBackground() const73 			bool isFillBackground() const { return mbFillBackground; }
74 
operator ==(const ImpFillHatchAttribute & rCandidate) const75 			bool operator==(const ImpFillHatchAttribute& rCandidate) const
76             {
77 			    return (getStyle() == rCandidate.getStyle()
78                     && getDistance() == rCandidate.getDistance()
79 				    && getAngle() == rCandidate.getAngle()
80 				    && getColor() == rCandidate.getColor()
81                     && getMinimalDiscreteDistance() == rCandidate.getMinimalDiscreteDistance()
82 				    && isFillBackground() == rCandidate.isFillBackground());
83             }
84 
get_global_default()85             static ImpFillHatchAttribute* get_global_default()
86             {
87                 static ImpFillHatchAttribute* pDefault = 0;
88 
89                 if(!pDefault)
90                 {
91                     pDefault = new ImpFillHatchAttribute(
92                         HATCHSTYLE_SINGLE,
93                         0.0, 0.0,
94                         basegfx::BColor(),
95                         3, // same as VCL
96                         false);
97 
98                     // never delete; start with RefCount 1, not 0
99     			    pDefault->mnRefCount++;
100                 }
101 
102                 return pDefault;
103             }
104 		};
105 
FillHatchAttribute(HatchStyle eStyle,double fDistance,double fAngle,const basegfx::BColor & rColor,sal_uInt32 nMinimalDiscreteDistance,bool bFillBackground)106         FillHatchAttribute::FillHatchAttribute(
107             HatchStyle eStyle,
108             double fDistance,
109             double fAngle,
110             const basegfx::BColor& rColor,
111             sal_uInt32 nMinimalDiscreteDistance,
112             bool bFillBackground)
113 		:	mpFillHatchAttribute(
114                 new ImpFillHatchAttribute(
115                     eStyle,
116                     fDistance,
117                     fAngle,
118                     rColor,
119                     nMinimalDiscreteDistance,
120                     bFillBackground))
121 		{
122 		}
123 
FillHatchAttribute()124 		FillHatchAttribute::FillHatchAttribute()
125         :	mpFillHatchAttribute(ImpFillHatchAttribute::get_global_default())
126 		{
127 			mpFillHatchAttribute->mnRefCount++;
128 		}
129 
FillHatchAttribute(const FillHatchAttribute & rCandidate)130         FillHatchAttribute::FillHatchAttribute(const FillHatchAttribute& rCandidate)
131 		:	mpFillHatchAttribute(rCandidate.mpFillHatchAttribute)
132 		{
133 			mpFillHatchAttribute->mnRefCount++;
134 		}
135 
~FillHatchAttribute()136 		FillHatchAttribute::~FillHatchAttribute()
137 		{
138 			if(mpFillHatchAttribute->mnRefCount)
139 			{
140 				mpFillHatchAttribute->mnRefCount--;
141 			}
142 			else
143 			{
144 				delete mpFillHatchAttribute;
145 			}
146 		}
147 
isDefault() const148         bool FillHatchAttribute::isDefault() const
149         {
150             return mpFillHatchAttribute == ImpFillHatchAttribute::get_global_default();
151         }
152 
operator =(const FillHatchAttribute & rCandidate)153         FillHatchAttribute& FillHatchAttribute::operator=(const FillHatchAttribute& rCandidate)
154 		{
155 			if(rCandidate.mpFillHatchAttribute != mpFillHatchAttribute)
156 			{
157 				if(mpFillHatchAttribute->mnRefCount)
158 				{
159 					mpFillHatchAttribute->mnRefCount--;
160 				}
161 				else
162 				{
163 					delete mpFillHatchAttribute;
164 				}
165 
166 				mpFillHatchAttribute = rCandidate.mpFillHatchAttribute;
167 				mpFillHatchAttribute->mnRefCount++;
168 			}
169 
170 			return *this;
171 		}
172 
operator ==(const FillHatchAttribute & rCandidate) const173 		bool FillHatchAttribute::operator==(const FillHatchAttribute& rCandidate) const
174 		{
175 			if(rCandidate.mpFillHatchAttribute == mpFillHatchAttribute)
176 			{
177 				return true;
178 			}
179 
180 			if(rCandidate.isDefault() != isDefault())
181 			{
182 				return false;
183 			}
184 
185 			return (*rCandidate.mpFillHatchAttribute == *mpFillHatchAttribute);
186 		}
187 
188 		// data read access
getStyle() const189 		HatchStyle FillHatchAttribute::getStyle() const
190         {
191             return mpFillHatchAttribute->getStyle();
192         }
193 
getDistance() const194 		double FillHatchAttribute::getDistance() const
195         {
196             return mpFillHatchAttribute->getDistance();
197         }
198 
getAngle() const199 		double FillHatchAttribute::getAngle() const
200         {
201             return mpFillHatchAttribute->getAngle();
202         }
203 
getColor() const204 		const basegfx::BColor& FillHatchAttribute::getColor() const
205         {
206             return mpFillHatchAttribute->getColor();
207         }
208 
getMinimalDiscreteDistance() const209         sal_uInt32 FillHatchAttribute::getMinimalDiscreteDistance() const
210         {
211             return mpFillHatchAttribute->getMinimalDiscreteDistance();
212         }
213 
isFillBackground() const214 		bool FillHatchAttribute::isFillBackground() const
215         {
216             return mpFillHatchAttribute->isFillBackground();
217         }
218 
219     } // end of namespace attribute
220 } // end of namespace drawinglayer
221 
222 //////////////////////////////////////////////////////////////////////////////
223 // eof
224