Show
Ignore:
Timestamp:
03/10/09 11:56:00 (5 years ago)
Author:
robert
Message:

From David Callu, "Problem:

osgText::Text and osgText::Text3D use the same font file.
The first really load the file and obtain an osgText::Font object,
the second use the cache created during the first load of the
font file, and so obtain an osgText::Font object instead of
osgText::Font3D object. To obtain an osgText::Font3D object,
osgText::Text3D call osgDB::readObjectFile(...) with an option
to specify the plugin we want an osgText::Font3D instead of
osgText::Font.

Generalised Problem:

In osgDB::Registry, loaded file cache is referenced by the name
of this file, so if I load a file with some options, and the cache
already contain object for this filename, I obtain an object
potentially not loaded with my options.

Behaviours:

Cache management is delegate to osgDB::Registry, but cache
coherence (load a file with option then reuse it, deactivate the
cache when load a specific file or don't cached the loaded file)
is user's responsibility.

Text3D solution:

Postfix the font file name by .text3d or something similar and then have the freetype plugin return
osgText::Font3D when it detects this.
This operation is done by osgText::readFont3DFile() which unsure the filename have .text3d as extension.
This is totaly transparent for user, and backward compatible.

BTW, I fix the bug about the Normal of 3D text. Currently, the front and wall face have
the same normal (0,0,1) in the Text3D object coordinate. Now the wall face have its own
normal array computed by the plugin.

BTW 2, I implement
- void Text3D::accept(osg::Drawable::ConstAttributeFunctor?& af) const
- void Text3D::accept(osg::PrimitiveFunctor?& pf) const
so now statistics are well reported.
"

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/src/osgPlugins/freetype/ReaderWriterFreeType.cpp

    r8680 r9881  
    1818            supportsExtension("cff","OpenType format"); 
    1919            supportsExtension("cef","OpenType format"); 
    20             supportsExtension("fon","Windows bitmap fonts format"); 
     20            supportsExtension("fon","Windows bitmap fonts format"); 
    2121            supportsExtension("fnt","Windows bitmap fonts format"); 
     22            supportsExtension("text3d","use 3D Font instead of 2D Font"); 
    2223 
    2324            supportsOption("monochrome","Select monochrome font."); 
    2425        } 
    25          
     26 
    2627        virtual const char* className() const { return "FreeType Font Reader/Writer"; } 
    27          
     28 
    2829        static unsigned int getFlags(const osgDB::ReaderWriter::Options* options) 
    2930        { 
     
    3334                flags |= FT_LOAD_MONOCHROME; 
    3435            } 
    35              
     36 
    3637            return flags; 
    3738        } 
     
    3940        virtual ReadResult readObject(const std::string& file, const osgDB::ReaderWriter::Options* options) const 
    4041        { 
    41             std::string ext = osgDB::getLowerCaseFileExtension(file); 
     42            std::string tmpFile = file; 
     43            bool needFont3D = false; 
     44 
     45            std::string ext = osgDB::getLowerCaseFileExtension(tmpFile); 
     46            if (ext == "text3d") 
     47            { 
     48                needFont3D = true; 
     49                tmpFile.erase(tmpFile.size()-7, 7); 
     50                ext = osgDB::getLowerCaseFileExtension(tmpFile); 
     51            } 
     52            else if ((options != NULL) && (options->getPluginData("3D"))) 
     53            { 
     54                needFont3D = true; 
     55            } 
     56 
    4257            if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; 
    4358 
    44             std::string fileName = osgDB::findDataFile( file, options ); 
     59            std::string fileName = osgDB::findDataFile( tmpFile, options ); 
    4560            if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; 
    46              
     61 
    4762            FreeTypeLibrary* freeTypeLibrary = FreeTypeLibrary::instance(); 
    48             if (!freeTypeLibrary)  
     63            if (!freeTypeLibrary) 
    4964            { 
    5065                osg::notify(osg::WARN)<<"Warning:: cannot create freetype font after freetype library has been deleted."<<std::endl; 
     
    5267            } 
    5368 
    54             if ( (options != NULL) && (options->getPluginData("3D")) ) 
     69            if (needFont3D) 
    5570                return freeTypeLibrary->getFont3D(fileName,0,getFlags(options)); 
    5671            else 
     
    6176        { 
    6277            FreeTypeLibrary* freeTypeLibrary = FreeTypeLibrary::instance(); 
    63             if (!freeTypeLibrary)  
     78            if (!freeTypeLibrary) 
    6479            { 
    6580                osg::notify(osg::WARN)<<"Warning:: cannot create freetype font after freetype library has been deleted."<<std::endl;