Fixed BBox null string bug. Better error handling. Got rid of pre cache flag.
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
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)