Commit e674078e07f2c8bfd4d7e15334e0f4537dfca8b5

henry 2003-07-21T09:46:25

Merged FTGL_2_0_4

diff --git a/include/FTFont.h b/include/FTFont.h
index f7edcb6..f48c949 100755
--- a/include/FTFont.h
+++ b/include/FTFont.h
@@ -90,7 +90,7 @@ class FTGL_EXPORT FTFont
          * @param res       the resolution of the target device.
          * @return          <code>true</code> if size was set correctly
          */
-        bool FaceSize( const unsigned int size, const unsigned int res = 72);
+        virtual bool FaceSize( const unsigned int size, const unsigned int res = 72);
         
         /**
          * Get the current face size in points.
diff --git a/include/FTGLTextureFont.h b/include/FTGLTextureFont.h
index 7196884..ff42e3f 100755
--- a/include/FTGLTextureFont.h
+++ b/include/FTGLTextureFont.h
@@ -35,17 +35,16 @@ class  FTGL_EXPORT FTGLTextureFont : public FTFont
          * Destructor
          */
         virtual ~FTGLTextureFont();
-        
-        /**
-         * Get the total width of the texture that holds this font
-         */
-        GLsizei TextureWidth() const { return textureWidth;}
-        
+
         /**
-         * Get the total height of the texture that holds this font
+            * Set the char size for the current face.
+         *
+         * @param size      the face size in points (1/72 inch)
+         * @param res       the resolution of the target device.
+         * @return          <code>true</code> if size was set correctly
          */
-        GLsizei TextureHeight() const { return textureHeight;}
-        
+        virtual bool FaceSize( const unsigned int size, const unsigned int res = 72);
+
         /**
          * Renders a string of characters
          * 
@@ -116,12 +115,6 @@ class  FTGL_EXPORT FTGLTextureFont : public FTFont
         unsigned int numTextures;
 
         /**
-         * The memory where the textures are built before being transferred 
-         * to OpenGL
-         */
-        unsigned char* textMem;
-        
-        /**
          * The max height for glyphs in the current font
          */
         int glyphHeight;
