From Mathias Froehlich, "If you want to have that qfont plugin loader, this is the updated
implementation which uses osgQt and includes the changes to make fonts load without a file on disk."
This commit is contained in:
parent
737378c967
commit
10a2f389d7
@ -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()
|
||||
|
6
src/osgPlugins/qfont/CMakeLists.txt
Normal file
6
src/osgPlugins/qfont/CMakeLists.txt
Normal file
@ -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)
|
66
src/osgPlugins/qfont/ReaderQFont.cpp
Normal file
66
src/osgPlugins/qfont/ReaderQFont.cpp
Normal file
@ -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 <osgDB/FileNameUtils>
|
||||
#include <osgDB/Registry>
|
||||
#include <osgText/Font>
|
||||
|
||||
#include <QtCore/QThread>
|
||||
#include <QtGui/QApplication>
|
||||
#include <QtGui/QFont>
|
||||
#include <QtGui/QFontDatabase>
|
||||
|
||||
#include <osgQt/QFontImplementation>
|
||||
|
||||
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)
|
||||
|
||||
}
|
@ -83,16 +83,17 @@ std::string osgText::findFontFile(const std::string& str)
|
||||
}
|
||||
|
||||
// Not found, return empty string
|
||||
osg::notify(osg::WARN)<<"Warning: font file \""<<str<<"\" not found."<<std::endl;
|
||||
osg::notify(osg::INFO)<<"Warning: font file \""<<str<<"\" not found."<<std::endl;
|
||||
return std::string();
|
||||
}
|
||||
|
||||
osgText::Font* osgText::readFontFile(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<OpenThreads::Mutex> lock(s_FontFileMutex);
|
||||
|
||||
@ -149,10 +150,11 @@ osgText::Font* osgText::readFontStream(std::istream& stream, const osgDB::Reader
|
||||
|
||||
osg::ref_ptr<Font> 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<OpenThreads::Mutex> 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)
|
||||
|
Loading…
Reference in New Issue
Block a user