|
|
@@ -28,23 +28,28 @@ Font::Font(String fileName) {
|
|
|
FT_Library FTLibrary;
|
|
|
FT_Init_FreeType(&FTLibrary);
|
|
|
|
|
|
+ loaded = false;
|
|
|
+ buffer = NULL;
|
|
|
OSFILE *file = OSBasics::open(fileName, "rb");
|
|
|
- OSBasics::seek(file, 0, SEEK_END);
|
|
|
- long progsize = OSBasics::tell(file);
|
|
|
- OSBasics::seek(file, 0, SEEK_SET);
|
|
|
- buffer = (unsigned char*)malloc(progsize);
|
|
|
- memset(buffer, 0, progsize);
|
|
|
- OSBasics::read(buffer, progsize, 1, file);
|
|
|
+ if(file) {
|
|
|
+ OSBasics::seek(file, 0, SEEK_END);
|
|
|
+ long progsize = OSBasics::tell(file);
|
|
|
+ OSBasics::seek(file, 0, SEEK_SET);
|
|
|
+ buffer = (unsigned char*)malloc(progsize);
|
|
|
+ memset(buffer, 0, progsize);
|
|
|
+ OSBasics::read(buffer, progsize, 1, file);
|
|
|
|
|
|
- valid = true;
|
|
|
- if(FT_New_Memory_Face(FTLibrary, buffer, progsize, 0, &ftFace) != 0) {
|
|
|
- Logger::log("Error loading font %s\n", fileName.c_str());
|
|
|
- valid = false;
|
|
|
- }
|
|
|
+ valid = true;
|
|
|
+ if(FT_New_Memory_Face(FTLibrary, buffer, progsize, 0, &ftFace) != 0) {
|
|
|
+ Logger::log("Error loading font %s\n", fileName.c_str());
|
|
|
+ valid = false;
|
|
|
+ }
|
|
|
|
|
|
- FT_Select_Charmap(ftFace, FT_ENCODING_UNICODE);
|
|
|
- //FT_New_Face(FTLibrary, fileName.c_str(), 0, &ftFace);
|
|
|
-// free(buffer);
|
|
|
+ FT_Select_Charmap(ftFace, FT_ENCODING_UNICODE);
|
|
|
+ loaded = true;
|
|
|
+ } else {
|
|
|
+ Logger::log("Invalid font file specified (%s)\n", fileName.c_str());
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
bool Font::isValid() {
|
|
|
@@ -52,7 +57,9 @@ bool Font::isValid() {
|
|
|
}
|
|
|
|
|
|
Font::~Font() {
|
|
|
- free(buffer);
|
|
|
+ if(buffer) {
|
|
|
+ free(buffer);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
FT_Face Font::getFace() {
|