From 19d1a563fe839b211c34918e293454dc4c2015d5 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 2 Jul 2007 12:30:14 +0000 Subject: [PATCH] From Csaba Halasz and Robert Osfield, support for passing in ReaderWriter::Options object into readFontFile --- include/osgText/Font | 7 +++---- src/osgText/Font.cpp | 24 ++++++++++++++++-------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/include/osgText/Font b/include/osgText/Font index 764484650..ce299ab1f 100644 --- a/include/osgText/Font +++ b/include/osgText/Font @@ -23,14 +23,13 @@ #include #include #include - +#include #include 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); diff --git a/src/osgText/Font.cpp b/src/osgText/Font.cpp index 06b705c4f..a674a6ea1 100644 --- a/src/osgText/Font.cpp +++ b/src/osgText/Font.cpp @@ -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 options = new osgDB::ReaderWriter::Options; - options->setObjectCacheHint(osgDB::ReaderWriter::Options::CACHE_OBJECTS); + osg::ref_ptr 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(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 options = new osgDB::ReaderWriter::Options; - options->setObjectCacheHint(osgDB::ReaderWriter::Options::CACHE_OBJECTS); + osg::ref_ptr 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;