Removed Open functions. C_stors now open face
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 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250
diff --git a/include/FTFace.h b/include/FTFace.h
index 9600b75..648fad0 100755
--- a/include/FTFace.h
+++ b/include/FTFace.h
@@ -22,25 +22,13 @@ class FTGL_EXPORT FTFace
{
public:
/**
- * Default Constructor
- */
- FTFace();
-
- /**
- * Destructor
- *
- * Disposes of the current Freetype Face.
- */
- virtual ~FTFace();
-
- /**
* Opens and reads a face file.
*
* @param filename font file name.
* @return <code>true</code> if file has opened
* successfully.
*/
- bool Open( const char* filename);
+ FTFace( const char* filename);
/**
* Read face data from an in-memory buffer.
@@ -50,13 +38,21 @@ class FTGL_EXPORT FTFace
* @return <code>true</code> if file has opened
* successfully.
*/
- bool Open( const unsigned char *pBufferBytes, size_t bufferSizeInBytes );
+ FTFace( const unsigned char *pBufferBytes, size_t bufferSizeInBytes );
+
+ /**
+ * Destructor
+ *
+ * Disposes of the current Freetype Face.
+ */
+ virtual ~FTFace();
/**
* Attach auxilliary file to font (e.g., font metrics).
*
* @param filename auxilliary font file name.
- *
+ * @return <code>true</code> if file has opened
+ * successfully.
*/
bool Attach( const char* filename);
@@ -109,10 +105,8 @@ class FTGL_EXPORT FTFace
FT_Glyph* Glyph( unsigned int index, FT_Int load_flags);
/**
- * Gets the current Freetype face.
+ * Gets the number of glyphs in the current face.
*/
-// FT_Face* Face() const { return ftFace;}
-
unsigned int GlyphCount() const { return numGlyphs;}
/**
diff --git a/src/FTFace.cpp b/src/FTFace.cpp
index 2cda0e9..8010495 100755
--- a/src/FTFace.cpp
+++ b/src/FTFace.cpp
@@ -3,68 +3,61 @@
#include "FTCharmap.h"
-FTFace::FTFace()
+FTFace::FTFace( const char* filename)
: charMap(0),
- ftFace(0),
numCharMaps(0),
numGlyphs(0),
err(0)
-{}
-
-
-FTFace::~FTFace()
-{
- delete charMap;
- Close();
-}
-
-
-bool FTFace::Open( const char* filename)
{
const FT_Long DEFAULT_FACE_INDEX = 0;
ftFace = new FT_Face;
-
- // FIXME check library for errors
+
err = FT_New_Face( *FTLibrary::Instance().GetLibrary(), filename, DEFAULT_FACE_INDEX, ftFace);
if( err)
{
delete ftFace;
ftFace = 0;
- return false;
}
else
{
charMap = new FTCharmap( *ftFace);
numGlyphs = (*ftFace)->num_glyphs;
- return true;
}
}
-bool FTFace::Open( const unsigned char *pBufferBytes, size_t bufferSizeInBytes )
+FTFace::FTFace( const unsigned char *pBufferBytes, size_t bufferSizeInBytes )
+: charMap(0),
+ numCharMaps(0),
+ numGlyphs(0),
+ err(0)
{
const FT_Long DEFAULT_FACE_INDEX = 0;
ftFace = new FT_Face;
- // FIXME check library for errors
err = FT_New_Memory_Face( *FTLibrary::Instance().GetLibrary(), (FT_Byte *)pBufferBytes, bufferSizeInBytes, DEFAULT_FACE_INDEX, ftFace);
if( err)
{
delete ftFace;
ftFace = 0;
- return false;
}
else
{
charMap = new FTCharmap( *ftFace);
numGlyphs = (*ftFace)->num_glyphs;
- return true;
}
}
+FTFace::~FTFace()
+{
+ delete charMap;
+ Close();
+}
+
+
bool FTFace::Attach( const char* filename)
{
err = FT_Attach_File( *ftFace, filename);
diff --git a/test/FTFace-Test.cpp b/test/FTFace-Test.cpp
index c3fe6d9..583ae9f 100755
--- a/test/FTFace-Test.cpp
+++ b/test/FTFace-Test.cpp
@@ -27,29 +27,26 @@ class FTFaceTest : public CppUnit::TestCase
void testOpenFace()
{
- CPPUNIT_ASSERT( !testFace->Open( BAD_FONT_FILE));
- CPPUNIT_ASSERT( testFace->Error() == 1);
+ FTFace face1( BAD_FONT_FILE);
+ CPPUNIT_ASSERT( face1.Error() == 1);
- CPPUNIT_ASSERT( testFace->Open( GOOD_FONT_FILE));
- CPPUNIT_ASSERT( testFace->Error() == 0);
+ FTFace face2( GOOD_FONT_FILE);
+ CPPUNIT_ASSERT( face2.Error() == 0);
}
void testOpenFaceFromMemory()
{
- CPPUNIT_ASSERT( !testFace->Open( (unsigned char*)100, 0));
- CPPUNIT_ASSERT( testFace->Error() == 85);
+ FTFace face1( (unsigned char*)100, 0);
+ CPPUNIT_ASSERT( face1.Error() == 85);
- CPPUNIT_ASSERT( testFace->Open( arial_ttf.dataBytes, arial_ttf.numBytes));
- CPPUNIT_ASSERT( testFace->Error() == 0);
+ FTFace face2( arial_ttf.dataBytes, arial_ttf.numBytes);
+ CPPUNIT_ASSERT( face2.Error() == 0);
}
void testAttachFile()
{
- CPPUNIT_ASSERT( testFace->Open( GOOD_FONT_FILE));
- CPPUNIT_ASSERT( testFace->Error() == 0);
-
CPPUNIT_ASSERT( !testFace->Attach( GOOD_FONT_FILE));
CPPUNIT_ASSERT( testFace->Error() == 7);
}
@@ -57,17 +54,12 @@ class FTFaceTest : public CppUnit::TestCase
void testGlyphCount()
{
- CPPUNIT_ASSERT( testFace->Open( GOOD_FONT_FILE));
- CPPUNIT_ASSERT( testFace->Error() == 0);
-
CPPUNIT_ASSERT(testFace->GlyphCount() == 14099);
}
void testSetFontSize()
{
- testFace->Open( GOOD_FONT_FILE);
-
FTSize size = testFace->Size( GOOD_SIZE, RESOLUTION);
CPPUNIT_ASSERT( testFace->Error() == 0);
}
@@ -75,8 +67,6 @@ class FTFaceTest : public CppUnit::TestCase
void testSetCharMap()
{
- testFace->Open( GOOD_FONT_FILE);
-
CPPUNIT_ASSERT( testFace->CharMap( ft_encoding_unicode));
CPPUNIT_ASSERT( testFace->Error() == 0);
@@ -87,8 +77,6 @@ class FTFaceTest : public CppUnit::TestCase
void testCharacterIndex()
{
- testFace->Open( GOOD_FONT_FILE);
-
CPPUNIT_ASSERT( testFace->CharIndex( 'A') == 34);
CPPUNIT_ASSERT( testFace->CharIndex( 0x6FB3) == 4838);
}
@@ -96,8 +84,6 @@ class FTFaceTest : public CppUnit::TestCase
void testKerning()
{
- testFace->Open( GOOD_FONT_FILE);
-
FTPoint kerningVector = testFace->KernAdvance( 'A', 'W');
CPPUNIT_ASSERT( kerningVector.x == 0);
CPPUNIT_ASSERT( kerningVector.y == 0);
@@ -112,7 +98,7 @@ class FTFaceTest : public CppUnit::TestCase
void setUp()
{
- testFace = new FTFace;
+ testFace = new FTFace( GOOD_FONT_FILE);
}