1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_drawinglayer.hxx" 30 31 #include <drawinglayer/attribute/fontattribute.hxx> 32 #include <tools/string.hxx> 33 34 ////////////////////////////////////////////////////////////////////////////// 35 36 namespace drawinglayer 37 { 38 namespace attribute 39 { 40 class ImpFontAttribute 41 { 42 public: 43 // refcounter 44 sal_uInt32 mnRefCount; 45 46 /// core data 47 String maFamilyName; // Font Family Name 48 String maStyleName; // Font Style Name 49 sal_uInt16 mnWeight; // Font weight 50 51 /// bitfield 52 unsigned mbSymbol : 1; // Symbol Font Flag 53 unsigned mbVertical : 1; // Vertical Text Flag 54 unsigned mbItalic : 1; // Italic Flag 55 unsigned mbOutline : 1; // Outline Flag 56 unsigned mbRTL : 1; // RTL Flag 57 unsigned mbBiDiStrong : 1; // BiDi Flag 58 unsigned mbMonospaced : 1; 59 60 ImpFontAttribute( 61 const String& rFamilyName, 62 const String& rStyleName, 63 sal_uInt16 nWeight, 64 bool bSymbol, 65 bool bVertical, 66 bool bItalic, 67 bool bMonospaced, 68 bool bOutline, 69 bool bRTL, 70 bool bBiDiStrong) 71 : mnRefCount(0), 72 maFamilyName(rFamilyName), 73 maStyleName(rStyleName), 74 mnWeight(nWeight), 75 mbSymbol(bSymbol), 76 mbVertical(bVertical), 77 mbItalic(bItalic), 78 mbOutline(bOutline), 79 mbRTL(bRTL), 80 mbBiDiStrong(bBiDiStrong), 81 mbMonospaced(bMonospaced) 82 { 83 } 84 85 // data read access 86 const String& getFamilyName() const { return maFamilyName; } 87 const String& getStyleName() const { return maStyleName; } 88 sal_uInt16 getWeight() const { return mnWeight; } 89 bool getSymbol() const { return mbSymbol; } 90 bool getVertical() const { return mbVertical; } 91 bool getItalic() const { return mbItalic; } 92 bool getOutline() const { return mbOutline; } 93 bool getRTL() const { return mbRTL; } 94 bool getBiDiStrong() const { return mbBiDiStrong; } 95 bool getMonospaced() const { return mbMonospaced; } 96 97 bool operator==(const ImpFontAttribute& rCompare) const 98 { 99 return (getFamilyName() == rCompare.getFamilyName() 100 && getStyleName() == rCompare.getStyleName() 101 && getWeight() == rCompare.getWeight() 102 && getSymbol() == rCompare.getSymbol() 103 && getVertical() == rCompare.getVertical() 104 && getItalic() == rCompare.getItalic() 105 && getOutline() == rCompare.getOutline() 106 && getRTL() == rCompare.getRTL() 107 && getBiDiStrong() == rCompare.getBiDiStrong() 108 && getMonospaced() == rCompare.getMonospaced()); 109 } 110 111 static ImpFontAttribute* get_global_default() 112 { 113 static ImpFontAttribute* pDefault = 0; 114 115 if(!pDefault) 116 { 117 pDefault = new ImpFontAttribute( 118 String(), String(), 119 0, 120 false, false, false, false, false, false, false); 121 122 // never delete; start with RefCount 1, not 0 123 pDefault->mnRefCount++; 124 } 125 126 return pDefault; 127 } 128 }; 129 130 FontAttribute::FontAttribute( 131 const String& rFamilyName, 132 const String& rStyleName, 133 sal_uInt16 nWeight, 134 bool bSymbol, 135 bool bVertical, 136 bool bItalic, 137 bool bMonospaced, 138 bool bOutline, 139 bool bRTL, 140 bool bBiDiStrong) 141 : mpFontAttribute(new ImpFontAttribute( 142 rFamilyName, rStyleName, nWeight, bSymbol, bVertical, bItalic, bMonospaced, bOutline, bRTL, bBiDiStrong)) 143 { 144 } 145 146 FontAttribute::FontAttribute() 147 : mpFontAttribute(ImpFontAttribute::get_global_default()) 148 { 149 mpFontAttribute->mnRefCount++; 150 } 151 152 FontAttribute::FontAttribute(const FontAttribute& rCandidate) 153 : mpFontAttribute(rCandidate.mpFontAttribute) 154 { 155 mpFontAttribute->mnRefCount++; 156 } 157 158 FontAttribute::~FontAttribute() 159 { 160 if(mpFontAttribute->mnRefCount) 161 { 162 mpFontAttribute->mnRefCount--; 163 } 164 else 165 { 166 delete mpFontAttribute; 167 } 168 } 169 170 bool FontAttribute::isDefault() const 171 { 172 return mpFontAttribute == ImpFontAttribute::get_global_default(); 173 } 174 175 FontAttribute& FontAttribute::operator=(const FontAttribute& rCandidate) 176 { 177 if(rCandidate.mpFontAttribute != mpFontAttribute) 178 { 179 if(mpFontAttribute->mnRefCount) 180 { 181 mpFontAttribute->mnRefCount--; 182 } 183 else 184 { 185 delete mpFontAttribute; 186 } 187 188 mpFontAttribute = rCandidate.mpFontAttribute; 189 mpFontAttribute->mnRefCount++; 190 } 191 192 return *this; 193 } 194 195 bool FontAttribute::operator==(const FontAttribute& rCandidate) const 196 { 197 if(rCandidate.mpFontAttribute == mpFontAttribute) 198 { 199 return true; 200 } 201 202 if(rCandidate.isDefault() != isDefault()) 203 { 204 return false; 205 } 206 207 return (*rCandidate.mpFontAttribute == *mpFontAttribute); 208 } 209 210 const String& FontAttribute::getFamilyName() const 211 { 212 return mpFontAttribute->getFamilyName(); 213 } 214 215 const String& FontAttribute::getStyleName() const 216 { 217 return mpFontAttribute->getStyleName(); 218 } 219 220 sal_uInt16 FontAttribute::getWeight() const 221 { 222 return mpFontAttribute->getWeight(); 223 } 224 225 bool FontAttribute::getSymbol() const 226 { 227 return mpFontAttribute->getSymbol(); 228 } 229 230 bool FontAttribute::getVertical() const 231 { 232 return mpFontAttribute->getVertical(); 233 } 234 235 bool FontAttribute::getItalic() const 236 { 237 return mpFontAttribute->getItalic(); 238 } 239 240 bool FontAttribute::getOutline() const 241 { 242 return mpFontAttribute->getOutline(); 243 } 244 245 bool FontAttribute::getRTL() const 246 { 247 return mpFontAttribute->getRTL(); 248 } 249 250 bool FontAttribute::getBiDiStrong() const 251 { 252 return mpFontAttribute->getBiDiStrong(); 253 } 254 255 bool FontAttribute::getMonospaced() const 256 { 257 return mpFontAttribute->getMonospaced(); 258 } 259 260 261 } // end of namespace attribute 262 } // end of namespace drawinglayer 263 264 ////////////////////////////////////////////////////////////////////////////// 265 // eof 266