diff --git a/src/osgPlugins/CMakeLists.txt b/src/osgPlugins/CMakeLists.txt index aaf671d02..e6229f99a 100644 --- a/src/osgPlugins/CMakeLists.txt +++ b/src/osgPlugins/CMakeLists.txt @@ -221,6 +221,10 @@ IF(FREETYPE_FOUND) ADD_SUBDIRECTORY(freetype) ENDIF() +IF (QT4_FOUND) + ADD_SUBDIRECTORY(qfont) +ENDIF() + IF(ZLIB_FOUND) ADD_SUBDIRECTORY(zip) ENDIF() diff --git a/src/osgPlugins/qfont/CMakeLists.txt b/src/osgPlugins/qfont/CMakeLists.txt new file mode 100644 index 000000000..7f59b59f5 --- /dev/null +++ b/src/osgPlugins/qfont/CMakeLists.txt @@ -0,0 +1,6 @@ +INCLUDE_DIRECTORIES(${QT_INCLUDE_DIR}) +SET(TARGET_SRC ReaderQFont.cpp) +SET(TARGET_ADDED_LIBRARIES osgText osgQt) + +SET(TARGET_LIBRARIES_VARS ${QT_QTCORE_LIBRARY_RELEASE} ${QT_QTGUI_LIBRARY_RELEASE}) +SETUP_PLUGIN(qfont) diff --git a/src/osgPlugins/qfont/ReaderQFont.cpp b/src/osgPlugins/qfont/ReaderQFont.cpp new file mode 100644 index 000000000..d3c97f5e0 --- /dev/null +++ b/src/osgPlugins/qfont/ReaderQFont.cpp @@ -0,0 +1,66 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 2009-2010 Mathias Froehlich + * + * This library is open source and may be redistributed and/or modified under + * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * OpenSceneGraph Public License for more details. +*/ +#include +#include +#include + +#include +#include +#include +#include + +#include + +namespace osgQFont { + +class ReaderQFont : public osgDB::ReaderWriter +{ + public: + ReaderQFont() + { + supportsExtension("qfont", "Qt font meta loader"); + } + + virtual const char* className() const { return "QFont Font Reader"; } + + virtual ReadResult readObject(const std::string& file, const osgDB::ReaderWriter::Options* options) const + { + if (!acceptsExtension(osgDB::getLowerCaseFileExtension(file))) + return ReadResult::FILE_NOT_HANDLED; + + if (!QApplication::instance()) + { + osg::notify(osg::WARN) << "Trying to load qfont \"" << file << "\" from within a non qt application!" << std::endl; + return ReadResult::FILE_NOT_FOUND; + } + + if (!QFontDatabase::supportsThreadedFontRendering() && QApplication::instance()->thread() != QThread::currentThread()) + { + osg::notify(osg::WARN) << "Trying to load qfont \"" << file << "\" from a non gui thread " + "within qt application without threaded font rendering!" << std::endl; + return ReadResult::FILE_NOT_FOUND; + } + + QFont font; + if (!font.fromString(QString::fromStdString(osgDB::getNameLessExtension(file)))) + return ReadResult::FILE_NOT_FOUND; + + return new osgText::Font(new osgQt::QFontImplementation(font)); + } +}; + +// now register with Registry to instantiate the above +// reader/writer. +REGISTER_OSGPLUGIN(qfont, ReaderQFont) + +} diff --git a/src/osgText/Font.cpp b/src/osgText/Font.cpp index 1e00ba935..5d3305dea 100644 --- a/src/osgText/Font.cpp +++ b/src/osgText/Font.cpp @@ -83,16 +83,17 @@ std::string osgText::findFontFile(const std::string& str) } // Not found, return empty string - osg::notify(osg::WARN)<<"Warning: font file \""< lock(s_FontFileMutex); @@ -149,10 +150,11 @@ osgText::Font* osgText::readFontStream(std::istream& stream, const osgDB::Reader osg::ref_ptr osgText::readRefFontFile(const std::string& filename, const osgDB::ReaderWriter::Options* userOptions) { - if (filename=="") return 0; + if (filename.empty()) return 0; std::string foundFile = findFontFile(filename); - if (foundFile.empty()) return 0; + if (foundFile.empty()) + foundFile = filename; OpenThreads::ScopedLock lock(s_FontFileMutex); @@ -252,7 +254,7 @@ const Font::FontImplementation* Font::getImplementation() const std::string Font::getFileName() const { if (_implementation.valid()) return _implementation->getFileName(); - return ""; + return std::string(); } void Font::setGlyphImageMargin(unsigned int margin)