Changeset 9881 for OpenSceneGraph/trunk/src/osgText/Font3D.cpp
- Timestamp:
- 03/10/09 11:56:00 (4 years ago)
- Files:
-
- 1 modified
-
OpenSceneGraph/trunk/src/osgText/Font3D.cpp (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/src/osgText/Font3D.cpp
r7874 r9881 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield 2 2 * 3 * This library is open source and may be redistributed and/or modified under 4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 3 * This library is open source and may be redistributed and/or modified under 4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 5 5 * (at your option) any later version. The full license is in LICENSE file 6 6 * included with this distribution, and on the openscenegraph.org website. 7 * 7 * 8 8 * This library is distributed in the hope that it will be useful, 9 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 11 * OpenSceneGraph Public License for more details. 12 12 */ … … 87 87 88 88 // Not found, return empty string 89 osg::notify(osg::WARN)<<"Warning: font file \""<<str<<"\" not found."<<std::endl; 89 osg::notify(osg::WARN)<<"Warning: font file \""<<str<<"\" not found."<<std::endl; 90 90 return std::string(); 91 91 } … … 95 95 if (filename=="") return 0; 96 96 97 std::string foundFile = findFont3DFile(filename); 97 // unsure filename have not .text3d at the end 98 std::string tmpFilename; 99 std::string text3dExt = ".text3d"; 100 std::string ext = osgDB::getFileExtensionIncludingDot(filename); 101 if (ext == text3dExt) 102 tmpFilename = filename.substr(filename.size() - ext.size(), ext.size()); 103 else 104 tmpFilename = filename; 105 106 //search font file 107 std::string foundFile = findFont3DFile(tmpFilename); 98 108 if (foundFile.empty()) return 0; 99 109 110 //unsure filename have .text3d at the end 111 foundFile += text3dExt; 112 100 113 OpenThreads::ScopedLock<OpenThreads::Mutex> lock(s_Font3DFileMutex); 101 114 … … 105 118 localOptions = new osgDB::ReaderWriter::Options; 106 119 localOptions->setObjectCacheHint(osgDB::ReaderWriter::Options::CACHE_OBJECTS); 107 // ** HACK to load Font3D instead of Font108 localOptions->setPluginData("3D", (void*) 1);109 }110 else111 {112 userOptions->setPluginData("3D", (void*) 1);113 120 } 114 121 115 122 osg::Object* object = osgDB::readObjectFile(foundFile, userOptions ? userOptions : localOptions.get()); 116 123 117 124 // if the object is a font then return it. 118 125 osgText::Font3D* font3D = dynamic_cast<osgText::Font3D*>(object); … … 143 150 osgDB::ReaderWriter *reader = osgDB::Registry::instance()->getReaderWriterForExtension("ttf"); 144 151 if (reader == 0) return 0; 145 152 146 153 osgDB::ReaderWriter::ReadResult rr = reader->readObject(stream, userOptions ? userOptions : localOptions.get()); 147 154 if (rr.error()) … … 151 158 } 152 159 if (!rr.validObject()) return 0; 153 160 154 161 osg::Object *object = rr.takeObject(); 155 162 … … 167 174 if (filename=="") return 0; 168 175 169 std::string foundFile = findFont3DFile(filename); 176 std::string tmpFilename; 177 std::string text3dExt = ".text3d"; 178 std::string ext = osgDB::getFileExtensionIncludingDot(filename); 179 if (ext == text3dExt) 180 tmpFilename = filename.substr(0, filename.size() - ext.size()); 181 else 182 tmpFilename = filename; 183 184 std::string foundFile = findFont3DFile(tmpFilename); 170 185 if (foundFile.empty()) return 0; 171 186 187 foundFile += text3dExt; 188 172 189 OpenThreads::ScopedLock<OpenThreads::Mutex> lock(s_Font3DFileMutex); 173 190 … … 177 194 localOptions = new osgDB::ReaderWriter::Options; 178 195 localOptions->setObjectCacheHint(osgDB::ReaderWriter::Options::CACHE_OBJECTS); 179 // ** HACK to load Font3D instead of Font180 localOptions->setPluginData("3D", (void*) 1);181 }182 else183 {184 userOptions->setPluginData("3D", (void*) 1);185 196 } 186 197 187 198 osg::ref_ptr<osg::Object> object = osgDB::readRefObjectFile(foundFile, userOptions ? userOptions : localOptions.get()); 188 199 189 200 // if the object is a font then return it. 190 201 osgText::Font3D* font3D = dynamic_cast<osgText::Font3D*>(object.get()); … … 213 224 osgDB::ReaderWriter *reader = osgDB::Registry::instance()->getReaderWriterForExtension("ttf"); 214 225 if (reader == 0) return 0; 215 226 216 227 osgDB::ReaderWriter::ReadResult rr = reader->readObject(stream, userOptions ? userOptions : localOptions.get()); 217 228 if (rr.error()) … … 268 279 Font3D::Glyph3D* Font3D::getGlyph(unsigned int charcode) 269 280 { 270 Glyph3D * glyph3D = NULL; 271 281 Glyph3D * glyph3D = NULL; 282 272 283 Glyph3DMap::iterator itr = _glyph3DMap.find(charcode); 273 284 if (itr!=_glyph3DMap.end()) glyph3D = itr->second.get(); 274 285 275 286 else if (_implementation.valid()) 276 287 { … … 278 289 if (glyph3D) _glyph3DMap[charcode] = glyph3D; 279 290 } 280 291 281 292 return glyph3D; 282 293 } … … 285 296 { 286 297 Glyph3DMap::iterator it,end = _glyph3DMap.end(); 287 298 288 299 for (it=_glyph3DMap.begin(); it!=end; ++it) 289 300 it->second->setThreadSafeRefUnref(threadSafe);
