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 TextFaceFactory TextFaceFactory::_the;
00070
00071
00072
00073
00074
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
00084 #elif defined(FT2_LIB)
00085 _backend = new TextFT2Backend();
00086 #else
00087 _backend = 0;
00088 #endif
00089 }
00090
00091
00092
00093
00094
00095
00096 TextFaceFactory::~TextFaceFactory()
00097 {
00098 clearCache();
00099 delete _backend;
00100 }
00101
00102
00103
00104
00105
00106
00107 TextVectorFace *TextFaceFactory::createVectorFace(const string &family,
00108 TextFace::Style style)
00109 {
00110
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
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
00134
00135
00136 TextPixmapFace *TextFaceFactory::createPixmapFace(const string &family,
00137 TextFace::Style style,
00138 UInt32 size)
00139 {
00140
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
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
00164
00165
00166 TextTXFFace *TextFaceFactory::createTXFFace(const string &family,
00167 TextFace::Style style,
00168 const TextTXFParam ¶m)
00169 {
00170
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
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
00194
00195
00196 void TextFaceFactory::clearCache()
00197 {
00198
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
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
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
00229
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
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