Hash :
789b1cf3
Author :
Date :
2001-11-04T04:33:30
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
#include "FTFace.h"
#include "FTFont.h"
#include "FTGlyphContainer.h"
#include "FTGL.h"
FTFont::FTFont()
: numFaces(0),
glyphList(0),
numGlyphs(0),
preCache(true),
err(0)
{
pen.x = 0;
pen.y = 0;
}
FTFont::~FTFont()
{
Close();
}
bool FTFont::Open( const char* fontname, bool p)
{
preCache = p;
if( face.Open( fontname))
{
FT_Face* ftFace = face.Face();
numGlyphs = (*ftFace)->num_glyphs;
return true;
}
else
{
err = face.Error();
return false;
}
}
void FTFont::Close()
{
delete glyphList;
}
bool FTFont::FaceSize( const unsigned int size, const unsigned int res )
{
charSize = face.Size( size, res);
if( glyphList)
delete glyphList;
glyphList = new FTGlyphContainer( &face, numGlyphs, preCache);
if( MakeGlyphList())
{
return true;
}
else
{
return false;
}
}
bool FTFont::MakeGlyphList()
{
for( unsigned int c = 0; c < numGlyphs; ++c)
{
if( preCache)
{
glyphList->Add( MakeGlyph( c), c);
}
else
{
glyphList->Add( NULL, c);
}
}
return !err;
}
bool FTFont::CharMap( FT_Encoding encoding)
{
err = face.CharMap( encoding);
return !err;
}
int FTFont::Ascender() const
{
return charSize.Ascender();
}
int FTFont::Descender() const
{
return charSize.Descender();
}
float FTFont::Advance( const wchar_t* string)
{
const wchar_t* c = string; // wchar_t IS unsigned?
float width = 0;
while( *c)
{
if( !glyphList->Glyph( static_cast<unsigned int>(*c)))
{
unsigned int g = face.CharIndex( static_cast<unsigned int>(*c));
glyphList->Add( MakeGlyph( g), g);
}
width += glyphList->Advance( *c, *(c + 1));
++c;
}
return width;
}
float FTFont::Advance( const char* string)
{
const unsigned char* c = (unsigned char*)string; // This is ugly, what is the c++ way?
float width = 0;
while( *c)
{
if( !glyphList->Glyph( static_cast<unsigned int>(*c)))
{
unsigned int g = face.CharIndex( static_cast<unsigned int>(*c));
glyphList->Add( MakeGlyph( g), g);
}
width += glyphList->Advance( *c, *(c + 1));
++c;
}
return width;
}
void FTFont::render( const char* string )
{
const unsigned char* c = (unsigned char*)string; // This is ugly, what is the c++ way?
FT_Vector kernAdvance;
pen.x = 0; pen.y = 0;
while( *c)
{
if( !glyphList->Glyph( static_cast<unsigned int>(*c)))
{
unsigned int g = face.CharIndex( static_cast<unsigned int>(*c));
glyphList->Add( MakeGlyph( g), g);
}
kernAdvance = glyphList->render( *c, *(c + 1), pen);
pen.x += kernAdvance.x;
pen.y += kernAdvance.y;
++c;
}
}
void FTFont::render( const wchar_t* string )
{
const wchar_t* c = string; // wchar_t IS unsigned?
FT_Vector kernAdvance;
pen.x = 0; pen.y = 0;
while( *c)
{
if( !glyphList->Glyph( static_cast<unsigned int>(*c)))
{
unsigned int g = face.CharIndex( static_cast<unsigned int>(*c));
glyphList->Add( MakeGlyph( g), g);
}
kernAdvance = glyphList->render( *c, *(c + 1), pen);
pen.x += kernAdvance.x;
pen.y += kernAdvance.y;
++c;
}
}