Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

freetype2

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

like image 333
patchwork Avatar asked Jul 01 '15 12:07

patchwork


2 Answers

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.

like image 134
N. Yoda Avatar answered Oct 22 '22 03:10

N. Yoda


In case anyone else stumbles upon this question, FT_Error_String was introduced in FreeType2 version 2.10.1 to retrieve the error string of an FT_Error code.

FT_Error error = ...
if (error != 0)
{
    puts(FT_Error_String(error), stderr);
}

Important: You must define FT_CONFIG_OPTION_ERROR_STRINGS when compiling FreeType otherwise the function will return NULL.

like image 40
hgs3 Avatar answered Oct 22 '22 04:10

hgs3