Better error handling and remove platform/encoding function
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
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
{