summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPriyeshkkumar <priyeshkkumar@gmail.com>2020-07-04 13:09:33 +0530
committerPriyeshkkumar <priyeshkkumar@gmail.com>2020-07-04 13:09:33 +0530
commitbfe6d5218ae1ae54bc062139f8f586b7cce1450f (patch)
tree4cb125673f6ae1d32eb9a47c6fb84f8aedbf275c
parentb378812f2209b22354aea3b7de074c8a59b45945 (diff)
downloadfreetype2-bfe6d5218ae1ae54bc062139f8f586b7cce1450f.tar.gz
Added support of callback functions to handle logs outside FreeType
-rw-r--r--[priyesh]ChangeLog13
-rw-r--r--include/freetype/ftlogging.h16
-rw-r--r--include/freetype/internal/ftdebug.h24
-rw-r--r--src/base/ftdebug.c45
4 files changed, 58 insertions, 40 deletions
diff --git a/[priyesh]ChangeLog b/[priyesh]ChangeLog
index d826b4e5e..e309b04f0 100644
--- a/[priyesh]ChangeLog
+++ b/[priyesh]ChangeLog
@@ -1,3 +1,16 @@
+2020-07-04 Priyesh Kumar <priyeshkkumar@gmail.com>
+
+ * include/freetype/ftlogging.h: Added two functions `FT_Set_Log_Handler()`
+ and `FT_Set_Default_Log_Handler()` to enable the callback functionality.
+
+ * include/freetype/internal/ftdebug.h: Some Code Cleanup
+
+ * src/base/ftdebug.c:
+ 1. Added definitions for functions:
+ `FT_Set_Default_Log_Handler()` and `FT_Set_Log_Handler()`.
+ 2. Added support for callback function.
+
+
2020-07-03 Priyesh Kumar <priyeshkkumar@gmail.com>
* Code Cleanup and Added more comments
diff --git a/include/freetype/ftlogging.h b/include/freetype/ftlogging.h
index ee96db2e1..195d768ec 100644
--- a/include/freetype/ftlogging.h
+++ b/include/freetype/ftlogging.h
@@ -22,20 +22,24 @@ FT_BEGIN_HEADER
/* An external callback function to be used to define an output handler */
typedef void
- (*ft_custom_output_handler)( const char* string );
+ (*ft_custom_log_handler)( const char* fmt, va_list args );
/**************************************************************************
*
- * comments on callback
+ * If FT_LOGGING is enabled user can provide their own function to handle
+ * the log messages using the function `FT_Set_Log_Handler()` by passing
+ * the function name which they want to use.
+ * User could also revert back to use FreeType's inbuilt function to
+ * handle logs using function `FT_Set_Default_Log_Handler()`
+ * Defined in src/base/ftdebug.c
*
*/
- /*
FT_EXPORT( void )
- FT_Trace_Set_Output( ft_ouput_handler handler );
+ FT_Set_Log_Handler( ft_custom_log_handler handler );
FT_EXPORT( void )
- FT_Trace_Set_Default_Output();
- */
+ FT_Set_Default_Log_Handler();
+
FT_END_HEADER
diff --git a/include/freetype/internal/ftdebug.h b/include/freetype/internal/ftdebug.h
index 16b50cfdb..c5a1a5159 100644
--- a/include/freetype/internal/ftdebug.h
+++ b/include/freetype/internal/ftdebug.h
@@ -109,18 +109,6 @@ FT_BEGIN_HEADER
*
*/
-#ifdef FT_LOGGING
-
-#undef FT_Log
-#define FT_Log dlg_trace
-
-#else
-
-#undef FT_Log
-#define FT_Log FT_Message
-
-#endif /* FT_LOGGING */
-
#ifdef FT_DEBUG_LEVEL_TRACE
/* we need two macros here to make cpp expand `FT_COMPONENT' */
@@ -131,7 +119,7 @@ FT_BEGIN_HEADER
do \
{ \
if ( ft_trace_levels[FT_TRACE_COMP( FT_COMPONENT )] >= level ) \
- FT_Log varformat; \
+ FT_Message varformat; \
} while ( 0 )
#else /* !FT_DEBUG_LEVEL_TRACE */
@@ -341,7 +329,7 @@ FT_BEGIN_HEADER
*/
FT_BASE( void )
- ft_output_handler( const struct dlg_origin* origin, const char* string,
+ ft_log_handler( const struct dlg_origin* origin, const char* string,
void* data );
@@ -360,14 +348,14 @@ FT_BEGIN_HEADER
* 4. ft_default_output_handler: stores the function pointer which is used
* internally by FreeType to print logs to file.
*
- * 5. fileptr: store the FILE*
+ * 5. ft_fileptr: store the FILE*
*
*/
static const char* ft_default_trace_level = NULL;
static const char* ft_custom_trace_level = NULL;
- static ft_custom_output_handler custom_output_handler = NULL;
- static dlg_handler ft_default_output_handler = NULL;
- static FILE* fileptr = NULL;
+ static ft_custom_log_handler custom_output_handler = NULL;
+ static dlg_handler ft_default_log_handler = NULL;
+ static FILE* ft_fileptr = NULL;
/**************************************************************************
*
diff --git a/src/base/ftdebug.c b/src/base/ftdebug.c
index 9d629c12c..7b6de1531 100644
--- a/src/base/ftdebug.c
+++ b/src/base/ftdebug.c
@@ -53,12 +53,25 @@
FT_Message( const char* fmt,
... )
{
+#ifdef FT_LOGGING
+
+ if( custom_output_handler != NULL )
+ {
+ va_list ap;
+ va_start( ap, fmt );
+ custom_output_handler( fmt, ap );
+ va_end( ap );
+ }
+ else
+ dlg_trace( fmt );
+#else
va_list ap;
va_start( ap, fmt );
vfprintf( stderr, fmt, ap );
va_end( ap );
+#endif /* FT_LOGGING */
}
@@ -340,20 +353,20 @@ else
FT_BASE_DEF( void )
ft_logging_init( void )
{
- ft_default_output_handler = &ft_output_handler;
+ ft_default_log_handler = ft_log_handler;
ft_default_trace_level = ft_getenv( "FT2_DEBUG" );
- fileptr = fopen( "freetype2.log", "w" );
+ ft_fileptr = fopen( "freetype2.log", "w" );
ft_debug_init();
/* We need to set the default FreeType specific dlg's output handler */
- dlg_set_handler( ft_default_output_handler, NULL );
+ dlg_set_handler( ft_default_log_handler, NULL );
}
FT_BASE_DEF( void )
ft_logging_deinit( void )
{
- fclose( fileptr );
+ fclose( ft_fileptr );
}
/*************************************************************************
@@ -363,9 +376,9 @@ else
*
*/
FT_BASE_DEF( void )
- ft_output_handler( const struct dlg_origin* origin,
+ ft_log_handler( const struct dlg_origin* origin,
const char* string, void* data )
- {
+ {
unsigned int features;
if( origin->tags[0] == "error_log" )
{
@@ -376,9 +389,9 @@ else
features = dlg_output_threadsafe /*| dlg_output_tags*/ ;
}
- dlg_generic_output_stream( fileptr, features, origin, string,
+ dlg_generic_output_stream( ft_fileptr, features, origin, string,
dlg_default_output_styles );
- }
+ }
/**************************************************************************
*
@@ -408,22 +421,22 @@ else
/****************************************************************************
*
- * comments on callback
+ * Functions to handle custom log handler:
*
*/
- /*
+
FT_EXPORT_DEF( void )
- FT_Trace_Set_Output( ft_ouput_handler handler )
+ FT_Set_Log_Handler( ft_custom_log_handler handler )
{
- ft_custom_output_handler = handler;
+ custom_output_handler = handler;
}
-
+
FT_EXPORT_DEF( void )
- FT_Trace_Set_Default_Output()
+ FT_Set_Default_Log_Handler()
{
- ft_custom_output_handler = NULL;
+ custom_output_handler = NULL;
}
- */
+
#endif /* FT_LOGGING */
/* END */