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