Commit 3f78baa9415089598a109667de79f2ef4055cb2d

henry 2002-12-01T07:50:59

Better error handling and remove platform/encoding function

diff --git a/include/FTCharmap.h b/include/FTCharmap.h
index 053271c..d75200a 100644
--- a/include/FTCharmap.h
+++ b/include/FTCharmap.h
@@ -60,23 +60,14 @@ class FTGL_EXPORT FTCharmap
          *      ft_encoding_adobe_custom
          *      ft_encoding_apple_roman
          *
-         * @param encoding      the Freetype encoding symbol. See above.
-         * @return              <code>true</code> if charmap was valid
-         *                      and set correctly
+         * @param encoding  the Freetype encoding symbol. See above.
+         * @return          <code>true</code> if charmap was valid and set
+         *                  correctly. If the requested encoding is
+         *                  unavailable it will be set to ft_encoding_none.
          */
         bool CharMap( FT_Encoding encoding);
 
         /**
-         * Sets the character map for the face.
-         *
-         * @param platform      
-         * @param encoding      the Freetype encoding symbol. See above.
-         * @return              <code>true</code> if charmap was valid
-         *                      and set correctly
-         */
-        bool CharMap( FT_UShort platform, FT_UShort encoding);
-
-        /**
          * Get the glyph index of the input character.
          *
          * @param index The character code of the requested glyph in the
@@ -101,7 +92,7 @@ class FTGL_EXPORT FTCharmap
         /**
          * The current Freetype face.
          */
-        FT_Face ftFace;
+        const FT_Face ftFace;
         
         /**
          * A structure that maps glyph indices to character codes
diff --git a/src/FTCharmap.cpp b/src/FTCharmap.cpp
index 6965033..04caddf 100644
--- a/src/FTCharmap.cpp
+++ b/src/FTCharmap.cpp
@@ -5,13 +5,12 @@ FTCharmap::FTCharmap( FT_Face face)
 :   ftFace( face),
     err(0)
 {
-    // Check that the default is valid
     if( !face->charmap)
     {
-        FT_Set_Charmap( ftFace, ftFace->charmaps[0]);
+        err = FT_Set_Charmap( ftFace, ftFace->charmaps[0]);
     }
     
-    ftEncoding = face->charmap->encoding;
+    ftEncoding = ftFace->charmap->encoding;
 }
 
 
@@ -33,61 +32,26 @@ bool FTCharmap::CharMap( FT_Encoding encoding)
     if( !err)
     {
         ftEncoding = encoding;
-        charMap.clear();
     }
-    
-    return !err;
-}
-
-
-bool FTCharmap::CharMap( FT_UShort platform, FT_UShort encoding)
-{
-    FT_CharMap  found = 0;
-    FT_CharMap  charmap;
- 
-    for( int n = 0; n < ftFace->num_charmaps; n++ )
-    {
-        charmap = ftFace->charmaps[n];
-
-        if( charmap->platform_id == platform && charmap->encoding_id == encoding)
-        {
-            found = charmap;
-            break;
-        }
-    }
- 
-    if( !found )
-    {
-        return false;
-    }
- 
-    if( ftEncoding == found->encoding)
-    {
-        return true;
-    }
-    
-    /* now, select the charmap for the face object */
-    err = FT_Set_Charmap( ftFace, found );
-    
-    if( !err)
+    else
     {
-        ftEncoding = found->encoding;
-        charMap.clear();
+        ftEncoding = ft_encoding_none;
     }
-    
+        
+    charMap.clear();
     return !err;
 }
 
 
-unsigned int FTCharmap::CharIndex( unsigned int index )
+unsigned int FTCharmap::CharIndex( unsigned int characterCode )
 {
-    const CharacterMap::GlyphIndex *result = charMap.find(index);
+    const CharacterMap::GlyphIndex *result = charMap.find( characterCode);
     
     if( !result)
     {
-        unsigned int glyph = FT_Get_Char_Index( ftFace, index);
-        charMap.insert( index, glyph);
-        return glyph;
+        unsigned int glyphIndex = FT_Get_Char_Index( ftFace, characterCode);
+        charMap.insert( characterCode, glyphIndex);
+        return glyphIndex;
     }
     else
     {