Commit d74f95ce2f57bf48a3fc21d0b89422b4aabee287

henry 2001-09-19T04:54:59

Added functions to calc the advance width of a string

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;