freetype2

How can I get the corresponding error string from an FT_Error code?


Given an FT_Error, is there a macro/function to return the corresponding error message string?


Solution

  • The answer is No, as far as I know.

    You should create your own macro or function, using macros defined in fterrors.h. For example, the following code will work:

    #include <ft2build.h>
    #include FT_FREETYPE_H
    
    const char* getErrorMessage(FT_Error err)
    {
        #undef FTERRORS_H_
        #define FT_ERRORDEF( e, v, s )  case e: return s;
        #define FT_ERROR_START_LIST     switch (err) {
        #define FT_ERROR_END_LIST       }
        #include FT_ERRORS_H
        return "(Unknown error)";
    }
    

    Read fterrors.h (found in /usr/local/include/freetype2/ in my environment) for more detail and another example.