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