diff --git a/src/FTContour.cpp b/src/FTContour.cpp
index d24a0cd..edb882a 100644
--- a/src/FTContour.cpp
+++ b/src/FTContour.cpp
@@ -9,7 +9,7 @@ FTContour::FTContour( FT_Vector* contour, char* pointTags, unsigned int numberOf
     {
         char pointTag = pointTags[pointIndex];
         
-        if( pointTag == FT_Curve_Tag_On)
+        if( pointTag == FT_Curve_Tag_On || numberOfPoints < 2)
         {
             AddPoint( contour[pointIndex].x, contour[pointIndex].y);
             continue;
diff --git a/src/FTFace.cpp b/src/FTFace.cpp
index 06dcd53..42f7d58 100755
--- a/src/FTFace.cpp
+++ b/src/FTFace.cpp
@@ -149,17 +149,19 @@ FTPoint FTFace::KernAdvance( unsigned int index1, unsigned int index2)
 
 FT_Glyph* FTFace::Glyph( unsigned int index, FT_Int load_flags)
 {
-    err = FT_Load_Glyph( *ftFace, index, load_flags);   
-    err = FT_Get_Glyph( (*ftFace)->glyph, &ftGlyph);
-        
-    if( !err)
+    err = FT_Load_Glyph( *ftFace, index, load_flags);
+    if( err)
     {
-        return &ftGlyph;
+        return NULL;
     }
-    else
+    
+    err = FT_Get_Glyph( (*ftFace)->glyph, &ftGlyph);
+    if( err)
     {
         return NULL;
     }
+
+    return &ftGlyph;
 }
 
 
diff --git a/src/FTGLTextureFont.cpp b/src/FTGLTextureFont.cpp
index 902e2e2..ec72a20 100755
--- a/src/FTGLTextureFont.cpp
+++ b/src/FTGLTextureFont.cpp
@@ -1,7 +1,7 @@
-#include    <string>
+#include <string> // For memset
 
-#include    "FTGLTextureFont.h"
-#include    "FTTextureGlyph.h"
+#include "FTGLTextureFont.h"
+#include "FTTextureGlyph.h"
 
 
 inline GLuint NextPowerOf2( GLuint in)
@@ -24,7 +24,6 @@ FTGLTextureFont::FTGLTextureFont( const char* fontname)
     textureWidth(0),
     textureHeight(0),
     numTextures(0),
-    textMem(0),
     glyphHeight(0),
     glyphWidth(0),
     padding(3),
@@ -41,7 +40,6 @@ FTGLTextureFont::FTGLTextureFont( const unsigned char *pBufferBytes, size_t buff
     textureWidth(0),
     textureHeight(0),
     numTextures(0),
-    textMem(0),
     glyphHeight(0),
     glyphWidth(0),
     padding(3),
@@ -125,9 +123,9 @@ GLuint FTGLTextureFont::CreateTexture()
 {   
     CalculateTextureSize();
     
-    int totalMem = textureWidth * textureHeight;
-    textMem = new unsigned char[totalMem];
-    memset( textMem, 0, totalMem);
+    int totalMemory = textureWidth * textureHeight;
+    unsigned char* textureMemory = new unsigned char[totalMemory];
+    memset( textureMemory, 0, totalMemory);
 
     GLuint textID;
     glGenTextures( 1, (GLuint*)&textID);
@@ -138,14 +136,27 @@ GLuint FTGLTextureFont::CreateTexture()
     glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
     glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
 
-    glTexImage2D( GL_TEXTURE_2D, 0, GL_ALPHA, textureWidth, textureHeight, 0, GL_ALPHA, GL_UNSIGNED_BYTE, textMem);
+    glTexImage2D( GL_TEXTURE_2D, 0, GL_ALPHA, textureWidth, textureHeight, 0, GL_ALPHA, GL_UNSIGNED_BYTE, textureMemory);
 
-    delete [] textMem;
+    delete [] textureMemory;
 
     return textID;
 }
 
 
+bool FTGLTextureFont::FaceSize( const unsigned int size, const unsigned int res)
+{
+    if( numTextures)
+    {
+        glDeleteTextures( numTextures, (const GLuint*)glTextureID);
+        numTextures = 0;
+        remGlyphs = numGlyphs = face.GlyphCount();
+    }
+
+    return FTFont::FaceSize( size, res);
+}
+
+
 void FTGLTextureFont::Render( const char* string)
 {   
     glPushAttrib( GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT);
diff --git a/test/FTContour-Test.cpp b/test/FTContour-Test.cpp
index 3df4f96..e268fe8 100755
--- a/test/FTContour-Test.cpp
+++ b/test/FTContour-Test.cpp
@@ -9,6 +9,12 @@
 // FT_Curve_Tag_Conic        0
 // FT_Curve_Tag_Cubic        2
 
+static FT_Vector shortLine[2] =
+{
+    { 1, 1},
+    { 2, 2},
+};
+
 static FT_Vector straightLinePoints[3] = 
 {
     { 0,  0},
@@ -152,6 +158,12 @@ class FTContourTest : public CppUnit::TestCase
         {
             FTContour contour( brokenPoints, simpleConicTags, 3);
             CPPUNIT_ASSERT( contour.PointCount() == 1);
+
+            FTContour shortContour( shortLine, simpleConicTags, 2);
+            CPPUNIT_ASSERT_DOUBLES_EQUAL( 6, shortContour.PointCount(), 0.0);
+
+            FTContour reallyShortContour( shortLine, simpleConicTags, 1);
+            CPPUNIT_ASSERT_DOUBLES_EQUAL( 1, reallyShortContour.PointCount(), 0.0);
         }