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; }
|
||||
|
||||
|
||||
@@ -128,8 +128,7 @@ QFontImplementation::getGlyph(const osgText::FontResolution& fontRes, unsigned i
|
||||
}
|
||||
|
||||
osg::Vec2
|
||||
QFontImplementation::getKerning(const osgText::FontResolution& fontRes, unsigned int leftcharcode,
|
||||
unsigned int rightcharcode, osgText::KerningType kerningType)
|
||||
QFontImplementation::getKerning(unsigned int leftcharcode, unsigned int rightcharcode, osgText::KerningType kerningType)
|
||||
{
|
||||
return osg::Vec2(0, 0);
|
||||
}
|
||||
|
||||
@@ -27,7 +27,6 @@ ADD_LIBRARY(${LIB_NAME}
|
||||
DefaultFont.cpp
|
||||
DefaultFont.h
|
||||
Font.cpp
|
||||
Font3D.cpp
|
||||
String.cpp
|
||||
FadeText.cpp
|
||||
TextBase.cpp
|
||||
|
||||
@@ -74,7 +74,7 @@ osgText::Glyph* DefaultFont::getGlyph(const FontResolution& fontRes, unsigned in
|
||||
}
|
||||
|
||||
|
||||
osg::Vec2 DefaultFont::getKerning(const FontResolution&, unsigned int,unsigned int, KerningType)
|
||||
osg::Vec2 DefaultFont::getKerning(unsigned int,unsigned int, KerningType)
|
||||
{
|
||||
// no kerning on default font.
|
||||
return osg::Vec2(0.0f,0.0f);
|
||||
|
||||
@@ -37,7 +37,7 @@ public:
|
||||
|
||||
virtual osgText::Glyph3D* getGlyph3D(unsigned int charcode) { return 0; }
|
||||
|
||||
virtual osg::Vec2 getKerning(const FontResolution&, unsigned int leftcharcode,unsigned int rightcharcode, KerningType kerningType);
|
||||
virtual osg::Vec2 getKerning(unsigned int leftcharcode,unsigned int rightcharcode, KerningType kerningType);
|
||||
|
||||
virtual bool hasVertical() const;
|
||||
|
||||
|
||||
@@ -422,9 +422,9 @@ void Font::releaseGLObjects(osg::State* state) const
|
||||
// const_cast<Font*>(this)->_sizeGlyphMap.clear();
|
||||
}
|
||||
|
||||
osg::Vec2 Font::getKerning(const FontResolution& fontRes, unsigned int leftcharcode,unsigned int rightcharcode, KerningType kerningType)
|
||||
osg::Vec2 Font::getKerning(unsigned int leftcharcode,unsigned int rightcharcode, KerningType kerningType)
|
||||
{
|
||||
if (_implementation.valid()) return _implementation->getKerning(fontRes, leftcharcode,rightcharcode,kerningType);
|
||||
if (_implementation.valid()) return _implementation->getKerning(leftcharcode,rightcharcode,kerningType);
|
||||
else return osg::Vec2(0.0f,0.0f);
|
||||
}
|
||||
|
||||
@@ -943,3 +943,9 @@ void Glyph::subload() const
|
||||
"\t 0x"<<(unsigned long)data()<<");"<<dec<<std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void Glyph3D::setThreadSafeRefUnref(bool threadSafe)
|
||||
{
|
||||
if (_vertexArray.valid()) _vertexArray->setThreadSafeRefUnref(threadSafe);
|
||||
if (_normalArray.valid()) _normalArray->setThreadSafeRefUnref(threadSafe);
|
||||
}
|
||||
|
||||
@@ -312,9 +312,4 @@ bool Font3D::hasVertical() const
|
||||
else return false;
|
||||
}
|
||||
|
||||
void Glyph3D::setThreadSafeRefUnref(bool threadSafe)
|
||||
{
|
||||
if (_vertexArray.valid()) _vertexArray->setThreadSafeRefUnref(threadSafe);
|
||||
if (_normalArray.valid()) _normalArray->setThreadSafeRefUnref(threadSafe);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,14 +149,14 @@ String::iterator Text::computeLastCharacterOnLine(osg::Vec2& cursor, String::ite
|
||||
{
|
||||
case LEFT_TO_RIGHT:
|
||||
{
|
||||
osg::Vec2 delta(activefont->getKerning(_fontSize, previous_charcode,charcode,_kerningType));
|
||||
osg::Vec2 delta(activefont->getKerning(previous_charcode,charcode,_kerningType));
|
||||
cursor.x() += delta.x() * wr;
|
||||
cursor.y() += delta.y() * hr;
|
||||
break;
|
||||
}
|
||||
case RIGHT_TO_LEFT:
|
||||
{
|
||||
osg::Vec2 delta(activefont->getKerning(_fontSize, charcode,previous_charcode,_kerningType));
|
||||
osg::Vec2 delta(activefont->getKerning(charcode,previous_charcode,_kerningType));
|
||||
cursor.x() -= delta.x() * wr;
|
||||
cursor.y() -= delta.y() * hr;
|
||||
break;
|
||||
@@ -418,14 +418,14 @@ void Text::computeGlyphRepresentation()
|
||||
{
|
||||
case LEFT_TO_RIGHT:
|
||||
{
|
||||
osg::Vec2 delta(activefont->getKerning(_fontSize, previous_charcode,charcode,_kerningType));
|
||||
osg::Vec2 delta(activefont->getKerning(previous_charcode,charcode,_kerningType));
|
||||
cursor.x() += delta.x() * wr;
|
||||
cursor.y() += delta.y() * hr;
|
||||
break;
|
||||
}
|
||||
case RIGHT_TO_LEFT:
|
||||
{
|
||||
osg::Vec2 delta(activefont->getKerning(_fontSize, charcode,previous_charcode,_kerningType));
|
||||
osg::Vec2 delta(activefont->getKerning(charcode,previous_charcode,_kerningType));
|
||||
cursor.x() -= delta.x() * wr;
|
||||
cursor.y() -= delta.y() * hr;
|
||||
break;
|
||||
|
||||
@@ -135,7 +135,7 @@ String::iterator Text3D::computeLastCharacterOnLine(osg::Vec2& cursor, String::i
|
||||
return lastChar;
|
||||
}
|
||||
|
||||
Glyph3D* glyph = _font->getGlyph(charcode);
|
||||
Glyph3D* glyph = _font->getGlyph3D(charcode);
|
||||
if (glyph)
|
||||
{
|
||||
const osg::BoundingBox & bb = glyph->getBoundingBox();
|
||||
@@ -245,7 +245,7 @@ String::iterator Text3D::computeLastCharacterOnLine(osg::Vec2& cursor, String::i
|
||||
// Subtract off glyphs from the cursor position (to correctly center text)
|
||||
if(*prevChar != '-')
|
||||
{
|
||||
Glyph3D* glyph = _font->getGlyph(*prevChar);
|
||||
Glyph3D* glyph = _font->getGlyph3D(*prevChar);
|
||||
if (glyph)
|
||||
{
|
||||
switch(_layout)
|
||||
@@ -316,7 +316,7 @@ void Text3D::computeGlyphRepresentation()
|
||||
{
|
||||
unsigned int charcode = *itr;
|
||||
|
||||
Glyph3D* glyph = _font->getGlyph(charcode);
|
||||
Glyph3D* glyph = _font->getGlyph3D(charcode);
|
||||
if (glyph)
|
||||
{
|
||||
const osg::BoundingBox & bb = glyph->getBoundingBox();
|
||||
|
||||
Reference in New Issue
Block a user