Refactored to use a typedef of Font to Font3D rather than have a separate Font3D class
This commit is contained in:
@@ -10,12 +10,10 @@ ENDIF()
|
||||
|
||||
SET(TARGET_SRC
|
||||
FreeTypeFont.cpp
|
||||
FreeTypeFont3D.cpp
|
||||
FreeTypeLibrary.cpp
|
||||
ReaderWriterFreeType.cpp )
|
||||
SET(TARGET_H
|
||||
FreeTypeFont.h
|
||||
FreeTypeFont3D.h
|
||||
FreeTypeLibrary.h )
|
||||
SET(TARGET_ADDED_LIBRARIES osgText )
|
||||
SET(TARGET_LIBRARIES_VARS FREETYPE_LIBRARY )
|
||||
|
||||
@@ -620,14 +620,12 @@ osgText::Glyph3D * FreeTypeFont::getGlyph3D(unsigned int charcode)
|
||||
return glyph3D.release();
|
||||
}
|
||||
|
||||
osg::Vec2 FreeTypeFont::getKerning(const osgText::FontResolution& fontRes, unsigned int leftcharcode,unsigned int rightcharcode, osgText::KerningType kerningType)
|
||||
osg::Vec2 FreeTypeFont::getKerning(unsigned int leftcharcode,unsigned int rightcharcode, osgText::KerningType kerningType)
|
||||
{
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(FreeTypeLibrary::instance()->getMutex());
|
||||
|
||||
if (!FT_HAS_KERNING(_face) || (kerningType == osgText::KERNING_NONE)) return osg::Vec2(0.0f,0.0f);
|
||||
|
||||
setFontResolution(fontRes);
|
||||
|
||||
FT_Kerning_Mode mode = (kerningType==osgText::KERNING_DEFAULT) ? ft_kerning_default : ft_kerning_unfitted;
|
||||
|
||||
// convert character code to glyph index
|
||||
|
||||
@@ -35,7 +35,7 @@ public:
|
||||
|
||||
virtual osgText::Glyph3D* getGlyph3D(unsigned int charcode);
|
||||
|
||||
virtual osg::Vec2 getKerning(const osgText::FontResolution& fontRes, unsigned int leftcharcode,unsigned int rightcharcode, osgText::KerningType _kerningType);
|
||||
virtual osg::Vec2 getKerning(unsigned int leftcharcode,unsigned int rightcharcode, osgText::KerningType _kerningType);
|
||||
|
||||
virtual bool hasVertical() const;
|
||||
|
||||
|
||||
@@ -49,15 +49,6 @@ FreeTypeLibrary::~FreeTypeLibrary()
|
||||
else fontImplementation->_facade = 0;
|
||||
}
|
||||
|
||||
while(!_font3DImplementationSet.empty())
|
||||
{
|
||||
FreeTypeFont3D* font3DImplementation = *_font3DImplementationSet.begin();
|
||||
_font3DImplementationSet.erase(_font3DImplementationSet.begin());
|
||||
osgText::Font3D* font3D = font3DImplementation->_facade;
|
||||
if (font3D) font3D->setImplementation(0);
|
||||
else font3DImplementation->_facade = 0;
|
||||
}
|
||||
|
||||
FT_Done_FreeType( _ftlibrary);
|
||||
}
|
||||
|
||||
@@ -189,37 +180,6 @@ osgText::Font* FreeTypeLibrary::getFont(std::istream& fontstream, unsigned int i
|
||||
return font;
|
||||
}
|
||||
|
||||
osgText::Font3D* FreeTypeLibrary::getFont3D(const std::string& fontfile, unsigned int index, unsigned int flags)
|
||||
{
|
||||
FT_Face face;
|
||||
if (getFace(fontfile, index, face) == false) return (0);
|
||||
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(getMutex());
|
||||
|
||||
FreeTypeFont3D* font3DImp = new FreeTypeFont3D(fontfile,face,flags);
|
||||
osgText::Font3D* font3D = new osgText::Font3D(font3DImp);
|
||||
|
||||
_font3DImplementationSet.insert(font3DImp);
|
||||
|
||||
return font3D;
|
||||
}
|
||||
osgText::Font3D* FreeTypeLibrary::getFont3D(std::istream& fontstream, unsigned int index, unsigned int flags)
|
||||
{
|
||||
|
||||
FT_Face face = 0;
|
||||
FT_Byte * buffer = getFace(fontstream, index, face);
|
||||
if (face == 0) return (0);
|
||||
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(getMutex());
|
||||
|
||||
FreeTypeFont3D* font3DImp = new FreeTypeFont3D(buffer,face,flags);
|
||||
osgText::Font3D* font3D = new osgText::Font3D(font3DImp);
|
||||
|
||||
_font3DImplementationSet.insert(font3DImp);
|
||||
|
||||
return font3D;
|
||||
}
|
||||
|
||||
void FreeTypeLibrary::verifyCharacterMap(FT_Face face)
|
||||
{
|
||||
//
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
#define FREETYPE_LIBRARY
|
||||
|
||||
#include "FreeTypeFont.h"
|
||||
#include "FreeTypeFont3D.h"
|
||||
|
||||
#include <set>
|
||||
#include <istream>
|
||||
@@ -40,11 +39,7 @@ public:
|
||||
osgText::Font* getFont(const std::string& fontfile,unsigned int index=0, unsigned int flags=0);
|
||||
osgText::Font* getFont(std::istream& fontstream, unsigned int index=0, unsigned int flags=0);
|
||||
|
||||
osgText::Font3D* getFont3D(const std::string& fontfile, unsigned int index=0, unsigned int flags=0);
|
||||
osgText::Font3D* getFont3D(std::istream& fontstream, unsigned int index=0, unsigned int flags=0);
|
||||
|
||||
void removeFontImplmentation(FreeTypeFont* fontImpl) { _fontImplementationSet.erase(fontImpl); }
|
||||
void removeFont3DImplmentation(FreeTypeFont3D* font3DImpl) { _font3DImplementationSet.erase(font3DImpl); }
|
||||
|
||||
protected:
|
||||
|
||||
@@ -61,12 +56,10 @@ protected:
|
||||
FreeTypeLibrary();
|
||||
|
||||
typedef std::set< FreeTypeFont* > FontImplementationSet;
|
||||
typedef std::set< FreeTypeFont3D* > Font3DImplementationSet;
|
||||
|
||||
mutable OpenThreads::Mutex _mutex;
|
||||
FT_Library _ftlibrary;
|
||||
FontImplementationSet _fontImplementationSet;
|
||||
Font3DImplementationSet _font3DImplementationSet;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -39,24 +39,10 @@ class ReaderWriterFreeType : public osgDB::ReaderWriter
|
||||
|
||||
virtual ReadResult readObject(const std::string& file, const osgDB::ReaderWriter::Options* options) const
|
||||
{
|
||||
std::string tmpFile = file;
|
||||
bool needFont3D = false;
|
||||
|
||||
std::string ext = osgDB::getLowerCaseFileExtension(tmpFile);
|
||||
if (ext == "text3d")
|
||||
{
|
||||
needFont3D = true;
|
||||
tmpFile.erase(tmpFile.size()-7, 7);
|
||||
ext = osgDB::getLowerCaseFileExtension(tmpFile);
|
||||
}
|
||||
else if ((options != NULL) && (options->getPluginData("3D")))
|
||||
{
|
||||
needFont3D = true;
|
||||
}
|
||||
|
||||
std::string ext = osgDB::getLowerCaseFileExtension(file);
|
||||
if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED;
|
||||
|
||||
std::string fileName = osgDB::findDataFile( tmpFile, options );
|
||||
std::string fileName = osgDB::findDataFile( file, options );
|
||||
if (fileName.empty()) return ReadResult::FILE_NOT_FOUND;
|
||||
|
||||
FreeTypeLibrary* freeTypeLibrary = FreeTypeLibrary::instance();
|
||||
@@ -66,10 +52,7 @@ class ReaderWriterFreeType : public osgDB::ReaderWriter
|
||||
return ReadResult::ERROR_IN_READING_FILE;
|
||||
}
|
||||
|
||||
if (needFont3D)
|
||||
return freeTypeLibrary->getFont3D(fileName,0,getFlags(options));
|
||||
else
|
||||
return freeTypeLibrary->getFont(fileName,0,getFlags(options));
|
||||
return freeTypeLibrary->getFont(fileName,0,getFlags(options));
|
||||
}
|
||||
|
||||
virtual ReadResult readObject(std::istream& stream, const osgDB::ReaderWriter::Options* options) const
|
||||
|
||||
@@ -118,7 +118,7 @@ TXFFont::hasVertical() const
|
||||
}
|
||||
|
||||
osg::Vec2
|
||||
TXFFont::getKerning(const osgText::FontResolution&, unsigned int, unsigned int, osgText::KerningType)
|
||||
TXFFont::getKerning(unsigned int, unsigned int, osgText::KerningType)
|
||||
{
|
||||
return osg::Vec2(0, 0);
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ public:
|
||||
|
||||
virtual bool hasVertical() const;
|
||||
|
||||
virtual osg::Vec2 getKerning(const osgText::FontResolution& fontRes, unsigned int leftcharcode,unsigned int rightcharcode, osgText::KerningType kerningType);
|
||||
virtual osg::Vec2 getKerning(unsigned int leftcharcode,unsigned int rightcharcode, osgText::KerningType kerningType);
|
||||
|
||||
virtual float getScale() const { return 1.0; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user