Improved font error handling when file isn't found

This commit is contained in:
MattTuttle
2015-01-23 15:48:52 -06:00
parent 9c5352a110
commit 3827df6952
3 changed files with 32 additions and 14 deletions

View File

@@ -23,25 +23,19 @@ namespace lime {
class Image;
#ifdef LIME_FREETYPE
typedef struct {
unsigned long codepoint;
size_t size;
#ifdef LIME_FREETYPE
FT_UInt index;
FT_Pos height;
} GlyphInfo;
#else
typedef struct {
unsigned long codepoint;
size_t size;
int index;
int height;
#endif
} GlyphInfo;
#endif
class Font {
@@ -49,7 +43,7 @@ namespace lime {
public:
Font (const char *fontFace);
static Font *FromFile (const char *fontFace);
value Decompose (int em);
value GetFamilyName ();
@@ -59,14 +53,15 @@ namespace lime {
void SetSize (size_t size);
bool InsertCodepointFromIndex (unsigned long codepoint);
private:
#ifdef LIME_FREETYPE
Font (FT_Face face);
FT_Face face;
#else
void* face;
#endif
private:
bool InsertCodepoint (unsigned long codepoint, bool b = true);
std::list<GlyphInfo> glyphList;

View File

@@ -160,10 +160,18 @@ namespace lime {
value lime_font_load (value fontFace) {
#ifdef LIME_FREETYPE
Font *font = new Font (val_string (fontFace));
Font *font = Font::FromFile (val_string (fontFace));
if (font) {
value v = alloc_float ((intptr_t)font);
val_gc (v, lime_font_destroy);
return v;
} else {
return alloc_null ();
}
#else
return alloc_null ();
#endif

View File

@@ -259,7 +259,7 @@ namespace lime {
}
Font::Font (const char *fontFace) {
Font *Font::FromFile (const char *fontFace) {
int error;
FT_Library library;
@@ -270,8 +270,9 @@ namespace lime {
printf ("Could not initialize FreeType\n");
}
} else {
FT_Face face;
error = FT_New_Face (library, fontFace, 0, &face);
if (error == FT_Err_Unknown_File_Format) {
@@ -282,8 +283,22 @@ namespace lime {
printf ("Failed to load font face %s\n", fontFace);
} else {
return new Font(face);
}
}
return 0;
}
Font::Font (FT_Face face) {
this->face = face;
/* Set charmap
*
* See http://www.microsoft.com/typography/otspec/name.htm for a list of