Commit 09dc868f3927ef388cfc728c0e3fb472ddcf26cb

henry 2002-12-02T06:27:02

Fixed BBox null string bug. Better error handling. Got rid of pre cache flag.

diff --git a/include/FTFont.h b/include/FTFont.h
index 5dba96b..917f0aa 100755
--- a/include/FTFont.h
+++ b/include/FTFont.h
@@ -42,28 +42,20 @@ class FTGL_EXPORT FTFont
          * Open and read a font file.
          *
          * @param fontname  font file name.
-         * @param preCache  A flag to indicate whether or not to build
-         *                  a complete set of glyphs at startup
-         *                  (<code>true</code>) or as required
-         *                  (<code>false</code>). Defaults to true.
          * @return          <code>true</code> if file has opened
          *                  successfully.
          */
-        bool Open( const char* fontname, bool preCache = true);
+        bool Open( const char* fontname);
         
         /**
          * Open and read a font from a buffer in memory.
          *
          * @param pBufferBytes  the in-memory buffer
          * @param bufferSizeInBytes  the length of the buffer in bytes
-         * @param preCache  A flag to indicate whether or not to build
-         *                  a complete set of glyphs at startup
-         *                  (<code>true</code>) or as prequired
-         *                  (<code>false</code>). Defaults to true.
          * @return          <code>true</code> if file has opened
          *                  successfully.
          */
-        bool Open( const unsigned char *pBufferBytes, size_t bufferSizeInBytes, bool preCache = true);
+        bool Open( const unsigned char *pBufferBytes, size_t bufferSizeInBytes);
 
         /**
          * Attach auxilliary file to font (e.g., font metrics).
@@ -74,6 +66,15 @@ class FTGL_EXPORT FTFont
         bool Attach( const char* filename);
 
         /**
+         * Set the character map for the face.
+         *
+         * @param encoding      Freetype enumerate for char map code.
+         * @return              <code>true</code> if charmap was valid and
+         *                      set correctly
+         */
+        bool CharMap( FT_Encoding encoding );
+        
+        /**
          * Set the char size for the current face.
          *
          * @param size      the face size in points (1/72 inch)
@@ -98,15 +99,6 @@ class FTGL_EXPORT FTFont
         virtual void Depth( float d){}
 
         /**
-         * Set the character map for the face.
-         *
-         * @param encoding      Freetype enumerate for char map code.
-         * @return              <code>true</code> if charmap was valid and
-         *                      set correctly
-         */
-        bool CharMap( FT_Encoding encoding );
-        
-        /**
          * Get the global ascender height for the face.
          *
          * @return  Ascender height
@@ -231,11 +223,6 @@ class FTGL_EXPORT FTFont
         unsigned int numGlyphs;
         
         /**
-         * Have glyphs been pre-cached
-         */
-        bool preCache;
-        
-        /**
          * Current pen or cursor position;
          */
         FTPoint pen;
diff --git a/src/FTFont.cpp b/src/FTFont.cpp
index 80da315..1b2059d 100755
--- a/src/FTFont.cpp
+++ b/src/FTFont.cpp
@@ -8,7 +8,6 @@ FTFont::FTFont()
 :   numFaces(0),
     glyphList(0),
     numGlyphs(0),
-    preCache(true),
     err(0)
 {
     pen.x = 0;
@@ -22,10 +21,8 @@ FTFont::~FTFont()
 }
 
 
-bool FTFont::Open( const char* fontname, bool p)
+bool FTFont::Open( const char* fontname)
 {
-    preCache = p;
-    
     if( face.Open( fontname))
     {
         FT_Face* ftFace = face.Face();      
@@ -41,10 +38,8 @@ bool FTFont::Open( const char* fontname, bool p)
 }
 
 
-bool FTFont::Open( const unsigned char *pBufferBytes, size_t bufferSizeInBytes, bool p )
+bool FTFont::Open( const unsigned char *pBufferBytes, size_t bufferSizeInBytes)
 {
-    preCache = p;
-    
     if( face.Open( pBufferBytes, bufferSizeInBytes ))
     {
         FT_Face* ftFace = face.Face();      
@@ -69,20 +64,20 @@ bool FTFont::Attach( const char* filename)
 bool FTFont::FaceSize( const unsigned int size, const unsigned int res )
 {
     charSize = face.Size( size, res);
-
-    if( glyphList)
-        delete glyphList;
-    
-    glyphList = new FTGlyphContainer( &face, numGlyphs, preCache);
     
-    if( MakeGlyphList())
+    if( face.Error())
     {
-        return true;
+        return false;
     }
-    else
+    
+    if( glyphList)
     {
-        return false;
+        delete glyphList;
     }
+    
+    glyphList = new FTGlyphContainer( &face, numGlyphs);
+    
+    return MakeGlyphList();
 }
 
 
@@ -94,19 +89,7 @@ unsigned int FTFont::FaceSize() const
 
 bool FTFont::MakeGlyphList()
 {
-    for( unsigned int c = 0; c < numGlyphs; ++c)
-    {
-        if( preCache)
-        {
-            glyphList->Add( MakeGlyph( c), c);
-        }
-        else
-        {
-            glyphList->Add( NULL, c);
-        }
-    }
-    
-    return !err; // FIXME what err?
+    return true;
 }
 
 
@@ -135,6 +118,12 @@ void FTFont::BBox( const char* string,
 {
     const unsigned char* c = (unsigned char*)string;
     llx = lly = llz = urx = ury = urz = 0.0f;
+    
+    if( !*string)
+    {
+        return;
+    }
+    
     FTBBox bbox;
  
     while( *c)
@@ -171,6 +160,12 @@ void FTFont::BBox( const wchar_t* string,
 {
     const wchar_t* c = string;
     llx = lly = llz = urx = ury = urz = 0.0f;
+    
+    if( !*string)
+    {
+        return;
+    }
+
     FTBBox bbox;
  
     while( *c)