|
43 | 43 |
|
44 | 44 | FT_Library _ft2Library; |
45 | 45 |
|
| 46 | +// FreeType error codes; loaded as per fterror.h. |
| 47 | +static char const* ft_error_string(FT_Error error) { |
| 48 | +#undef __FTERRORS_H__ |
| 49 | +#define FT_ERROR_START_LIST switch (error) { |
| 50 | +#define FT_ERRORDEF( e, v, s ) case v: return s; |
| 51 | +#define FT_ERROR_END_LIST default: return NULL; } |
| 52 | +#include FT_ERRORS_H |
| 53 | +} |
| 54 | + |
46 | 55 | void throw_ft_error(std::string message, FT_Error error) { |
| 56 | + char const* s = ft_error_string(error); |
47 | 57 | std::ostringstream os(""); |
48 | | - os << message << " (error code 0x" << std::hex << error << ")"; |
| 58 | + if (s) { |
| 59 | + os << message << " (" << s << "; error code 0x" << std::hex << error << ")"; |
| 60 | + } else { // Should not occur, but don't add another error from failed lookup. |
| 61 | + os << message << " (error code 0x" << std::hex << error << ")"; |
| 62 | + } |
49 | 63 | throw std::runtime_error(os.str()); |
50 | 64 | } |
51 | 65 |
|
@@ -324,14 +338,7 @@ FT2Font::FT2Font(FT_Open_Args &open_args, long hinting_factor_) : image(), face( |
324 | 338 | clear(); |
325 | 339 |
|
326 | 340 | FT_Error error = FT_Open_Face(_ft2Library, &open_args, 0, &face); |
327 | | - |
328 | | - if (error == FT_Err_Unknown_File_Format) { |
329 | | - throw std::runtime_error("Can not load face. Unknown file format."); |
330 | | - } else if (error == FT_Err_Cannot_Open_Resource) { |
331 | | - throw std::runtime_error("Can not load face. Can not open resource."); |
332 | | - } else if (error == FT_Err_Invalid_File_Format) { |
333 | | - throw std::runtime_error("Can not load face. Invalid file format."); |
334 | | - } else if (error) { |
| 341 | + if (error) { |
335 | 342 | throw_ft_error("Can not load face", error); |
336 | 343 | } |
337 | 344 |
|
|
0 commit comments