[errors] Introduce `FT_Error_String'. * include/freetype/fterrors.h (FT_Error_String), src/base/fterrors.c (FT_Error_String): Implement `FT_Error_String'. * src/base/ftbase.c, src/base/Jamfile (_source), src/base/rules.mk (BASE_SRC): Add `fterrors.c' to the build logic. * src/base/ftdebug.c (FT_Throw): Use `FT_Error_String'.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
diff --git a/ChangeLog b/ChangeLog
index d8613e5..bcd6b47 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2018-08-30 Armin Hasitzka <prince.cherusker@gmail.com>
+
+ [errors] Introduce `FT_Error_String'.
+
+ * include/freetype/fterrors.h (FT_Error_String),
+ src/base/fterrors.c (FT_Error_String): Implement `FT_Error_String'.
+
+ * src/base/ftbase.c, src/base/Jamfile (_source),
+ src/base/rules.mk (BASE_SRC): Add `fterrors.c' to the build logic.
+
+ * src/base/ftdebug.c (FT_Throw): Use `FT_Error_String'.
+
2018-08-30 Werner Lemberg <wl@gnu.org>
[autofit] Trace `before' and `after' edges of strong points.
diff --git a/include/freetype/fterrors.h b/include/freetype/fterrors.h
index f319811..bed67cb 100644
--- a/include/freetype/fterrors.h
+++ b/include/freetype/fterrors.h
@@ -166,6 +166,8 @@
/* */
#ifndef FT_ERRORDEF
+#define FT_INCLUDE_ERR_PROTOS
+
#define FT_ERRORDEF( e, v, s ) e = v,
#define FT_ERROR_START_LIST enum {
#define FT_ERROR_END_LIST FT_ERR_CAT( FT_ERR_PREFIX, Max ) };
@@ -228,6 +230,42 @@
#undef FT_ERR_PREFIX
#endif
+#ifdef FT_INCLUDE_ERR_PROTOS
+
+
+ /**************************************************************************
+ *
+ * @function:
+ * FT_Error_String
+ *
+ * @description:
+ * Retrieve the description of a valid FreeType error code.
+ *
+ * @input:
+ * error_code ::
+ * A valid FreeType error code.
+ *
+ * @return:
+ * A C~string or `NULL`, if any error occurred.
+ *
+ * @note:
+ * FreeType has to be compiled with `FT_CONFIG_OPTION_ERROR_STRINGS` or
+ * `FT_DEBUG_LEVEL_ERROR` to get meaningful descriptions.
+ * 'error_string' will be `NULL` otherwise.
+ *
+ * Module identification will be ignored:
+ *
+ * ```c
+ * strcmp( FT_Error_String( FT_Err_Unknown_File_Format ),
+ * FT_Error_String( BDF_Err_Unknown_File_Format ) ) == 0;
+ * ```
+ */
+ FT_EXPORT( const char* )
+ FT_Error_String( FT_Error error_code );
+
+
+#endif /* FT_INCLUDE_ERR_PROTOS */
+
#endif /* !(FTERRORS_H_ && __FTERRORS_H__) */
diff --git a/src/base/Jamfile b/src/base/Jamfile
index a1c5fe2..fab7ef4 100644
--- a/src/base/Jamfile
+++ b/src/base/Jamfile
@@ -22,6 +22,7 @@ SubDir FT2_TOP $(FT2_SRC_DIR) base ;
ftcalc
ftcolor
ftdbgmem
+ fterrors
ftfntfmt
ftgloadr
fthash
diff --git a/src/base/ftbase.c b/src/base/ftbase.c
index 5f7d818..5fe4c1d 100644
--- a/src/base/ftbase.c
+++ b/src/base/ftbase.c
@@ -23,6 +23,7 @@
#include "ftcalc.c"
#include "ftcolor.c"
#include "ftdbgmem.c"
+#include "fterrors.c"
#include "ftfntfmt.c"
#include "ftgloadr.c"
#include "fthash.c"
diff --git a/src/base/ftdebug.c b/src/base/ftdebug.c
index 19b0058..d5045da 100644
--- a/src/base/ftdebug.c
+++ b/src/base/ftdebug.c
@@ -87,9 +87,12 @@
int line,
const char* file )
{
- FT_UNUSED( error );
- FT_UNUSED( line );
- FT_UNUSED( file );
+ fprintf( stderr,
+ "%s:%d: error 0x%02x: %s\n",
+ file,
+ line,
+ error,
+ FT_Error_String( error ) );
return 0;
}
diff --git a/src/base/fterrors.c b/src/base/fterrors.c
new file mode 100644
index 0000000..956d6af
--- /dev/null
+++ b/src/base/fterrors.c
@@ -0,0 +1,45 @@
+/****************************************************************************
+ *
+ * fterrors.c
+ *
+ * FreeType API for error code handling.
+ *
+ * Copyright 2018 by
+ * Armin Hasitzka, David Turner, Robert Wilhelm, and Werner Lemberg.
+ *
+ * This file is part of the FreeType project, and may only be used,
+ * modified, and distributed under the terms of the FreeType project
+ * license, LICENSE.TXT. By continuing to use, modify, or distribute
+ * this file you indicate that you have read the license and
+ * understand and accept it fully.
+ *
+ */
+
+
+#include <ft2build.h>
+#include FT_ERRORS_H
+
+
+ /* documentation is in fterrors.h */
+
+ FT_EXPORT_DEF( const char* )
+ FT_Error_String( FT_Error error_code )
+ {
+ if ( error_code < 0 ||
+ error_code >= FT_ERR_CAT( FT_ERR_PREFIX, Max ) )
+ return NULL;
+
+#if defined( FT_CONFIG_OPTION_ERROR_STRINGS ) || \
+ defined( FT_DEBUG_LEVEL_ERROR )
+
+#undef FTERRORS_H_
+#define FT_ERROR_START_LIST switch ( FT_ERROR_BASE( error_code ) ) {
+#define FT_ERRORDEF( e, v, s ) case v: return s;
+#define FT_ERROR_END_LIST }
+
+#include FT_ERRORS_H
+
+#endif /* defined( FT_CONFIG_OPTION_ERROR_STRINGS ) || ... */
+
+ return NULL;
+ }
diff --git a/src/base/rules.mk b/src/base/rules.mk
index 214fd77..887e4e7 100644
--- a/src/base/rules.mk
+++ b/src/base/rules.mk
@@ -40,6 +40,7 @@ BASE_SRC := $(BASE_DIR)/ftadvanc.c \
$(BASE_DIR)/ftcalc.c \
$(BASE_DIR)/ftcolor.c \
$(BASE_DIR)/ftdbgmem.c \
+ $(BASE_DIR)/fterrors.c \
$(BASE_DIR)/ftfntfmt.c \
$(BASE_DIR)/ftgloadr.c \
$(BASE_DIR)/fthash.c \