| 61 | } |
| 62 | |
| 63 | Font* LoadFont(const char* path, const char* id, int sz){ |
| 64 | Font* font = new Font; |
| 65 | |
| 66 | if(int err = FT_New_Face(library, path, 0, &font->face)){ |
| 67 | // Freetype Error loading custom font from memory |
| 68 | throw FontException(FontException::FontLoadError, err); |
| 69 | return nullptr; |
| 70 | } |
| 71 | |
| 72 | if(int err = FT_Set_Pixel_Sizes(font->face, 0, sz)){ |
| 73 | // Freetype Error Setting Font Size |
| 74 | throw FontException(FontException::FontSizeError, err); |
| 75 | return nullptr; |
| 76 | } |
| 77 | |
| 78 | if(!id){ |
| 79 | char buf[32]; |
| 80 | sprintf(buf, "%s", path); |
| 81 | font->id = new char[strlen(buf) + 1]; |
| 82 | strcpy(font->id, buf); |
| 83 | } else { |
| 84 | font->id = new char[strlen(id) + 1]; |
| 85 | strcpy(font->id, id); |
| 86 | } |
| 87 | |
| 88 | font->height = sz; |
| 89 | font->lineHeight = sz + sz / 3; |
| 90 | font->monospace = FT_IS_FIXED_WIDTH(font->face); |
| 91 | font->width = 8; |
| 92 | font->tabWidth = 4; |
| 93 | |
| 94 | fonts[font->id] = font; |
| 95 | |
| 96 | fontState = 1; |
| 97 | |
| 98 | return font; |
| 99 | } |
| 100 | |
| 101 | Font* GetFont(const char* id){ |
| 102 | Font* font; |