From Tree, updates to osgText and freetype plugin to support are kerning paramter.
This commit is contained in:
parent
5bf9be4473
commit
8d4ab4668e
@ -29,6 +29,13 @@ namespace osgText {
|
|||||||
class Font;
|
class Font;
|
||||||
class Text;
|
class Text;
|
||||||
|
|
||||||
|
enum KerningType
|
||||||
|
{
|
||||||
|
KERNING_DEFAULT, //default locked to integer kerning values
|
||||||
|
KERNING_UNFITTED, //use floating point value for kerning
|
||||||
|
KERNING_NONE, //no kerning
|
||||||
|
};
|
||||||
|
|
||||||
/** read a font from specified file.*/
|
/** read a font from specified file.*/
|
||||||
extern OSGTEXT_EXPORT Font* readFontFile(const std::string& filename);
|
extern OSGTEXT_EXPORT Font* readFontFile(const std::string& filename);
|
||||||
|
|
||||||
@ -62,12 +69,12 @@ public:
|
|||||||
unsigned int getWidth();
|
unsigned int getWidth();
|
||||||
unsigned int getHeight();
|
unsigned int getHeight();
|
||||||
|
|
||||||
|
/** Get a kerning (adjustment of spacing of two adjacent character) for specified charcodes, w.r.t the current font size hint.*/
|
||||||
|
virtual osg::Vec2 getKerning(unsigned int leftcharcode,unsigned int rightcharcode, KerningType kerningType);
|
||||||
|
|
||||||
/** Get a Glyph for specified charcode, and the font size nearest to the current font size hint.*/
|
/** Get a Glyph for specified charcode, and the font size nearest to the current font size hint.*/
|
||||||
virtual Glyph* getGlyph(unsigned int charcode);
|
virtual Glyph* getGlyph(unsigned int charcode);
|
||||||
|
|
||||||
/** Get a kerning (adjustment of spacing of two adjacent character) for specified charcodes, w.r.t the current font size hint.*/
|
|
||||||
virtual osg::Vec2 getKerning(unsigned int leftcharcode,unsigned int rightcharcode);
|
|
||||||
|
|
||||||
/** Return true if this font provides vertical alignments and spacing or glyphs.*/
|
/** Return true if this font provides vertical alignments and spacing or glyphs.*/
|
||||||
virtual bool hasVertical() const;
|
virtual bool hasVertical() const;
|
||||||
|
|
||||||
@ -149,7 +156,7 @@ public:
|
|||||||
virtual Glyph* getGlyph(unsigned int charcode) = 0;
|
virtual Glyph* getGlyph(unsigned int charcode) = 0;
|
||||||
|
|
||||||
/** Get a kerning (adjustment of spacing of two adjacent character) for specified charcodes, w.r.t the current font size hint.*/
|
/** Get a kerning (adjustment of spacing of two adjacent character) for specified charcodes, w.r.t the current font size hint.*/
|
||||||
virtual osg::Vec2 getKerning(unsigned int leftcharcode,unsigned int rightcharcode) = 0;
|
virtual osg::Vec2 getKerning(unsigned int leftcharcode,unsigned int rightcharcode, KerningType kerningType) = 0;
|
||||||
|
|
||||||
/** Return true if this font provides vertical alignments and spacing or glyphs.*/
|
/** Return true if this font provides vertical alignments and spacing or glyphs.*/
|
||||||
virtual bool hasVertical() const = 0;
|
virtual bool hasVertical() const = 0;
|
||||||
@ -166,7 +173,6 @@ public:
|
|||||||
Font* _facade;
|
Font* _facade;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class OSGTEXT_EXPORT GlyphTexture : public osg::Texture2D
|
class OSGTEXT_EXPORT GlyphTexture : public osg::Texture2D
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -211,6 +211,9 @@ public:
|
|||||||
|
|
||||||
unsigned int getDrawMode() const { return _drawMode; }
|
unsigned int getDrawMode() const { return _drawMode; }
|
||||||
|
|
||||||
|
void setKerningType(KerningType kerningType) { _kerningType = kerningType; }
|
||||||
|
|
||||||
|
KerningType getKerningType() const { return _kerningType; }
|
||||||
|
|
||||||
/** Draw the text.*/
|
/** Draw the text.*/
|
||||||
virtual void drawImplementation(osg::State& state) const;
|
virtual void drawImplementation(osg::State& state) const;
|
||||||
@ -266,13 +269,12 @@ public:
|
|||||||
typedef std::map<osg::ref_ptr<osg::StateSet>,GlyphQuads> TextureGlyphQuadMap;
|
typedef std::map<osg::ref_ptr<osg::StateSet>,GlyphQuads> TextureGlyphQuadMap;
|
||||||
|
|
||||||
/** Direct Access to GlyphQuads */
|
/** Direct Access to GlyphQuads */
|
||||||
const GlyphQuads* getGlyphQuad(unsigned int index) const
|
const GlyphQuads* getGlyphQuads(osg::StateSet* stateSet) const
|
||||||
{
|
{
|
||||||
if (index>=_textureGlyphQuadMap.size()) return NULL;
|
TextureGlyphQuadMap::iterator itGlyphQuad = _textureGlyphQuadMap.find(stateSet);
|
||||||
|
if (itGlyphQuad == _textureGlyphQuadMap.end()) return NULL;
|
||||||
|
|
||||||
TextureGlyphQuadMap::const_iterator itGlyph = _textureGlyphQuadMap.begin();
|
return &itGlyphQuad->second;
|
||||||
while((index--) && (itGlyph!=_textureGlyphQuadMap.end())) itGlyph++;
|
|
||||||
return &itGlyph->second;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@ -303,6 +305,7 @@ protected:
|
|||||||
Layout _layout;
|
Layout _layout;
|
||||||
osg::Vec4 _color;
|
osg::Vec4 _color;
|
||||||
unsigned int _drawMode;
|
unsigned int _drawMode;
|
||||||
|
KerningType _kerningType;
|
||||||
|
|
||||||
// iternal map used for rendering. Set up by the computeGlyphRepresentation() method.
|
// iternal map used for rendering. Set up by the computeGlyphRepresentation() method.
|
||||||
mutable TextureGlyphQuadMap _textureGlyphQuadMap;
|
mutable TextureGlyphQuadMap _textureGlyphQuadMap;
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "FreeTypeFont.h"
|
#include "FreeTypeFont.h"
|
||||||
//#include FT_GLYPH_H
|
|
||||||
|
|
||||||
#include <osg/Notify>
|
#include <osg/Notify>
|
||||||
#include <osgDB/WriteFile>
|
#include <osgDB/WriteFile>
|
||||||
@ -126,10 +125,11 @@ osgText::Font::Glyph* FreeTypeFont::getGlyph(unsigned int charcode)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
osg::Vec2 FreeTypeFont::getKerning(unsigned int leftcharcode,unsigned int rightcharcode)
|
osg::Vec2 FreeTypeFont::getKerning(unsigned int leftcharcode,unsigned int rightcharcode, osgText::KerningType kerningType)
|
||||||
{
|
{
|
||||||
if (!FT_HAS_KERNING(_face)) return osg::Vec2(0.0f,0.0f);
|
if (!FT_HAS_KERNING(_face) || (kerningType == osgText::KERNING_NONE)) return osg::Vec2(0.0f,0.0f);
|
||||||
|
|
||||||
|
FT_Kerning_Mode mode = (kerningType==osgText::KERNING_DEFAULT) ? ft_kerning_default : ft_kerning_unfitted;
|
||||||
|
|
||||||
// convert character code to glyph index
|
// convert character code to glyph index
|
||||||
FT_UInt left = FT_Get_Char_Index( _face, leftcharcode );
|
FT_UInt left = FT_Get_Char_Index( _face, leftcharcode );
|
||||||
@ -137,10 +137,11 @@ osg::Vec2 FreeTypeFont::getKerning(unsigned int leftcharcode,unsigned int rightc
|
|||||||
|
|
||||||
// get the kerning distances.
|
// get the kerning distances.
|
||||||
FT_Vector kerning;
|
FT_Vector kerning;
|
||||||
|
|
||||||
FT_Error error = FT_Get_Kerning( _face, // handle to face object
|
FT_Error error = FT_Get_Kerning( _face, // handle to face object
|
||||||
left, // left glyph index
|
left, // left glyph index
|
||||||
right, // right glyph index
|
right, // right glyph index
|
||||||
FT_KERNING_UNFITTED, // kerning mode
|
mode, // kerning mode
|
||||||
&kerning ); // target vector
|
&kerning ); // target vector
|
||||||
|
|
||||||
if (error)
|
if (error)
|
||||||
|
@ -34,7 +34,7 @@ public:
|
|||||||
|
|
||||||
virtual osgText::Font::Glyph* getGlyph(unsigned int charcode);
|
virtual osgText::Font::Glyph* getGlyph(unsigned int charcode);
|
||||||
|
|
||||||
virtual osg::Vec2 getKerning(unsigned int leftcharcode,unsigned int rightcharcode);
|
virtual osg::Vec2 getKerning(unsigned int leftcharcode,unsigned int rightcharcode, osgText::KerningType _kerningType);
|
||||||
|
|
||||||
virtual bool hasVertical() const;
|
virtual bool hasVertical() const;
|
||||||
|
|
||||||
|
@ -80,7 +80,7 @@ Font::Glyph* DefaultFont::getGlyph(unsigned int charcode)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
osg::Vec2 DefaultFont::getKerning(unsigned int,unsigned int)
|
osg::Vec2 DefaultFont::getKerning(unsigned int,unsigned int, KerningType)
|
||||||
{
|
{
|
||||||
// no kerning on default font.
|
// no kerning on default font.
|
||||||
return osg::Vec2(0.0f,0.0f);
|
return osg::Vec2(0.0f,0.0f);
|
||||||
|
@ -35,7 +35,7 @@ public:
|
|||||||
|
|
||||||
virtual Font::Glyph* getGlyph(unsigned int charcode);
|
virtual Font::Glyph* getGlyph(unsigned int charcode);
|
||||||
|
|
||||||
virtual osg::Vec2 getKerning(unsigned int leftcharcode,unsigned int rightcharcode);
|
virtual osg::Vec2 getKerning(unsigned int leftcharcode,unsigned int rightcharcode, KerningType kerningType);
|
||||||
|
|
||||||
virtual bool hasVertical() const;
|
virtual bool hasVertical() const;
|
||||||
|
|
||||||
|
@ -196,9 +196,9 @@ Font::Glyph* Font::getGlyph(unsigned int charcode)
|
|||||||
else return 0;
|
else return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
osg::Vec2 Font::getKerning(unsigned int leftcharcode,unsigned int rightcharcode)
|
osg::Vec2 Font::getKerning(unsigned int leftcharcode,unsigned int rightcharcode, KerningType kerningType)
|
||||||
{
|
{
|
||||||
if (_implementation.valid()) return _implementation->getKerning(leftcharcode,rightcharcode);
|
if (_implementation.valid()) return _implementation->getKerning(leftcharcode,rightcharcode,kerningType);
|
||||||
else return osg::Vec2(0.0f,0.0f);
|
else return osg::Vec2(0.0f,0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,7 +35,8 @@ Text::Text():
|
|||||||
_autoRotateToScreen(false),
|
_autoRotateToScreen(false),
|
||||||
_layout(LEFT_TO_RIGHT),
|
_layout(LEFT_TO_RIGHT),
|
||||||
_color(1.0f,1.0f,1.0f,1.0f),
|
_color(1.0f,1.0f,1.0f,1.0f),
|
||||||
_drawMode(TEXT)
|
_drawMode(TEXT),
|
||||||
|
_kerningType(KERNING_DEFAULT)
|
||||||
{
|
{
|
||||||
setUseDisplayList(false);
|
setUseDisplayList(false);
|
||||||
}
|
}
|
||||||
@ -57,7 +58,8 @@ Text::Text(const Text& text,const osg::CopyOp& copyop):
|
|||||||
_autoRotateToScreen(text._autoRotateToScreen),
|
_autoRotateToScreen(text._autoRotateToScreen),
|
||||||
_layout(text._layout),
|
_layout(text._layout),
|
||||||
_color(text._color),
|
_color(text._color),
|
||||||
_drawMode(text._drawMode)
|
_drawMode(text._drawMode),
|
||||||
|
_kerningType(text._kerningType)
|
||||||
{
|
{
|
||||||
computeGlyphRepresentation();
|
computeGlyphRepresentation();
|
||||||
}
|
}
|
||||||
@ -310,14 +312,14 @@ void Text::computeGlyphRepresentation()
|
|||||||
{
|
{
|
||||||
case LEFT_TO_RIGHT:
|
case LEFT_TO_RIGHT:
|
||||||
{
|
{
|
||||||
osg::Vec2 delta(activefont->getKerning(previous_charcode,charcode));
|
osg::Vec2 delta(activefont->getKerning(previous_charcode,charcode,_kerningType));
|
||||||
cursor.x() += delta.x() * wr;
|
cursor.x() += delta.x() * wr;
|
||||||
cursor.y() += delta.y() * hr;
|
cursor.y() += delta.y() * hr;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case RIGHT_TO_LEFT:
|
case RIGHT_TO_LEFT:
|
||||||
{
|
{
|
||||||
osg::Vec2 delta(activefont->getKerning(charcode,previous_charcode));
|
osg::Vec2 delta(activefont->getKerning(charcode,previous_charcode,_kerningType));
|
||||||
cursor.x() -= delta.x() * wr;
|
cursor.x() -= delta.x() * wr;
|
||||||
cursor.y() -= delta.y() * hr;
|
cursor.y() -= delta.y() * hr;
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user