Allow fonts to return null

This commit is contained in:
Joshua Granick
2015-03-23 18:55:29 -07:00
parent 0ab97dd98a
commit 48ec618204
3 changed files with 29 additions and 9 deletions

View File

@@ -66,7 +66,12 @@ class Font {
var font = new Font ();
font.__fromBytes (bytes);
#if (cpp || neko || nodejs)
return (font.src != null) ? font : null;
#else
return font;
#end
}
@@ -75,7 +80,12 @@ class Font {
var font = new Font ();
font.__fromFile (path);
#if (cpp || neko || nodejs)
return (font.src != null) ? font : null;
#else
return font;
#end
}

View File

@@ -282,9 +282,17 @@ namespace lime {
if (font) {
value v = alloc_float ((intptr_t)font);
val_gc (v, lime_font_destroy);
return v;
if (font->face) {
value v = alloc_float ((intptr_t)font);
val_gc (v, lime_font_destroy);
return v;
} else {
delete font;
}
}
#endif

View File

@@ -388,6 +388,7 @@ namespace lime {
ByteArray data = ByteArray (resource->path);
unsigned char *buffer = (unsigned char*)malloc (data.Size ());
memcpy (buffer, data.Bytes (), data.Size ());
lime::fclose (file);
error = FT_New_Memory_Face (library, buffer, data.Size (), faceIndex, &face);
}
@@ -396,6 +397,7 @@ namespace lime {
unsigned char *buffer = (unsigned char*)malloc (resource->data->Size ());
memcpy (buffer, resource->data->Bytes (), resource->data->Size ());
lime::fclose (file);
error = FT_New_Memory_Face (library, buffer, resource->data->Size (), faceIndex, &face);
}
@@ -406,13 +408,13 @@ namespace lime {
}
if (error == FT_Err_Unknown_File_Format) {
if (error) {
printf ("Invalid font type\n");
} else if (error) {
printf ("Failed to load font face %s\n", resource->path);
if (file) {
lime::fclose (file);
}
} else {