Added functions to calc the advance width of a string
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
diff --git a/include/FTFont.h b/include/FTFont.h
index 433c5cd..cc13bfa 100755
--- a/include/FTFont.h
+++ b/include/FTFont.h
@@ -89,6 +89,10 @@ class FTFont
*/
virtual int Descender() const;
+ float Advance( const wchar_t* string);
+ float Advance( const char* string);
+
+
/**
* Gets the bounding box dimensions for a string.
*
@@ -98,7 +102,7 @@ class FTFont
* @param XXXXXXX
* @param XXXXXXX
*/
- virtual void BBox( const char* string, int& llx, int& lly, int& urx, int& ury ) const;
+// virtual void BBox( const char* string, int& llx, int& lly, int& urx, int& ury ) const;
/**
* Renders a string of characters
diff --git a/include/FTGlyphContainer.h b/include/FTGlyphContainer.h
index 2283a6c..c2d3a93 100755
--- a/include/FTGlyphContainer.h
+++ b/include/FTGlyphContainer.h
@@ -40,6 +40,16 @@ class FTGlyphContainer
bool Add( FTGlyph* glyph);
/**
+ * Returns the kerned advance width for a glyph.
+ *
+ * param index glyph index of the character
+ * param next the next glyph in a string
+ * return advance width
+ *
+ */
+ float Advance( unsigned int index, unsigned int next);
+
+ /**
* renders a character
*/
FT_Vector& render( unsigned int index, unsigned int next, FT_Vector pen);
diff --git a/src/FTFont.cpp b/src/FTFont.cpp
index c1694ac..7c980e7 100755
--- a/src/FTFont.cpp
+++ b/src/FTFont.cpp
@@ -82,12 +82,42 @@ int FTFont::Descender() const
}
-void FTFont::BBox( const char* text, int& llx, int& lly, int& urx, int& ury ) const
+float FTFont::Advance( const wchar_t* string)
{
+ const wchar_t* c = string; // wchar_t IS unsigned?
+ float width = 0;
+
+ while( *c)
+ {
+ 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)
+ {
+ width += glyphList->Advance( *c, *(c + 1));
+ ++c;
+ }
+
+ return width;
+}
+
+
+//void FTFont::BBox( const char* text, int& llx, int& lly, int& urx, int& ury ) const
+//{
//Insert your own code here.
//End of user code.
-}
+//}
void FTFont::render( const char* string )
@@ -110,7 +140,7 @@ void FTFont::render( const char* string )
void FTFont::render( const wchar_t* string )
{
- const unsigned wchar_t* c = (unsigned wchar_t*)string; // This is ugly, what is the c++ way?
+ const wchar_t* c = string; // wchar_t IS unsigned?
FT_Vector kernAdvance;
pen.x = 0; pen.y = 0;
diff --git a/src/FTGlyphContainer.cpp b/src/FTGlyphContainer.cpp
index ff31b14..33ea20e 100755
--- a/src/FTGlyphContainer.cpp
+++ b/src/FTGlyphContainer.cpp
@@ -34,6 +34,18 @@ bool FTGlyphContainer::Add( FTGlyph* tempGlyph)
}
+float FTGlyphContainer::Advance( unsigned int index, unsigned int next)
+{
+ unsigned int left = face->CharIndex( index);
+ unsigned int right = face->CharIndex( next);
+
+ float width = face->KernAdvance( left, right).x;
+ width += glyphs[left]->Advance();
+
+ return width;
+}
+
+
FT_Vector& FTGlyphContainer::render( unsigned int index, unsigned int next, FT_Vector pen)
{
kernAdvance.x = 0; kernAdvance.y = 0;
@@ -41,9 +53,12 @@ FT_Vector& FTGlyphContainer::render( unsigned int index, unsigned int next, FT_V
unsigned int left = face->CharIndex( index);
unsigned int right = face->CharIndex( next);
- kernAdvance = face->KernAdvance( left, right);
+ kernAdvance = face->KernAdvance( left, right);
+
if( !face->Error())
+ {
advance = glyphs[left]->Render( pen);
+ }
kernAdvance.x = advance + kernAdvance.x; // FIXME float to long
// kernAdvance.y = advance.y + kernAdvance.y;