Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

OSGTextFaceFactory.cpp

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002  *                                OpenSG                                     *
00003  *                                                                           *
00004  *                                                                           *
00005  *             Copyright (C) 2000-2002 by the OpenSG Forum                   *
00006  *                                                                           *
00007  *                            www.opensg.org                                 *
00008  *                                                                           *
00009  *   contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de          *
00010  *                                                                           *
00011 \*---------------------------------------------------------------------------*/
00012 /*---------------------------------------------------------------------------*\
00013  *                                License                                    *
00014  *                                                                           *
00015  * This library is free software; you can redistribute it and/or modify it   *
00016  * under the terms of the GNU Library General Public License as published    *
00017  * by the Free Software Foundation, version 2.                               *
00018  *                                                                           *
00019  * This library is distributed in the hope that it will be useful, but       *
00020  * WITHOUT ANY WARRANTY; without even the implied warranty of                *
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
00022  * Library General Public License for more details.                          *
00023  *                                                                           *
00024  * You should have received a copy of the GNU Library General Public         *
00025  * License along with this library; if not, write to the Free Software       *
00026  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                 *
00027  *                                                                           *
00028 \*---------------------------------------------------------------------------*/
00029 /*---------------------------------------------------------------------------*\
00030  *                                Changes                                    *
00031  *                                                                           *
00032  *                                                                           *
00033  *                                                                           *
00034  *                                                                           *
00035  *                                                                           *
00036  *                                                                           *
00037 \*---------------------------------------------------------------------------*/
00038 
00039 #ifdef _MSC_VER
00040 # pragma warning (disable: 4786)
00041 #endif
00042 
00043 #include "OSGTextFaceFactory.h"
00044 #include "OSGTextBackend.h"
00045 #include "OSGTextVectorFace.h"
00046 #include "OSGTextPixmapFace.h"
00047 #include "OSGTextTXFFace.h"
00048 #include "OSGTextWIN32Backend.h"
00049 #include "OSGTextMacBackend.h"
00050 #include "OSGTextFT2Backend.h"
00051 
00052 #ifdef __sgi
00053 # include <assert.h>
00054 #else
00055 # include <cassert>
00056 #endif
00057 
00058 
00059 using namespace std;
00060 
00061 
00062 OSG_BEGIN_NAMESPACE
00063 
00064 
00065 //----------------------------------------------------------------------
00066 // Static Class Variable implementations
00067 // Author: pdaehne
00068 //----------------------------------------------------------------------
00069 TextFaceFactory TextFaceFactory::_the;
00070 
00071 
00072 //----------------------------------------------------------------------
00073 // Constructor
00074 // Author: pdaehne
00075 //----------------------------------------------------------------------
00076 TextFaceFactory::TextFaceFactory()
00077 : _backend(), _vectorFaceMap(), _pixmapFaceMap(), _txfFaceMap()
00078 {
00079 #if defined(_WIN32)
00080     _backend = new TextWIN32Backend();
00081 #elif defined(__APPLE__)
00082     _backend = new TextMacBackend();
00083     //_backend = new TextFT2Backend();
00084 #elif defined(FT2_LIB)
00085     _backend = new TextFT2Backend();
00086 #else
00087     _backend = 0;
00088 #endif
00089 }
00090 
00091 
00092 //----------------------------------------------------------------------
00093 // Destructor
00094 // Author: pdaehne
00095 //----------------------------------------------------------------------
00096 TextFaceFactory::~TextFaceFactory()
00097 {
00098     clearCache();
00099     delete _backend;
00100 }
00101 
00102 
00103 //----------------------------------------------------------------------
00104 // Returns a vector face
00105 // Author: pdaehne
00106 //----------------------------------------------------------------------
00107 TextVectorFace *TextFaceFactory::createVectorFace(const string &family,
00108                                                  TextFace::Style style)
00109 {
00110     // Try to find the face in the cache
00111     pair<VectorFaceMap::iterator, VectorFaceMap::iterator> range = _vectorFaceMap.equal_range(family);
00112     VectorFaceMap::iterator it;
00113     for (it = range.first; it != range.second; ++it)
00114     {
00115         assert(it->second != 0);
00116         if (it->second->getStyle() == style)
00117             return it->second;
00118     }
00119 
00120     // We did not find the face in the cache, so let the backend create it
00121     if (_backend == 0)
00122         return 0;
00123     TextVectorFace *face = _backend->createVectorFace(family, style);
00124     if (face == 0)
00125         return 0;
00126     _vectorFaceMap.insert(VectorFaceMap::value_type(family, face));
00127     addRefP(face);
00128     return face;
00129 }
00130 
00131 
00132 //----------------------------------------------------------------------
00133 // Returns a pixmap face
00134 // Author: pdaehne
00135 //----------------------------------------------------------------------
00136 TextPixmapFace *TextFaceFactory::createPixmapFace(const string &family,
00137                                                   TextFace::Style style,
00138                                                   UInt32 size)
00139 {
00140     // Try to find the face in the cache
00141     pair<PixmapFaceMap::iterator, PixmapFaceMap::iterator> range = _pixmapFaceMap.equal_range(family);
00142     PixmapFaceMap::iterator it;
00143     for (it = range.first; it != range.second; ++it)
00144     {
00145         assert(it->second != 0);
00146         if ((it->second->getStyle() == style) && (it->second->getSize() == size))
00147             return it->second;
00148     }
00149 
00150     // We did not find the face in the cache, so let the backend create it
00151     if (_backend == 0)
00152         return 0;
00153     TextPixmapFace *face = _backend->createPixmapFace(family, style, size);
00154     if (face == 0)
00155         return 0;
00156     _pixmapFaceMap.insert(PixmapFaceMap::value_type(family, face));
00157     addRefP(face);
00158     return face;
00159 }
00160 
00161 
00162 //----------------------------------------------------------------------
00163 // Returns a TXF face
00164 // Author: pdaehne
00165 //----------------------------------------------------------------------
00166 TextTXFFace *TextFaceFactory::createTXFFace(const string &family,
00167                                             TextFace::Style style,
00168                                             const TextTXFParam &param)
00169 {
00170     // Try to find the face in the cache
00171     pair<TXFFaceMap::iterator, TXFFaceMap::iterator> range = _txfFaceMap.equal_range(family);
00172     TXFFaceMap::iterator it;
00173     for (it = range.first; it != range.second; ++it)
00174     {
00175         assert(it->second != 0);
00176         if ((it->second->getStyle() == style) && (it->second->getParam() == param))
00177             return it->second;
00178     }
00179 
00180     // We did not find the face in the cache, so let the backend create it
00181     if (_backend == 0)
00182         return 0;
00183     TextTXFFace *face = _backend->createTXFFace(family, style, param);
00184     if (face == 0)
00185         return 0;
00186     _txfFaceMap.insert(TXFFaceMap::value_type(family, face));
00187     addRefP(face);
00188     return face;
00189 }
00190 
00191 
00192 //----------------------------------------------------------------------
00193 // Removes all faces from the face cache
00194 // Author: pdaehne
00195 //----------------------------------------------------------------------
00196 void TextFaceFactory::clearCache()
00197 {
00198     // Vector faces
00199     VectorFaceMap::iterator vIt;
00200     for (vIt = _vectorFaceMap.begin(); vIt != _vectorFaceMap.end(); ++vIt)
00201     {
00202         assert(vIt->second != 0);
00203         subRefP(vIt->second);
00204     }
00205     _vectorFaceMap.clear();
00206 
00207     // Pixmap faces
00208     PixmapFaceMap::iterator pIt;
00209     for (pIt = _pixmapFaceMap.begin(); pIt != _pixmapFaceMap.end(); ++pIt)
00210     {
00211         assert(pIt->second != 0);
00212         subRefP(pIt->second);
00213     }
00214     _pixmapFaceMap.clear();
00215 
00216     // TXF faces
00217     TXFFaceMap::iterator tIt;
00218     for (tIt = _txfFaceMap.begin(); tIt != _txfFaceMap.end(); ++tIt)
00219     {
00220         assert(tIt->second != 0);
00221         subRefP(tIt->second);
00222     }
00223     _txfFaceMap.clear();
00224 }
00225 
00226 
00227 //----------------------------------------------------------------------
00228 // Returns the names of all font families available
00229 // Author: pdaehne
00230 //----------------------------------------------------------------------
00231 void TextFaceFactory::getFontFamilies(vector<string> &families) const
00232 {
00233     families.clear();
00234     if (_backend != 0)
00235         _backend->getFontFamilies(families);
00236 }
00237 
00238 
00239 OSG_END_NAMESPACE
00240 
00241 
00242 /*------------------------------------------------------------------------*/
00243 /*                              cvs id's                                  */
00244 
00245 #ifdef OSG_SGI_CC
00246 #pragma set woff 1174
00247 #endif
00248 
00249 #ifdef OSG_LINUX_ICC
00250 #pragma warning( disable : 177 )
00251 #endif
00252 
00253 namespace
00254 {
00255     static OSG::Char8 cvsid_cpp[] = "@(#)$Id: OSGTextFaceFactory.cpp,v 1.1 2005/03/03 13:43:06 a-m-z Exp $";
00256     static OSG::Char8 cvsid_hpp[] = OSGTEXTFACEFACTORY_HEADER_CVSID;
00257     static OSG::Char8 cvsid_inl[] = OSGTEXTFACEFACTORY_INLINE_CVSID;
00258 }
00259 
00260 #ifdef __sgi
00261 #pragma reset woff 1174
00262 #endif

Generated on Thu Aug 25 04:11:18 2005 for OpenSG by  doxygen 1.4.3