2012-03-22 01:36:20 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
2003-01-22 00:45:36 +08:00
|
|
|
*
|
2012-03-22 01:36:20 +08:00
|
|
|
* 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
|
2003-01-22 00:45:36 +08:00
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
2012-03-22 01:36:20 +08:00
|
|
|
*
|
2003-01-22 00:45:36 +08:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2012-03-22 01:36:20 +08:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2003-01-22 00:45:36 +08:00
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*/
|
2001-11-12 18:04:57 +08:00
|
|
|
|
|
|
|
#ifndef OSGTEXT_FONT
|
2003-03-03 05:05:05 +08:00
|
|
|
#define OSGTEXT_FONT 1
|
2001-11-12 18:04:57 +08:00
|
|
|
|
2004-08-04 16:27:43 +08:00
|
|
|
#include <string>
|
2005-11-07 19:05:16 +08:00
|
|
|
#include <istream>
|
2004-08-04 16:27:43 +08:00
|
|
|
|
2006-08-29 03:37:40 +08:00
|
|
|
#include <osg/TexEnv>
|
2010-09-08 02:18:35 +08:00
|
|
|
#include <osgText/Glyph>
|
|
|
|
#include <osgDB/Options>
|
2001-11-12 18:04:57 +08:00
|
|
|
|
2007-09-01 04:16:02 +08:00
|
|
|
#include <OpenThreads/Mutex>
|
|
|
|
|
2003-03-03 05:05:05 +08:00
|
|
|
namespace osgText {
|
2001-11-12 18:04:57 +08:00
|
|
|
|
2010-09-08 02:18:35 +08:00
|
|
|
// forward declare Font
|
2003-03-03 05:05:05 +08:00
|
|
|
class Font;
|
2017-09-12 18:50:47 +08:00
|
|
|
class TextBase;
|
2007-12-10 23:15:56 +08:00
|
|
|
|
2015-10-22 21:42:19 +08:00
|
|
|
#ifdef OSG_PROVIDE_READFILE
|
2005-09-28 21:45:32 +08:00
|
|
|
/** Read a font from specified file. The filename may contain a path.
|
2012-03-22 01:36:20 +08:00
|
|
|
* It will search for the font file in the following places in this order:
|
2005-09-28 21:45:32 +08:00
|
|
|
* - In the current directory
|
|
|
|
* - All paths defined in OSG_FILE_PATH or OSGFILEPATH environment variable
|
|
|
|
* - Filename with path stripped: In the current directory
|
|
|
|
* - Filename with path stripped: All paths defined in OSG_FILE_PATH or OSGFILEPATH
|
|
|
|
*
|
|
|
|
* Then the file will be searched in OS specific directories in the following order:
|
|
|
|
* - Again in the current directory
|
|
|
|
* - Windows: In C:/winnt/fonts
|
|
|
|
* - Windows: In C:/windows/fonts
|
|
|
|
* - Windows: In the fonts directory of the windows install directory
|
|
|
|
* - Other OS: In /usr/share/fonts/ttf
|
|
|
|
* - Other OS: In /usr/share/fonts/ttf/western
|
|
|
|
* - Other OS: In /usr/share/fonts/ttf/decoratives
|
2012-03-22 01:36:20 +08:00
|
|
|
*
|
2005-09-28 21:45:32 +08:00
|
|
|
* 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.
|
|
|
|
*/
|
2010-09-08 02:18:35 +08:00
|
|
|
extern OSGTEXT_EXPORT Font* readFontFile(const std::string& filename, const osgDB::Options* userOptions = 0);
|
2005-11-07 19:05:16 +08:00
|
|
|
|
|
|
|
/** read a font from specified stream.*/
|
2010-09-08 02:18:35 +08:00
|
|
|
extern OSGTEXT_EXPORT Font* readFontStream(std::istream& stream, const osgDB::Options* userOptions = 0);
|
2015-10-22 21:42:19 +08:00
|
|
|
#endif
|
2005-11-07 19:05:16 +08:00
|
|
|
|
2010-09-08 02:18:35 +08:00
|
|
|
extern OSGTEXT_EXPORT osg::ref_ptr<Font> readRefFontFile(const std::string& filename, const osgDB::Options* userOptions = 0);
|
2007-12-13 01:04:48 +08:00
|
|
|
|
2010-09-08 02:18:35 +08:00
|
|
|
extern OSGTEXT_EXPORT osg::ref_ptr<Font> readRefFontStream(std::istream& stream, const osgDB::Options* userOptions = 0);
|
2007-12-13 01:04:48 +08:00
|
|
|
|
2005-11-02 18:57:42 +08:00
|
|
|
extern OSGTEXT_EXPORT std::string findFontFile(const std::string& str);
|
Added support for shallow and deep copy of nodes, drawables and state, via a
copy constructor which takes an optional Cloner object, and the old
osg::Object::clone() has changed so that it now requires a Cloner as paramter.
This is passed on to the copy constructor to help control the shallow vs
deep copying. The old functionality of clone() which was clone of type has
been renamed to cloneType().
Updated all of the OSG to work with these new conventions, implemention all
the required copy constructors etc. A couple of areas will do shallow
copies by design, a couple of other still need to be updated to do either
shallow or deep.
Neither of the shallow or deep copy operations have been tested yet, only
the old functionality of the OSG has been checked so far, such running the
viewer on various demo datasets.
Also fixed a problem in osg::Optimize::RemoveRendundentNodesVisitor which
was not checking that Group didn't have have any attached StateSet's, Callbacks
or UserData. These checks have now been added, which fixes a bug which was
revealled by the new osgscribe demo, this related to removal of group acting
as state decorator.
method
2002-01-29 05:17:01 +08:00
|
|
|
|
2003-03-03 05:05:05 +08:00
|
|
|
/** Pure virtual base class for fonts.
|
|
|
|
* Concrete implementation are the DefaultFont found in src/osgText/DefaultFont.cpp
|
|
|
|
* and FreeTypeFont found in src/osgPlugins/freetype/FreeTypeFont.cpp*/
|
2001-11-12 18:04:57 +08:00
|
|
|
class OSGTEXT_EXPORT Font : public osg::Object
|
|
|
|
{
|
2003-03-03 05:05:05 +08:00
|
|
|
// declare the interface to a font.
|
|
|
|
public:
|
2001-11-12 18:04:57 +08:00
|
|
|
|
2003-03-03 05:05:05 +08:00
|
|
|
// forward declare nested classes.
|
2003-03-07 01:11:24 +08:00
|
|
|
class FontImplementation;
|
2001-11-12 18:04:57 +08:00
|
|
|
|
2005-05-16 04:32:10 +08:00
|
|
|
public:
|
2003-03-07 01:11:24 +08:00
|
|
|
Font(FontImplementation* implementation=0);
|
2001-11-12 18:04:57 +08:00
|
|
|
|
2003-03-03 05:05:05 +08:00
|
|
|
virtual osg::Object* cloneType() const { return 0; } // cloneType() not appropriate
|
|
|
|
virtual osg::Object* clone(const osg::CopyOp&) const { return 0; } // clone() not appropriate
|
|
|
|
virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const Font*>(obj)!=NULL; }
|
|
|
|
virtual const char* className() const { return "Font"; }
|
|
|
|
virtual const char* libraryName() const { return "osgText"; }
|
2001-11-12 18:04:57 +08:00
|
|
|
|
2003-03-07 01:11:24 +08:00
|
|
|
virtual std::string getFileName() const;
|
2001-11-12 18:04:57 +08:00
|
|
|
|
2010-09-03 16:26:46 +08:00
|
|
|
static osg::ref_ptr<Font>& getDefaultFont();
|
|
|
|
|
2017-09-12 18:50:47 +08:00
|
|
|
typedef std::vector< osg::ref_ptr<osg::StateSet> > StateSets;
|
|
|
|
StateSets& getCachedStateSets() { return _statesets; }
|
|
|
|
const StateSets& getCachedStateSets() const { return _statesets; }
|
2006-07-04 21:56:29 +08:00
|
|
|
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2016-02-15 21:30:39 +08:00
|
|
|
/** Get a kerning (adjustment of spacing of two adjacent character) for specified charcodes and a font resolution.*/
|
|
|
|
virtual osg::Vec2 getKerning(const FontResolution& fontRes, unsigned int leftcharcode, unsigned int rightcharcode, KerningType kerningType);
|
2003-06-27 00:21:49 +08:00
|
|
|
|
2003-03-07 01:11:24 +08:00
|
|
|
/** Get a Glyph for specified charcode, and the font size nearest to the current font size hint.*/
|
2007-12-24 02:15:54 +08:00
|
|
|
virtual Glyph* getGlyph(const FontResolution& fontSize, unsigned int charcode);
|
2010-09-03 16:26:46 +08:00
|
|
|
|
2010-09-03 17:08:19 +08:00
|
|
|
|
2016-02-15 21:30:39 +08:00
|
|
|
/** Get a Glyph3D for specified charcode and a font size.*/
|
|
|
|
virtual Glyph3D* getGlyph3D(const FontResolution& fontSize, unsigned int charcode);
|
2010-09-03 16:26:46 +08:00
|
|
|
|
2003-03-07 01:11:24 +08:00
|
|
|
/** Return true if this font provides vertical alignments and spacing or glyphs.*/
|
|
|
|
virtual bool hasVertical() const;
|
|
|
|
|
2011-10-03 18:36:18 +08:00
|
|
|
/** Get the ascender and descender sizes of the font where supported by the FontImplementation,
|
|
|
|
* return true on success, return false when not supported.*/
|
|
|
|
virtual bool getVerticalSize(float& ascender, float& descender) const { return _implementation ? _implementation->getVerticalSize(ascender, descender) : false; }
|
|
|
|
|
2003-03-07 01:11:24 +08:00
|
|
|
/** Set the size of texture to create to store the glyph images when rendering.
|
|
|
|
* Note, this doesn't affect already created Texture Glhph's.*/
|
|
|
|
void setTextureSizeHint(unsigned int width,unsigned int height);
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2003-03-10 17:15:59 +08:00
|
|
|
unsigned int getTextureWidthHint() const;
|
|
|
|
unsigned int getTextureHeightHint() const;
|
2003-03-07 01:11:24 +08:00
|
|
|
|
|
|
|
/** Set the minification texture filter to use when creating the texture to store the glyph images when rendering.
|
|
|
|
* Note, this doesn't affect already created Texture Glhph's.*/
|
|
|
|
void setMinFilterHint(osg::Texture::FilterMode mode);
|
2003-03-10 17:15:59 +08:00
|
|
|
osg::Texture::FilterMode getMinFilterHint() const;
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2003-03-07 01:11:24 +08:00
|
|
|
/** Set the magnification texture filter to use when creating the texture to store the glyph images when rendering.
|
|
|
|
* Note, this doesn't affect already created Texture Glhph's.*/
|
|
|
|
void setMagFilterHint(osg::Texture::FilterMode mode);
|
2003-03-10 17:15:59 +08:00
|
|
|
osg::Texture::FilterMode getMagFilterHint() const;
|
2001-11-12 18:04:57 +08:00
|
|
|
|
2017-09-08 23:59:43 +08:00
|
|
|
void setMaxAnisotropy(float anis) { _maxAnisotropy = anis; }
|
|
|
|
float getMaxAnisotropy() const { return _maxAnisotropy; }
|
|
|
|
|
2010-09-03 16:26:46 +08:00
|
|
|
unsigned int getFontDepth() const { return _depth; }
|
|
|
|
|
|
|
|
void setNumberCurveSamples(unsigned int numSamples) { _numCurveSamples = numSamples; }
|
|
|
|
unsigned int getNumberCurveSamples() const { return _numCurveSamples; }
|
|
|
|
|
|
|
|
|
2003-03-04 20:34:42 +08:00
|
|
|
// make Text a friend to allow it add and remove its entry in the Font's _textList.
|
2003-03-07 01:11:24 +08:00
|
|
|
friend class FontImplementation;
|
|
|
|
|
|
|
|
void setImplementation(FontImplementation* implementation);
|
|
|
|
|
2003-03-10 17:15:59 +08:00
|
|
|
FontImplementation* getImplementation();
|
|
|
|
const FontImplementation* getImplementation() const;
|
2003-03-07 01:11:24 +08:00
|
|
|
|
2007-01-09 04:40:29 +08:00
|
|
|
/** Set whether to use a mutex to ensure ref() and unref() are thread safe.*/
|
|
|
|
virtual void setThreadSafeRefUnref(bool threadSafe);
|
|
|
|
|
|
|
|
/** Resize any per context GLObject buffers to specified size. */
|
|
|
|
virtual void resizeGLObjectBuffers(unsigned int maxSize);
|
|
|
|
|
2005-05-07 17:17:55 +08:00
|
|
|
/** If State is non-zero, this function releases OpenGL objects for
|
|
|
|
* the specified graphics context. Otherwise, releases OpenGL objexts
|
|
|
|
* for all graphics contexts. */
|
2005-05-08 04:47:09 +08:00
|
|
|
virtual void releaseGLObjects(osg::State* state=0) const;
|
Added support for shallow and deep copy of nodes, drawables and state, via a
copy constructor which takes an optional Cloner object, and the old
osg::Object::clone() has changed so that it now requires a Cloner as paramter.
This is passed on to the copy constructor to help control the shallow vs
deep copying. The old functionality of clone() which was clone of type has
been renamed to cloneType().
Updated all of the OSG to work with these new conventions, implemention all
the required copy constructors etc. A couple of areas will do shallow
copies by design, a couple of other still need to be updated to do either
shallow or deep.
Neither of the shallow or deep copy operations have been tested yet, only
the old functionality of the OSG has been checked so far, such running the
viewer on various demo datasets.
Also fixed a problem in osg::Optimize::RemoveRendundentNodesVisitor which
was not checking that Group didn't have have any attached StateSet's, Callbacks
or UserData. These checks have now been added, which fixes a bug which was
revealled by the new osgscribe demo, this related to removal of group acting
as state decorator.
method
2002-01-29 05:17:01 +08:00
|
|
|
|
2007-09-01 04:16:02 +08:00
|
|
|
typedef OpenThreads::Mutex FontMutex;
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2011-05-14 03:08:04 +08:00
|
|
|
typedef std::vector< osg::ref_ptr<GlyphTexture> > GlyphTextureList;
|
|
|
|
GlyphTextureList& getGlyphTextureList() { return _glyphTextureList; }
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2017-10-23 21:50:35 +08:00
|
|
|
void assignGlyphToGlyphTexture(Glyph* glyph, ShaderTechnique shaderTechnique);
|
|
|
|
|
2003-03-03 05:05:05 +08:00
|
|
|
protected:
|
2001-11-12 18:04:57 +08:00
|
|
|
|
2003-03-03 05:05:05 +08:00
|
|
|
virtual ~Font();
|
2010-09-03 16:26:46 +08:00
|
|
|
|
2007-12-24 02:15:54 +08:00
|
|
|
void addGlyph(const FontResolution& fontRes, unsigned int charcode, Glyph* glyph);
|
2010-09-03 16:26:46 +08:00
|
|
|
|
2003-03-03 05:05:05 +08:00
|
|
|
typedef std::map< unsigned int, osg::ref_ptr<Glyph> > GlyphMap;
|
2010-09-03 16:26:46 +08:00
|
|
|
typedef std::map< unsigned int, osg::ref_ptr<Glyph3D> > Glyph3DMap;
|
|
|
|
|
|
|
|
typedef std::map< FontResolution, GlyphMap > FontSizeGlyphMap;
|
2016-02-15 21:30:39 +08:00
|
|
|
typedef std::map< FontResolution, Glyph3DMap > FontSizeGlyph3DMap;
|
2010-09-03 16:26:46 +08:00
|
|
|
|
2008-02-25 20:54:54 +08:00
|
|
|
mutable OpenThreads::Mutex _glyphMapMutex;
|
2010-09-03 16:26:46 +08:00
|
|
|
|
2017-09-12 18:50:47 +08:00
|
|
|
StateSets _statesets;
|
2007-12-23 21:18:40 +08:00
|
|
|
FontSizeGlyphMap _sizeGlyphMap;
|
2003-03-07 01:11:24 +08:00
|
|
|
GlyphTextureList _glyphTextureList;
|
2010-09-03 16:26:46 +08:00
|
|
|
|
|
|
|
|
2016-02-15 21:30:39 +08:00
|
|
|
FontSizeGlyph3DMap _sizeGlyph3DMap;
|
2010-09-03 16:26:46 +08:00
|
|
|
|
2003-03-03 05:05:05 +08:00
|
|
|
// current active size of font
|
2008-02-25 20:54:54 +08:00
|
|
|
FontResolution _fontSize;
|
2017-09-30 03:21:13 +08:00
|
|
|
|
2003-03-07 01:11:24 +08:00
|
|
|
unsigned int _textureWidthHint;
|
2012-03-22 01:36:20 +08:00
|
|
|
unsigned int _textureHeightHint;
|
2003-03-07 01:11:24 +08:00
|
|
|
osg::Texture::FilterMode _minFilterHint;
|
|
|
|
osg::Texture::FilterMode _magFilterHint;
|
2017-09-08 23:59:43 +08:00
|
|
|
float _maxAnisotropy;
|
2010-09-03 16:26:46 +08:00
|
|
|
|
|
|
|
unsigned int _depth;
|
|
|
|
unsigned int _numCurveSamples;
|
|
|
|
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2003-03-07 01:11:24 +08:00
|
|
|
osg::ref_ptr<FontImplementation> _implementation;
|
2001-11-12 18:04:57 +08:00
|
|
|
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2003-03-03 05:05:05 +08:00
|
|
|
// declare the nested classes.
|
|
|
|
public:
|
Added support for shallow and deep copy of nodes, drawables and state, via a
copy constructor which takes an optional Cloner object, and the old
osg::Object::clone() has changed so that it now requires a Cloner as paramter.
This is passed on to the copy constructor to help control the shallow vs
deep copying. The old functionality of clone() which was clone of type has
been renamed to cloneType().
Updated all of the OSG to work with these new conventions, implemention all
the required copy constructors etc. A couple of areas will do shallow
copies by design, a couple of other still need to be updated to do either
shallow or deep.
Neither of the shallow or deep copy operations have been tested yet, only
the old functionality of the OSG has been checked so far, such running the
viewer on various demo datasets.
Also fixed a problem in osg::Optimize::RemoveRendundentNodesVisitor which
was not checking that Group didn't have have any attached StateSet's, Callbacks
or UserData. These checks have now been added, which fixes a bug which was
revealled by the new osgscribe demo, this related to removal of group acting
as state decorator.
method
2002-01-29 05:17:01 +08:00
|
|
|
|
2003-03-08 17:51:41 +08:00
|
|
|
class FontImplementation : public osg::Referenced
|
2003-03-07 01:11:24 +08:00
|
|
|
{
|
|
|
|
public:
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2007-08-22 20:14:15 +08:00
|
|
|
FontImplementation():
|
2007-12-17 01:01:40 +08:00
|
|
|
osg::Referenced(true),
|
|
|
|
_facade(0) {}
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2003-03-07 01:11:24 +08:00
|
|
|
virtual std::string getFileName() const = 0;
|
|
|
|
|
2011-05-14 03:08:04 +08:00
|
|
|
virtual bool supportsMultipleFontResolutions() const = 0;
|
|
|
|
|
2003-03-07 01:11:24 +08:00
|
|
|
/** Get a Glyph for specified charcode, and the font size nearest to the current font size hint.*/
|
2007-12-24 02:15:54 +08:00
|
|
|
virtual Glyph* getGlyph(const FontResolution& fontRes, unsigned int charcode) = 0;
|
2003-03-07 01:11:24 +08:00
|
|
|
|
2010-09-03 16:26:46 +08:00
|
|
|
/** Get a Glyph3D for specified charcode.*/
|
2016-02-15 21:30:39 +08:00
|
|
|
virtual Glyph3D* getGlyph3D(const FontResolution& fontRes, unsigned int charcode) = 0;
|
2010-09-03 16:26:46 +08:00
|
|
|
|
2003-03-07 01:11:24 +08:00
|
|
|
/** Get a kerning (adjustment of spacing of two adjacent character) for specified charcodes, w.r.t the current font size hint.*/
|
2016-02-15 21:30:39 +08:00
|
|
|
virtual osg::Vec2 getKerning(const FontResolution& fontRes, unsigned int leftcharcode, unsigned int rightcharcode, KerningType kerningType) = 0;
|
2003-03-07 01:11:24 +08:00
|
|
|
|
|
|
|
/** Return true if this font provides vertical alignments and spacing or glyphs.*/
|
|
|
|
virtual bool hasVertical() const = 0;
|
2010-09-03 16:26:46 +08:00
|
|
|
|
2007-12-24 02:15:54 +08:00
|
|
|
void addGlyph(const FontResolution& fontRes, unsigned int charcode, Glyph* glyph)
|
2003-03-07 01:11:24 +08:00
|
|
|
{
|
2007-12-24 02:15:54 +08:00
|
|
|
_facade->addGlyph(fontRes, charcode, glyph);
|
2003-03-07 01:11:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Font* _facade;
|
2011-10-03 18:36:18 +08:00
|
|
|
|
2013-06-28 20:00:43 +08:00
|
|
|
virtual bool getVerticalSize(float & /*ascender*/, float & /*descender*/) const { return false; }
|
2003-03-07 01:11:24 +08:00
|
|
|
};
|
|
|
|
|
2001-11-12 18:04:57 +08:00
|
|
|
};
|
Added support for shallow and deep copy of nodes, drawables and state, via a
copy constructor which takes an optional Cloner object, and the old
osg::Object::clone() has changed so that it now requires a Cloner as paramter.
This is passed on to the copy constructor to help control the shallow vs
deep copying. The old functionality of clone() which was clone of type has
been renamed to cloneType().
Updated all of the OSG to work with these new conventions, implemention all
the required copy constructors etc. A couple of areas will do shallow
copies by design, a couple of other still need to be updated to do either
shallow or deep.
Neither of the shallow or deep copy operations have been tested yet, only
the old functionality of the OSG has been checked so far, such running the
viewer on various demo datasets.
Also fixed a problem in osg::Optimize::RemoveRendundentNodesVisitor which
was not checking that Group didn't have have any attached StateSet's, Callbacks
or UserData. These checks have now been added, which fixes a bug which was
revealled by the new osgscribe demo, this related to removal of group acting
as state decorator.
method
2002-01-29 05:17:01 +08:00
|
|
|
|
2002-02-03 20:33:41 +08:00
|
|
|
}
|
2001-11-12 18:04:57 +08:00
|
|
|
|
2003-03-03 05:05:05 +08:00
|
|
|
#endif
|