From Csaba Halasz and Robert Osfield, support for passing in ReaderWriter::Options object into readFontFile
This commit is contained in:
@@ -23,14 +23,13 @@
|
||||
#include <osg/StateSet>
|
||||
#include <osg/buffered_value>
|
||||
#include <osg/TexEnv>
|
||||
|
||||
#include <osgDB/ReaderWriter>
|
||||
#include <osgText/Export>
|
||||
|
||||
namespace osgText {
|
||||
|
||||
class Font;
|
||||
class Text;
|
||||
|
||||
enum KerningType
|
||||
{
|
||||
KERNING_DEFAULT, //default locked to integer kerning values
|
||||
@@ -57,10 +56,10 @@ enum KerningType
|
||||
* If the given file could not be found, the path part will be stripped and
|
||||
* the file will be searched again in the OS specific directories.
|
||||
*/
|
||||
extern OSGTEXT_EXPORT Font* readFontFile(const std::string& filename);
|
||||
extern OSGTEXT_EXPORT Font* readFontFile(const std::string& filename, const osgDB::ReaderWriter::Options* userOptions = 0);
|
||||
|
||||
/** read a font from specified stream.*/
|
||||
extern OSGTEXT_EXPORT Font* readFontStream(std::istream& stream);
|
||||
extern OSGTEXT_EXPORT Font* readFontStream(std::istream& stream, const osgDB::ReaderWriter::Options* userOptions = 0);
|
||||
|
||||
extern OSGTEXT_EXPORT std::string findFontFile(const std::string& str);
|
||||
|
||||
|
||||
@@ -81,17 +81,21 @@ std::string osgText::findFontFile(const std::string& str)
|
||||
return std::string();
|
||||
}
|
||||
|
||||
osgText::Font* osgText::readFontFile(const std::string& filename)
|
||||
osgText::Font* osgText::readFontFile(const std::string& filename, const osgDB::ReaderWriter::Options* userOptions)
|
||||
{
|
||||
if (filename=="") return 0;
|
||||
|
||||
std::string foundFile = findFontFile(filename);
|
||||
if (foundFile.empty()) return 0;
|
||||
|
||||
osg::ref_ptr<osgDB::ReaderWriter::Options> options = new osgDB::ReaderWriter::Options;
|
||||
options->setObjectCacheHint(osgDB::ReaderWriter::Options::CACHE_OBJECTS);
|
||||
osg::ref_ptr<osgDB::ReaderWriter::Options> localOptions;
|
||||
if (!userOptions)
|
||||
{
|
||||
localOptions = new osgDB::ReaderWriter::Options;
|
||||
localOptions->setObjectCacheHint(osgDB::ReaderWriter::Options::CACHE_OBJECTS);
|
||||
}
|
||||
|
||||
osg::Object* object = osgDB::readObjectFile(foundFile, options.get());
|
||||
osg::Object* object = osgDB::readObjectFile(foundFile, userOptions ? userOptions : localOptions.get());
|
||||
|
||||
// if the object is a font then return it.
|
||||
osgText::Font* font = dynamic_cast<osgText::Font*>(object);
|
||||
@@ -102,15 +106,19 @@ osgText::Font* osgText::readFontFile(const std::string& filename)
|
||||
return 0;
|
||||
}
|
||||
|
||||
osgText::Font* osgText::readFontStream(std::istream& stream)
|
||||
osgText::Font* osgText::readFontStream(std::istream& stream, const osgDB::ReaderWriter::Options* userOptions)
|
||||
{
|
||||
osg::ref_ptr<osgDB::ReaderWriter::Options> options = new osgDB::ReaderWriter::Options;
|
||||
options->setObjectCacheHint(osgDB::ReaderWriter::Options::CACHE_OBJECTS);
|
||||
osg::ref_ptr<osgDB::ReaderWriter::Options> localOptions;
|
||||
if (!userOptions)
|
||||
{
|
||||
localOptions = new osgDB::ReaderWriter::Options;
|
||||
localOptions->setObjectCacheHint(osgDB::ReaderWriter::Options::CACHE_OBJECTS);
|
||||
}
|
||||
|
||||
// there should be a better way to get the FreeType ReaderWriter by name...
|
||||
osgDB::ReaderWriter *reader = osgDB::Registry::instance()->getReaderWriterForExtension("ttf");
|
||||
if (reader == 0) return 0;
|
||||
osgDB::ReaderWriter::ReadResult rr = reader->readObject(stream, options.get());
|
||||
osgDB::ReaderWriter::ReadResult rr = reader->readObject(stream, userOptions ? userOptions : localOptions.get());
|
||||
if (rr.error())
|
||||
{
|
||||
osg::notify(osg::WARN) << rr.message() << std::endl;
|
||||
|
||||
Reference in New Issue
Block a user