Commit 86933a4b487df1caa3c369b1fe690738a303902d

henry 2002-12-20T22:13:43

Removed Open functions. C_stors now open face

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);
     }