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 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.*/
|
||||
extern OSGTEXT_EXPORT Font* readFontFile(const std::string& filename);
|
||||
|
||||
@ -62,12 +69,12 @@ public:
|
||||
unsigned int getWidth();
|
||||
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.*/
|
||||
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.*/
|
||||
virtual bool hasVertical() const;
|
||||
|
||||
@ -149,7 +156,7 @@ public:
|
||||
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.*/
|
||||
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.*/
|
||||
virtual bool hasVertical() const = 0;
|
||||
@ -166,7 +173,6 @@ public:
|
||||
Font* _facade;
|
||||
};
|
||||
|
||||
|
||||
class OSGTEXT_EXPORT GlyphTexture : public osg::Texture2D
|
||||
{
|
||||
public:
|
||||
|
@ -211,6 +211,9 @@ public:
|
||||
|
||||
unsigned int getDrawMode() const { return _drawMode; }
|
||||
|
||||
void setKerningType(KerningType kerningType) { _kerningType = kerningType; }
|
||||
|
||||
KerningType getKerningType() const { return _kerningType; }
|
||||
|
||||
/** Draw the text.*/
|
||||
virtual void drawImplementation(osg::State& state) const;
|
||||
@ -266,13 +269,12 @@ public:
|
||||
typedef std::map<osg::ref_ptr<osg::StateSet>,GlyphQuads> TextureGlyphQuadMap;
|
||||
|
||||
/** 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();
|
||||
while((index--) && (itGlyph!=_textureGlyphQuadMap.end())) itGlyph++;
|
||||
return &itGlyph->second;
|
||||
return &itGlyphQuad->second;
|
||||
}
|
||||
|
||||
protected:
|
||||
@ -303,6 +305,7 @@ protected:
|
||||
Layout _layout;
|
||||
osg::Vec4 _color;
|
||||
unsigned int _drawMode;
|
||||
KerningType _kerningType;
|
||||
|
||||
// iternal map used for rendering. Set up by the computeGlyphRepresentation() method.
|
||||
mutable TextureGlyphQuadMap _textureGlyphQuadMap;
|
||||
|
@ -12,7 +12,6 @@
|
||||
*/
|
||||
|
||||
#include "FreeTypeFont.h"
|
||||
//#include FT_GLYPH_H
|
||||
|
||||
#include <osg/Notify>
|
||||
#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
|
||||
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.
|
||||
FT_Vector kerning;
|
||||
|
||||
FT_Error error = FT_Get_Kerning( _face, // handle to face object
|
||||
left, // left glyph index
|
||||
right, // right glyph index
|
||||
FT_KERNING_UNFITTED, // kerning mode
|
||||
mode, // kerning mode
|
||||
&kerning ); // target vector
|
||||
|
||||
if (error)
|
||||
|
@ -34,7 +34,7 @@ public:
|
||||
|
||||
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;
|
||||
|
||||
|
@ -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.
|
||||
return osg::Vec2(0.0f,0.0f);
|
||||
|
@ -35,7 +35,7 @@ public:
|
||||
|
||||
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;
|
||||
|
||||
|
@ -196,9 +196,9 @@ Font::Glyph* Font::getGlyph(unsigned int charcode)
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -35,7 +35,8 @@ Text::Text():
|
||||
_autoRotateToScreen(false),
|
||||
_layout(LEFT_TO_RIGHT),
|
||||
_color(1.0f,1.0f,1.0f,1.0f),
|
||||
_drawMode(TEXT)
|
||||
_drawMode(TEXT),
|
||||
_kerningType(KERNING_DEFAULT)
|
||||
{
|
||||
setUseDisplayList(false);
|
||||
}
|
||||
@ -57,7 +58,8 @@ Text::Text(const Text& text,const osg::CopyOp& copyop):
|
||||
_autoRotateToScreen(text._autoRotateToScreen),
|
||||
_layout(text._layout),
|
||||
_color(text._color),
|
||||
_drawMode(text._drawMode)
|
||||
_drawMode(text._drawMode),
|
||||
_kerningType(text._kerningType)
|
||||
{
|
||||
computeGlyphRepresentation();
|
||||
}
|
||||
@ -310,14 +312,14 @@ void Text::computeGlyphRepresentation()
|
||||
{
|
||||
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.y() += delta.y() * hr;
|
||||
break;
|
||||
}
|
||||
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.y() -= delta.y() * hr;
|
||||
break;
|
||||
@ -526,7 +528,7 @@ void Text::computePositions(unsigned int contextID) const
|
||||
|
||||
float pixelSizeVector_w = M(3,2)*P23 + M(3,3)*P33;
|
||||
|
||||
float pixelSize = (_characterHeight*sqrtf(scale_00.length2()+scale_10.length2()))/(pixelSizeVector_w*0.701f);
|
||||
float pixelSize = (_characterHeight*sqrtf(scale_00.length2()+scale_10.length2()))/(pixelSizeVector_w*0.701f);
|
||||
|
||||
if (_characterSizeMode==SCREEN_COORDS)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user