Merged FTGL_2_0_4
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 193 194 195 196 197 198 199 200 201 202 203
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);
}