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 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_drawinglayer.hxx"
26 
27 #include <drawinglayer/attribute/fontattribute.hxx>
28 #include <tools/string.hxx>
29 
30 //////////////////////////////////////////////////////////////////////////////
31 
32 namespace drawinglayer
33 {
34 	namespace attribute
35 	{
36 		class ImpFontAttribute
37 		{
38 		public:
39 			// refcounter
40 			sal_uInt32								mnRefCount;
41 
42             /// core data
43 			String   									maFamilyName;       // Font Family Name
44 			String   									maStyleName;        // Font Style Name
45 			sal_uInt16									mnWeight;           // Font weight
46 
47 			/// bitfield
48 			unsigned									mbSymbol : 1;       // Symbol Font Flag
49 			unsigned									mbVertical : 1;     // Vertical Text Flag
50 			unsigned									mbItalic : 1;       // Italic Flag
51 			unsigned									mbOutline : 1;      // Outline Flag
52             unsigned                                    mbRTL : 1;          // RTL Flag
53             unsigned                                    mbBiDiStrong : 1;   // BiDi Flag
54             unsigned                                    mbMonospaced : 1;
55 
ImpFontAttribute(const String & rFamilyName,const String & rStyleName,sal_uInt16 nWeight,bool bSymbol,bool bVertical,bool bItalic,bool bMonospaced,bool bOutline,bool bRTL,bool bBiDiStrong)56             ImpFontAttribute(
57                 const String& rFamilyName,
58                 const String& rStyleName,
59                 sal_uInt16 nWeight,
60                 bool bSymbol,
61                 bool bVertical,
62                 bool bItalic,
63                 bool bMonospaced,
64                 bool bOutline,
65                 bool bRTL,
66                 bool bBiDiStrong)
67 			:	mnRefCount(0),
68                 maFamilyName(rFamilyName),
69 			    maStyleName(rStyleName),
70 			    mnWeight(nWeight),
71 			    mbSymbol(bSymbol),
72 			    mbVertical(bVertical),
73 			    mbItalic(bItalic),
74 			    mbOutline(bOutline),
75                 mbRTL(bRTL),
76                 mbBiDiStrong(bBiDiStrong),
77                 mbMonospaced(bMonospaced)
78             {
79             }
80 
81             // data read access
getFamilyName() const82             const String& getFamilyName() const { return maFamilyName; }
getStyleName() const83             const String& getStyleName() const { return maStyleName; }
getWeight() const84             sal_uInt16 getWeight() const { return mnWeight; }
getSymbol() const85             bool getSymbol() const { return mbSymbol; }
getVertical() const86             bool getVertical() const { return mbVertical; }
getItalic() const87             bool getItalic() const { return mbItalic; }
getOutline() const88             bool getOutline() const { return mbOutline; }
getRTL() const89             bool getRTL() const { return mbRTL; }
getBiDiStrong() const90             bool getBiDiStrong() const { return mbBiDiStrong; }
getMonospaced() const91             bool getMonospaced() const { return mbMonospaced; }
92 
operator ==(const ImpFontAttribute & rCompare) const93             bool operator==(const ImpFontAttribute& rCompare) const
94             {
95 			    return (getFamilyName() == rCompare.getFamilyName()
96 				    && getStyleName() == rCompare.getStyleName()
97 				    && getWeight() == rCompare.getWeight()
98 				    && getSymbol() == rCompare.getSymbol()
99 				    && getVertical() == rCompare.getVertical()
100 				    && getItalic() == rCompare.getItalic()
101 				    && getOutline() == rCompare.getOutline()
102 				    && getRTL() == rCompare.getRTL()
103 				    && getBiDiStrong() == rCompare.getBiDiStrong()
104 				    && getMonospaced() == rCompare.getMonospaced());
105             }
106 
get_global_default()107             static ImpFontAttribute* get_global_default()
108             {
109                 static ImpFontAttribute* pDefault = 0;
110 
111                 if(!pDefault)
112                 {
113                     pDefault = new ImpFontAttribute(
114                         String(), String(),
115                         0,
116                         false, false, false, false, false, false, false);
117 
118                     // never delete; start with RefCount 1, not 0
119     			    pDefault->mnRefCount++;
120                 }
121 
122                 return pDefault;
123             }
124 		};
125 
FontAttribute(const String & rFamilyName,const String & rStyleName,sal_uInt16 nWeight,bool bSymbol,bool bVertical,bool bItalic,bool bMonospaced,bool bOutline,bool bRTL,bool bBiDiStrong)126         FontAttribute::FontAttribute(
127             const String& rFamilyName,
128             const String& rStyleName,
129             sal_uInt16 nWeight,
130             bool bSymbol,
131             bool bVertical,
132             bool bItalic,
133             bool bMonospaced,
134             bool bOutline,
135             bool bRTL,
136             bool bBiDiStrong)
137 		:	mpFontAttribute(new ImpFontAttribute(
138                 rFamilyName, rStyleName, nWeight, bSymbol, bVertical, bItalic, bMonospaced, bOutline, bRTL, bBiDiStrong))
139 		{
140 		}
141 
FontAttribute()142 		FontAttribute::FontAttribute()
143         :	mpFontAttribute(ImpFontAttribute::get_global_default())
144 		{
145 			mpFontAttribute->mnRefCount++;
146 		}
147 
FontAttribute(const FontAttribute & rCandidate)148 		FontAttribute::FontAttribute(const FontAttribute& rCandidate)
149 		:	mpFontAttribute(rCandidate.mpFontAttribute)
150 		{
151 			mpFontAttribute->mnRefCount++;
152 		}
153 
~FontAttribute()154 		FontAttribute::~FontAttribute()
155 		{
156 			if(mpFontAttribute->mnRefCount)
157 			{
158 				mpFontAttribute->mnRefCount--;
159 			}
160 			else
161 			{
162 				delete mpFontAttribute;
163 			}
164 		}
165 
isDefault() const166         bool FontAttribute::isDefault() const
167         {
168             return mpFontAttribute == ImpFontAttribute::get_global_default();
169         }
170 
operator =(const FontAttribute & rCandidate)171         FontAttribute& FontAttribute::operator=(const FontAttribute& rCandidate)
172 		{
173 			if(rCandidate.mpFontAttribute != mpFontAttribute)
174 			{
175 				if(mpFontAttribute->mnRefCount)
176 				{
177 					mpFontAttribute->mnRefCount--;
178 				}
179 				else
180 				{
181 					delete mpFontAttribute;
182 				}
183 
184 				mpFontAttribute = rCandidate.mpFontAttribute;
185 				mpFontAttribute->mnRefCount++;
186 			}
187 
188 			return *this;
189 		}
190 
operator ==(const FontAttribute & rCandidate) const191 		bool FontAttribute::operator==(const FontAttribute& rCandidate) const
192 		{
193 			if(rCandidate.mpFontAttribute == mpFontAttribute)
194 			{
195 				return true;
196 			}
197 
198 			if(rCandidate.isDefault() != isDefault())
199 			{
200 				return false;
201 			}
202 
203 			return (*rCandidate.mpFontAttribute == *mpFontAttribute);
204 		}
205 
getFamilyName() const206         const String& FontAttribute::getFamilyName() const
207         {
208             return mpFontAttribute->getFamilyName();
209         }
210 
getStyleName() const211         const String& FontAttribute::getStyleName() const
212         {
213             return mpFontAttribute->getStyleName();
214         }
215 
getWeight() const216         sal_uInt16 FontAttribute::getWeight() const
217         {
218             return mpFontAttribute->getWeight();
219         }
220 
getSymbol() const221         bool FontAttribute::getSymbol() const
222         {
223             return mpFontAttribute->getSymbol();
224         }
225 
getVertical() const226         bool FontAttribute::getVertical() const
227         {
228             return mpFontAttribute->getVertical();
229         }
230 
getItalic() const231         bool FontAttribute::getItalic() const
232         {
233             return mpFontAttribute->getItalic();
234         }
235 
getOutline() const236         bool FontAttribute::getOutline() const
237         {
238             return mpFontAttribute->getOutline();
239         }
240 
getRTL() const241         bool FontAttribute::getRTL() const
242         {
243             return mpFontAttribute->getRTL();
244         }
245 
getBiDiStrong() const246         bool FontAttribute::getBiDiStrong() const
247         {
248             return mpFontAttribute->getBiDiStrong();
249         }
250 
getMonospaced() const251         bool FontAttribute::getMonospaced() const
252         {
253             return mpFontAttribute->getMonospaced();
254         }
255 
256 
257     } // end of namespace attribute
258 } // end of namespace drawinglayer
259 
260 //////////////////////////////////////////////////////////////////////////////
261 // eof
262