00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
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
00067
00068
00069 static bool terminateFaceFactory()
00070 {
00071
00072
00073
00074
00075
00076
00077 if(TextFaceFactory::isValid())
00078 TextFaceFactory::the().clearCache();
00079
00080 return true;
00081 }
00082
00083
00084
00085
00086
00087
00088 bool TextFaceFactory::_valid = false;
00089 TextFaceFactory TextFaceFactory::_the;
00090
00091
00092
00093
00094
00095 TextFaceFactory::TextFaceFactory()
00096 : _backend(), _vectorFaceMap(), _pixmapFaceMap(), _txfFaceMap()
00097 {
00098 _valid = true;
00099 #if defined(_WIN32)
00100 _backend = new TextWIN32Backend();
00101 #elif defined(__APPLE__)
00102 _backend = new TextMacBackend();
00103
00104 #elif defined(FT2_LIB)
00105 _backend = new TextFT2Backend();
00106 #else
00107 _backend = 0;
00108 #endif
00109
00110 addSystemExitFunction(&terminateFaceFactory);
00111 }
00112
00113
00114
00115
00116
00117
00118 TextFaceFactory::~TextFaceFactory()
00119 {
00120 _valid = false;
00121 clearCache();
00122 delete _backend;
00123 }
00124
00125
00126
00127
00128
00129
00130 TextVectorFace *TextFaceFactory::createVectorFace(const string &family,
00131 TextFace::Style style)
00132 {
00133
00134 pair<VectorFaceMap::iterator, VectorFaceMap::iterator> range = _vectorFaceMap.equal_range(family);
00135 VectorFaceMap::iterator it;
00136 for (it = range.first; it != range.second; ++it)
00137 {
00138 assert(it->second != 0);
00139 if (it->second->getStyle() == style)
00140 return it->second;
00141 }
00142
00143
00144 if (_backend == 0)
00145 return 0;
00146 TextVectorFace *face = _backend->createVectorFace(family, style);
00147 if (face == 0)
00148 return 0;
00149 _vectorFaceMap.insert(VectorFaceMap::value_type(family, face));
00150 addRefP(face);
00151 return face;
00152 }
00153
00154
00155
00156
00157
00158
00159 TextPixmapFace *TextFaceFactory::createPixmapFace(const string &family,
00160 TextFace::Style style,
00161 UInt32 size)
00162 {
00163
00164 pair<PixmapFaceMap::iterator, PixmapFaceMap::iterator> range = _pixmapFaceMap.equal_range(family);
00165 PixmapFaceMap::iterator it;
00166 for (it = range.first; it != range.second; ++it)
00167 {
00168 assert(it->second != 0);
00169 if ((it->second->getStyle() == style) && (it->second->getSize() == size))
00170 return it->second;
00171 }
00172
00173
00174 if (_backend == 0)
00175 return 0;
00176 TextPixmapFace *face = _backend->createPixmapFace(family, style, size);
00177 if (face == 0)
00178 return 0;
00179 _pixmapFaceMap.insert(PixmapFaceMap::value_type(family, face));
00180 addRefP(face);
00181 return face;
00182 }
00183
00184
00185
00186
00187
00188
00189 TextTXFFace *TextFaceFactory::createTXFFace(const string &family,
00190 TextFace::Style style,
00191 const TextTXFParam ¶m)
00192 {
00193
00194 pair<TXFFaceMap::iterator, TXFFaceMap::iterator> range = _txfFaceMap.equal_range(family);
00195 TXFFaceMap::iterator it;
00196 for (it = range.first; it != range.second; ++it)
00197 {
00198 assert(it->second != 0);
00199 if ((it->second->getStyle() == style) && (it->second->getParam() == param))
00200 return it->second;
00201 }
00202
00203
00204 if (_backend == 0)
00205 return 0;
00206 TextTXFFace *face = _backend->createTXFFace(family, style, param);
00207 if (face == 0)
00208 return 0;
00209 _txfFaceMap.insert(TXFFaceMap::value_type(family, face));
00210 addRefP(face);
00211 return face;
00212 }
00213
00214
00215
00216
00217
00218
00219 void TextFaceFactory::clearCache()
00220 {
00221
00222 VectorFaceMap::iterator vIt;
00223 for (vIt = _vectorFaceMap.begin(); vIt != _vectorFaceMap.end(); ++vIt)
00224 {
00225 assert(vIt->second != 0);
00226 subRefP(vIt->second);
00227 }
00228 _vectorFaceMap.clear();
00229
00230
00231 PixmapFaceMap::iterator pIt;
00232 for (pIt = _pixmapFaceMap.begin(); pIt != _pixmapFaceMap.end(); ++pIt)
00233 {
00234 assert(pIt->second != 0);
00235 subRefP(pIt->second);
00236 }
00237 _pixmapFaceMap.clear();
00238
00239
00240 TXFFaceMap::iterator tIt;
00241 for (tIt = _txfFaceMap.begin(); tIt != _txfFaceMap.end(); ++tIt)
00242 {
00243 assert(tIt->second != 0);
00244 subRefP(tIt->second);
00245 }
00246 _txfFaceMap.clear();
00247 }
00248
00249
00250
00251
00252
00253
00254 void TextFaceFactory::getFontFamilies(vector<string> &families) const
00255 {
00256 families.clear();
00257 if (_backend != 0)
00258 _backend->getFontFamilies(families);
00259 }
00260
00261 bool TextFaceFactory::isValid(void)
00262 {
00263 return _valid;
00264 }
00265
00266 OSG_END_NAMESPACE
00267
00268
00269
00270
00271
00272 #ifdef OSG_SGI_CC
00273 #pragma set woff 1174
00274 #endif
00275
00276 #ifdef OSG_LINUX_ICC
00277 #pragma warning( disable : 177 )
00278 #endif
00279
00280 namespace
00281 {
00282 static OSG::Char8 cvsid_cpp[] = "@(#)$Id: OSGTextFaceFactory.cpp,v 1.3 2006/10/27 13:52:13 a-m-z Exp $";
00283 static OSG::Char8 cvsid_hpp[] = OSGTEXTFACEFACTORY_HEADER_CVSID;
00284 static OSG::Char8 cvsid_inl[] = OSGTEXTFACEFACTORY_INLINE_CVSID;
00285 }
00286
00287 #ifdef __sgi
00288 #pragma reset woff 1174
00289 #endif