Better error handling
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
diff --git a/src/FTFace.cpp b/src/FTFace.cpp
index b6ae66b..18162fb 100755
--- a/src/FTFace.cpp
+++ b/src/FTFace.cpp
@@ -83,11 +83,9 @@ void FTFace::Close()
FTSize& FTFace::Size( const unsigned int size, const unsigned int res)
{
- if( !charSize.CharSize( ftFace, size, res, res))
- {
- err = charSize.Error();
- }
-
+ charSize.CharSize( ftFace, size, res, res);
+ err = charSize.Error();
+
return charSize;
}
diff --git a/src/FTSize.cpp b/src/FTSize.cpp
index a9ad747..15f7d0b 100755
--- a/src/FTSize.cpp
+++ b/src/FTSize.cpp
@@ -3,6 +3,7 @@
FTSize::FTSize()
: ftFace(0),
+ ftSize(0),
size(0),
err(0)
{}
@@ -14,11 +15,20 @@ FTSize::~FTSize()
bool FTSize::CharSize( FT_Face* face, unsigned int point_size, unsigned int x_resolution, unsigned int y_resolution )
{
- ftFace = face;
- size = point_size;
err = FT_Set_Char_Size( *ftFace, 0L, point_size * 64, x_resolution, y_resolution);
-
- ftSize = (*ftFace)->size;
+
+ if( !err)
+ {
+ ftFace = face;
+ size = point_size;
+ ftSize = (*ftFace)->size;
+ }
+ else
+ {
+ ftFace = 0;
+ size = 0;
+ ftSize = 0;
+ }
return !err;
}
@@ -32,18 +42,23 @@ unsigned int FTSize::CharSize() const
int FTSize::Ascender() const
{
- return ftSize->metrics.ascender >> 6;
+ return ftSize == 0 ? 0 : ftSize->metrics.ascender >> 6;
}
int FTSize::Descender() const
{
- return ftSize->metrics.descender >> 6;
+ return ftSize == 0 ? 0 : ftSize->metrics.descender >> 6;
}
int FTSize::Height() const
{
+ if( ftSize == 0)
+ {
+ return 0;
+ }
+
if( FT_IS_SCALABLE((*ftFace)))
{
float height = ( (*ftFace)->bbox.yMax - (*ftFace)->bbox.yMin)
@@ -60,6 +75,11 @@ int FTSize::Height() const
int FTSize::Width() const
{
+ if( ftSize == 0)
+ {
+ return 0;
+ }
+
if( FT_IS_SCALABLE((*ftFace)))
{
float width = ( (*ftFace)->bbox.xMax - (*ftFace)->bbox.xMin)